我用fsolve算非线性方程组出错,求大神指教。

5 ビュー (過去 30 日間)
nogak
nogak 2022 年 11 月 17 日
回答済み: tilojej 2022 年 11 月 17 日
function F=answer(x)
Ya=-300;Yb=300;Yc=-500;Zc=-450;Yd=500;Zd=-450;Theta=8;
F=[(x(1)-Ya)^2+x(2)^2-((Yc-Ya)^2+Zc^2);(x(3)-Yb)^2+x(4)^2-((Yd-Yb)^2+Zd^2);(x(1)-x(3))^2+(x(2)-x(4))^2-((Yc-Yd)^2+(Zc-Zd)^2);(x(2)-x(4))/(x(1)-x(3))-(tan(180*Theta/pi))];
end
x0=[1;2;3]
options=optimset('Display','iter');
[x,fval]=fsolve(@answer,x0,options)
Attempted to access x(4); index out of bounds because numel(x)=3.
Error in answer (line 3)
F=[(x(1)-Ya)^2+x(2)^2-((Yc-Ya)^2+Zc^2);(x(3)-Yb)^2+x(4)^2-((Yd-Yb)^2+Zd^2);(x(1)-x(3))^2+(x(2)-x(4))^2-((Yc-Yd)^2+(Zc-Zd)^2);(x(2)-x(4))/(x(1)-x(3))-(tan(180*Theta/pi))];
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
如题,不知错误在哪里。。谢谢!

採用された回答

tilojej
tilojej 2022 年 11 月 17 日
方程中有4个未知数,那你初值对应应该给4个:
function main
x0=[1;2;3;41111]
options=optimset('Display','iter');
[x,fval]=fsolve(@answer,x0,options)
end
function F=answer(x)
Ya=-300;Yb=300;Yc=-500;Zc=-450;Yd=500;Zd=-450;Theta=8;
F=[(x(1)-Ya)^2+x(2)^2-((Yc-Ya)^2+Zc^2);(x(3)-Yb)^2+x(4)^2-((Yd-Yb)^2+Zd^2);(x(1)-x(3))^2+(x(2)-x(4))^2-((Yc-Yd)^2+(Zc-Zd)^2);(x(2)-x(4))/(x(1)-x(3))-(tan(180*Theta/pi))];
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!