- Aug 10, 2001
- 10,420
- 2
- 0
The following program gives a rational approximation for an irrational number (pi,e,sqrt(2), etc.). How do I tell maple only to print out the current p/q if it is closer to r than all the previous p/q's? Currently I'm just printing out thousands of numbers. 
ratapprox:=proc(r,N)
local rr,p,q,z;
rr:=evalf(r);
p := 1; q := 1;
while N > q do
z:=(p/q);
if evalf(z)<rr then
p:=p+1;
print(z);
else
q:=q+1;
print(z);
end if;
end do;
end proc;
ratapprox:=proc(r,N)
local rr,p,q,z;
rr:=evalf(r);
p := 1; q := 1;
while N > q do
z:=(p/q);
if evalf(z)<rr then
p:=p+1;
print(z);
else
q:=q+1;
print(z);
end if;
end do;
end proc;
