chap3
chap3
xml
HEAD PREVIOUS
Chapter 3
Two-point Boundary Conditions
Very often, the boundary conditions that determine the solution of an ordinary differential equation are applied
not just at a single value of the independent variable, 𝑥, but at two points, 𝑥 1 and 𝑥 2 . This type of problem is
inherently different from the "initial value problems" discussed previously. Initial value problems are single-
point boundary conditions. There must be more than one condition if the system is higher order than one, but in
an initial value problem, all conditions are applied at the same place (or time). In two-point problems we have
boundary conditions at more than one place (more than one value of the independent variable) and we are
interested in solving for the dependent variable(s) in the interval 𝑥 1 ≤ 𝑥 ≤ 𝑥 2 of the independent variable.
Figure 3.1: Electrostatic configuration independent of 𝑦 and 𝑧 with conducting boundaries at 𝑥 1 and 𝑥 2 where
𝜑 = 0. This is a second-order two-point boundary problem.
In a slab geometry where 𝜌 varies in a single direction (coordinate) 𝑥, but not in 𝑦 or 𝑧, an ordinary differential
equation arises
𝑑2 𝜑 𝜌(𝑥)
= - . (3 . 2)
2 𝜀0
dx
If we suppose (see Fig. 3.1) that the potential is held equal to zero at two planes, 𝑥 1 and 𝑥 2 , by placing grounded
conductors there, then its variation between them depends upon the distribution of the charge density 𝜌(𝑥).
Solving for 𝜑(𝑥) is a two-point problem. In effect, this is a conservation equation for electric flux, 𝐸. Its
divergence is equal to the source density, which is the charge density.
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 1/10
12/13/24, 3:47 PM chap3.xml
Figure 3.2: Heat balance equation in cylindrical geometry leads to a two-point problem with conditions
consisting of fixed temperature at the edge, 𝑟 = 𝑎 and zero gradient at the center 𝑟 = 0.
A second-order two-point problem also arises from steady heat conduction. See Fig. 3.2. Suppose a cylindrical
reactor fuel rod experiences volumetric heating from the nuclear reactions inside it with a power density 𝑝(𝑟)
(Watts per cubic meter), that varies with cylindrical radius 𝑟.
Its boundary, at 𝑟 = 𝑎 say, is held at a constant temperature 𝑇𝑎 . If the thermal conductivity of the rod is 𝜅(𝑟),
then the radial heat flux density (Watts per square meter) is
𝑑𝑇
𝑞 = -𝜅 . (3 . 3)
dr
In steady state, the total heat flux across the surface at radius 𝑟 (per unit rod length) must equal the total heating
within it:
𝑑𝑇 𝑟
2𝜋𝑟𝑞 = - 2𝜋𝑟𝜅(𝑟) = ∫ 𝑝(𝑟')2𝜋𝑟'dr' . (3 . 4)
dr 0
Differentiating this equation we obtain:
𝑑 𝑑𝑇
(𝑟𝜅 ) = - 𝑟𝑝(𝑟) . (3 . 5)
dr dr
This second-order differential equation requires two boundary conditions. One is 𝑇(𝑎) = 𝑇𝑎 , but the other is less
immediately obvious. It is that the solution must be nonsingular at 𝑟 = 0, which requires that the derivative of 𝑇
be zero there:
𝑑𝑇
| = 0. (3 . 6)
dr
𝑟=0
3.2 Shooting
3.2.1 Solving two-point problems by initial-value iteration
One approach to computing the solution to two-point problems is to use the same technique used to solve initial
value problems. We treat 𝑥 1 as if it were the starting point of an initial value problem. We choose enough
boundary conditions there to specify the entire solution. For a second-order equation such as (3.2) or (3.5), we
would need to choose two conditions: 𝑦(𝑥 1 ) = 𝑦1 , and dy / dx |𝑥1 = 𝑠, say, where 𝑦1 and 𝑠 are the chosen
values. Only one of these is actually the boundary condition to be applied at the initial point, 𝑥 1 . We'll suppose it
is 𝑦1 . The other, 𝑠, is an arbitrary guess at the start of our solution procedure.
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 2/10
12/13/24, 3:47 PM chap3.xml
Given these initial conditions, we can solve for 𝑦 over the entire range 𝑥 1 ≤ 𝑥 ≤ 𝑥 2 . When we have done so for
this case, we can find the value 𝑦 at 𝑥 2 (or its derivative if the original boundary conditions there required it).
Generally, this first solution will not satisfy the actual two-point boundary condition at 𝑥 2 , which we'll take as
𝑦 = 𝑦2 . That's because our guess of 𝑠 was not correct.
Figure 3.3: Multiple successive shots from a cannon can take advantage of observations of where the earlier ones
hit, in order to iterate the aiming elevation 𝑠 until they strike the target.
It's as if we are aiming at the point (𝑥 2 , 𝑦2 ) with a cannon located at (𝑥 1 , 𝑦1 ) (see Fig. 3.3). We elevate the
cannon so that the cannonball's initial angle is dy / dx |𝑥 = 𝑠, which is our initial guess at the best aim. We
1
shoot. The cannonball flies over, (within our metaphor, the initial value solution is found) but is not at the correct
height when it reaches 𝑥 2 because our first guess at the aim was imperfect. What do we do? We see the height at
which the cannonball hits, above or below the target. We adjust our aim accordingly with a new elevation 𝑠2 ,
dy / dx |𝑥1 = 𝑠2 , and shoot again. Then we iteratively refine our aim taking as many shots as necessary, and
improving the aim each time, till we hit the target. This is the "shooting" method of solving a two-point problem.
The cannonball's trajectory stands for the initial value integration with assumed initial condition.
One question that is left open in this description is exactly how we refine our aim. That is, how do we change the
guess of the initial slope 𝑠 so as to get a solution that is nearer to the correct value of 𝑦(𝑥 2 )? One of the easiest
and most robust ways to do this is by bisection.
3.2.2 Bisection
Suppose we have a continuous function 𝑓(𝑠) over some interval [𝑠𝑙 , 𝑠𝑢 ] (i.e. 𝑠𝑙 ≤ 𝑠 ≤ 𝑠𝑢 ), and we wish to find a
solution to 𝑓(𝑠) = 0 within that range. If 𝑓(𝑠𝑙 ) and 𝑓(𝑠𝑢 ) have opposite signs, then we know that there is a
solution (a "root" of the equation) somewhere between 𝑠𝑙 and 𝑠𝑢 . For definiteness in our description, we'll take
𝑓(𝑠𝑙 ) ≤ 0 and 𝑓(𝑠𝑢 ) ≥ 0. To get a better estimate of where 𝑓 = 0 is, we can bisect the interval and examine the
value of 𝑓 at the point 𝑠 = (𝑠𝑙 + 𝑠𝑢 ) / 2. If 𝑓(𝑠) < 0, then we know that a solution must be in the half interval
[𝑠, 𝑠𝑢 ], whereas if 𝑓(𝑠) > 0, then a solution must be in the other interval [𝑠𝑙 , 𝑠]. We choose whichever half-
interval the solution lies in, and update one or other end of our interval to be the new s-value. In other words, we
set either 𝑠𝑙 = 𝑠 or 𝑠𝑢 = 𝑠 respectively. The new interval [𝑠𝑙 , 𝑠𝑢 ] is half the length of the original, so it gives us a
better estimate of where the solution value is.
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 3/10
12/13/24, 3:47 PM chap3.xml
Figure 3.4: Bisection successively divides in two an interval in which there is a root, always retaining the
subinterval in which a root lies.
Now we just iterate the above procedure, as illustrated in Fig. 3.4. At each step we get an interval of half the
length of the previous step, in which we know a solution lies. Eventually the interval becomes small enough that
its extent can be ignored; we then know the solution accurately enough, and can stop the iteration.
The wonderful thing about bisection is that it highly efficient, because it is guaranteed to converge in
"logarithmic time". If we start with an interval of length 𝐿, then at the 𝑘th interation the interval length is 𝐿 / 2𝑘 .
So if the tolerance with which we need the 𝑠-value solution is 𝛿 (generally a small length), the number of
iterations we must take before convergence is 𝑁 = log2 (𝐿 / 𝛿). For example if 𝐿 / 𝛿 = 106 , then 𝑁 = 20. This
is a quite modest number of iterations even for a very high degree of refinement.
There are iterative methods of root finding that converge faster than bisection for well behaved functions. One is
"Newton's method", which may succinctly be stated as 𝑠𝑘 + 1 = 𝑠𝑘 - 𝑓(𝑠𝑘 ) / df / ds|𝑠 . It converges in a few
𝑘
steps when the starting guess is not too far from the solution. Unlike bisection, it does not require two starting
points on opposite sides of the root. However, Newton's method (1) requires derivatives of the function, which
makes it more complicated to code, (2) is less robust, because it takes big steps near df / ds = 0, and may even
step in the wrong direction and not converge at all in some cases. Bisection is guaranteed to converge after a
modest number of steps. Robustness is in practice usually more important than speed.16
In the context of our shooting solution of a two-point problem, the function 𝑓 is the error in the boundary value
at the second point 𝑦(𝑥 2 ) - 𝑦2 of the inital-value solution 𝑦(𝑥) that takes initial-value 𝑠 for its derivative at 𝑥 1 .
The bisection generally adjusts the initial-value 𝑠 until |𝑦(𝑥 2 ) - 𝑦2 | is less than some tolerance (rather than
requiring some tolerance on 𝑠).
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 4/10
12/13/24, 3:47 PM chap3.xml
First let's consider how one ought to represent a second-order derivative as finite differences. Suppose we have a
uniformly spaced grid (or mesh) of values of the independent variable 𝑥 𝑛 such that 𝑥 𝑛 + 1 - 𝑥 𝑛 = 𝛥𝑥. The natural
definition of the first derivative is
dy 𝛥𝑦 𝑦𝑛 + 1 - 𝑦𝑛
| = = ; (3 . 7)
dx 𝑛 + 1 / 2 𝛥𝑥 𝑥 𝑛 + 1 - 𝑥 𝑛
and this should be regarded as an estimate of the value at the midpoint 𝑥 𝑛 + 1 / 2 = (𝑥 𝑛 + 𝑥 𝑛 + 1 ) / 2, which we
denote via a half-integral index 𝑛 + 1 / 2. The second derivative is the derivative of the derivative. Its most
natural definition, therefore is
1 1
Figure 3.5: Discrete second derivative at 𝑛 is the difference between the discrete derivatives at 𝑛 + 2 and 𝑛 - 2 .
In a uniform mesh, it is divided by the same 𝛥𝑥.
Because the first derivative is the value at 𝑛 + 1 / 2, the second derivative (the derivative of the first derivative)
is the value at a point mid way between 𝑛 + 1 / 2 and 𝑛 - 1 / 2, i.e. at 𝑛. Substituting from the previous equation
(3.7) we get17 :
𝑑2 𝑦 (𝑦 - 𝑦 ) / 𝛥𝑥 - (𝑦𝑛 - 𝑦𝑛 - 1 ) / 𝛥𝑥 𝑦𝑛 + 1 - 2𝑦𝑛 + 𝑦𝑛 - 1
2|
= 𝑛+1 𝑛 = . (3 . 9)
dx 𝛥𝑥 𝛥𝑥 2
𝑛
Now think of the entire mesh stretching from 𝑛 = 1 to 𝑛 = 𝑁. The values 𝑦𝑛 at all the nodes can be considered
to be a column vector of length 𝑁. The second derivative can then be considered to be a matrix operating on that
column vector, to give the values of eq. (3.9). So, written in matrix form we have:
𝑑2 𝑦 / dx2 |
( 1 ) ⋱ ⋱ 0 0 0 𝑦1
( 1 -2 1 0 0 )
1 ( )
𝑑2 𝑦 / dx2 | = 0 ⋱ ⋱ ⋱ 0 𝑦𝑛 , (3 . 10)
𝑛 𝛥𝑥 2
0 0 1 -2 1 𝑦𝑁
𝑑2 𝑦 / dx2 | 0 0 0 ⋱ ⋱
𝑁
where the square 𝑁 × 𝑁 matrix has diagonal elements equal to -2. On the adjacent diagonals, sometimes called
subdiagonals, (indices 𝑛, 𝑛 + 1 and 𝑛, 𝑛 - 1) it has 1; and everywhere else it is zero. This overall form is called
tridiagonal.
If we are considering the equation
𝑑2 𝑦
= 𝑔(𝑥) (3 . 11)
dx2
where 𝑔(𝑥) is some function (for example 𝑔 = - 𝜌 / 𝜀0 for our electrostatic example) then the equation is
represented by putting the column vector ( 𝑑2 𝑦 / dx2 | ) equal to the column vector (𝑔𝑛 ) = (𝑔(𝑥 𝑛 )).
𝑛
However, in eq. (3.10), the top left and bottom right corners of the derivative matrix have deliberately been left
ambiguous, because that's where the boundary conditions come into play. Assuming they are on the boundaries,
the quantities 𝑦1 and 𝑦𝑁 are determined not by the differential equation and the function 𝑔, but by the boundary
values. We must adjust the first and last row of the matrix accordingly to represent those boundary conditions. A
convenient way to do this when the conditions consist of specifying 𝑦𝐿 and 𝑦𝑅 at the left and right-hand ends is
to write the equation as:
-2𝑦𝐿
-2 0 0 0 0 0 0 𝑦1
( )
( 1 -2 1 0 0 0 0 )( 𝑦 ) 𝑔2 𝛥𝑥 2
2
0 ⋱ ⋱ ⋱ 0 0 0
0 0 1 -2 1 0 0 𝑦𝑛 = 𝑔𝑛 𝛥𝑥 2 . (3 . 12)
0 0 0 ⋱ ⋱ ⋱ 0 𝑦𝑁 - 1
0 0 0 0 1 -2 1 𝑔𝑁 - 1 𝛥𝑥 2
𝑦𝑁
0 0 0 0 0 0 -2 -2𝑦𝑅
Notice that the first and last rows of the matrix have been made purely diagonal, and the column vector on the
right hand side (call it ℎ) uses for the first and last rows the boundary values, and for the others the elements of
𝑔𝛥𝑥 2 . These adjustments enforce that the first and last values of 𝑦 are always the boundary values 𝑦𝐿 and 𝑦𝑅 .18
Once we have constructed this matrix form of the differential equation, which we can write:
𝐷𝑦 = ℎ, (3 . 13)
it is obvious that we can solve it by simply inverting the matrix 𝐷 and finding
𝑦 = 𝐷-1 ℎ . (3 . 14)
(Or we can use some other appropriate matrix equation solution technique.)
In general, we must make the first and last rows of the matrix equation into discrete expressions of the boundary
conditions there. If instead of Dirichlet boundary conditions (value is specified), we are given Neumann
conditions, that is, the derivative (e.g. dy / dx|1 ) is specified, a different adjustment of the corners is necessary.
The most obvious thing to do is to make the first row of the matrix equation proportional to
(-1 1 0 … )(𝑦) = 𝑦2 - 𝑦1 = 𝛥𝑥( dy / dx|1 ) . (3 . 15)
However, this choice does not calculate the derivative at the right place. The expression (𝑦2 - 𝑦1 ) / 𝛥𝑥 is the
derivative at 𝑥 3 / 2 rather than 𝑥 1 , which is the boundary19 . So the scheme (3.15) is not properly centered and
will give only first order accuracy.20 A better extrapolation of the derivative to the boundary is to write instead
for the first row
3 1 1 3
(- 2 - 0 … )(𝑦) = - (𝑦3 - 𝑦2 ) + (𝑦2 - 𝑦1 ) = 𝛥𝑥( dy / dx|1 ) . (3 . 16)
2 2 2 2
1
This is a discrete form of the expression 𝑦'1 ≈ 𝑦'3 / 2 - 𝑦2 . 2 𝛥𝑥, which is accurate to second-order, because it
cancels out the first-order error in the derivative. The same treatment applies to a Neumann condition at 𝑥 𝑁 (but
of course using the mirror image of the row given in eq. (3.16)).
If the boundary condition is of a more general form (the so-called Robin condition)
Ay + By' + 𝐶 = 0, (3 . 17)
Then we want the first row to represent this equation discretely. The natural way to do this, based upon our
previous forms, is to make it
𝐵 3 1
[𝐴(1 0 0 …)+ (- 2 - 0 … ) ](𝑦) = - 𝐶 . (3 . 18)
𝛥𝑥 2 2
In addition to combining the previous inhomogeneous boundary forms, this expression can also represent the
specification of homogeneous boundary conditions, or in other words logarithmic gradient conditions. When
𝐶 = 0, the boundary condition is 𝑑(ln𝑦) / dx = 𝑦' / 𝑦 = - 𝐴 / 𝐵. This form (with 𝐴 / 𝐵 = 1) is the condition
that one might apply to the potential due to a spherically symmetric electrostatic charge at the outer boundary,
for example.
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 6/10
12/13/24, 3:47 PM chap3.xml
It may be preferable in some cases to scale the first row of the matrix equation to make the diagonal entry the
same as all the other diagonals, namely -2. This is done by multiplying all the row's elements of 𝐷, and the
corresponding entry of ℎ by a factor -2 / 𝐷11 , or -2 / 𝐷NN respectively. This can improve the conditioning of the
matrix, making inversion easier and more accurate.
Figure 3.6: Periodic boundary conditions apply when the independent variable is, for example, distance around a
periodic domain.
A final type of boundary condition worth discussing is called "periodic". This expression means that the end of
the 𝑥-domain is considered to be connected to its beginning. Such a situation arises, for example, if the domain
is actually a circle in two-dimensional space. But it is also sometimes used to approximate an infinite domain.
For periodic boundary conditions it is usually convenient to label the first and last point 0 and 𝑁. See Fig. 3.6.
They are the same point; so the values at 𝑥 0 and 𝑥 𝑁 are the same. There are then 𝑁 different points and the
discretized differential equation must be satisfied at them all, with the differences wrapping round to the
corresponding point across the boundary. The resulting matrix equation is then
𝑔1 𝛥𝑥 2
-2 1 … 0 … 0 1 𝑦1 ( )
( 1 -2 1 0 0 0 0 )( 𝑦 ) 𝑔2 𝛥𝑥 2
2
⋱ ⋱ ⋱ 0 0
0 0 1 -2 1 0 0 𝑦𝑛 = 𝑔𝑛 𝛥𝑥 2 , (3 . 19)
0 0 ⋱ ⋱ ⋱ 𝑦𝑁 - 1
0 0 0 0 1 -2 1 𝑔𝑁 - 1 𝛥𝑥 2
𝑦𝑁
1 0 … 0 … 1 -2 𝑔𝑁 𝛥𝑥 2
which maintains the pattern 1, - 2, 1 for every row, without exception. For the first and last rows, the
subdiagonal 1 element that would be outside the matrix, is wrapped round to the other end of the row. It gives a
new entry in the top right and bottom left corners.21
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 7/10
12/13/24, 3:47 PM chap3.xml
conservation of energy that required the heat flux through a particular radius cylinder 2𝜋𝑟𝜅dT / dr to vary with
radius only so as to account for the power density at radius 𝑟. It is therefore best to develop the second-order
differential in this way. First we form dT / dr in the usual discrete form at 𝑛 - 1 / 2 and 𝑛 + 1 / 2. Then we
multiply those values by 𝑟𝜅 at the same half-mesh positions 𝑛 - 1 / 2 and 𝑛 + 1 / 2. Then we take the difference
of those two fluxes writing:
𝑑 𝑑𝑇 𝑇𝑛 + 1 - 𝑇𝑛 𝑇𝑛 - 𝑇𝑛 - 1 1
( 𝑟𝜅 ) = ( 𝑟𝑛 + 1 / 2 𝜅𝑛 + 1 / 2 - 𝑟𝑛 - 1 / 2 𝜅𝑛 - 1 / 2 )
dr dr 𝛥𝑟 𝛥𝑟 𝛥𝑟
1
= 𝛥𝑟2
[ 𝑟𝑛 + 1 / 2 𝜅𝑛 + 1 / 2 𝑇𝑛 + 1 (3 . 21)
- (𝑟𝑛 + 1 / 2 𝜅𝑛 + 1 / 2 + 𝑟𝑛 - 1 / 2 𝜅𝑛 - 1 / 2 ) 𝑇𝑛
+ 𝑟𝑛 - 1 / 2 𝜅𝑛 - 1 / 2 𝑇𝑛 - 1 ] .
The big advantage of this expression is that it exactly conserves the heat flux. This property can be seen by
considering the exact heat conservation in integral form over the cell consisting of the range
𝑟𝑛 - 1 / 2 < 𝑟 < 𝑟𝑛 + 1 / 2 :
dT dT 𝑟
2𝜋𝑟𝑛 + 1 / 2 𝜅𝑛 + 1 / 2 | - 2𝜋𝑟𝑛 - 1 / 2 𝜅𝑛 - 1 / 2 | = - ∫ 𝑛 + 1 / 2 𝑝2𝜋𝑟'dr' . (3 . 22)
dr 𝑛 + 1 / 2 dr 𝑛 - 1 / 2 𝑟𝑛 - 1 / 2
dT
Then adding together the versions of this equation for two adjacent positions 𝑛 = 𝑘, 𝑘 + 1, the |
dr 𝑘 + 1 / 2
terms
dT
cancel, provided the expression for 𝑟𝜅 is the same at the same 𝑛 value regardless of which adjacent cell (𝑘 or
dr
dT
𝑘 + 1) it arises from. This symmetry is present when using |
dr 𝑛 + 1 / 2
= (𝑇𝑛 + 1 - 𝑇𝑛 ) / 𝛥𝑟 and the half-mesh
values of 𝑟𝜅. The sum of the equations is therefore the exact total conservation for the region
𝑟𝑘 - 1 / 2 < 𝑟 < 𝑟𝑘 + 3 / 2 , consisting of the sum of the two adjacent cells. This process can then be extended over
the whole domain, proving total heat conservation. Approaching the discrete equations in this way is sometimes
called the method of "finite volumes"22 . The finite volume in our illustrative case is the annular region between
𝑟𝑛 - 1 / 2 and 𝑟𝑛 + 1 / 2 .
A less satisfactory alternative which remains second-order accurate might be to evaluate the right hand side of
eq. (3.20) using double distance derivatives that are centered at the 𝑛 mesh as follows
𝑑 𝑑𝑇 𝑇𝑛 + 1 - 2𝑇𝑛 + 𝑇𝑛 - 1 𝑟 𝑛 + 1 𝜅 𝑛 + 1 - 𝑟 𝑛 - 1 𝜅 𝑛 - 1 𝑇𝑛 + 1 - 𝑇𝑛 - 1
( 𝑟𝜅 ) = ( 𝑟𝑛 𝜅𝑛 + )
dr dr 𝛥𝑟2 2𝛥𝑟 2𝛥𝑟
1
= 𝛥𝑟2
[ (𝑟𝑛 + 1 𝜅𝑛 + 1 / 4 + 𝑟𝑛 𝜅𝑛 - 𝑟𝑛 - 1 𝜅𝑛 - 1 / 4) 𝑇𝑛 + 1 (3 . 23)
-2𝑟𝑛 𝜅𝑛 𝑇𝑛
+( - 𝑟𝑛 + 1 𝜅𝑛 + 1 / 4 + 𝑟𝑛 𝜅𝑛 + 𝑟𝑛 - 1 𝜅𝑛 - 1 / 4) 𝑇𝑛 - 1 ] .
None of the coefficients of the 𝑇s in this expression is the same as in eq. (3.21) unless 𝑟𝜅 is independent of
position. This is true even in the case where 𝑟𝜅 is known only at whole mesh points so the half-point values in
(3.21) are obtained by interpolation. Expression (3.23) does not exactly conserve heat flux, which is an
important weakness. Expression (3.21) is usually to be preferred.
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 8/10
12/13/24, 3:47 PM chap3.xml
dy 𝑦𝑛 + 1 - 𝑦𝑛
We write down the finite difference equation at a generic position: dr
| = 𝛥
. Substituting this into
𝑛+1/2
the differential equation, we get
𝑑 dy dy dy 1
-𝑟𝑛 𝑔𝑛 = (𝑟 ) = (𝑟𝑛 + 1 / 2 | - 𝑟𝑛 - 1 / 2 | )
dr dr 𝑛 dr 𝑛 + 1 / 2 dr 𝑛 - 1 / 2 𝛥
𝑦𝑛 + 1 - 𝑦𝑛 𝑦 -𝑦 1
= ( 𝑟𝑛 + 1 / 2 - 𝑟𝑛 - 1 / 2 𝑛 𝑛 - 1 )
𝛥 𝛥 𝛥
1
= ( 𝑟𝑛 + 1 / 2 𝑦𝑛 + 1 - 2𝑟𝑛 𝑦𝑛 + 𝑟𝑛 - 1 / 2 𝑦𝑛 - 1 ) 2 . (3 . 25)
𝛥
It is convenient (and improves matrix conditioning) to divide this equation through by 𝑟𝑛 / 𝛥2 , so that the 𝑛th
equation reads
𝑟𝑛 + 1 / 2 𝑟𝑛 - 1 / 2
( )𝑦𝑛 + 1 - 2𝑦𝑛 + ( )𝑦𝑛 - 1 = - 𝛥2 𝑔𝑛 (3 . 26)
𝑟𝑛 𝑟𝑛
For definiteness we will take the position of the 𝑛th grid point to be 𝑟𝑛 = 𝑛𝛥, so 𝑛 runs from 0 to 𝑁. Then the
coefficients become
𝑟𝑛 ± 1 / 2 𝑛 ± 1 / 2 1
= =1± . (3 . 27)
𝑟𝑛 𝑛 2𝑛
The boundary condition at 𝑛 = 𝑁 is 𝑦𝑁 = 0. At 𝑛 = 0 we want dy / dr = 0, but we need to use an expression
that is centered at 𝑛 = 0, not 𝑛 = 1 / 2, to give second-order accuracy. Therefore following eq. (3.16) we write
the equation at 𝑛 = 0
1 3 3 1
𝛥 dy / dx|0 = - (𝑦2 - 𝑦1 ) + (𝑦1 - 𝑦0 ) = ( - 2 - 0 … )(𝑦) = 0 . (3 . 28)
2 2 2 2
Gathering all our equations into a matrix we have:
3 1
- 2 - 0 0 0 0
( 2 2 )
1 1 𝑦0 0
1- 2
-2 1 + 2
0 0 0 0
( 𝑦1 ) ( 𝑔1 )
0 ⋱ ⋱ ⋱ 0 0 0
0 0 1 - 2𝑛
1
-2 1+
1
0 0
𝑦𝑛 = - 𝛥2 𝑔𝑛 (3 . 29)
2𝑛
0 0 0 ⋱ ⋱ ⋱ 0 𝑦𝑁 - 1 𝑔𝑁 - 1
1 1 𝑦𝑁 0
0 0 0 0 1- 2(𝑁 - 1)
-2 1 + 2(𝑁 - 1)
0 0 0 0 0 0 -2
Fig. 3.7 shows the solution of an illustrative case.
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 9/10
12/13/24, 3:47 PM chap3.xml
Figure 3.7: Example of the result of a finite difference solution for 𝑦 of eq. (3.24) using a matrix of the form of
eq. (3.29). The source 𝑔 is purely illustrative, and is plotted in the figure. The boundary points at the ends of the
range of solution are 𝑟 = 0, and 𝑟 = 𝑁𝛥 = 4. A grid size 𝑁 = 25 is used.
on the 𝑥-domain [0, 1], spanned by an equally spaced mesh of 𝑁 nodes, with Dirichlet boundary conditions
𝑦(0) = 𝑦0 , 𝑦(1) = 𝑦1 .
When you have got it working, obtain your personal expressions for 𝑓(𝑥), 𝑁, 𝑦0 , and 𝑦1 from
http://silas.psfc.mit.edu/22.15/giveassign3.cgi. (Or use 𝑓(𝑥) = 𝑎 + bx, 𝑎 = 0 . 15346, 𝑏 = 0 . 56614,
𝑁 = 44, 𝑦0 = 0 . 53488, 𝑦1 = 0 . 71957.) And solve the differential equation so posed. Plot the solution.
Submit the following as your solution:
2. Save your code and make a copy with a new name. Edit the new code so that it solves the ODE
𝑑2 𝑦
2
+ 𝑘2 𝑦 = 𝑓(𝑥)
dx
on the same domain and with the same boundary conditions, but with the extra parameter 𝑘2 . Verify that your
new code works correctly for small values of 𝑘2 , yielding results close to those of the previous problem.
Investigate what happens to the solution in the vicinity of 𝑘 = 𝜋.
Describe what the cause of any interesting behavior is.
Submit the following as your solution:
HEAD NEXT
silas.psfc.mit.edu/22.15/lectures/chap3.xml#tth_chAp3 10/10