用MATLAB的fsolve做运动分析时,初始值不同,解出来的答案也不同,怎么选择呢?

来源:百度知道 编辑:UC知道 时间:2024/06/08 17:02:32
用MATLAB做机构运动分析时,我用fsolve解非线性矩阵方程,给定的初始值不同解出的运动结果也不同,里面肯定有很多错误的,应该怎么选择初始值或者怎么选择解呢?

多解问题,不奇怪。例如,直线与圆的交点。

function hah
x0=[-1 -1];
%x0=[1 1];
x=fsolve(@myfun,x0)
ezplot('x^2+y^2-1'),hold
ezplot('x-y')
axis equal
function f=myfun(X)
x=X(1);y=X(2);
f(1)=x-y;
f(2)=x^2+y^2-1;

结果:

Optimization terminated: first-order optimality is less than options.TolFun.

x =

-0.7071 -0.7071

function hah
%x0=[-1 -1];
x0=[1 1];
x=fsolve(@myfun,x0)
function f=myfun(X)
x=X(1);y=X(2);
f(1)=x-y;
f(2)=x^2+y^2-1;

结果:
Optimization terminated: first-order optimality is less than options.TolFun.

x =

0.7071 0.7071

都是答案。