Fslove don't find the right solution

2 views (last 30 days)
Jessie Bessel
Jessie Bessel on 12 Mar 2018
Answered: Alex Sha on 11 Dec 2019
I try to solve a non linear system, but Fsolve can't solve it.
F=@(q)[sqrt((q(1)-5)^2 + q(2)^2 + q(3)^2 )-sqrt( q(1)^2 + (q(2)+10)^2 + q(3)^2)-Rez1;
sqrt(q(1)^2 + (q(2)+10)^2 + q(3)^2 )-sqrt( q(1)^2 + (q(2)-10)^2 + q(3)^2)-Rez2;
sqrt( q(1)^2 + (q(2)-10)^2 + q(3)^2 )-sqrt( q(1)^2 + q(2)^2 + q(3)^2)-Rez3];
q0=[50,0,0];
options = optimset('Display','iter','maxfunevals',500,'tolfun',1e-1,'tolx',1e-1,'tolcon',1e-2);
fsolve(F,q0,options)
Rez1,2,3 are some variable that I calculate before that. And the response of matlab is
I try to modify the values of tolfun and tolx, but no succes. Any help?

Answers (2)

Star Strider
Star Strider on 12 Mar 2018
We don’t have your ‘Rez’ constants, so we can’t run your code.
However, using 0 as any initial parameter estimate results in a much more difficult optimisation.
Try this instead:
q0=[50,-1,1];
  2 Comments
Jessie Bessel
Jessie Bessel on 12 Mar 2018
v=340;
Tsos1=1.35
Tsos2=1.47
Tsos3=1.47
Tsos4=1.44
Rez1=v*(Tsos1-Tsos2)/10
Rez2=v*(Tsos2-Tsos3)/10
Rez3=v*(Tsos3-Tsos4)/10
F=@(q)[sqrt((q(1)-5)^2 + q(2)^2 + q(3)^2 )-sqrt( q(1)^2 + (q(2)+10)^2 + q(3)^2)-Rez1;
sqrt(q(1)^2 + (q(2)+10)^2 + q(3)^2 )-sqrt( q(1)^2 + (q(2)-10)^2 + q(3)^2)-Rez2;
sqrt( q(1)^2 + (q(2)-10)^2 + q(3)^2 )-sqrt( q(1)^2 + q(2)^2 + q(3)^2)-Rez3];
q0=[50,0,0];
options = optimset('Display','iter','maxfunevals',500,'tolfun',1e-1,'tolx',1e-1,'tolcon',1e-2);
fsolve(F,q0,options)
Star Strider
Star Strider on 12 Mar 2018
With this initial estimate:
q0 = randi(99, 3, 1);
and assigning an output for the fsolve result:
Qv = fsolve(F,q0,options)
I get solutions that appear to converge to the same value to ‘q(1)’ and ‘q(3)’, with ‘q(2)’ less well defined:
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the selected value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
Qv =
31.0008e+000
103.9495e-003
37.4620e+000
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the selected value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
Qv =
30.5924e+000
208.7728e-003
36.5371e+000
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the selected value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
Qv =
31.3360e+000
19.2740e-003
37.2166e+000

Sign in to comment.


Alex Sha
Alex Sha on 11 Dec 2019
I get the results:
1:
q1: 31.25152
q2: -3.3648581278838E-15
q3: -37.1015437789933
2:
q1: 31.2515200000001
q2: 1.37892196278414E-15
q3: 37.1015437789935

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!