Post Reply 
Convergents of a Continued Fraction
09-20-2024, 05:27 PM (This post was last modified: 09-20-2024 05:31 PM by Albert Chan.)
Post: #5
RE: Convergents of a Continued Fraction
(03-13-2022 11:41 PM)Thomas Klemm Wrote:  We enter the program at label 00.
At that point you can consider \(\frac{w}{v} = 1\) and \(\frac{1}{v} = 0\).

We start with the first two elements of the continued fraction and place them on the stack.
However, we must enter the values \(1\) and \(0\) in between:

\(a_0\) ENTER
1 ENTER
0 ENTER
\(a_1\) ENTER
XEQ 00

I was curious if we enter some other value pairs between a0, a1

Code:
            a0     a1          a2
h(n)    z   a0  (a0*a1+z)  (a0*a1+z)*a2 + a0
k(n)    y   1   (a1+y)     (a1+y)*a2 + 1

\(\displaystyle \frac{h_1}{k_1}
= \frac{a_0\;a_1 + z}{a_1 + y}
\;=\; a_0 + \frac{z - a_0\;y}{a_1 + y} \)

\(\displaystyle \frac{h_2}{k_2}
= \frac{(a_0\;a_1+z)×a_2 + a_0}{(a_1+y)×a_2+1}
\;=\; a_0 + \frac{z - a_0\;y}{a_1 + y + \frac{1}{a_2}} \)
...

\(\displaystyle \frac{h_∞}{k_∞}
= a_0 + \frac{z - a_0\;y}{[a_1 + y ;\; a_2 , a_3 ,\; ...]}\)

If {z,y} = {1,0}, this reduced to simple continued fraction \([a_0 ;\; a_1, a_2, a_3, \; ...]\)

Confirm by example:

3 Enter 14 Enter 159 Enter 2654
XEQ 00      → 2.835407038748666903661571276217561
1 R/S         → 2.835465529495380241648898365316275
2 R/S         → 2.835446037199383959246534770761757

lua> a0, z, y, a1 = 3, 14, 159, 2654
lua> f = dfc2f(a0)
lua> f(z-a0*y, a1+y)
2.835407038748667
lua> f(1)
2.83546552949538
lua> f(2)
2.835446037199384
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Convergents of a Continued Fraction - Albert Chan - 09-20-2024 05:27 PM



User(s) browsing this thread: 3 Guest(s)