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