
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 23 11:35:11 2026

@author: pjaub
"""

import numpy as np
import matplotlib.pyplot as plt

plt.close('all')

def A_chap(x, y):
    x_bar = np.mean(x)
    y_bar = np.mean(y)
    num = np.sum((x - x_bar)*(y - y_bar))
    den = np.sum((x - x_bar)**2)
    return num / den

def B_chap(x, y):
    x_bar = np.mean(x)
    y_bar = np.mean(y)
    A = A_chap(x, y)
    return y_bar - A * x_bar

x = [5,7,9,11,13,15,17,19]
y = [1.2,1.8,2.5,3.3,4.2,5.1,6.3,7.4]

plt.figure(" linéaire sur donnée")
plt.plot(x, y, linestyle='None', marker='.', markersize=6)

a = A_chap(x, y)
b = B_chap(x, y)

t = np.linspace(2,20)
plt.plot(t, a*t +b)
plt.grid(True)
plt.show()

plt.figure( "modele exponentiel")
plt.plot(x, y, linestyle='None', marker='.', markersize=6)
a = A_chap(x, np.log(y))
b = B_chap(x, np.log(y))
k = np.exp(b)

t = np.linspace(2, 20)
p = k * np.exp(a * t)

plt.plot(t, p)
plt.grid(True)
plt.show()

plt.figure( "modele puissance")
plt.plot(x, y, linestyle='None', marker='.', markersize=6)

X = np.log(x)
Y = np.log(y)
a = A_chap(X, Y)
b = B_chap(X, Y)
k = np.exp(b) 

t = np.linspace(2,20)
p = k * t**a

plt.plot(t, p)
plt.grid(True)
plt.show()

