Hello All,
I am attempting to code the Vectorial Newton Raphson Method to solve a system of equations and my code does not seem to be working. Rather, after running 100 iterations of the code I am merely getting my input back as the answer.
Here is the code:
function[xfinal,yfinal]=NewtonVectorial(x, y, d1, d2, R, H, tol, maxiter) xR=x; yR=y; iter=0; while(1) xold=xR; yold=yR; new=[xold;yold]-([-sin(xold)-sin(xold+yold),- sin(xold+yold);cos(xold)+cos(xold+yold),cos(xold+yold)])\([d1.*cos(xold)+d2.*cos(xold+yold)-R;d1.*sin(xold)+d2.*sin(xold+yold)-H]) iter=iter+1; if abs(new-[xold;yold])<tol break end if iter>maxiter break end xold=new(1,1); yold=new(2,1); end xold yold iter
I have hard coded my partial derivatives for my Jacobian as well as the two functions I am trying to solve.
As an example for the output, this is what I am getting:
>> NewtonVectorial(pi/2,pi/4,1,1,1,1.1,.01,100)
xold =
1.5708
yold =
0.7854
iter =
101
Where yold and xold are just the numbers I initially put into the code.
Any insight as to why my code is not yielding correct values would be greatly appreciated.
Thanks.
Best Answer