0% found this document useful (0 votes)
28 views9 pages

Lecture 4

The document discusses converting boundary value problems into initial value problems that can be solved using numerical methods like Euler's method and Runge-Kutta. It explains that these methods require initial conditions, so the shooting method guesses an initial derivative value, integrates to find the endpoint, and iteratively adjusts the initial guess until the endpoint condition is met. The document also discusses representing systems of differential equations as vector equations and gives an example of a harmonic oscillator problem in vector form.

Uploaded by

Debayan Biswas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views9 pages

Lecture 4

The document discusses converting boundary value problems into initial value problems that can be solved using numerical methods like Euler's method and Runge-Kutta. It explains that these methods require initial conditions, so the shooting method guesses an initial derivative value, integrates to find the endpoint, and iteratively adjusts the initial guess until the endpoint condition is met. The document also discusses representing systems of differential equations as vector equations and gives an example of a harmonic oscillator problem in vector form.

Uploaded by

Debayan Biswas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computational Physics: Lecture – IV

Initial value problem

Consider a second order differential equation

𝑑! 𝑦 𝑑𝑦
= 𝑓 &𝑥, 𝑦, (
𝑑𝑥 ! 𝑑𝑥
#$
With the initial conditions 𝑦(𝑥" ) = 𝑦" and #% |%! = 𝑦"& . We seek for the solution required for
𝑥" < 𝑥 < 𝑥'

Boundary value problem

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?

Note that the boundary conditions

𝑦 (𝑥 = 0) = 𝑦" and 𝑦 1𝑥 = 𝑥' 2 = 𝑦'

are called Dirichlet boundary conditions. The derivatives of 𝑦 at the boundaries, i.e.

𝑦 & (𝑥 = 0) = 𝑦"& and 𝑦 & 1𝑥 = 𝑥' 2 = 𝑦'&

are called Neumann conditions.

Shooting method

Consider a particle of mass 𝑚 obeying the following 2nd order differential equation

𝑑 ! 𝑥(𝑡)
𝑚 = 𝐹"
𝑑𝑡 !

The analytical solution of this equation is

𝐹" !
𝑥(𝑡) = 𝑡 +𝐴𝑡+𝐵
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.

At 𝑡 = 0, 𝑥 = 𝑥" and 𝑣 = 𝑣"


This implies, 𝐵 = 𝑥" and using the following equation, we get

𝑑 𝑥(𝑡) 𝐹"
= 𝑣(𝑡) = 𝑡+𝐴
𝑑𝑡 2𝑚

𝐴 = 𝑣"
The final solution is
𝐹" !
𝑥(𝑡) = 𝑡 + 𝑣" 𝑡 + 𝑥"
2𝑚

This is called the initial value problem.


If, instead of initial conditions, assume that we have the boundary conditions at 𝑡 = 0 and
𝑡 = 𝑇, where 𝑇 is some final time. Using this information, we can find the unknowns as

𝐹" !
𝑥(𝑡) = 𝑡 +𝐴𝑡+𝐵
2𝑚

At 𝑡 = 0, 𝑥 = 𝑥" . This implies, 𝐵 = 𝑥"

At 𝑡 = 𝑇, 𝑥 = 𝑥( . This implies,

𝐹" !
𝑥( = 𝑇 + 𝐴 𝑇 + 𝑥"
2𝑚

Implies,

1 𝐹" !
𝐴= =(𝑥( − 𝑥" ) − 𝑇 ?
𝑇 2𝑚

The final solution is


𝐹" ! 𝑡 𝐹" !
𝑥(𝑡) = 𝑡 + =(𝑥( − 𝑥" ) − 𝑇 ? + 𝑥"
2𝑚 𝑇 2𝑚

This is called the boundary value problem.

Question: What value of 𝑣" should we choose such that the particle that starts at 𝑥" to be at
𝑥( at time 𝑇 ?

It is obvious from the above two solutions that

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

𝑑! 𝑦 𝑑𝑦
!
= 𝑓 &𝑥, 𝑦, (
𝑑𝑥 𝑑𝑥

With the boundary conditions 𝑦(𝑥 = 0) = 𝑦" and 𝑦(𝑥 = 𝐿) = 𝑦)

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.

If 𝑦). − 𝑦) (actual value) = 0 then we are lucky !

# $(%,")
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 (𝑦) , 𝛽)

The slope (m) of this line is

𝛽− 𝛼
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:

Consider 2nd ODE


𝑑! 𝑦
− 2 𝑦 = 8 𝑥 (9 − 𝑥)
𝑑𝑥 !

With the boundary conditions 𝑦(𝑥 = 0) = 0 and 𝑦(𝑥 = 9) = 0

x range

1) Try with 𝑦 & (𝑥 = 0) = 4.

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.

2) Try with 𝑦 & (𝑥 = 0) = −24.

With the initial conditions 𝑦(𝑥 = 0) = 0 and 𝑦 & (𝑥 = 0) = −24, we get


𝑦(𝑥 = 9) = −216 for the same increment in x as ℎ = 3. But -216 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

This will give 𝑦(9) = 0.09, which is close to zero !!

Note that if you take a smaller step size, you may get a value very close to zero.

Vectors

So far, we are using a single variable in the differential equation,

𝑑𝑓(𝑥)
= 𝐺(𝑥, 𝑓(𝑥))
𝑑𝑥

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)

𝑑 ! 𝑥(𝑡)
𝑚 = −𝑘 𝑥(𝑡)
𝑑𝑡 !
𝑑 ! 𝑥(𝑡)
= −𝜔! 𝑥(𝑡)
𝑑𝑡 !

Where 𝜔! = 𝑘/𝑚. The above 2nd order ODE can be expressed as

𝑑𝑥
=𝑣
𝑑𝑡
𝑑𝑣
= −𝜔! 𝑥
𝑑𝑡

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.
𝑣 −𝜔 𝑥

Stability of numerical methods


The above equation is re-written as

𝑑 𝑥 𝑣 0 1 𝑥
Y Z=Y ! Z = Y ZY Z
𝑑𝑡 𝑣 −𝜔 𝑥 −𝜔! 0 𝑣

𝑑 0 1 ̅
𝑓̅ = Y ! Z𝑓
𝑑𝑡 −𝜔 0

Thus, the increment in 𝑓 ̅ is

̅ 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.

The backward Euler method is defined as

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̅

The nth step of this method can be written as

𝑓4̅ = (𝔇26 )4 𝑓"̅


6
The corresponding norm of the vector 𝑓4̅ will grow as √658% % < 1 (for 𝜔 > 0).
9
This method is stable because 𝑥(𝑡) is converging. The results obtained by the backward method
may be physical. In general, oscillations decay due to damping.
However, the ideal behavior is

Stability of the program

Consider the Euler’s method for the 1st order ODE

𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥

Let us say the error in 𝑦4 in the nth step is 𝑒4

𝑦4 = 𝑦4∗ + 𝑒4

where 𝑦4∗ is the actual value. Similarly, in n+1 step



𝑦456 = 𝑦456 + 𝑒456

𝑦4 + ℎ 𝑓(𝑥4 , 𝑦4 ) = 𝑦456 + 𝑒456

(𝑦4∗ + 𝑒4 ) + ℎ 𝑓(𝑥4 , 𝑦4∗ + 𝑒4 ) = 𝑦456 + 𝑒456

By expanding 𝑓(𝑥4 , 𝑦4∗ + 𝑒4 ), we get

𝑓(𝑥4 , 𝑦4∗ + 𝑒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:

Absolute forward error | 𝑦b − 𝑦|

$<2$
Relative forward error c $
c

Backward error:

𝑦b is the exact value at 𝑓(𝑥 + ℎ). Then |ℎ| is the backward error (see the diagram).

Example:

𝑦 = √𝑥 . As a test case, take 𝑥 = 2, and the approximate value 𝑦b = 1.4

The forward error | 𝑦b − 𝑦| = |1.4 − 1.4142135623| ≈ 0.0142

$<2$
Relative forward error c $
c ≈ 0.0100410126

Backward error:

𝑦b = 𝑓(𝑥 + ℎ) → 1.4 = √1.96

Implies, ℎ = |2 − 1.96| = 0.04

You might also like