I have more non-linear equations than unknowns. How can I solve it in matlab? One method I know is non-linear least squares, how can I implement it in Matlab or you just suggest me anything you deem more proper.
18 views (last 30 days)
Show older comments
x1=475060;y1=1096300;z1=4670;x2=481500;y2=1094900;z2=4694;x3=482230;y3=1088430;z3=4831;x4=478050;y4=1087810;z4=4775;
% ((x-x1)^2)+((y-y1)^2)+((z-z1)^2)=5942.607^2 % ((x-x2)^2)+((y-y2)^2)+((z-z2)^2)=2426.635^2 % ((x-x3)^2)+((y-y3)^2)+((z-z3)^2)=5094.254^2 % ((x-x4)^2)+((y-y4)^2)+((z-z4)^2)=5549.874^2
%4 equations
%x y z unknowns
2 Comments
Matt J
on 2 Dec 2013
Is this question still relevant? It seems to be a duplicate of your earlier question
and you Accepted answers given there.
Accepted Answer
Matt J
on 3 Dec 2013
Edited: Matt J
on 3 Dec 2013
Aside from FSOLVE, you can try LSQNONLIN which is another least squares solver. However, I obtain nearly the same results (x,y,z) for your problem with both FSOLVE and LSQNONLIN.
F=@(x,y,z)[((x-x1)^2)+((y-y1)^2)+((z-z1)^2)-5942.607^2
((x-x2)^2)+((y-y2)^2)+((z-z2)^2)-2426.635^2;
((x-x3)^2)+((y-y3)^2)+((z-z3)^2)-5094.254^2;
((x-x4)^2)+((y-y4)^2)+((z-z4)^2)-5549.874^2
]
fun=@(u) F(u(1),u(2),u(3));
x0=mean([x1 y1 z1;x2 y2 z2; x3 y3 z3; x4 y4 z4])
[u1,fval1]=fsolve(fun,x0),
[u2,~,fval2]=lsqnonlin(fun,x0)
>> norm(u1-u2)
ans =
9.7868e-04
4 Comments
Matt J
on 3 Dec 2013
Edited: Matt J
on 3 Dec 2013
@Sermet,
FSOLVE is telling you that an exact solution could not be found. However, because you had more equations than unknowns, it did default to a least squares algorithm. So, there was no real point to using lsqnonlin, except in my example to prove to you that they produce nearly the same thing.
As the three of us have discussed before, an exact solution is generally not available. However, for the particular data you've given, the least squares solution's residuals fairly small, compared to the radii of the spheres, in all 4 equations,
>> [xyz,residuals]=fsolve(fun,x0)
xyz =
1.0e+06 *
0.4800 1.0930 0.0045
residuals =
6.5293
-10.6212
12.1881
-10.1086
So, you could say that all 4 spheres "almost" intersect in this specific case.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!