我用fsolve算非线性方程组出错,求大神指教。
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
nogak
el 17 de Nov. de 2022
Respondida: tilojej
el 17 de Nov. de 2022
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.
如题,不知错误在哪里。。谢谢!
0 comentarios
Respuesta aceptada
tilojej
el 17 de Nov. de 2022
方程中有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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!