Newton raphson for 2d function

조회 수: 28 (최근 30일)
bbah
bbah 2019년 12월 1일
답변: Neeraj Rajpurohit 2021년 4월 7일
I need to implement a function which approximations the root of a 2dimensional function using the NewtonRaphson
method. J is the Jacobian matrix of f. Both need to be described as a set of anonymous
function. The iteration should start with the vector x_0 ,and carried out until the termination criterion E_tol is reached. The
termination criterion shall be calculated in regards to the absolute improvement of the solution x in the 2norm
Input = [f,J,x_0,E_tol]
Output = x[x1,x2]
I cannot find my mistake
function x = my_newton_raphson(f,J,x_0,E_tol)
x = [];
f = @(x)[0.5*cos(x(1))-0.5*sin(x(2))-x(1);0.5*sin(x(1))+0.5*cos(x(2)-x(2))];
J = @(x)[-0.5*sin(x(1))-1,-0.5*cos(x(2));0.5*cos(x(1)),-0.5*sin(x(2))-1];
x_0 =[0 0]';
E_tol = 10E-04;
delta_e = 1;
while E_tol < delta_e
g = f(x_0);
Jg = J(x_0);
y = x_0 - Jg\g;
ep = norm(y-x_0)
x_0 = y
end
end
OUTPUT x = [0.0 0.0 ;0.2 0.6;0.2287 0.5423;0.2291 0.5391]
  댓글 수: 2
darova
darova 2019년 12월 1일
There is no change of E_tol or delta_e
321.PNG
bbah
bbah 2019년 12월 1일
while E_tol < delta_e
g = f(x_0);
Jg = J(x_0);
y = x_0 - Jg\g;
delta_e = norm(y-x_0)
x_0 = y
end
end
it is still not working

댓글을 달려면 로그인하십시오.

답변 (1개)

Neeraj Rajpurohit
Neeraj Rajpurohit 2021년 4월 7일
DISCLAIMER: These are my own views and in no way depict those of MathWorks.
Greetings,
Please find the matlab script for newton-raphson method for 2 variables in the fileexchange link given below.

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by