1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# 3_b une fonction RungeKutta4()
# la declaration de constat
N = "[valeur de N]"
Do =" [valeur de Dt]"
Dt =" [valeur de Dt]"
A = " [valeur de Dt]"
B = " [valeur de Dt]"
k =[np.arange(0, N/2, 1), np.arange(-N/2, 0, 1)]
t[0] = 0
def righthandside1(Ft,Fo):
righthandside1 = Do*(1j)**2*k**2*Fo+Dt*(1j)**2*k**2*Ft
return righthandside1
def righthandside2(Ft,Fo):
righthandside2 = A*(1j)**2*k**2*Fo+B*(1j)**2*k**2*Ft
return righthandside2
def RungeKutta4_1(righthandside1, Ft[0],Fo[0],t args=()):
n = len(t)
Ft = np.zeros((n,len(Ft0)))
Fo = np.zeros((n,len(Fo0)))
Ft[0] = Ft0
Ft[0] = Ft0
for i in range (n-1):
h = t[i+1]-t[i]
k1 = h*righthandside1(t[i],X[i])
k2 = h*righthandside1(t[i]+h/2,X[i]+k1/2)
k3 = h*righthandside1(t[i]+h/2,X[i]+k2/2)
k4 = h*righthandside1(t[i]+h/2,X[i]+k3/2)
Ft[i+1]= Ft[i]+(k1+2*k2+2*k3+k4)/6.0
k1 = h*righthandside2(t[i],X[i])
k2 = h*righthandside2(t[i]+h/2,X[i]+k1/2)
k3 = h*righthandside2(t[i+h/2,X[i]+k2/2)
k4 = h*righthandside2(t[i]+h/2,X[i]+k3/2)
Fo[i+1]= Ft[i]+(k1+2*k2+2*k3+k4)/6.0
return Ft Fo |
Partager