]> AND Private Git Repository - cours-mesi.git/blob - tps/chap3/jjm.py~
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
correction pbnum
[cours-mesi.git] / tps / chap3 / jjm.py~
1 def iteration_lagrange(x0, q0, m, epsilon, f):
2     def maj_test(xn,xnm1):
3         return f(xn)!=0 and abs(xn-xnm1)>epsilon
4
5     n=0
6     test=f(x0)!=0
7     X=[x0]
8     xnm1=x0
9     xn=float(x0-f(x0))/q0
10     qn=q0
11     print(xn,q0)
12     while n<=m and test:
13         qn=float((f(xn)-f(xnm1)))/(xn-xnm1)
14         xnm1=xn
15         xn=xnm1-f(xnm1)/qn
16
17         X+=[xn]
18         test=maj_test(xn,xnm1)
19         n+=1
20     return (n,X)
21
22 ////////////////////////////////////////////////////////////////////////////
23 print(iteration_lagrange(pi/4,1,200,0.0000001,f))