Newton raphson for 2d function
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!