Hi I'm using falsi regula algorithm in maple. For first function it worked fine :
restart;
epsilon := 1e-3:
f := x->x^3+x^2-3:
a:= 1:
b:=2:
step:=infinity:
while abs(step) >= epsilon or( abs(f(a)) >= epsilon and abs(f(b)) >= epsilon) do
c := (f(a)*b - f(b)*a)/(f(a) - f(b));
if f(c) = 0 then
break;
elif f(a)*f(c) < 0 then
step:=b-c:
b := c;
else
step:=a-c;
a := c;
fi;
od:
evalf([a, b]);
[1.174421025, 2.]
but I've problem with two another functions when using the same code :
restart;
epsilon := 1e-3:
f := x->exp(x)-x^2:
a:= -1:
b:=0:
step:=2:
while abs(step) >= epsilon or( abs(f(a)) >= epsilon and abs(f(b)) >= epsilon) do
c := evalf((f(a)*b - f(b)*a)/(f(a) - f(b));
if (f(a)*f(c)) < 0 then
step:=b-c:
b := c;
else
step:=a-c;
a := c;
fi;
od:
I got error: cannot evaluate boolean, the same situation for f:=x->x-sin(x)-0.25;. Can anyone help me with this problem???
The default inequality comparators in Maple will not deal with transcendental numbers such as exp(1) and sin(1). You need to convert these numbers to floating point with evalf. You can change the definition of f from x-> whatever to x-> evalf( whatever ).