Newton raphson for 2d function
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Neeraj Rajpurohit
le 7 Avr 2021
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 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!