Convergents of a Continued Fraction
|
09-18-2024, 04:50 PM
Post: #2
|
|||
|
|||
RE: Convergents of a Continued Fraction
Code work even if continued fraction coefficient is 0. Very nice!
OP HP-42S code: 1 1 0 2 XEQ 00 --> 1 + 1/2 = 1.5 0 R/S --> 1 + 1/(2 + 1/0) = 1 + 1/inf = 1 3 R/S --> 1 + 1/(2 + 1/(0 + 1/3)) = 1 + 1/(2 + 3) = 1.2 Here is lua code to allow for Generalized Continued Fraction We simply scale CF numerator to 1, then use OP simple continued fraction code. x = b0 + a1/(b1 + a2/(b2 + a3/(b3 + ... = b0 + 1/(b1/a1 + (a2/a1)/(b2 + a3/(b3 + ... = b0 + 1/(b1/a1 + 1/(b2/(a2/a1) + a3/(a2/a1)/(b3 + ... Code: function dfc2f(b0) Lets try tan(pi/4)=1, using generalized CF form, and simple CF form (both are equivalent) lua> CF1, CF2 = dfc2f(0), dfc2f(0) lua> x = pi/4 lua> CF1(x,1), CF2(1/x) 0.7853981633974483 0.7853981633974483 lua> for k=1,8 do n=2*k+1; print(CF1(-x*x, n), CF2((-1)^k*n/x)) end 0.988689239934205 0.988689239934205 0.9997876809149683 0.9997876809149683 0.9999978684156949 0.9999978684156949 0.9999999865263551 0.9999999865263551 0.9999999999413254 0.9999999999413254 0.9999999999998131 0.9999999999998131 0.9999999999999997 0.9999999999999997 1.0000000000000002 1.0000000000000002 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Convergents of a Continued Fraction - Thomas Klemm - 03-13-2022, 11:41 PM
RE: Convergents of a Continued Fraction - Albert Chan - 09-18-2024 04:50 PM
RE: Convergents of a Continued Fraction - Albert Chan - 09-18-2024, 08:24 PM
RE: Convergents of a Continued Fraction - Albert Chan - 09-20-2024, 12:04 AM
RE: Convergents of a Continued Fraction - Albert Chan - 09-20-2024, 05:27 PM
RE: Convergents of a Continued Fraction - C.Ret - 09-20-2024, 10:24 PM
RE: Convergents of a Continued Fraction - Thomas Klemm - 09-21-2024, 08:33 AM
|
User(s) browsing this thread: 5 Guest(s)