Professional Documents
Culture Documents
Simultaneous or Coupled
First Order ODEs
Euler method
I1
t=0
I1
C = 0.25 farad
I2
I2
R1 =4 ohms
V = 12 Volts
R2 =4 ohms
This has two coupled loops. The Kirchoffs law for voltage
balance can yield the model equations:
12 1 dI1 / dt 4( I1 I 2 )
or
dI1
4 I1 4 I 2 12
dt
Where I1 is the current in first loop and I2 is the current in the second
loop. For the next loop again the voltage balance gives:
0 6 I 2 4( I 2 I1 ) 4 I 2 dt
When we differentiate it we get the following balance equation:
dI 2
dI1
0 10
4
4I 2
dt
dt
dI 2
dI1
0.4
0.4 I 2 0
dt
dt
dI1
4 I1 4 I 2 12
dt
dI 2
dI1
0.4
0.4 I 2 0
dt
dt
Switch
I1
t=0
I1
C = 0.25 farad
I2
R1 =4 ohms
V = 12 Volts
R2 =4 ohms
I2(0) =0.0
I2
T1
T2
T1
2
2
y2
y1 (T1 )
100
100
2
2
y 2 inflow/min - outflow/min
y1
y2 (T2 )
100
100
Hence, mathematical model is a system of first order ODEs:
y 1 inflow/min - outflow/min
T2
Simultaneous ODEs
We have already gone through various methods to solve numerically
a single ODE such as dy/dt = f(t, y).
The methods can be modified easily to solve coupled (say two)
ODEs. For example, we have two first order simultaneous Ordinary
Differential Equations with initial conditions.
dx
f t , x, y ,
dx
dy
g t , x, y ,
dx
x t0 x0 , y t0 y0 , t t0
Simultaneous ODEs
The methods used for a single ODE were:
Euler method
Improved Euler
Runge Kutta, order 2
Runge Kutta, order 4
Now each of these will be used for two simultaneus first order
ODEs. The general form will be
dx
f t , x, y ,
dx
dy
g t , x, y ,
dx
x t0 x0 , y t0 y0 , t t0
dx
f t , x, y ,
dx
dy
g t , x, y ,
dx
x t0 x0 , y t0 y0 , t t0
h xi 1 xi
h yi 1 yi
x1 x0 h f t0 , x0 , y0
y1 y0 h g t0 , x0 , y0
x3 x2 h f t 2 , x2 , y2
y3 y 2 h g t 2 , x2 , y 2
x2 x1 h f t1 , x1 , y1
xn 1 xn h f t n , xn , yn
y2 y1 h g t1 , x1 , y1
yn 1 yn h g t n , xn , yn
dx / dt f (t , x, y ) t x y,
dy / dt g (t , x, y ) 2t 3 x y,
x ( 0) 1 , y ( 0) 2
Solution:
t0 0
x0 1,
y0 2 ,
f (t , x, y ) t x y,
h 0.1;
f (t0 , x0 , y0 ) 0 1 2 3,
g (t , x, y ) 2t 3 x y, g (t0 , x0 , y0 ) 0 3 2 1,
Example 1:
1st point:
t1 t 0 h 0 0.1 0.1
x1 x0 h f t 0 , x0 , y0 1 (0.1)(3) 1.3
y1 y0 h g t 0 , x0 , y0 2 (0.1)(1) 2.1
2nd point:
3rd point:
A computer program
% It Uses Euler method to solve Simultaneous first order
odes:
%
dx/dt = -t + x + y ; x(0) = 1.0
%
dy/dt = 2*t + 3*x y ; y(0) = 2.0
%
Input: x0 = initial guess; h = step size (h = 0.1)
%
n = number of iterations; default: n = 10;
%
Output: estimate of x and y;
n = 10; t0 = 0.0; x0=1.0; y0 = 2.0; h = 0.1;
t = t0; x = x0;
y = y0;
% Initial Guess
fprintf('
time
x-est
y-est
\n');
for k=1:n
f = -t + x + y ;
g = 2*t + 3*x - y ;
t = t + h; x = x + h*f ; y = y + h*g ;
fprintf('%6.2f %12.6f
%12.6f \n', t, x, y );
end
Example 1 :
These results are approximate values of x and y as a function of
time and error is substantially large
time
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
>>
x-est
1.300000
1.630000
2.003000
2.433200
2.936520
3.531168
4.238277
5.082632
6.093519
7.305711
y-est
2.100000
2.300000
2.599000
3.000000
3.509960
4.139920
4.905278
5.826234
6.928400
8.243616
x(t 0) x0
v(t 0) v0
dx
v f (t , x, v)
dt
dv
k
c
v x g (t , x, v)
dt
m
m
Now assume,
c=1
m=1
k =1
dx / dt f (t , x, y ) v, x(0) 0 , v(0) 1
dv / dt g (t , x, y ) x v,
t0 0
x0 0,
v0 1,
h 0.1;
f (t , x, v) v,
f (t0 , x0 , v0 ) 1
g (t , x, v) x v,
g (t0 , x0 , v0 ) 0 1 1,
x1 x0 h f t0 , x0 , y0 0 (0.1)(1) 0.1
v1 v0 h g t0 , x0 , y0 1 (0.1)(1) 0.9
t1 t0 h 0 0.1 0.1
This can be further continued for t = 0.2, 0.3 and so on.
d 2x k
d 2x
x
4x 0
2
2
dt
m
dt
The initial conditions are
x(0) =0.2,
x(0) =0
and t = 0.02.
dx
v f (t , x, v)
dt
dv
g (t , x, v) 4 x
dt
x-est
0.200000
0.192000
0.176000
0.152320
0.121600
0.084787
0.043110
-0.001958
-0.048751
y-est
-0.080000
-0.160000
-0.236800
-0.307200
-0.368128
-0.416768
-0.450683
-0.467927
-0.467144
exact-x
0.196013
0.184212
0.165067
0.139341
0.108060
0.072472
0.033993
-0.005840
-0.045440
error (%)
2.033884
4.227625
6.623292
9.314291
12.529596
16.993771
26.819805
66.473972
7.284645
1.00
-0.095465
-0.447644
-0.083229
14.701077
Euler Example
xi 1 xi t vi
0.5
vi 1 vi t 4vi
0.4
0.3
actual value
Displacement
0.2
0.1
0
-0.1
0.5
-0.2
-0.3
-0.4
-0.5
Time (t)
1.5
x f t , x, y ,
y g t , x, y ,
x t0 x0 , y t0 y0 , t t0
h xi 1 xi
h yi 1 yi
x1p x0 h f t 0 , x0 , y0 ;
y1p y0 h g t 0 , x0 , y0
h / 2 g t , x , y g t , x , y
h f t , x , y ;
y y h g t , x
h / 2 f t , x , y f t , x , y
h / 2 g t , x , y g t , x , y
x1c x0 h / 2 f t 0 , x0 , y0 f t 0 , x 1p , y 1p
y1c y0
x 2p x 1c
x2c x 1c
y 2c y 1c
c
1
c
1
p
2
p
2
p
2
p
2
c
,
y
1
1
y
True
value
y1
y0
h
xo
x1
h xi 1 xi
c
n 1
h
x f (t n , xnc , ync ) f t n , xnp1 , ynp1
2
c
n
c
n 1
h
y g (t n , xnc , ync ) g t n , xnp1 , ynp1
2
c
n
x ( 0) 1
y ( 0) 2
1st step:
t1 t0 h 0 0.1 0.1
x ( 0) 1
y ( 0) 2
2nd step:
t 2 t1 h 0.1 0.1 0.2
x2p 1.315 (0.1 1.315 2.15) 0.1 1.315 0.3365 1.6515
y2p 2.15 (2 0.1 3 1.315 2.15) 0.1 2.15 0.1995 2.3495
g t , x
p
2
, y2p
A computer program
% It Uses Improved Euler method to solve two Simultaneous first order odes:
%
dx/dt = -t + x + y ; x(0) = 1.0
%
dy/dt = 2*t + 3*x y ; y(0) = 2.0
% Input: x0 = initial guess; h = step size (h = 0.1)
%
n = number of iterations; default: n = 10;
% Output: estimate of x and y;
n = 10; t0 = 0.0; x0=1.0; y0 = 2.0; h = 0.1;
t = t0; x_c = x0; y_c = y0; % Initial Guess
fprintf(' time
x-p
x_c
y_p
y_c
\n');
for k=1:n
fa = ( -t + x_c + y_c );
ga = ( 2.*t + 3.*x_c - y_c );
x_p = x_c + h*fa;
y_p = y_c + h*ga;
fb = ( -(t+h) + x_p + y_p);
gb = ( 2.*(t+h) + 3.*x_p - y_p );
x_c = x_c + (h/2.)*(fa + fb);
y_c = y_c + (h/2.)*(ga + gb);
fprintf('%6.2f %12.5f %12.5f %12.5f %12.5f \n', t, x_p, x_c, y_p, y_c );
t = t + h;
end
x_p
1.30000
1.65150
2.06063
2.54460
3.12361
3.82160
4.66726
5.69511
6.94694
8.47338
x_c
1.31500
1.67330
2.09010
2.58291
3.17227
3.88255
4.74291
5.78847
7.06171
8.61412
y_p
2.10000
2.34950
2.70199
3.16652
3.75658
4.49064
5.39287
6.49411
7.83312
9.45805
y_c
2.15000
2.40000
2.75499
3.22412
3.82106
4.56456
5.47916
6.59620
7.95504
9.60465
Example 2:
A comparison table for estimated values for Euler and Improved
Euler method
Time
Euler Method
Improved Euler
(t)
x(t)
y(t)
x(t)
y(t)
0.1
1.30
2.1
1.3150
2.150
0.2
1.63
2.3
1.6733
2.400
0.3
2.0030
2.599
2.0901
2.755
0.4
2.4332
3.00
2.5829
3.2241
0.5
2.9365
3.51
3.1723
3.8211