MATLAB: False position infinite loop

false-positioninfinite loop

Hi there.
This function gets stuck in an infinite loop. Do you all have any suggestions for me?
function [R, E] = myFalsePosition(f, xL, xR, tol)
if sign (f(xL)) == sign(f(xR))
error 'you are arrested!!!'
end
yL = f(xL);
yR = f(xR);
new_x = ((xR*yL) - (xL*yR))/(yL - yR);
new_y = f(new_x);
e = abs(new_y);
E = e;
while e > tol
if f(xL)*f(new_x) > 0
xL = new_x;
yL = f(xL);
else
xR = new_x;
yR = f(xR);
end
end
new_x = ((xR*yL) - (xL*yR))/(yL - yR);
new_y = f(new_x);
R = [R new_x];
e = abs(new_y);
E = [E e];
end

Best Answer

Well you could tell us the values you used for f, xL, xR, tol when you called it. And you can use the debugger to figure out why "e" never falls below "tol". Using the debugger yourself will be your fastest course of action , rather than trying to debug it via back-and-forth Answers forum postings, which can take hours.