bonjour
j’ai un programme
peut on en python mettre une fonction comme argument dans une fonction?
quelque chose comme
#la fonction
def trapeze(f(x), a,b,n):
......................
......................
# on appelle la fonction trapeze avec comme paramètre la fonction f(x)
trapeze(math.exp(-x**2),0,1,10)
Le script ci-dessous fonctionne python3
def f(x):
return math.exp(-x**2)
def trapeze(a,b,n):
h=(b-a)/n
x=a+h
I=(f(a)+f(b))/2
for i in range(1,n):
I+=f(x)
x+=h
I*=h
return I
I=trapeze(0,1,4)
print("l'aire est ",I)
Merci de m’aider