Modéliser avec $y'=ay+b$ (thème 2)~2 min
Loi de refroidissement. Un café à $90\,{}^\circ$C est posé dans une pièce à $20\,{}^\circ$C ; sa température vérifie $\theta'=-0{,}15(\theta-20)$ ($t$ en minutes).
Forme $y'=ay+b$ : $\theta'=-0{,}15\theta+3$, équilibre $\theta=20$ (la température ambiante). Solutions : $\theta(t)=C\mathrm e^{-0{,}15t}+20$ ; $\theta(0)=C+20=90$, donc $C=70$ : $$\theta(t)=20+70\,\mathrm e^{-0{,}15t}.$$ Après $10$ minutes : $\theta(10)=20+70\mathrm e^{-1{,}5}\approx35{,}6\,{}^\circ$C. Le café est à $30\,{}^\circ$C quand $70\mathrm e^{-0{,}15t}=10\iff\mathrm e^{-0{,}15t}=\dfrac17\iff t=\dfrac{\ln7}{0{,}15}\approx13$ min.
def euler(a, b, y0, h, n):
# approche y(n*h) pour y' = a*y + b
y = y0
for k in range(n):
y = y + h * (a*y + b)
return y
Idée : sur un petit pas $h$, $y(x+h)\approx y(x)+h\,y'(x)=y(x)+h\,(ay(x)+b)$ ; on avance de pas en pas. Pour le café ($a=-0{,}15$, $b=3$, $y_0=90$), euler(-0.15, 3, 90, 0.1, 100) renvoie $\approx35{,}4$ (valeur exacte $\theta(10)\approx35{,}6$). Plus $h$ est petit, meilleure est l'approximation.