import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
m1=264000000
k1=225000000
x0=0.25
def f(X,t) :
x1, x2 = X
dx1_dt = x2
dx2_dt = -k1*x1/m1
return [dx1_dt, dx2_dt]
X0= [x0,0]
tab_instants= np.linspace(0,60,200000)
X_scipy= odeint(f, X0, tab_instants)
plt.plot(tab_instants,X_scipy[:,0])
plt.xlabel("temps")
plt.ylabel("x1")
plt.title("oscillation d'un système masse ressort avec 200000 points")
plt.grid()
plt.show()
def f2(X,t) :
x1, x2, x3, x4 = X
dx1_dt = x2
dx3_dt = x4
dx2_dt = -k1*x1/m1 + k2*(x2-x1)/m1
dx4_dt = -k2*(x2-x1)/m2- f(x4-x2)
return [dx1_dt, dx2_dt, dx3_dt, dx4_dt]
To embed this program on your website, copy the following code and paste it into your website's HTML: