Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.1
Lecture 7
Numerical Techniques : Differential
Equations - Boundary Value
Problems
Laplace Equation in Electrostatics
IKC-MH.55 Scientific Computing with Python at December 08,
2023
Dr. Cem Özdo
˘
gan
Engineering Sciences Department
˙
Izmir Kâtip Çelebi University
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.2
Contents
1 Differential Equations - Boundary Value Problems
Boundary Value Problems
Trial-and-Error (Linear Shooting) Method
Laplace Equation in Electrostatics
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.3
Differential Equations
1 Initial Value Problems.
2 Boundary Value Problems:
The solution of the differ ential equation is searched within
certain constraints, called the boundary conditions. For
example,
d
2
y
dx
2
= f (x, y , y
′
)
•
If the solution of the equation in the interval of x : [ 0, L] is
required,
•
the values at the y(0) and y(L) boundaries should be given.
3 Eigenvalue (characteristic-value) Problems.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.4
Boundary/Eigen Value Problems I
•
Consider a 2nd-order differential equation in the interval
[a,b]:
y
′′
= f (x, y, y
′
)
Two necessary conditions for the solution
of this equation are given at two extremes:
y(a) = A
y(b) = B
•
This problem is more difficult to solve than the initial value
problem that we previously discussed.
•
In initial value problem, y(0) and y
′
(0) are both given at
x = 0.
•
It was possible to start with these two initial values and
progress th e sol ution through the interval.
•
In the boundary value problem, the number of ini tial
conditions is insufficient.
•
We cann ot directly obtain the solution with methods
such as Euler or Runge-Kutta.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.5
Boundary/Eigen Value Problems II
•
Eigenvalue problems are even more difficult.
•
See the following 2nd degree differential equation:
y
′′
= f (x, y , y
′
: λ)
•
Again, let the boundary conditions of this equation to be
given at both ends.
•
If these conditions can only be satisfied for certain λ
values, we call it the eigenvalue problem.
•
e.g.: Vibrations of a wire with both ends fixed give stable
solution o nly for certain wavelengths.
•
e.g.: Solutions of the Schrödinger equation that are zero at
infinity exist only for certain energy eigenvalues.
•
In terms of numerical solu tion, boundar y value and
eigenvalue problems are solved by the same method.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.6
Linear Shooting I
Figure: First guess.
Figure: Second guess.
. . .
Figure: Expected
result.
•
The bas ic approach in s olving boundary value and
eigenvalue problems is known as the t rial-and -error
method.
•
At one boundary, the soluti on is started by giving an
estimated value to the missing initial condition,
•
A trial solution is then found with either Euler or
Runge-Kutta method at the other boundary (First guess),
•
How much deviation from the g iven boundary condition is
determined,
•
Taking this deviation into account, a new solution is
restarted wi th a new estimation (Second g uess),
•
This process is repeated (. . .) until the other boundary
condition is satisfied (Expected result).
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.7
Linear Shooting II
•
Let’s see this method on an example:
y
′′
(x) − (4x
2
− 2)y = 0 y(0) = 1.0
with BCs y(1) = 1/e = 0.36787944
•
This differential equation has the solution of y = e
(−x
2
)
(Gaussian function).
First, let’s transform this
boundary value problem into a
first-order system of equations:
•
y
1
= y
•
y
2
= y
′
•
dy
1
dx
= y
2
•
dy
2
dx
= (4x
2
−2)y
1
•
Notice that the boundary conditions are given only for
y
1
: y
1
(0) = 1.0 and y
1
(1) = 0.368.
•
Notice that there is no initial condition for y
2
.
•
Now, we have a set of equations.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.8
Linear Shooting III
•
Here, let’s take an estimated initial value of a:
first guess : y
2
(0) = a
•
Now, find the solutions y
1
(x) and y
2
(x) (by let’s say RK4)
with these y
1
(0) and y
2
(0) values.
•
Denote the value obtained for y
1
in the other boundary
with y
1a
(1)
•
and find the difference (∆
a
) with the real one y
1
(1) (here,
0.368):
y
2
(0) = a → solution : y
1a
(x) → ∆
a
= y
1a
(1) − y
1
(1)
•
Now, let’s make a second (another) guess of b and
calculate the error again at the other boundary:
y
2
(0) = b → solution : y
1b
(x) → ∆
b
= y
1b
(1) − y
1
(1)
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.9
Linear Shooting IV
•
Remind the secant methods for root finding.
•
After these two estimated shoots, the most acc urate
starting value to choose will be the extension of the line
passing through two points:
y
2
(0) = b −
∆
b
∆
b
− ∆
a
(b − a)
•
Then, the calculation (RK4) is repeated with this selected
value by secant method.
•
Finally, the solution is found when the margin of error in
the other boundary is smaller than a certain tolerance.
•
(Example py-file: mylinearshooting.py)
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.10
Linear Shooting V
Table: Solution for t he Boundary Value Problem for the ODE:
y
′′
(x) − (4x
2
− 2)y = 0.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.11
Linear Shooting VI
0.0 0.2 0.4 0.6 0.8 1.0
x
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Approximate a d Exact Solutio for BVP ODE:
dy
2
dx
= (4
x
2
− 2)
y
1
Approximate
Exact
SciPy
Figure: Solution for the Boundary Value Problem for the ODE:
y
′′
(x) − (4x
2
− 2)y = 0.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.12
Laplace Equation in Electrostatics I
•
The electrostatic potential created by a static charge
distribution at a charge-free region is given by the following
Laplace equation:
∇
2
V =
∂
2
V
∂x
2
+
∂
2
V
∂y
2
+ +
∂
2
V
∂z
2
= 0
Here, V (x , y, z) is the potential within the region.
•
The solution of this problem for particular charge
distributions concerns the subject of partial differential
equations.
•
However, the dimensions of the problem can be reduced if
the charge distribution exhibit a spatial symmetry.
•
For example, in a system with spherical symmetry, the
solution of the problem becomes easier if the partial
derivatives in Laplace’s equation are expressed in terms of
spherical coordinates (r, θ, φ):
∇
2
V =
1
r
2
∂
∂r
r
2
∂V
∂r
+
1
r
2
sin θ
∂
∂θ
sin θ
∂V
∂θ
+
1
r
2
sin
2
θ
∂
2
V
∂φ
2
= 0
(1)
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.13
Laplace Equation in Electrostatics II
•
Let the two concentric conductive
spherical shells of radii R
a
and R
b
be
held at constant potentials V
a
and V
b
(Figure).
•
Because of spherical symmetry, the
potential distribution in the region
between the two spheres (R
a
< r < R
b
)
will be a function of distance r only.
•
Accordingly, the derivatives with
respect to the variables (θ, φ) in
Equation 1 bec ome zero, and the
partial derivative in the remaining term
becomes the full derivative:
1
r
2
∂
∂r
r
2
∂V
∂r
→
d
2
V
dr
2
+
2
r
dV
dr
= 0
Figure: The region
between two spherical
shells of different
potential.
The boundar y conditions of this differential
equation become:
V (R
a
) = V
a
V (R
b
) = V
b
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.14
Laplace Equation in Electrostatics III
As an example: Let’s find the numerical solution of this
equation for R
a
= 1 m, R
b
= 2 m, V
a
= 100 V , and V
b
= 0 V .
First, we transform this equation into a
linear system of equations:
V → V
1
dV
dr
→ V
2
with these values (V
1
andV
2
), the s ystem of
equations to be solved
dV
1
dr
= V
2
dV
2
dr
= −
2
r
V
2
and the boundary conditions are:
V (R
a
) = 100
V (R
b
) = 0
•
Now, we have a set of equations.
•
The analytical solution to this spherically symmetric
problem would be:
V (R) =
R
a
(R
b
− r )
(R
b
− R
a
)r
V
a
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.15
Laplace Equation in Electrostatics IV
We had a set of equations.
We transformed this boundary value problem into a first-order
system of equations.
V
1
= V
V
2
= V
′
dV
1
dr
= V
2
dV
2
dr
= −
2
r
V
2
(Example py-file: laplaceequation.py)
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.16
Laplace Equation in Electrostatics V
Table: Solution for t he Boundary Value Problem for the ODE:
V
′′
= −
2
r
V
′
.
Numerical Techniques:
Differential Equations -
Boundary Value
Problems
Dr. Cem Özdo
˘
gan
LOGIK
Differential Equations -
Boundary Value
Problems
Boundary Value Problems
Trial-and-Error (Linear
Shooting) Method
Laplace Equation in
Electrostatics
7.17
Laplace Equation in Electrostatics VI
1.0 1.2 1.4 1.6 1.8 2.0
x
0
20
40
60
80
100
y
Approximate and Exact Sol tion for BVP ODE:
dV
2
dr
= −
2
r
V
2
Approximate
Exact
SciPy
Figure: Solution for the Boundary Value Problem for the ODE:
V
′′
= −
2
r
V
′
.