How to get my code for Newtons method for non-linear equationsystems working?

1 回表示 (過去 30 日間)
Marcus
Marcus 2014 年 12 月 26 日
コメント済み: Marcus 2014 年 12 月 26 日
I'm trying to make my code for Newtons method for non-linear equationsystems working. I have three equations and three variables, u(1), u(2), u(3):
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))
We have also been given several different values of L3, m1 and m2 to work with and the code should be able to find the solution for these different values. My code looks like this:
function g = uppgift12(L3, m1, m2)
u=[pi/4 pi/4 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
My startguesses is pi/4 for all three variables (that can change if necessary of course). I can't get the code to work however. I'm really bad at coding and I don't know what to do so I would be really grateful for any help I can get.
  2 件のコメント
Mohammad Abouali
Mohammad Abouali 2014 年 12 月 26 日
Give a sample value for m1,m2,L3
Marcus
Marcus 2014 年 12 月 26 日
1,1,1

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by