int_par_trapezes.py

Created by yann-rougeron

Created on April 28, 2020

659 Bytes

calcule l’intégrale d’une fonction entre 2 bornes. Méthode des trapèzes


from random import *
from math import *

print("Calcule l'intégrale d'une fonction continue entre deux bornes")
print('Méthode des TRAPEZES')

binf=float(input('borne inf='))
bsup=float(input('borne sup='))
dx=0.001#-------------largeur du rectangle
S=0

def f(x):
  return x*x

def controle_borne(a,b):#---a doit être inférieur à b, sinon inversement des bornes
  c=0
  if a>b:
    c=a
    a=b
    b=c
  return(a,b)

binf,bsup=controle_borne(binf,bsup)#on vérifie que les bornes sont ordonnées

xi=binf
while xi+dx<=bsup:
    yi=(f(xi)+f(xi+dx))/2#--------hauteur moyenne du TRAPEZE
    S=S+yi*dx
    xi=xi+dx
print('AIRE=',S)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.