# -*- coding: utf-8 -*-
"""
Created on Sun Dec 11 19:47:05 2022

@author: EYER
"""

import numpy as np
import matplotlib.pyplot as plt

a = 0
b = np.pi/4
n = 100 ## nombre de subdivisions

def f(x):
    return (np.cos(x))**(x)

dx = (b-a)/n
lx = [i*dx for i in range(0,n+1)]   ## lx est la liste des xi 
                            ## il y a bien (n+1) valeurs
                            ## mais n subdivisions !
                            
lf = [f(xi) for xi in lx]

plt.plot(lx,lf)

## Rectangles à gauche
Ig = 0
ni = 10
dx = (b-a)/ni
for i in range(0,ni):
    Ig = Ig + dx*f(a+i*dx)
print('Ig =',Ig)

## Rectangles à droite
Id = 0
ni = 10
dx = (b-a)/ni
for i in range(1,ni+1):
    Id = Id + dx*f(a+i*dx)
print('Id =',Id)

## Trapèzes
It = 0
ni = 10
dx = (b-a)/ni
for i in range(0,ni):
    It = It + dx*(f(a+i*dx)+f(a+(i+1)*dx))/2
print('It =',It)

