using fsolve for solving a set of nonlinear equations
6 views (last 30 days)
Show older comments
I have a set of 6 nonlinear equations (a1,a2,a3,b1,b2,b3 are unknowns). I know that one of the answers must be as following: a1=3, a2=1, a3=3, b1=0.2, b2=0.3, b3=0.4 . When I use "fsolve" it gives me the answer as: a1=3.037, a2=1.003, a3=3.037, b1=0.221, b2=0.451, b3=0.413 and you see that b2 has a significant deviation from its expected value(0.3) How can I adjust fsolve to solve more accurately? (e.g. decrease the error bound or ... I already read the fsolve documentation and I understood that the reason is that it finds a local and not global minimum for F, but still I could not do anything helpful)
global X Z
X(1)=0.160000;
X(2)=0.946667;
X(3)=2.970000;
Z(1)=2.970000;
Z(2)=0.986667;
Z(3)=0.380000;
options = optimoptions('fsolve','Algorithm','levenberg-marquardt','TolFun',1e-7, 'TolX',1e-7,'MaxIter',1000,'Display','iter')
x0=[1,1,1,1,1,1];
ans=fsolve(@equ_set,x0,options)
----------------------------------
function z=equ_set(x)
global X Z
z(1)=x(4)-x(5)*x(6)/x(1)-X(1);
z(2)=x(2)-x(6)^2/x(1)-X(2);
z(3)=x(3)-x(5)^2/x(1)-X(3);
% z(4)=x(1)-x(6)^2/x(2)-Y(1);
% z(5)=x(5)-x(4)*x(6)/x(2)-Y(2);
% z(6)=x(3)-x(4)^2/x(2)-Y(3);
z(7)=x(1)-x(5)^2/x(3)-Z(1);
z(8)=x(2)-x(4)^2/x(3)-Z(2);
z(9)=x(6)-x(4)*x(5)/x(3)-Z(3);
end
0 Comments
Answers (1)
Matt J
on 24 Sep 2014
Edited: Matt J
on 24 Sep 2014
I know that one of the answers must be as following: a1=3, a2=1, a3=3, b1=0.2, b2=0.3, b3=0.4
That doesn't appear to be the case. The result that fsolve is giving you solves the equations much more precisely than the solution that you hypothesize,
[x,F]=fsolve(@equ_set,x0,options)
x =
3.0369 1.0028 3.0369 0.2213 0.4507 0.4128
F =
1.0e-15 *
0.2498 -0.3331 -0.4441 0 0 0 -0.4441 -0.4441 -0.6106
Conversely, when we plug in your hypothesized solution, we get much larger errors in F
>> F=equ_set([3 1 3 .2 .3 .4])
F =
1.0e-06 *
0 -0.3333 0 0 0 0 0 -0.3333 0
3 Comments
Matt J
on 24 Sep 2014
Edited: Matt J
on 24 Sep 2014
What can I do with fsolve to givge me 6 answers that each of them is close to its exact value?
I think I already addressed that in my last comment, but I'll recap:
If xtrue=[3,1,3,0.2,0.3,0.4] is supposed to be an exact solution, then you must have errors, possibly precision errors, in the X(i), Y(i) data that you've provided. With the current X(i), Y(i) data, we already know that xtrue is not an exact answer because equ_set(xtrue) is not returning zeros. Therefore, you must improve the accuracy of X(i), Y(i) somehow.
Also, you must choose an initial x0 much closer to xtrue than your previous choice of x0=ones(1,6). Otherwise, fsolve will converge to alternative solutions.
Finally, if it happens that xtrue is one of infinite solutions that are continuously connected together, then you have no hope of controlling which of those solutions fsolve will reach and it is game over. You either accept alternative solutions, or you modify your equations so that the solution becomes unique.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!