Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 1021

Chapter 13 - Continued Fractions

Example 13.2 - Continued fraction expansion of 125/54

continued_fraction(125/54)
[2; 3, 5, 1, 2]

Example 13.6 - Convergents of 125/54

continued_fraction(125/54).convergents()
[2, 7/3, 37/16, 44/19, 125/54]

Continued fraction expansion of pi

c = continued_fraction_list(pi,nterms=6) c
[3, 7, 15, 1, 292, 1]
c.convergents()
[3, 22/7, 333/106, 355/113, 103993/33102, 104348/33215]

The procedure below will search for rational approximations of π better than 22/7.

for b in range(1,107): a=round(b*pi); if abs(pi-a/b)<abs(pi-22/7): print(a/b,N(abs(pi-a/b)),N(abs(b*pi-a)))
(179/57, 0.00124177639681067, 0.0707812546181970) (201/64, 0.000967653589793116, 0.0619298297467594) (223/71, 0.000747583167258092, 0.0530784048753219) (245/78, 0.000567012564152147, 0.0442269800038559) (267/85, 0.000416183001557879, 0.0353755551324184) (289/92, 0.000288305763706198, 0.0265241302609525) (311/99, 0.000178512175651679, 0.0176727053895434) (333/106, 0.0000832196275291075, 0.00882128051807740)
︠edfde9a2-7f4d-488b-afa3-9aef58de270c︠