dfc.py

Created by gilles-vrn

Created on April 24, 2018

348 Bytes

Décomposition en fraction continue d’un réel ‘real’ à l’ordre ‘ordre’.


from math import *

def DFC(real,ordre):
    z=real
    y=floor(z)
    d=[]
    d.append(y)
    n=ordre
    P0=1
    Q0=0
    P1=y
    Q1=1
    for i in range(n):
        z=1/(z-y)
        y=floor(z)
        d.append(y)
        P=P1
        Q=Q1
        P1=P1*y+P0
        Q1=Q1*y+Q0
        P0=P
        Q0=Q
        x=P/Q
    return d