def iteration_dichotomie(a,b,m,epsilon,f):
def iteration_dichotomie(a,b,m,epsilon,f):
- def maj_test(xn,xnm1):
- return f(xn) != 0 and abs(xnm1-xn) > epsilon
- xnm1 = a
- xn= a
+ def maj_test(xn,xnm1,n,m):
+ return f(xn) == 0 or abs(xnm1-xn) <= epsilon or n >= m
+ xn= float(a)
+ xnm1 =float(b)
return (n,X)
def iteration_newton(x0,m,epsilon,f,fp):
return (n,X)
def iteration_newton(x0,m,epsilon,f,fp):
- def maj_test(xn,xnm1):
- return f(xn) != 0 and abs(xnm1-xn) > epsilon
- n=0;
- test= f(x0) != 0
- xn=x0
- X=[x0]
- while n < m and test:
+ def maj_test(xn,xnm1,epsilon,n,m,f):
+ return f(xn) == 0 or abs(xnm1-xn) <= epsilon or n >= m
+ n = 0
+ xn = float(x0)
+ X = [x0]
+ test = maj_test(xn,xn+2*epsilon,epsilon,n,m,f)
+ while not test:
- test= maj_test(xn,xnm1)
-
-#f(x) !=0 and n<m and abs(x-xm1)>epsilon
+ test= maj_test(xn,xnm1,epsilon,n,m,f)
return (n,X)
def iteration_corde(a,b,x0,m,epsilon,f):
return (n,X)
def iteration_corde(a,b,x0,m,epsilon,f):
- def maj_test(xn,xnm1):
- return f(xn) != 0 and abs(xnm1-xn) > epsilon
- n=0;
+ def maj_test(xn,xnm1,n,m,f):
+ return f(xn)== 0 or abs(xnm1-xn) <= epsilon or n >= m
+ n=0
- test= maj_test(xn,xnm1)
-
-#f(x) !=0 and n<m and abs(x-xm1)>epsilon
+ test= maj_test(xn,xnm1,n,m,f)
def iteration_lagrange(x0,x1,m,epsilon,f):
n=0;
def iteration_lagrange(x0,x1,m,epsilon,f):
n=0;
- print iteration_dichotomie(0,pi/2,200,0.00000001,f)
+ print iteration_dichotomie(0,pi/2,45,1E-9,f)
- print iteration_corde(0,pi/2,0,200,0.00000001,f)
-
+ print iteration_corde(0,pi/2,0,200,1E-9,f)
- print iteration_newton(0,200,0.00000001,f,fp)
+ print iteration_newton(0,200,1E-9,f,fp)
print "TP 3.1 ............ lagrange"
print iteration_lagrange(0,pi/2,200,0.00000001,f)
print "TP 3.1 ............ muller"
print iteration_muller(0,pi/4,pi/2,200,0.00000001,f)
print "TP 3.1 ............ lagrange"
print iteration_lagrange(0,pi/2,200,0.00000001,f)
print "TP 3.1 ............ muller"
print iteration_muller(0,pi/4,pi/2,200,0.00000001,f)