solution using newton raphson method?

1 次查看(过去 30 天)
this is my code i am unable to substitue x1,x2,x3,x4 values in the matrix.Please help in solve this.
syms x1 x2 x3 x4
g1=cos(x1)+cos(x2)+cos(x3)+cos(x4)-0.9424;
g2=cos(5*x1)+cos(5*x2)+cos(5*x3)+cos(5*x4);
g3=cos(7*x1)+cos(7*x2)+cos(7*x3)+cos(7*x4);
g4=cos(11*x1)+cos(11*x2)+cos(11*x3)+cos(11*x4);
g=[g1;g2;g3;g4];
x=[x1;x2;x3;x4];
j=jacobian(g,x)
j_inv=inv(j)
p=j_inv*-g
x1=input('enter initial values of x1')
x2=input('enter initial values of x2')
x3=input('enter initial values of x3')
x4=input('enter initial values of x4')
disp(x)
disp(p)
subs(p)

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-19
MATLAB does not automatically know which values to substitute. You need to specify this in the call to subs() explicitly. Try the following code
syms x1 x2 x3 x4
g1=cos(x1)+cos(x2)+cos(x3)+cos(x4)-0.9424;
g2=cos(5*x1)+cos(5*x2)+cos(5*x3)+cos(5*x4);
g3=cos(7*x1)+cos(7*x2)+cos(7*x3)+cos(7*x4);
g4=cos(11*x1)+cos(11*x2)+cos(11*x3)+cos(11*x4);
g=[g1;g2;g3;g4];
x=[x1;x2;x3;x4];
j=jacobian(g,x);
j_inv=inv(j);
p=j_inv*-g;
X1=input('enter initial values of x1');
X2=input('enter initial values of x2');
X3=input('enter initial values of x3');
X4=input('enter initial values of x4');
disp(x)
disp(p)
subs(p, [x1 x2 x3 x4], [X1 X2 X3 X4])
  19 个评论
Ameer Hamza
Ameer Hamza 2020-5-3
编辑:Ameer Hamza 2020-5-3
Can you start a new question and post the details of your question? You can then post the link of your question in the next comment.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by