<

Question: Can someone please help me on this problem?

I am having a problem with my loop. It only gives me one result.

In this program when i enter the initial values [B,C] it works and gives me an approximation. It then askes me if i want to find another root when i press "Y", it asks for the new values but when i insert the new values it does not evaluate them. It returns the previous result.

I have been trying to find the bug for ages but had no success. I would be very grateful if someone could help me out please.


f:=x->x^3 + 6*x^2 - 11*x - 10:
A:=1:
M:=0.0001:
E:=M+1:

while (A<>n) do
A:=readstat("Would You Like To Find Another Root?[y/n](n to quit)"):
if A=y then
B:=readstat(`Initial Value One?`);
C:=readstat(`Initial Value Two?`);
if sign(f(B)) = sign(f(C)) then
printf("No Roots In The Interval %a",[B,C]);
else
while E>M do
d:=evalf((B+C)/2):
print(d):
print(f(d)):
if f(d)>0 and (f(d)<f(C)) then
C:=d;
E:=(abs(f(d))):
else
if f(d)>0 and (f(d)<f(B)) then
B:=d:
E:=(abs(f(d))):
else
if f(d)<0 and (f(d)>f(B))then
B:=d;
E:=(abs(f(d))):
else
if f(d)<0 and (f(d)>f(C)) then
C:=d:
E:=(abs(f(d))):
else
if f(d)=0 then
E:=0:
end if:
end if:
end if:
end if:
end if:
end do;
print(evalf(d));
end if;
end if:
end do;
 

Please Wait...