MATLAB: I am trying to solve 3 simultaneous nonlinear system of equations by newton’s method.

nonlinear system of equations

I am trying to solve 3 simultaneous nonlinear system of equations by newton's method. I am getting an error in solving that system.
The code is written below.
clear all
syms x y z
a=[1;1;1];
% The Newton-Raphson iterations starts here
del=1;
indx=0;
h=4;
gma=18.4;
ka1=0.2;
kp1=8.76;
ka2=0.2;
kp2=8.76;
sind=0.437;
cosd=0.9;
pa1=ka1*gma*(h*x+0.5*(x^2));
pp1=kp1*gma*0.5*(x^2);
pa2=ka2*gma*(x*y+0.5*(y^2));
pp2=kp2*gma*(y*(h+x)+0.5*(y^2));
za1=(0.5*h*(x^2)+(x^3)/6)/(h*x+0.5*(x^2));
zp2=(0.5*(h+x)*(y^2)+((y^3)/3))/((h+x)*y+0.5*(y^2));
za2=(0.5*x*(y^2)+((y^3)/3))+(x*y+0.5*(y^2));
e1=(pp1*sind)-(pa1*sind)-(pp2*sind)-(pa2*sind);
e2=pp1*cosd+pa2*cosd-pa1*cosd-pp2*cosd-z;
e3=pp1*cosd*(x/3)+pp2*cosd*zp2-pa1*cosd*za1-pa2*cosd*za2-z*(x+(h/3));
while del>1e-6
g=[e1; e2; e3];
J=jacobian([e1, e2, e3], [x, y, z]);
delx=-inv(J)*g;
a=a+delx;
del=max(abs(g));
indx=indx+1;
end
'NEWTON-RAPHSON SOLUTION CONVERGES IN ITERATIONS',indx,pause
'FINAL VALUES OF x ARE',x

Best Answer

Don't use symbolic variables together with Newton-Raphson.
Instead of using "jacobian" , look at the solution suggested by John D'Errico under
https://de.mathworks.com/matlabcentral/answers/28066-numerical-jacobian-in-matlab