Non linear system by Newton-Raphson
Mostrar comentarios más antiguos
Hey, I m trying to solve a non-linear system by Newton-Raphson method with an iteration max of 10 and 10^(-8) max error.
It 's my 1st time using matrices in Matlab and i think i don t get it right because my answer shoul be somewhat around x=0,88 y=0,99
I would love to know what is going wrong in my code ( I hope my derivatives are right (they should be))
thanks !
f1=@(x,y) atan(y)-y.*x.^2;
f2=@(x,y) x.^2+y.^2-2*x;
x1 = 1;
y1 = 1;
P = [x1 ; y1];
F= @(P) [atan(y1)-y1.*x1.^2 ; x1.^2+y1.^2-2*x1];
JF = @(P) [-2.*x1.*y1 (1/(1+y1.^2))-(x1.^(-2)) ; 2.*x1-2 2.*y1];
error = 1;
k = 1;
while k<10 && error > 10^(-8)
Q = P-JF(P)\F(P);
error = abs( norm(Q-P)/norm(Q+eps));
P=Q;
k=k+1;
end
P
Respuesta aceptada
Más respuestas (1)
x1 = 1;
y1 = 1;
P = [x1 ; y1];
F= @(x,y) [atan(y)-y.*x.^2 ; x.^2+y.^2-2*x];
JF = @(x,y) [-2.*x.*y (1/(1+y.^2))-(x.^(-2)) ; 2.*x-2 2.*y];
error = 1;
k = 1;
while k<10 && error > 10^(-8)
Q = P-JF(P(1),P(2))\F(P(1),P(2));
error = abs( norm(Q-P)/norm(Q+eps));
P=Q;
k=k+1;
end
P
Categorías
Más información sobre Newton-Raphson Method en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!