This question has been answered
Question

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.
[f, fp]=fun(x);
x0 = 1;
iter = 0;
TolX = 1e-6;
itmax = 20;








while (iter<itmax && abs(fun(x))>TolX)
[f, fp]=fun(x0);
x = x0-f/fp;
x0 = x;
iter = iter +1;








% Start the iteration.
if iter == itmax
msg = 'rfNewtonR:IterationLimitExceeded';
error(msg)




else
disp(x)




end
end




end




Please revise base on my codes thank you.

Answered by Expert Tutors
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...
Get unstuck

230,453 students got unstuck by Course
Hero in the last week

step by step solutions

Our Expert Tutors provide step by step solutions to help you excel in your courses