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));
```