Lecture 4
Lecture 4
𝑑! 𝑦 𝑑𝑦
= 𝑓 &𝑥, 𝑦, (
𝑑𝑥 ! 𝑑𝑥
#$
With the initial conditions 𝑦(𝑥" ) = 𝑦" and #% |%! = 𝑦"& . We seek for the solution required for
𝑥" < 𝑥 < 𝑥'
Consider the value of 𝑦(𝑥) in the range [𝑦" , 𝑦' ], where 𝑦' is the value of 𝑦 at 𝑥 = 𝑥' .
The Euler and RK methods require initial values to find the solution. The question is, how to
convert this boundary value problem into initial value problem?
are called Dirichlet boundary conditions. The derivatives of 𝑦 at the boundaries, i.e.
Shooting method
Consider a particle of mass 𝑚 obeying the following 2nd order differential equation
𝑑 ! 𝑥(𝑡)
𝑚 = 𝐹"
𝑑𝑡 !
𝐹" !
𝑥(𝑡) = 𝑡 +𝐴𝑡+𝐵
2𝑚
where the constants A and B can be obtained using the boundary conditions. For example, if
we know the initial position and velocity then we can obtain the values of A and B.
𝑑 𝑥(𝑡) 𝐹"
= 𝑣(𝑡) = 𝑡+𝐴
𝑑𝑡 2𝑚
𝐴 = 𝑣"
The final solution is
𝐹" !
𝑥(𝑡) = 𝑡 + 𝑣" 𝑡 + 𝑥"
2𝑚
𝐹" !
𝑥(𝑡) = 𝑡 +𝐴𝑡+𝐵
2𝑚
At 𝑡 = 𝑇, 𝑥 = 𝑥( . This implies,
𝐹" !
𝑥( = 𝑇 + 𝐴 𝑇 + 𝑥"
2𝑚
Implies,
1 𝐹" !
𝐴= =(𝑥( − 𝑥" ) − 𝑇 ?
𝑇 2𝑚
Question: What value of 𝑣" should we choose such that the particle that starts at 𝑥" to be at
𝑥( at time 𝑇 ?
1 𝐹" !
𝑣" = =(𝑥( − 𝑥" ) − 𝑇 ?
𝑇 2𝑚
Thus, we have turned a boundary value problem into an initial value problem. Why do we need
this conversion? In general, the numerical method that we discussed so far, e.g., Euler and RK,
are initial value problems. Then, how to solve the boundary value problem using these
methods?
Let us consider the ODE
𝑑! 𝑦 𝑑𝑦
!
= 𝑓 &𝑥, 𝑦, (
𝑑𝑥 𝑑𝑥
In order to use one of the numerical methods (Euler and RK) to solve the above problem, we
#$
need to know #% at 𝑥 = 0. So, guess it !!
# $(%,")
Now, using this guessed initial condition #% = 𝛼 (say) calculate 𝑦(𝑥 = 𝐿). Let us say we
get the value 𝑦). with the guessed initial condition.
# $(%,")
Otherwise, choose another initial condition #%
= 𝛽 (say) and repeat the same process.
&
Here, 𝑦#/0 is the desired initial
condition.
1
The line passing through the points (𝑦). , 𝛼) and (𝑦) , 𝛽)
𝛽− 𝛼
1
𝑦) − 𝑦).
12 . &
The line 𝑦 = # 𝑥 + 𝑐 passes through the point (𝑦) , 𝑦#/0 ). It implies,
$" 2$"$
&
𝛽− 𝛼
𝑦#/0 = 1
𝑦) + 𝑐
𝑦) − 𝑦).
The same line passes through the point (𝑦). , 𝛼), from this information one can calculate the
constant value c.
𝛽− 𝛼
𝑐= 𝛼− 1
𝑦).
𝑦) − 𝑦).
Thus,
&
𝛽− 𝛼
𝑦#/0 = 1
(𝑦) − 𝑦). ) + 𝛼
𝑦) − 𝑦).
Example:
x range
With the initial conditions 𝑦(𝑥 = 0) = 0 and 𝑦 & (𝑥 = 0) = 4, we get 𝑦(𝑥 = 9) = 1548
if we choose the increment in x as ℎ = 3. But 1548 is not the desired number.
&
With the use of above two trails, we can get 𝑦#/0 using the formula
&
−24 − 4
𝑦#/0 = (9 − 1548) + 4
−216 − 1548
&
𝑦#/0 = −20.42
Note that if you take a smaller step size, you may get a value very close to zero.
Vectors
𝑑𝑓(𝑥)
= 𝐺(𝑥, 𝑓(𝑥))
𝑑𝑥
with the boundary conditions 𝑓(𝑥 = 𝑎) = 𝑓3 . If we have more than one coefficient obeying the
same differential equation, then we can express them in the vector form as
̅
𝑑𝑓(𝑥)
̅
= 𝐺̅ 1𝑥, 𝑓(𝑥)2
𝑑𝑥
The corresponding initial conditions are expressed in vector form as 𝑓 ̅(𝑥 = 𝑎) = 𝑓3̅
Example: Consider the case of a classical Harmonic oscillator (without any damping)
𝑑 ! 𝑥(𝑡)
𝑚 = −𝑘 𝑥(𝑡)
𝑑𝑡 !
𝑑 ! 𝑥(𝑡)
= −𝜔! 𝑥(𝑡)
𝑑𝑡 !
𝑑𝑥
=𝑣
𝑑𝑡
𝑑𝑣
= −𝜔! 𝑥
𝑑𝑡
Note that here both 𝑣 and 𝑥 are functions of time 𝑡. The above two equation can be written in
vector form as
𝑑 𝑥 𝑣
Y Z=Y ! Z
𝑑𝑡 𝑣 −𝜔 𝑥
𝑑
𝑓 ̅ = 𝐺̅
𝑑𝑡
𝑥 𝑣
Where 𝑓 ̅ = Y Z and 𝐺̅ = Y ! Z.
𝑣 −𝜔 𝑥
𝑑 𝑥 𝑣 0 1 𝑥
Y Z=Y ! Z = Y ZY Z
𝑑𝑡 𝑣 −𝜔 𝑥 −𝜔! 0 𝑣
𝑑 0 1 ̅
𝑓̅ = Y ! Z𝑓
𝑑𝑡 −𝜔 0
̅ 1 0 ̅ 0 1 ̅
𝑓456 =Y Z 𝑓4 + ℎ Y ! Z𝑓
0 1 −𝜔 0 4
̅
𝑓456 = 𝔇𝑓4̅
1 ℎ
where the matrix 𝔇 = Y Z and ℎ is the increment in time (time step). The nth step of
−𝜔! ℎ 1
the method can be written in terms of 𝔇 as
𝑓4̅ = 𝔇4 𝑓"̅
where 𝑓"̅ contains initial values. The spectral radius (the maximum of the absolute eigen value)
of this matrix 𝔇 is
𝜌(𝔇) = ]1 + 𝜔 ! ℎ!
The norm of the vector 𝑓4̅ will grow with each successive step, i.e., ℎ. This growth will
render any solution useless after some number of iterations. A method with this sort of
intrinsic growth is called an unstable method.
The lack of stability is nothing to do with the local error i.e., 𝑜(ℎ! ). The growth is due to the
definition of the method itself. We can fix this behavior by modifying the method.
1 0 ̅ 1 0 ̅ 0 1 ̅
Y Z 𝑓456 = Y Z 𝑓4 + ℎ Y ! Z𝑓
0 1 0 1 −𝜔 0 456
Note that the difference between forward and backward methods is in the 2nd term on RHS. In
the forward method it is 𝑓4̅ and in the backward method it is 𝑓456
̅ .
1 −ℎ ̅
Y Z𝑓 = 𝑓4̅
𝜔! 1 456
̅
𝔇 𝑓456 = 𝑓4̅ → 𝑓456
̅ = 𝔇26 𝑓4̅
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
𝑦4 = 𝑦4∗ + 𝑒4
∗
𝑦4∗ + 𝑒4 + ℎ 𝑓(𝑥4 , 𝑦4∗ ) + ℎ 𝑒4 𝑓 & = 𝑦456 + 𝑒456
∗
𝑦4∗ + ℎ 𝑓(𝑥4 , 𝑦4∗ ) + 𝑒4 (1 + ℎ 𝑓 & ) = 𝑦456 + 𝑒456
∗ ∗
𝑦456 + 𝑒4 (1 + ℎ 𝑓 & ) = 𝑦456 + 𝑒456
This implies,
𝑒456 = 𝑒4 (1 + ℎ 𝑓 & )
If (1 + ℎ 𝑓 & ) < 1 then errors will damp down with successive iterations. In this case, the
Euler’s method is said to be stable. The error builds up in Euler’s method is substantial.
Backward error and forward error
Let us consider the function 𝑦 = 𝑓(𝑥), and the approximate value of 𝑦 is 𝑦b.
Forward error:
$<2$
Relative forward error c $
c
Backward error:
𝑦b is the exact value at 𝑓(𝑥 + ℎ). Then |ℎ| is the backward error (see the diagram).
Example:
$<2$
Relative forward error c $
c ≈ 0.0100410126
Backward error: