1 import matplotlib.pyplot as plt
18 def iteration_dichotomie(a,b,m,epsilon,f):
19 def maj_test(xn,xnm1):
20 return f(xn) != 0 and abs(xnm1-xn) > epsilon
28 while n <= m and test:
31 test = maj_test(xn,xnm1)
40 def iteration_newton(x0,m,epsilon,f,fp):
41 def maj_test(xn,xnm1):
42 return f(xn) != 0 and abs(xnm1-xn) > epsilon
53 test= maj_test(xn,xnm1)
55 #f(x) !=0 and n<m and abs(x-xm1)>epsilon
59 def iteration_corde(a,b,x0,m,epsilon,f):
60 def maj_test(xn,xnm1):
61 return f(xn) != 0 and abs(xnm1-xn) > epsilon
63 q=float(f(b)-f(a))/(b-a)
72 test= maj_test(xn,xnm1)
74 #f(x) !=0 and n<m and abs(x-xm1)>epsilon
77 """def iteration_newton(x0,m,epsilon,f,fp):
89 test= not (f(x)==0 or n>=m or abs(x-xm1)<=epsilon)
93 def iteration_lagrange(x0,x1,m,epsilon,f):
95 delta=float(x1-x0)/(f(x1)-f(x0))
102 delta=float(x-xm1)/(f(x)-f(xm1))
105 test= not (f(x)==0 or n>=m or abs(x-xm1)<=epsilon)
110 print "TP 3.1 ............ dichotomie"
111 print iteration_dichotomie(0,pi/2,200,0.00000001,f)
114 print "TP 3.1 ............ corde"
115 print iteration_corde(0,pi/2,0,200,0.00000001,f)
118 print "TP 3.1 ............ newton"
119 print iteration_newton(0,200,0.00000001,f,fp)
122 print "TP 3.1 ............ lagrange"
123 print iteration_lagrange(0,pi/2,200,0.00000001,f)
126 if __name__ == '__main__':