%testing our newton's method on a known problem
%we know the root is pi
p0 = 1;%initial guess
tol = 1e-8;exact = 3.14159;%exact root
%enter function and its derivative
f = @(x) sin(x);fp = @(x) cos(x);%compare initial guess to exact root
diff = abs(p0-exact);%iterate newton's method
while diff > tol p = p0 - f(p0)/fp(p0); diff = abs(p-exact); %stop when our iterate is close to the exact root, pi
p0 = p;end%print the root to the screen
p
MATLAB: What is causing this to have an infinite loop?
infinite loopnewton's methodwhile loop
Related Question
- Newton’s method – how to make the computational performance faster
- Performing calculations (Newton’s method) over values in loop
- Why is the Fixed point iteration method only giving me first iteration. (i included info at the bottom of code and the next few iterations answers)
- Help storing the iterations into the variables
Best Answer