30 lines
518 B
Python
30 lines
518 B
Python
|
#!/usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
Created on Tue Feb 4 10:32:17 2020
|
||
|
|
||
|
@author: suwako
|
||
|
"""
|
||
|
|
||
|
|
||
|
def rectangle(f, a, b, n):
|
||
|
h = (b - a) / n
|
||
|
aire = 0
|
||
|
for i in range(n):
|
||
|
aire += f(a+i*h)
|
||
|
return aire*h
|
||
|
|
||
|
def trapeze(f, a, b, n):
|
||
|
h = (b - a) / n
|
||
|
aire = 0
|
||
|
for i in range(n):
|
||
|
aire += (f(i*h) + f((i+1)*h))
|
||
|
return aire*h/2
|
||
|
|
||
|
def milieu(f, a, b, n):
|
||
|
h = (b - a) / n
|
||
|
aire = 0
|
||
|
for i in range(n):
|
||
|
aire += f((a+h*i + a + h*(i+1))/2)
|
||
|
return aire*h
|