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.
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
Matt J
2013-12-2
Is this question still relevant? It seems to be a duplicate of your earlier question
and you Accepted answers given there.
采纳的回答
Matt J
2013-12-3
编辑:Matt J
2013-12-3
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 个评论
Matt J
2013-12-3
编辑:Matt J
2013-12-3
@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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!