Newton Rapson method code question
Show older comments
I am creating a MATLAB code that takes a function, differential function, initial value, and error tolerance and solves it using Newton-Raphson's method, but it repeats infinitely. Where is the problem?
function [root,iter] = newton_raphson(f,df,x0,tol)
iter=0;
err = 1;
x=x0;
while(err>=tol)
iter=1+iter;
xm=x-(f(x)/df(x));
err=abs(xm-x);
x=xm;
end
root=xm;
end
1 Comment
Torsten
on 26 Oct 2024
Where is the problem?
We don't know because you didn't supply the inputs to the function.
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



