RK4 02
RK4 02
RK4 02
dy
= f(x, y)
dx
La mthode RK4 utilise plusieurs points intermdiaires pour calculer la valeur de yi+1
partir de la valeur de yi :
On considre un point intermdiaire A d'abscisse xi+h/2 dont la valeur de l'ordonne est
donne par :
dy h
dy h k 1
y iA = y i +
soit y iA y i =
=
dx i 2
dx i 2 2
puis un point B d'ordonne :
h
h k
dy
dy
y iB = y i + soit y iB y i = = 2
dx iA 2
dx iA 2 2
On calcule alors l'ordonne d'un point C d'abscisse xi+h l'aide de la relation :
dy
dy
y iC = y i + h soit y iC y i = h = k 3
dx iB
dx iB
dy
la valeur de
dx ic
Soit
On pose :
dy
au point C.
dx
dy
h = k4
dx ic
L'ordonne dfinitive yi+1 du point d'abscisse xi+h est donne par la relation :
y i+1 = y i +
1 dy
dy
dy
dy
+ 2 + 2 + h
6 dx i
dx iA
dx iB dx iC
ou
y i+1 = y i +
RK4_02
1
[ k1 + 2 k 2 + 2 k 3 + k 4 ]
6
A
B
Pi+1
Pi
xi
tg =
xi+1=xi + h
1 dy
dy
dy
dy
+ 2 + 2 +
6 dx i
dx iA
dx iB dx iC
RK4_02
dy
= 2x.y
dx
Exemple :
Pi
x i
y
i
k
dy
= 2 x i y i = 1
dx
dx i
dx
xi +
k
dy
dx
y i +
= yi + 1
2
dx i 2
k k
dx
dy
= 2 x i +
yi + 1 = 2
2
2 dx
dx ia
dx
xi +
k
dx
dy
y i +
= yi + 2
2
dx iA 2
k k
dx
dy
= 2 x i +
yi + 2 = 3
2
2 dx
dx iB
x i + dx
y + dy dx = y + k
i
3
i dx
iB
k
dy
= 2 (x i + dx ) (y i + k 3 ) = 4
dx
dx iC
Pi+1
1 dy
dy
dy
dy
+ 2 + 2 + dx
6 dx i
dx iA
dx iB dx iC
1
= yi + [ k1 + 2 k 2 + 2 k 3 + k 4 ]
6
y i+1 = y i +
y i+1
RK4_02
dy
= 2x.y avec y(x=0)=1
dx
xi
0
0,1
0,2
0,3
0,4
0,5
yi
1
0,9900
0,9608
0,9139
0,8521
0,7788
Mthode RK4 :
i
0
1
2
3
4
5
xi
0
0,1
0,2
0,2
0,4
0,5
yi
1
0.990
k1=-2 xi yi x
-2 0 1 0,1=0
-2 0,1 0,99 0,1=0,0198
i
0
1
2
3
4
5
xi
0
0,1
0,2
0,2
0,4
0,5
yi
1
0,990
0,961
Avec EXCEL :
6
7
8
6
7
8
A
x
0
=A6+dx
=A7+dx
D
k3
=-2*(x+dx/2)*(y+k2/2)*dx
=-2*(x+dx/2)*(y+k2/2)*dx
=-2*(x+dx/2)*(y+k2/2)*dx
RK4_02
B
k1
=-2*x*y*dx
=-2*x*y*dx
=-2*x*y*dx
C
k2
=-2*(x+dx/2)*(y+k1/2)*dx
=-2*(x+dx/2)*(y+k1/2)*dx
=-2*(x+dx/2)*(y+k1/2)*dx
E
k4
=-2*(x+dx)*(y+k3)*dx
=-2*(x+dx)*(y+k3)*dx
=-2*(x+dx)*(y+k3)*dx
F
y
1
=F6+1/6*(B6+2*C6+2*D6+E6)
=F7+1/6*(B7+2*C7+2*D7+E7)
u = Ri = R
dq
du
= RC
dt
dt
du
1
u
=
dt
RC
Exercice : Utiliser la mthode RK4 pour rsoudre cette quation diffrentielle :
k1 = hf(xi,yi)
k2 = hf(xi+h/2,yi+k1/2)
k3 = hf(xi+h/2,yi+k2/2)
k4 = hf(xi+h,yi+k3)
k1 =
ui dt
RC
1
k
k 2 =
ui + 1 dt
2
RC
1
[ui + k 3 ]dt
k4 =
RC
1
k
k 3 =
ui + 2 dt
2
RC
u t + dt = u t +
1
[k1 + 2k 2 + 2k 3 + k 4 ]
6
6,0
5,0
4,0
u(Exact)
3,0
u(Euler)
u(RK4)
2,0
1,0
0,0
0
RK4_02
A
t
0
=A7+dt
=A8+dt
=A9+dt
=A10+dt
=A11+dt
=A12+dt
=A13+dt
=A14+dt
=A15+dt
=A16+dt
=A17+dt
6
7
8
9
10
11
12
13
14
15
16
17
18
B
k1
=-dt/RC*F7
=-dt/RC*F8
=-dt/RC*F9
=-dt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15+E15)
=F16+1/6*(B16+2*C16+2*D16+E16)
=F17+1/6*(B17+2*C17+2*D17+E17)
0,1
0,5
5
s
s
V
Conc. initiales
C(t)
c-y
c-y
dy
= k (c y )2
dt
La solution analytique est :
y = c 1
k t c + 1
On pourra donc confronter les valeurs obtenues par la mthode analytique et celles obtenus
par les mthodes numriques.
k 2 = dt k c - y t - 1
2
k 1 = dt k (c y t )
k 3 = dt k c - y t - 2
2
k 4 = dt k (c - y t - k 3 )2
y t + dt = y t +
1
[k1 + 2k 2 + 2k 3 + k 4 ]
6
0,01
0,009
0,008
0,007
0,006
0,005
0,004
0,003
0,002
0,001
0
0
100
200
yExact
h
10
s
RK4_02
k
3
L.mol-1s-1
300
y RK4
c0
0,01
mol.L-1
400
du
1
(e - u)
=
dt RC
1
[e t - u t ]
RC
k 2 = dt
k
1
e t+dt/2 u t 2
RC
2
k 4 = dt
k 1 = dt
k 3 = dt
u t + dt = u t +
k
1
e t+dt/2 u t 1
RC
2
1
(e t + dt - u t - k 3 )
RC
1
[k1 + 2k 2 + 2k 3 + k 4 ]
6
R(ohm) 1,0104
C(F)
1,010-6
f (Hz)
dt(s)
50
5,010-4
1,010-2
RC
30
20
10
e(t)
u(t)
-10
-20
-30
0,00
0,02
0,04
0,06
0,08
0,10
RK4_02
6
7
8
B
e(t)
=(24*SIN(2*PI()*f*t))
=(24*SIN(2*PI()*f*t))
=(24*SIN(2*PI()*f*t))
F
k2
=dt/RC*(I6-C6-k1/2)
=dt/RC*(I7-C7-k1/2)
=dt/RC*(I8-C8-k1/2)
RK4_02
C
u(t)
0
=C6+D6
=C7+D7
G
k3
=dt/RC*(I6-C6-k2/2)
=dt/RC*(I7-C7-k2/2)
=dt/RC*(I8-C8-k2/2)
D
u
(k1+2*k2+2*k3+k4)/6
(k1+2*k2+2*k3+k4)/6
(k1+2*k2+2*k3+k4)/6
H
k4
=dt/RC*(B7-C6-k3)
=dt/RC*(B8-C7-k3)
=dt/RC*(B9-C8-k3)
E
k1
=dt*1/RC*(B6-C6)
=dt*1/RC*(B7-C7)
=dt*1/RC*(B8-C8)
I
e(t+dt/2)
=(24*SIN(2*PI()*f*(t+dt/2)))
=(24*SIN(2*PI()*f*(t+dt/2)))
=(24*SIN(2*PI()*f*(t+dt/2)))
d2
dt 2
d
= 02 sin
dt
Mthode RK4 :
ti
i
Pi
j
d
= i = 1
h
dt i
k
d
2
= 0 sini = 1
h
dt i
ti +
2
j1
d h
i + = i +
2
dt i 2
k1
d h
i + dt 2 = i + 2
k
j
d
= i + 1 = 2
h
2
dt ia
j k
d
2
= 0 sin i + 1 = 2
2 h
dt ia
RK4_02
ti +
2
j2
h
d
i + = i +
2
dt ia 2
k2
h
d
i + dt 2 = i + 2
ia
j
k
d
= i + 2 = 3
2
h
dt ib
j k
d
2
= 0 sin i + 2 = 3
2 h
dt ib
ti + h
d
i + h = i + j3
dt ib
d
h = i + k 3
i +
dt ib
j
d
= i + k 3 = 4
h
dt ic
k
d
2
= 0 sin(i + j3 ) = 4
h
dt ic
Soit :
j1 = t dt
k 1 = 02 sin t dt
k
j 2 = t + 1 dt
2
k 2 = 02 sin t + 1 dt
2
j3 = t + 2 dt
2
k 3 = 02 sin t + 2 dt
2
j 4 = [ t + k 3 ] dt
k 4 = 02 sin[ t + j3 ] dt
(t + dt) = t +
(t + dt) = t +
RK4_02
1
[k1 + 2(k 2 + k 3 ) + k 4 ]
6
1
[j1 + 2(j2 + j3 ) + j 4 ]
6
9
10
11
12
13
14
15
A
t
0
=A10+dt
=A11+dt
=A12+dt
=A13+dt
=A14+dt
B
teta
C
omega
=teta0
=B10+1/6*(E10+2*G10+2*I10+K10)
=B11+1/6*(E11+2*G11+2*I11+K11)
=B12+1/6*(E12+2*G12+2*I12+K12)
=B13+1/6*(E13+2*G13+2*I13+K13)
=B14+1/6*(E14+2*G14+2*I14+K14)
=omega0
=C10+1/6*(D10+2*F10+2*H10+J10)
=C11+1/6*(D11+2*F11+2*H11+J11)
=C12+1/6*(D12+2*F12+2*H12+J12)
=C13+1/6*(D13+2*F13+2*H13+J13)
=C14+1/6*(D14+2*F14+2*H14+J14)
D
k1
E
j1
9
10
11
12
13
14
15
=-dt*w02_*SIN(teta)
=-dt*w02_*SIN(teta)
=-dt*w02_*SIN(teta)
=-dt*w02_*SIN(teta)
=-dt*w02_*SIN(teta)
=-dt*w02_*SIN(teta)
=dt*omega
=dt*omega
=dt*omega
=dt*omega
=dt*omega
=dt*omega
9
10
11
12
13
14
15
F
k2
=-dt*w02_*SIN(teta+j1_/2)
=-dt*w02_* SIN(teta+j1_/2)
=-dt*w02_* SIN(teta+j1_/2)
=-dt*w02_* SIN(teta+j1_/2)
=-dt*w02_* SIN(teta+j1_/2)
=-dt*w02_* SIN(teta+j1_/2)
G
j2
=dt*(omega+k1_/2)
=dt*(omega+k1_/2)
=dt*(omega+k1_/2)
=dt*(omega+k1_/2)
=dt*(omega+k1_/2)
=dt*(omega+k1_/2)
9
10
11
12
13
14
15
H
k3
=-dt*w02_*SIN(teta+j2_/2)
=-dt*w02_* SIN(teta+j2_/2)
=-dt*w02_* SIN(teta+j2_/2)
=-dt*w02_* SIN(teta+j2_/2)
=-dt*w02_* SIN(teta+j2_/2)
=-dt*w02_* SIN(teta+j2_/2)
9
10
11
12
13
14
15
J
k4
=-dt*w02_*SIN(teta+j3_)
=-dt*w02_* SIN(teta+j3_)
=-dt*w02_* SIN(teta+j3_)
=-dt*w02_* SIN(teta+j3_)
=-dt*w02_* SIN(teta+j3_)
=-dt*w02_* SIN(teta+j3_)
RK4_02
I
j3
=dt*(omega+k2_/2)
=dt*(omega+k2_/2)
=dt*(omega+k2_/2)
=dt*(omega+k2_/2)
=dt*(omega+k2_/2)
=dt*(omega+k2_/2)
K
j4
=dt*(omega+k3_)
=dt*(omega+k3_)
=dt*(omega+k3_)
=dt*(omega+k3_)
=dt*(omega+k3_)
=dt*(omega+k3_)
1
0,8
0,6
0,4
0 = 0,80 rad
(t=0)=0,15 rad/s
dt = 0,08 s
02=16 rad/s2
0,2
0
-0,2
-0,4
-0,6
-0,8
-1
0
4
tetaRK4
tetaEuler
RK4_02
10
' '+02 = 0
"= - 02
0 = 0,80 rad
(t=0)= 0,15 rad/s
dt = 0,16 s
02=16 rad/s2
1,00
0,80
0,60
0,40
0,20
0,00
-0,20 0
-0,40
-0,60
-0,80
-1,00
tetaRK4
tetaExact
teta =teta0/COS(ATAN(-omega0/w0/teta0))*COS(w0*t+ATAN(-omega0/w0/teta0))
RK4_02
y
dy
=v
dt
L'quation ci-dessus devient :
On pose :
d2 y
dt 2
dv
= -2v - 02 y
dt
Mthode RK4 :
ti
y i
v
i
j
dy
= vi = 1
h
dt i
k
dv
2
= 2 v i 0 y i = 1
h
dt i
ti +
2
j1
dy
h
yi + = yi +
2
dt i 2
k1
dv h
v i + dt 2 = v i + 2
i
k
j
dy
= vi + 1 = 2
2
h
dt ia
k
j k
dv
2
= 2 v i + 1 0 y i + 1 = 2
2
2 h
dt ia
RK4_02
ti +
2
j2
h
dy
yi + = yi +
2
dt ia 2
k2
h
dv
v i + dt 2 = v i + 2
ia
j
k
dy
= vi + 2 = 3
2
h
dt ib
k
j k
dv
2
= 2 v i + 2 0 y i + 2 = 3
2
2 h
dt ib
ti + h
dy
y i + h = y i + j3
dt ib
dv
v i + dt h = v i + k 3
ib
j
dy
= vi + k3 = 4
h
dt ic
k
dv
2
= 2 (v i + k 3 ) 0 (y i + j3 ) = 4
h
dt ic
Soit :
j1 = v t dt
k 1 = 2 v t 02 y t dt
k
j 2 = v t + 1 dt
2
k
j
k 2 = 2 v t + 1 02 y t + 1 dt
2
2
j3 = v t + 2 dt
2
k
j
k 3 = 2 v t + 2 02 y t + 2 dt
2
2
j 4 = [v t + k 3 ] dt
RK4_02
k 4 = 2 [v t + k 3 ] 02 [y t + j3 ] dt
v(t + dt) = v t +
1
[k1 + 2(k 2 + k 3 ) + k 4 ]
6
y(t + dt) = y t +
RK4_02
1
[j1 + 2( j2 + j3 ) + j 4 ]
6
alpha
w02
dt
7
8
9
7
8
9
s-1
s-2
s
1,00
50,0
0,10
v0
y0
j1
0
=A7+dt
=A8+dt
k1
=-dt*(2*alpha*v+w02_*y)
=-dt*(2*alpha*v+w02_*y)
=-dt*(2*alpha*v+w02_*y)
j2
=dt*(v+k1_/2)
=dt*(v+k1_/2)
=dt*(v+k1_/2)
k2
=-dt*(2*alpha*(v+k1_/2)+w02_*(y+j1_/2))
=-dt*(2*alpha*(v+k1_/2)+w02_*(y+j1_/2))
=-dt*(2*alpha*(v+k1_/2)+w02_*(y+j1_/2))
j3
=dt*(v+k2_/2)
=dt*(v+k2_/2)
=dt*(v+k2_/2)
k3
j4
=-dt*(2*alpha*(v+k2_/2)+w02_*(y+j2_/2)) =dt*(v+k3_)
=-dt*(2*alpha*(v+k2_/2)+w02_*(y+j2_/2)) =dt*(v+k3_)
=-dt*(2*alpha*(v+k2_/2)+w02_*(y+j2_/2)) =dt*(v+k3_)
7
8
9
RK4_02
m.s-1
m
=dt*J7
=dt*J8
=dt*J9
7
8
9
0,00
0,05
v
=v0
=J7+L7
=J8+L8
K
y
=y0
=K7+M7
=K8+M8
I
k4
=-dt*(2*alpha*(v+k3_)+w02_*(y+j3_))
=-dt*(2*alpha*(v+k3_)+w02_*(y+j3_))
=-dt*(2*alpha*(v+k3_)+w02_*(y+j3_))
L
k
=1/6*(k1_+2*k2_+2*k3_+k4_)
=1/6*(k1_+2*k2_+2*k3_+k4_)
=1/6*(k1_+2*k2_+2*k3_+k4_)
M
j
=1/6*(j1_+2*j2_+2*j3_+j4_)
=1/6*(j1_+2*j2_+2*j3_+j4_)
=1/6*(j1_+2*j2_+2*j3_+j4_)
Diffrents rgimes :
6,00
Rgime pseudopriodique
5,00
4,00
3,00
- 0 < 0
y(0) = 5 cm
v(0) = 0
=1
02=50
2,00
1,00
0,00
-1,00
-2,00
-3,00
-4,00
0,0
1,0
2,0
3,0
4,0
5,0
0,00
0,00
2,00
4,00
6,00
8,00
10,00
Rgime critique
6,00
2 - 02 = 0
5,00
y(0) = 5 cm
v(0) = 0
=1
02=1
Le retour l'quilibre
s'effectue plus rapidement
que dans le rgime
apriodique
4,00
3,00
2,00
1,00
6,00
Rgime apriodique
2
5,00
- 0 > 0
y(0) = 5 cm
v(0) = 0
=1
02=0,4
4,00
3,00
2,00
1,00
0,00
0,00
RK4_02
5,00
10,00
15,00
20,00
v0
x
ma = mg + R f
Vy3
Vy3
2
R f = Vx i +
j . L'expression
permet de tenir compte de la valeur algbrique.
vy
v y
2
d x = 2
Vx
2
dt
2
V3
d y = g y
dt 2
Vy
Mthode RK4
Pour la projection de l'quation diffrentielle sur l'axe des x :
vx =
dx
dt
dv x
= Vx2
dt
A partir des conditions initiales : t=0 ; y(0)=0; x(0) =0; vx(0), vy(0), on calcule de proche en
proches les valeurs suivantes :
RK4_02
ti
xi
(v x )i
Pi
j
dx
= (v x )i = x1
h
dt i
dv x
dt
2 k
= (v x )i = x1
h
i
ti +
2
dx h
x i + = x i + x1
2
dt i 2
dv
k x1
x h
(v x )i + dt 2 = (v x )i + 2
k
j
dx
= (v x )i + x1 = x2
2
h
dt ia
2
k
k
dv x
= (v x )i + x1 = x2
2
h
dt ia
RK4_02
ti +
2
j
h
dx
x i + = x i + x2
2
dt ia 2
k x2
h
dv x
(v x )i + dt 2 = (v x )i + 2
ia
j
k
dx
= (v x )i + x2 = x3
2
h
dt ib
dv x
dt
k
k
= (v x )i + x2 = x3
2
h
ib
ti + h
dx
x i + h = x i + j x3
dt ib
dv x
(v x )i + dt h = (v x )i + k x 3
ib
j
dx
= (v x )i + k x3 = x4
h
dt ic
dv x
2 k
= ((v x )i + k x3 ) = x4
h
dt ic
(v x )i +1 = (v x )i + 1 [k x1 + 2(k x2 + k x3 ) + k x4 ]i
6
Pi+1
x i +1 = x i +
RK4_02
1
[j x1 + 2( j x2 + j x3 ) + j x4 ]i
6
vy =
dv y
dt
dy
dt
= g
Vy3
vy
A partir des conditions initiales : t=0 ; y(0)=0; x(0) =0; vx(0), vy(0), on calcule de proche en
proches les valeurs suivantes :
ti
yi
v y
( )i
Pi
(v y )i = dy
dt
dv y
dt
j y1
h
( )
( )
v y 3 k y1
i =
= g
h
vy
i
i
ti +
j y1
dy h
yi + = yi +
2
dt i 2
dv y h
= v y + y1
v y i +
i
2
dt i 2
( )
( )
k y1 j y2
dy
=
= vy i +
2
h
dt ia
( )
v y + y1
i
k y2
2
dv y
= g
=
dt
k y1
h
ia
vy +
i
2
( )
( )
RK4_02
ti +
j y2
h
dy
yi + = yi +
2
dt ia 2
k
dv y
h
= v y + y2
v y i +
i
2
dt ia 2
( )
( )
k y2 j y3
dy
=
= vy i +
2
h
dt ib
( )
v y + y2
i
k y3
2
dv y
= g
=
dt
k y2
h
ib
vy +
i
2
( )
( )
ti + h
dy
y i + h = y i + j y3
dt ib
dv y
h = v y + k y3
v y i +
i
dt
ib
( )
j y4
dy
= v y i + k y3 =
h
dt ic
( )
dv y
dt
Pi+1
( )
(( )
( )
(v y )i+1 = v yi + 61 [k y1 + 2(k y2 + k y3 )+ k y4 ]i
yi+1 = yi +
RK4_02
v y + k y3 3 k y4
i
= g
=
h
+
v
k
ic
y i
y3
1
jy1 + 2 jy2 + jy3 + jy4
i
6
dt
g
B
vx0
vy0
0,01
10,0
0,30
4,00
3,00
S
m.s-2
m-1
m.s-1
m.s-1
0,45
0,40
0,35
0,30
0,25
0,20
0,15
0,10
0,05
0,00
0
y=f(x)
RK4_02