Question: Decimal to Fraction Converter

In principle I think this should be pretty easy. I need to make a MAPLE code that uses loops and arrays to carry out the prcedure described here: http://people.revoledu.com/kardi/tutorial/ContinuedFraction/Decimal-Fraction-Conversion.htm  

frac:=proc(x,Kmax,epsilon)
  local Kmax, epsilon:
    P:=Array(-1..Kmax-2):
    P[0]:=floor(x), P[-1]:=1:
   Q:=Array(-1..Kmax-2):
    Q[-1]:=0, Q[0]:=1:
    F:=Array(1..Kmax):
    a=floor(x):
    while i < Kmax and F[i]<epsilon do
    r=x-a
      y=1/r
      P[i]:=a*P[i-1]+P[i-2]:
      Q[i]:=a*Q[i-1]+Q[i-2]:
      F[i]:=P[i]/Q[i]:
  end do:
end proc:

i don't really understand why it's not working although i think it's to do with y and r.

any help appreciated. thanks.

 

Please Wait...