Méthodes des rectangles, des milieux, des trapèzesMéthode des rectangles
def f(x):
return x*x
def rectangleGauche(n,a,b,f):
pas = 1.0*(b-a)/n
s = 0
x = a
for i in range(0,n):
s = s + pas*f(x)
x = x + pas
return s
print(rectangleGauche(500,0,6,f))
def f(x):
return x*x
def rectangleGauche(n,a,b,f):
pas = 1.0*(b-a)/n
s = 0
x = a+pas
for i in range(0,n):
s = s + pas*f(x)
x = x + pas
return s
print(rectangleGauche(500,0,6,f))
def f(x):
return x*x
def rectangleGauche(n,a,b,f):
pas = 1.0*(b-a)/n
s = 0
x = a+pas/2.0
for i in range(0,n):
s = s + pas*f(x)
x = x + pas
return s
print(rectangleGauche(500,0,6,f))
Méthode des trapèzes
def f(x):
return x*x
def trapeze(n,a,b,f):
pas = 1.0*(b-a)/n
s = 0
x = a
for i in range(0,n):
s = s + pas*(f(x)+f(x+pas))/2.0
x = x + pas
return s
print(trapeze(500,0,6,f))