fsolve is not returning the right solutions

조회 수: 1 (최근 30일)
Eliyah Hawila
Eliyah Hawila 2020년 12월 31일
편집: Matt J 2020년 12월 31일
My code is below. The correct solutions must be (1,0,1) and (-1,0,1) but I keep getting weird answers regardless of my initial guess
function solveeqs()
x0 = [1 1 1];
x = fsolve(@eqns,x0);
x;
eqns(x0)
end
function F = eqns(z)
x1 = z(1);
x2 = z(2);
x3 = z(3);
F(1) = x1 - x1*x2 - x2.^3 + x3*x1.^2 + x3*x2.^2 - x3 - x3*x1 + x3*x1*x2 + x3*x2.^3;
F(2) = x1 - x3*x1 + x3*x2 + 2*x3*x1*x2;
F(3) = 1 + 2*x2.^2 + x3.^2;
end

답변 (2개)

Alex Sha
Alex Sha 2020년 12월 31일
Hi, if you think the solutions should be (1,0,1) or (-1,0,1) , then one equation:
F(3) = 1 + 2*x2.^2 + x3.^2;
should be:
F(3) = 1 + 2*x2.^2 - x3.^2;

Matt J
Matt J 2020년 12월 31일
편집: Matt J 2020년 12월 31일
The solutions you've cited definitely do not solve the equations you've provided,
F=eqns([-1,0,1])
F = 1×3
0 0 2
F=eqns([1,0,1])
F = 1×3
0 0 2
function F = eqns(z)
x1 = z(1);
x2 = z(2);
x3 = z(3);
F(1) = x1 - x1*x2 - x2.^3 + x3*x1.^2 + x3*x2.^2 - x3 - x3*x1 + x3*x1*x2 + x3*x2.^3;
F(2) = x1 - x3*x1 + x3*x2 + 2*x3*x1*x2;
F(3) = 1 + 2*x2.^2 + x3.^2;
end

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by