# lorenzSoluce.py

```# -------------------------------------------------------------------------
#
# PYTHON for DUMMIES 19-20
# Probleme 5
#
# Solution detaillée
#  Vincent Legat
#
# -------------------------------------------------------------------------

from numpy import *

# -------------------------------------------------------------------------
#
# -1- Equations de Lorenz avec les paramètres de l'énoncé
#
#
#
#           dudt(t) = 10 v(t) - 10 u(t)
#           dvdt(t) = 28 u(t) - v(t) - u(t)w(t)
#           dwdt(t) = u(t) v(t) - 8 w(t) / 3
#
#

def f(x,u):
dudt = 10 * u[1] - 10 * u[0]
dvdt = 28 * u[0] - u[1] - u[0] * u[2]
dwdt = u[0] * u[1] - 8 * u[2] / 3
return array([dudt,dvdt,dwdt])

# -------------------------------------------------------------------------
#
# -2- Schema de Runge-Kutta classique d'ordre 4
#

def lorenz(Xstart,Xend,Ustart,n):
X = linspace(Xstart,Xend,n+1)
U = zeros((n+1,3)); U[0,:] = Ustart
h = (Xend - Xstart)/n
for i in range(n):
K1 = f(X[i]    ,U[i,:]       )
K2 = f(X[i]+h/2,U[i,:]+K1*h/2)
K3 = f(X[i]+h/2,U[i,:]+K2*h/2)
K4 = f(X[i]+h  ,U[i,:]+K3*h  )
U[i+1,:] = U[i,:] + h*(K1+2*K2+2*K3+K4)/6
return X,U

# -------------------------------------------------------------------------

```