Here is a code for applying Newton's for finding roots for $x^2-1$. However, how to use this code or just make some changes and define something more,(like define the column vector of $(x_1,x_2)$) on the code below to find roots for this system of equations: $f(x_1,x_2)=x_1^2+x_2^2-1=0$, $f(x_1,x_2)=5x_1^2-x_2^2-2=0$
also using the newton's method. The formula will be: $x_{k+1}=x_k-(▽f(x_k))^{(-T)}f(x_k)$, where $(▽f(x_k))^{T}$ is the Jacobian matrix. What the code will be?
Here is the code for $x^2-1$ with first trial $x(1)=10$:
$function[]=newton_eg1 %% demonstration of Newton's method %% the derivative of f is nonzero at the solution. x(1)=10; epsilon=1.e-10; MaxIter=100; k=1; %% f=x^2-1 while abs(x(k)^2-1)>epsilon & k <MaxIter x(k+1)=x(k) - (x(k)^2-1)/(2*x(k)); k=k+1; end %%%%%%output solution and error: fprintf('step solution error \n'); for i=1:k err(i)=abs(x(i)-x(k)); fprintf('%i: %e %e\n', i, x(i), err(i)); end fprintf('\n convergence rate: \n'); for i=1:k-3 order(i)=log(err(i+2)/err(i+1)) / log( err(i+1)/err(i) ); fprintf('%i: %e \n', i, order(i)); end $