Regula falsi with error in x-axis

I want the regula falsi to get x +- .0001 so that f(x) = 0. But all the implemetations I see get x so that f(x) +- .0001 = 0 which doesn't make much sense. (f(x) = x^3).

How do I stop the regula falsi method when the error is .0001 on the x-axis?

I have this scilab code:

function salida = falsaposicion(fun, tolerancia, a, b)
deff("y=f(x)", "y="+fun);
if (f(a)*f(b)>0) then
disp("Error");
end

cAnt = 1e100
c =  b - f(b)*((b - a)/(f(b) - f(a)));

while 0 == 0
if f(b) - f(a) == 0 then
disp("Error");
break;
end

if abs(f(c)) < tolerancia then
break;
elseif f(a)*f(c) < 0 then
b = c;
elseif f(b)*f(c) < 0 then
a = c;
end

cAnt = c;
c = b - f(b)*((b - a)/(f(b) - f(a)));
end

salida = c;
endfunction

disp(falsaposicion("x^3", 0.0001, -6, 3));

$$$$


1 Answer

A loop invariant of regula falsi is that $$f(a)f(b)<0$$. Under the assumption that $$f$$ is continuous, this implies that there is a solution $$x_0$$ of $$f(x0)=0$$ inside $$(a,b)$$, since the eventual output $$c$$ is also in $$(a,b)$$, then for any output you have that $$|c−x_0|≤|a−b|$$. Therefore, you can add to the breaking condition, instead of it being abs(f(c))<tolerancia, to be abs(f(c))<tolerancia and abs(b-a)<.0001, or replace it completely by abs(b-a)<.0001`.

It is true that the distance between $$a$$ and $$b$$ doesn't always go to zero. That's the price you pay for converging faster than bisection in some cases. Still, that is the only condition that you have to bound the error, if regula falsi is applied by itself, since $$c$$ could be approaching a root only from one side. What people do is not to apply regula falsi by itself, but to mix it, among other methods, with bisection. For example, what is done in Brent's method.