# Les suites définies par récurrence¶

Attention : ne pas oublier d'exécuter la première cellule !

## Définition¶

In [1]:
nom="u"
nmin=0
u_nmin=3

def f(n) :
return 2*n+1

print(f"{nom}_{nmin} = {u_nmin} et pour tout n>={nmin}, {nom}_n+1 = f({nom}_n).")

u_0 = 3 et pour tout n>=0, u_n+1 = f(u_n).


## Calcul des premiers termes¶

In [5]:
n=nmin
u=u_nmin

while(n<=10):
print(f"{nom}_{n:2d} = {u:4d}")
n=n+1
u=f(u)

u_ 0 =    3
u_ 1 =    7
u_ 2 =   15
u_ 3 =   31
u_ 4 =   63
u_ 5 =  127
u_ 6 =  255
u_ 7 =  511
u_ 8 = 1023
u_ 9 = 2047
u_10 = 4095


## Calcul des premiers termes et des premières sommes¶

In [6]:
n=nmin
u=u_nmin
s=u

while(n<=10):
print(f"{nom}_{n:2d} = {u:4d}   S_{n:2d} = {s:4d}")
n=n+1
u=f(u)
s=s+u

u_ 0 =    3   S_ 0 =    3
u_ 1 =    7   S_ 1 =   10
u_ 2 =   15   S_ 2 =   25
u_ 3 =   31   S_ 3 =   56
u_ 4 =   63   S_ 4 =  119
u_ 5 =  127   S_ 5 =  246
u_ 6 =  255   S_ 6 =  501
u_ 7 =  511   S_ 7 = 1012
u_ 8 = 1023   S_ 8 = 2035
u_ 9 = 2047   S_ 9 = 4082
u_10 = 4095   S_10 = 8177


## Test sur la valeur de la suite¶

In [9]:
n=nmin
u=u_nmin

while(u<100):
print(f"{nom}_{n:2d} = {u:4d}")
n=n+1
u=f(u)

print("\n------------------\n")
print(f"{nom}_{n:2d} = {u:4d}")

u_ 0 =    3
u_ 1 =    7
u_ 2 =   15
u_ 3 =   31
u_ 4 =   63

------------------

u_ 5 =  127


## Test sur la valeur de la somme¶

In [11]:
n=nmin
u=u_nmin
s=u

while(s<1_000):
print(f"{nom}_{n:2d} = {u:4d}   S_{n:2d} = {s:4d}")
n=n+1
u=f(u)
s=s+u

print("\n------------------\n")
print(f"{nom}_{n:2d} = {u:4d}   S_{n:2d} = {s:4d}")

u_ 0 =    3   S_ 0 =    3
u_ 1 =    7   S_ 1 =   10
u_ 2 =   15   S_ 2 =   25
u_ 3 =   31   S_ 3 =   56
u_ 4 =   63   S_ 4 =  119
u_ 5 =  127   S_ 5 =  246
u_ 6 =  255   S_ 6 =  501

------------------

u_ 7 =  511   S_ 7 = 1012

In [ ]: