I'm trying to use the Newton-Raphson method to solve the root finding
problem f(x) = 0. I'm able to get the correct answer but I always get an error for iteration limit. The error message is "Error missed: Iteration limit exceeded". My codes are as the following:
function x = rfNewtonR(fun,x,TolX,itmax)
% Find the root of f(x) = 0 using the Newton-Raphson method.
x0 = 1;
iter = 0;
TolX = 1e-6;
itmax = 20;
while (iter<itmax && abs(fun(x))>TolX)
x = x0-f/fp;
x0 = x;
iter = iter +1;
% Start the iteration.
if iter == itmax
msg = 'rfNewtonR:IterationLimitExceeded';
Please revise base on my codes thank you.
230,453 students got unstuck by Course
Hero in the last week
Our Expert Tutors provide step by step solutions to help you excel in your courses