How to plot a graph of convergence for Newtons method of three variables?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have used Newtons method to find three unknown variables from three equations, but now I need to plot the graph to show the convergence and I'm not really sure how to do so. My code for Newtons method is below:
function g = uppgift12(L3, m1, m2)
u=[pi/4 0 -pi/4]';
iter=0;, dunorm=1;
while dunorm>0.5e-4 & iter<10
f=[cos(u(1))+cos(u(2))+L3*cos(u(3))-2
sin(u(1))+sin(u(2))+L3*sin(u(3))
m2*tan(u(1))-(m1+m2)*tan(u(2))+m1*tan(u(3))];
J=[-sin(u(1)) -sin(u(2)) -L3*sin(u(3))
cos(u(1)) cos(u(2)) L3*cos(u(3))
m2*sec(u(1))^2 -m1*sec(u(2))^2-m2*sec(u(2))^2 m1*sec(u(3))^2];
du=-J\f;
u=u+du;
dunorm=norm(du,inf);, iter=iter+1;
end
u, iter;
The variables are u(1), u(2), u(3). The variables L3, m1, m2 are given in four different parameters, (1,1,1), (1,1,2), (2,1,1) and (1,10,1) and I have to show the plots of convergence for all three variables of u for all four parameters. I really appreciate any response, thanks for your help.
0 个评论
回答(1 个)
Zoltán Csáti
2014-12-31
This is a classic parameter sweep. Alter one parameter while the others are fixed. Then solve the nonlinear equations. When you want to plot the convergence, you can do it as follows. On the horizontal axis, plot the iteration number. On the vertical axis, display the function value difference (in some norm) between the current and the former iteration.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!