How do I iterate my Newton method so that I get an array of values instead of just the last number?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Christopher
el 20 de Mzo. de 2014
Respondida: Andrei Bobrov
el 20 de Mzo. de 2014
I have my code, and I get the right value at the end, but I would like all the values that were outputed using this code:
Test case:
f=@(x) x^2 -2;
df=@(x) 2*x;
[R,E] = myNewton(f, df, 1, 1e-5)
my code:
function [R,E] = myNewton(f, df, x0, tol)
while abs(f(x0))>tol
B= x0-f(x0)/df(x0);
F= f(B);
x0=B;
R=B;
E=F;
end
end
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 20 de Mzo. de 2014
function R = yourNewton(f, df, x0, tol)
R = [];
ff = f(x0);
while abs(ff) > tol
B = x0 - ff/df(x0);
ff = f(B);
x0=B;
R=[R;B,ff];
end
end
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!