How to solve a set of non linear equations using second order newton raphson method in matlab?

1 次查看(过去 30 天)
I want to solve the following set of equations to find unknown alpha values(V and r values are known). Can anybody help me with this?
  1 个评论
Varun Agrawal
Varun Agrawal 2015-5-28
I have written a code by taking an example for which the final answer is known. But it is not giving the numerical values and gives expressions instead. Can anybody help me out?
v_mean = 3.089; v_sq_mean = 18.344; v_cu_mean = 191.042; v_min = 0; v_max = 17;
syms x a b c d
F1 = int(exp(-a-(b.*x)-(c.*x.^2)-(d.*x.^3)),v_min,v_max) - 1;
F2 = int(x.*(exp(-a-(b.*x)-(c.*x.^2)-(d.*x.^3))),v_min,v_max) - v_mean;
F3 = int((x.^2).*exp(-a-(b.*x)-(c.*x.^2)-(d.*x.^3)),v_min,v_max) - v_sq_mean;
F4 = int((x.^3).*exp(-a-(b.*x)-(c.*x.^2)-(d.*x.^3)),v_min,v_max) - v_cu_mean;
J11 = diff(F1,a);
J12 = diff(F1,b);
J13 = diff(F1,c);
J14 = diff(F1,d);
J21 = diff(F2,a);
J22 = diff(F2,b);
J23 = diff(F2,c);
J24 = diff(F2,d);
J31 = diff(F3,a);
J32 = diff(F3,b);
J33 = diff(F3,c);
J34 = diff(F3,d);
J41 = diff(F4,a);
J42 = diff(F4,b);
J43 = diff(F4,c);
J44 = diff(F4,d);
abcd = zeros(4,1);
error=1; while error > 0.0001
a=abcd(1,1); b=abcd(2,1); c=abcd(3,1); d=abcd(4,1);
J = [vpa(J11) vpa(J12) vpa(J13) vpa(J14) vpa(J21) vpa(J22) vpa(J23) vpa(J24) vpa(J31) vpa(J32) vpa(J33) vpa(J34) vpa(J41) vpa(J42) vpa(J43) vpa(J44)];
J_inverse = inv(J);
F = [vpa(F1) vpa(F2) vpa(F3) vpa(F4)];
JF = (J_inverse)*F;
abcd = abcd - JF;
error = sum(JF)
end

请先登录,再进行评论。

回答(1 个)

Torsten
Torsten 2015-5-28
Use double() instead of vpa().
Best wishes
Torsten.
  1 个评论
Varun Agrawal
Varun Agrawal 2015-5-28
if I use double in place of vpa, the following error will come
Error using ==> mupadmex Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Error in ==> sym.sym>sym.double at 927 Xstr = mupadmex('mllib::double', S.s, 0);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by