Newton raphson for 2d function

14 次查看(过去 30 天)
bbah
bbah 2019-12-1
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
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.

Community Treasure Hunt

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

Start Hunting!

Translated by