Implicit Euler
Short Description
This is a lecture note Implicit Euler (part 1) method taught at University of Melbourne. It shows how this method being ...
Description
ENGR90024 Computational Fluid Dynamics
Lecture O06 The Implicit Euler Method!
(see page 18 of printed lecture notes) Our analysis thus far shows that the explicit Euler’s method is not very accurate or stable. To come up with a method that is more stable, consider the Taylor series expanded about t=tl 2 2 3 3 t d t d t d l+1 l l l l +... (t ) = (t ) + (t ) + + (t ) (t ) 3 2 3! dt 2! dt 1! dt
If we now expand the Taylor series about t=tl+1
(tl ) = (tl+1 )
t d l+1 t2 d 2 l+1 (t ) + (t ) 2 2! dt 1! dt
Ignoring higher order terms give
t3 d 3 l+1 + . . . (t ) 3! dt3
(see page 18 of printed lecture notes) Our analysis thus far shows that the explicit Euler’s method is not very accurate or stable. To come up with a method that is more stable, consider the Taylor series expanded about t=tl 2 2 3 3 t d t d t d l+1 l l l l +... (t ) = (t ) + (t ) + + (t ) (t ) 3 2 3! dt 2! dt 1! dt
If we now expand the Taylor series about t=tl+1
Ignoring higher order terms give l
(t ) = (t
l+1
)
t d l+1 f(t ( l+1) , tl+1 ) 1! dt
Hence,
l+1
=
l
+
tf (
The above equation is called the implicit Euler method.
l+1
l+1
,t
)
l+1
=
l
+
tf (
l+1
, tl+1 )
Eq. (O06.1) is the formula for the implicit Euler method.
Compare now with the formula for the explicit Euler method
l+1
=
l
+
l
l
tf ( , t )
The only difference is the time level the right hand side, dɸ/dt=f(ɸ,t) is evaluated at. For the explicit Euler method, the function f(ɸ,t) is evaluated at time level tl. For the implicit Euler method, the the function f(ɸ,t) is evaluated at time level tl+1. This will give rise to complications, especially if f(ɸ,t) is a nonlinear function (see later).
(O06.1)
(t)
Smaller Δt will lead to smaller error
True value of ɸl+1 Error l
Predicted value of ɸl+1
t t
l
t
l+1
(t)
Smaller Δt will lead to smaller error
True value of ɸl+1 Error Predicted value of
l
t t
l
t
l+1
l+1 ɸ
(t)
Smaller Δt will lead to smaller error
True value of ɸl+1 Error
Predicted value of ɸl+1
l
t t
l
t
l+1
Example O06.1: !
Using implicit Euler’s method, solve
! ! ! ! !
d =1 dt
For 0 < t < 8 with ɸ(t=0)=0 and a) Δt=2 b) Δt=1 c) Δt=0.5 d) Δt=0.1
!
Compare your solution with the explicit Euler’s method
Start with the implicit Euler’s formula
l+1
=
l
+
l+1
tf (
l+1
,t
Replace f(ɸ,t) with the function given in the question
l+1
=
l
+
l+1
t (1
Rearranging gives
l+1
l
+ t = 1+ t
)
)
function MPO06p1() close all clear all tmin=0.0; tmax=8.0; [t1,phi1]=MyImplicitEuler([tmin tmax],0.0,1.0);
Output
plot(t1,phi1,'ko-'); hold on ezplot(@(t)1-exp(-t),[0,8,0,2]) xlabel('t'); ylabel('\phi'); legend('Euler','True');
function [t,phi]=MyImplicitEuler(tspan,phi0,Delta_t) t=tspan(1):Delta_t:tspan(2); phi=zeros(length(t),1); phi(1)=phi0; for n=1:length(t)-1 phi(n+1)=(phi(n)+Delta_t)/(1+Delta_t); end
1−exp(−t)
2
Euler True
1.8 1.6 1.4
φ
1.2 1 0.8 0.6 0.4 0.2 0
0
1
2
3
4 t
5
6
7
8
1−exp(−t)
2
Euler True
Δt=2.0
1.8
1.8
1.6
1.4
1.2
1.2
1
1
φ
φ
Euler True
Δt=1.0
1.6
1.4
0.8
0.8
0.6
0.6
0.4
0.4
0.2 0
1−exp(−t)
2
0.2 0
1
2
3
4 t
5
6
7
8
0
0
1
2
3
4 t
5
6
7
8
1−exp(−t)
2 1.8
Δt=0.5
1.6
1−exp(−t)
2
Euler True
Euler True
Δt=0.1
1.8 1.6
1.4 1.4 1.2 1 φ
φ
1.2 1
0.8 0.8 0.6 0.6 0.4 0.4 0.2 0.2 0
0
1
2
3
4 t
5
6
7
8
0
0
1
2
3
4 t
5
6
7
8
Compare implicit and explicit Euler’s method for Δt=2.0
1−exp(−t)
2
2
Euler True
Δt=2.0
1.8
1.6
1.4
1.4 1.2
1 φ
φ
1.2
0.8
1 0.8
0.6
0.6
0.4
0.4
0.2 0
Δt=2.0
1.8
1.6
Euler True
0.2
0
1
2
3
4 t
5
6
7
8
0
0
1
2
3
4 t
Implicit Euler’s method is much more stable than the explicit Euler’s method
5
6
7
8
End of Example O06.1
Stability analysis of the implicit Euler Method We will now analyse why the Implicit Euler method is so stable. Consider the model problem
d = dt Applying the implicit Euler method gives
(1
t)
l+1
=
l
l+1
=
l
l+1 l+1
= =
+
t
l+1
1 1
t l
l
Observe that
| |=
1 1
=p
t 1 (1
Re
t)2 + (
Im
t)2
Hence, the stability region is given by
(1
Re
t)2 + (
This is any area outside a circle of radius 1 centred at (1,0)
Im
t)2
1
(1
Re
2
t) + (
Im
t)
2
1
Im
t
1
2
Re
t
(1
Re
2
t) + (
Im
t)
2
1
Im
t
1
2
Re
Note that the implicit Euler method is will be stable as long as λRe is negative. This does not mean the the Euler method is accurate, only that the method is very stable. The implicit Euler method is much more stable than the explicit Euler method.
t
Implicit Euler’s method for a system of equations So far, we have learnt to solve single ODE using implicit Euler method. What if you are required a system of M ODEs? d 1 = f1 ( 1 , 2 , 3 , . . . . . . , dt d 2 = f2 ( 1 , 2 , 3 , . . . . . . , dt d 3 = f3 ( 1 , 2 , 3 , . . . . . . , dt .. .. .=. d M = fM ( 1 , 2 , 3 , . . . . . . , dt
M , t) M , t) M , t)
M , t)
Implicit Eulers method can easily be extended to solve a system of M equations
d 1 = f1 ( dt
d 1 = f1 ( dt d 2 = f2 ( dt d 3 = f3 ( dt
1 , t)
IMPLICIT EULER l+1 1
l 1
=
d 1 = f1 ( dt d 2 = f2 ( dt
+ f1 (
l l 1, t )
1,
2 , t)
1,
2 , t)
t
IMPLICIT EULER l+1 1 l+1 2
= =
l 1 l 2
+ f1 ( + f2 (
l+1 1 , l+1 1 ,
l+1 l+1 ) 2 ,t l+1 l+1 ) 2 ,t
t
1,
2,
3 , t)
1,
2,
3 , t)
1,
2,
3 , t)
t
IMPLICIT EULER l+1 1 l+1 2 l+1 3
= = =
l 1 l 2 l 3
+ f1 ( + f2 ( + f3 (
l+1 1 , l+1 1 , l+1 1 ,
l+1 2 , l+1 2 , l+1 2 ,
l+1 l+1 ) 3 ,t l+1 l+1 ) 3 ,t l+1 l+1 ) 3 ,t
t t t
If {f} is a linear function, then the system of equations can be put in matrix form as d 1 = f1 ( 1 , 2 , 3 , t) dt d 2 = f2 ( 1 , 2 , 3 , t) dt d 3 = f3 ( 1 , 2 , 3 , t) dt 8 d < dt :
1 2 3
9 =
2
K11 = 4 K21 ; K31
K12 K22 K32
K13 K23 K33
38 < 5 :
1 2 3
9 = ;
8 d < dt :
1 2 3
9 =
2
K11 = 4 K21 ; K31
K12 K22 K32
K13 K23 K33
38 < 5 :
1 2 3
9 = ;
d { } = [K] { } dt Applying implicit Euler’s formula gives
l+1
[I
=
l
+ [K]
[K] t] l+1
l+1
= [I
l+1
= [K] t]
t l 1
l
Example O06.2
! Rewrite the program MPO05p1.m and use functions to solve the following two ODEs ! ⇢ ⇢ ! d 0 1 1 1 ! = ! 4 1 dt 2 2 ! for 0 < t < 10 with ɸ1(t=0)=1 and ɸ2(t=0)=0. For this question
[K] =
0 4
So
[I
[K] t] =
1 1
1 0 0 1
0 4
For a linear set of ODEs, the implicit Euler’s formula gives
l+1
= [I
[K] t]
1
l
1 1
t
function MPO06p2()! !
close all! clear all! !
tmin=0.0;! tmax=10.0;! !
phi0=[1 0];! Delta_t=0.01;! !
[t,phi]=MyEulerLinearSysODEs(@f,[tmin tmax],phi0,Delta_t);! !
plot(t,phi(:,1),'k-',t,phi(:,2),'r-');! legend('\phi_1','\phi_2');!
[K] =
! ! ! !
0 4
1 1
[K] t]
1
function [t,phi]=MyEulerLinearSysODEs(ode,tspan,phi0,Delta_t)! !
a=tspan(1);! b=tspan(2);!
[I
!
t=a:Delta_t:b;! !
phi=zeros(length(t),numel(phi0));! !
phi(1,:)=phi0; !
K=[0 1; -4 -1];! temp=inv(eye(2)-K*Delta_t)! !
for n=1:length(t)-1! temp2=temp*phi(n,:)'! phi(n+1,:)= temp2';! end
%setting initial conditions!
l+1
= [I
[K] t]
1
l
5
3
3
2
φ1
φ1
φ2
φ2
Δt=1.0
1
1
0
0
−1
−1
−2
−2
−3
0
1
2
3
4
5
6
7
Δt=0.5
2
8
9
10
−3
0
1
2
3
4
6
7
8
9
10
3
3 φ1
φ1
φ2
φ2
2
2
Δt=0.2
Δt=0.1
1
1
0
0
−1
−1
−2
−2
−3
5
0
1
2
3
4
5
6
7
8
9
10
−3
0
1
2
3
4
5
6
7
8
9
10
Note that the solution computed using implicit Euler’s method is stable for all Δt. This is in! contrast with the solution computed using explicit Euler’s method which was unstable for larger! values of Δt (see Example O05.1)
End of Example O06.2
Nonlinear ODEs
Example O06.3a: Use explicit Euler’s method to solve the ODE! !
d = dt
!
2
! in the domain 0
View more...
Comments