MATLAB中牛顿的方程组方法

时间:2014-06-17 16:51:28

标签: matlab numerical-methods newtons-method

我试图用方程式系统实现牛顿方法,但我认为它不能正常工作。我应该获得[60 22.5 -60]度的角度,但现在我得到[995 90 -230]度。有人能看出我的代码出了什么问题吗?

hold on

l = 2;
L1 = 1;
L2 = 1;
L3 = 1;
m1 = 1;
m2 = 1;

% The system of equations to solve
%l = L1cos(u1)+L2cos(u2)+L3cos(u3);
%0 = L1sin(u1)+L2sin(u2)+L3sin(u3);
%0 = m2tan(u1)-(m1+m2)tan(u2)+m1tan(u3);

u = [pi/3 pi/8 -pi/3]

for i = 1:10
    F = [L1*cos(u(1))+L2*cos(u(2))+L3*cos(u(3))-l, L1*sin(u(1))+L2*sin(u(2))+L3*sin(u(3)), m2*tan(u(1))-(m1+m2)*tan(u(2))+m1*tan(u(3))];
    DF = [-L1*sin(u(1)) -L2*sin(u(2)) -L3*sin(u(3)); L1*cos(u(1)) L2*cos(u(2)) L3*cos(u(3)); m2*sec(u(1))^2 -(m1+m2)*(sec(u(2))^2) m1*sec(u(3))^2];
    u1 = u' + inv(DF)*F';
    u = u1';
end

rad = u1;
deg = (180/pi)*u1;

1 个答案:

答案 0 :(得分:1)

尝试替换以下行

u1 = u' + inv(DF)*F';

u1 = u' - inv(DF)*F';

当我做出这个改变时,我得到的解是[60,0,-60],它正确地解决了这三个方程式。