<?xml version="1.0"?>
<!DOCTYPE html    PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
           "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="GENERATOR" content="TtM 4.12" />
 <style type="text/css">
 div.p { margin-top: 7pt; }
 span.roman {font-family: serif; font-style: normal; font-weight: normal;} 
</style>
 <style type="text/css">
 .tiny {font-size:30%;}
 .scriptsize {font-size:xx-small;}
 .footnotesize {font-size:x-small;}
 .smaller {font-size:smaller;}
 .small {font-size:small;}
 .normalsize {font-size:medium;}
 .large {font-size:large;}
 .larger {font-size:x-large;}
 .largerstill {font-size:xx-large;}
 .huge {font-size:300%;}
 </style>
<title>chap3.xml</title>
</head>
<body><div>
<table width="100%"><tr><td>
 <a href="index.xml">HEAD</a></td><td align="right">
 <a href="chap2.xml">PREVIOUS
</a></td></tr></table>
 <a id="tth_chAp3"></a><h1>
Chapter 3 <br />Two-point Boundary Conditions</h1>

<div class="p"><!----></div>
<a 
id="two-point_boundary_conditions30153"></a><a 
id="boundary_condition30154"></a> Very
often, the boundary conditions that determine the solution of an
ordinary differential equation<a 
id="ODE30155"></a> are applied not just at a
single value of the independent variable<a 
id="independent_variable30156"></a>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>x</mi></mrow></math>, but at two points, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>.  This type of problem is
inherently different from the "initial value problems"<a 
id="initial___value_problem30157"></a> discussed previously. Initial value problems are
single-point boundary conditions. There must be more than one
<em>condition</em> 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 <em>place</em> (more than one value of the independent
variable) and we are interested in solving for the dependent
variable(s)<a 
id="dependent_variable30158"></a> in the interval <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>&le;</mo><mi>x</mi><mo>&le;</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math> of the independent variable.

<div class="p"><!----></div>
 <a id="tth_sEc3.1"></a><h2>
3.1&nbsp;&nbsp;Examples of Two-Point Problems</h2>

<div class="p"><!----></div>
Many examples of two-point problems arise from steady flux
conservation<a 
id="flux_conservation31159"></a> in the presence of
sources<a 
id="source31160"></a>.

<div class="p"><!----></div>
In electrostatics<a 
id="electrostatic31161"></a> the electric
potential<a 
id="potential31162"></a> <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&phi;</mi></mrow></math> is related to the charge
density<a 
id="charge_density31163"></a><a 
id="density_charge31164"></a> <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&rho;</mi></mrow></math> through one
of the Maxwell equations<a 
id="Maxwell_s_equations31165"></a>: a form of
Poisson's<a 
id="Poisson_equation31166"></a>  equation
<a id="2pt1">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo>&nabla;</mo><mo>.</mo><mi mathvariant="bold-italic">E</mi><mo>=</mo><mo>-</mo>
<msup><mrow><mo>&nabla;</mo></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi mathvariant="italic">&phi;</mi><mo>=</mo><mi mathvariant="italic">&rho;</mi><mo stretchy="false">/</mo>
<msub><mrow><mi mathvariant="italic">&epsi;</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>1</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold-italic">E</mi></mrow></math> is the electric field<a 
id="electric_field31167"></a> and
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi mathvariant="italic">&epsi;</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math> is the permittivity<a 
id="permittivity31168"></a> of free space.

<div class="p"><!----></div>
<a id="tth_fIg3.1">
</a>   <img src="figures/slabcharge.png" alt="figures/slabcharge.png" /><a id="slabcharge">
</a>
  
<div style="text-align:center">Figure 3.1: Electrostatic configuration independent of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi></mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>z</mi></mrow></math> with
  conducting boundaries at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math> where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&phi;</mi><mo>=</mo><mn>0</mn></mrow></math>. This is a
  second-order two-point boundary problem.<a id="lslabcharge">
</a></div>

<div class="p"><!----></div>
In a slab geometry<a 
id="slab31169"></a> where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&rho;</mi></mrow></math> varies
in a single direction (coordinate) <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>x</mi></mrow></math>, but not in <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi></mrow></math> or <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>z</mi></mrow></math>, an
ordinary differential equation arises
<a id="2pt2">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi mathvariant="italic">&phi;</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>=</mo><mo>-</mo>
<mfrac><mrow><mi mathvariant="italic">&rho;</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow>
<mrow>
<msub><mrow><mi mathvariant="italic">&epsi;</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow>
</mfrac>
<mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>2</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


If we suppose (see Fig.&nbsp;<a href="chap3.xml#lslabcharge">3.1</a>) that the potential is held
equal to zero at two planes, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>, by placing
grounded<a 
id="grounded31170"></a> conductors there, then its variation between
them depends upon the distribution of the charge density
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&rho;</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math>. Solving for <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&phi;</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math> is a two-point problem.  In effect,
this is a conservation equation for electric flux, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold-italic">E</mi></mrow></math>. Its
divergence<a 
id="divergence31171"></a> is equal to the source density, which is
the charge density.

<div class="p"><!----></div>
<a id="tth_fIg3.2">
</a>   <img src="figures/cylinderheat.png" alt="figures/cylinderheat.png" /><a id="cylinderheat">
</a>
  
<div style="text-align:center">Figure 3.2: Heat balance equation in cylindrical geometry leads to a
    two-point problem with conditions consisting of fixed temperature
    at the edge, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mi>a</mi></mrow></math> and zero gradient at the center <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow></math>.<a id="lcylinderheat">
</a></div>

<div class="p"><!----></div>
A second-order<a 
id="second-order31172"></a> two-point problem also arises from
steady heat conduction<a 
id="heat_conduction31173"></a>. See Fig.&nbsp;<a href="chap3.xml#lcylinderheat">3.2</a>. Suppose a cylindrical<a 
id="cylindrical31174"></a> reactor
fuel rod experiences volumetric heating from the nuclear reactions
inside it with a power density <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>p</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo></mrow></math> (Watts per cubic meter), that
varies with cylindrical radius <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi></mrow></math>.

<div class="p"><!----></div>
Its boundary, at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mi>a</mi></mrow></math> say, is held at a constant
temperature<a 
id="temperature31175"></a> <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>T</mi></mrow><mrow><mi>a</mi></mrow>
</msub>
</mrow></math>. If the thermal
conductivity<a 
id="thermal___conductivity31176"></a><a 
id="conductivity_thermal31177"></a><a 
id="conductivity31178"></a> of the
rod is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&kappa;</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo></mrow></math>, then the radial heat flux
density<a 
id="density_heat_flux31179"></a> (Watts per
square meter) is
<a id="2pt3">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mi>q</mi><mo>=</mo><mo>-</mo><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>3</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


In steady state, the total heat flux<a 
id="heat_flux31180"></a> across the
surface at radius <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi></mrow></math> (per unit rod length) must equal the total
heating within it:
<a id="2pt4">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mn>2</mn><mi mathvariant="italic">&pi;</mi><mi>r</mi><mi>q</mi><mo>=</mo><mo>-</mo><mn>2</mn><mi mathvariant="italic">&pi;</mi><mi>r</mi><mi mathvariant="italic">&kappa;</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>=</mo>
<msubsup><mrow><mo>&int;</mo></mrow><mrow><mn>0</mn> </mrow>
<mrow><mi>r</mi></mrow></msubsup>
<mi>p</mi><mo stretchy="false">(</mo><mi>r</mi><mo>'</mo><mo stretchy="false">)</mo><mn>2</mn><mi mathvariant="italic">&pi;</mi><mi>r</mi><mo>'</mo><mi mathvariant="italic">dr</mi><mo>'</mo><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>4</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


Differentiating this equation we obtain:
<a id="2pt5">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow><mi>d</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mrow><mo>(</mo><mi>r</mi><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>)</mo></mrow><mo>=</mo><mo>-</mo><mi>r</mi><mi>p</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>5</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


This second-order differential equation requires two boundary
conditions. One is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>T</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>=</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>a</mi></mrow>
</msub>
</mrow></math>, but the other is less immediately
obvious. It is that the solution must be
nonsingular<a 
id="nonsingularity31181"></a> at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow></math>, which requires that the
<em>derivative</em> of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>T</mi></mrow></math> be zero there:
<a id="2pt6">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow>
</msub>
<mo>=</mo><mn>0</mn><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>6</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>



<div class="p"><!----></div>
 <a id="tth_sEc3.2"></a><h2>
3.2&nbsp;&nbsp;Shooting</h2>

<div class="p"><!----></div>
<a 
id="shooting_method32182"></a>     <a id="tth_sEc3.2.1"></a><h3>
3.2.1&nbsp;&nbsp;Solving two-point problems by initial-value iteration</h3>

<div class="p"><!----></div>
One approach to computing the solution to two-point problems is to use
the same technique used to solve initial value problems. We
treat <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> 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 (<a href="chap3.xml#2pt2">3.2</a>) or
(<a href="chap3.xml#2pt5">3.5</a>), we would need to choose two conditions: <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>=</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>,
and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi>
<msub><mrow><mo stretchy="false">&verbar;</mo></mrow><mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow>
</msub>
<mo>=</mo><mi>s</mi></mrow></math>, say, where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math> are the chosen
values. Only one of these is actually the boundary condition to be
applied at the initial point, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>. We'll suppose it is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>. The
other, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math>, is an arbitrary guess at the start of our solution
procedure. 

<div class="p"><!----></div>
Given these initial conditions, we can solve for <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi></mrow></math> over the entire
range <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>&le;</mo><mi>x</mi><mo>&le;</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>. When we have done so for this case, we
can find the value <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi></mrow></math> at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math> (or its derivative if the original
boundary conditions there required it). Generally, this first solution will
<em>not</em> satisfy the actual two-point boundary condition at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>,
which we'll take as <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo>=</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>. That's because our guess of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math> was not
correct.

<div class="p"><!----></div>
<a id="tth_fIg3.3">
</a>   <img src="figures/cannonshoot.png" alt="figures/cannonshoot.png" /><a id="cannonshoot">
</a>
  
<div style="text-align:center">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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math> until they strike the target.<a id="lcannonshoot">
</a></div>

<div class="p"><!----></div>
It's as if we are aiming at the point <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo>,</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></math> with a cannon
located at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>,</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></math> (see Fig.&nbsp;<a href="chap3.xml#lcannonshoot">3.3</a>). We elevate the
cannon so that the cannonball's initial angle is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi>
<msub><mrow><mo stretchy="false">&verbar;</mo></mrow><mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow>
</msub>
<mo>=</mo><mi>s</mi></mrow></math>,
which is our initial guess at the best aim. We shoot. The cannonball
flies over, (within our metaphor, the initial value solution is found)
but is not at the correct height when it reaches <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math> because our
first guess<a 
id="initial_guess32183"></a> 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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi>
<msub><mrow><mo stretchy="false">&verbar;</mo></mrow><mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow>
</msub>
<mo>=</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math>, and shoot again. Then we
iteratively<a 
id="iteration32184"></a> 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.

<div class="p"><!----></div>
One question that is left open in this description is exactly
<em>how</em> we refine our aim. That is, how do we change the guess of
the initial slope <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math> so as to get a solution that is nearer to the
correct value of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></math>? One of the easiest and most robust ways to
do this is by bisection.

<div class="p"><!----></div>
     <a id="tth_sEc3.2.2"></a><h3>
3.2.2&nbsp;&nbsp;Bisection</h3>

<div class="p"><!----></div>
<a 
id="bisection32185"></a><a 
id="root-finding32186"></a> Suppose we have a continuous
function <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo></mrow></math> over some interval <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">[</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo>,</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo stretchy="false">]</mo></mrow></math> (i.e.&nbsp;<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo>&le;</mo><mi>s</mi><mo>&le;</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
</mrow></math>), and we wish to find a solution to <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow></math> within that range.
If <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></math> have <em>opposite signs</em>, then we know that
there is a solution (a "root" of the equation) somewhere between <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
</mrow></math>
and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
</mrow></math>. For definiteness in our description, we'll take <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo>&le;</mo><mn>0</mn></mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo>&ge;</mo><mn>0</mn></mrow></math>.  To get a better estimate of where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo>=</mo><mn>0</mn></mrow></math> is, we
can bisect the interval and examine the value of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi></mrow></math> at the point
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi><mo>=</mo><mo stretchy="false">(</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mn>2</mn></mrow></math>. If <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo><mo>&lt;</mo><mn>0</mn></mrow></math>, then we know that a solution must be in
the half interval <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">[</mo><mi>s</mi><mo>,</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo stretchy="false">]</mo></mrow></math>, whereas if <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo><mo>&gt;</mo><mn>0</mn></mrow></math>, then a solution must
be in the other interval <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">[</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo>,</mo><mi>s</mi><mo stretchy="false">]</mo></mrow></math>. 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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo>=</mo><mi>s</mi></mrow></math> or <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo>=</mo><mi>s</mi></mrow></math>
respectively. The new interval <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">[</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>l</mi></mrow>
</msub>
<mo>,</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>u</mi></mrow>
</msub>
<mo stretchy="false">]</mo></mrow></math> is half the length of the
original, so it gives us a better estimate of where the solution value
is.

<div class="p"><!----></div>
<a id="tth_fIg3.4">
</a>   <img src="figures/bisection.png" alt="figures/bisection.png" /><a id="bisection">
</a>
  
<div style="text-align:center">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.<a id="lbisection">
</a></div>

<div class="p"><!----></div>
Now we just iterate<a 
id="iteration32187"></a> the above procedure, as
illustrated in Fig.&nbsp;<a href="chap3.xml#lbisection">3.4</a>. 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.

<div class="p"><!----></div>
The wonderful thing about bisection is that it highly
efficient<a 
id="efficiency32188"></a>, because it is guaranteed to converge in
"logarithmic time"<a 
id="logarithmic_time32189"></a>. If we start with an
interval of length <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>L</mi></mrow></math>, then at the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>k</mi></mrow></math>th interation the interval
length is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>L</mi><mo stretchy="false">/</mo>
<msup><mrow><mn>2</mn></mrow><mrow><mi>k</mi></mrow>
</msup>
</mrow></math>. So if the tolerance<a 
id="tolerance32190"></a> with which we
need the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math>-value solution is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&delta;</mi></mrow></math> (generally a small length),
the number of iterations we must take before
convergence<a 
id="convergence32191"></a> is 
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi><mo>=</mo>
<msub><mrow><mi>log</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">(</mo><mi>L</mi><mo stretchy="false">/</mo><mi mathvariant="italic">&delta;</mi><mo stretchy="false">)</mo></mrow></math><a 
id="cost__computational_32192"></a><a 
id="cost__computational__logarithmic32193"></a>. For
example if <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>L</mi><mo stretchy="false">/</mo><mi mathvariant="italic">&delta;</mi><mo>=</mo>
<msup><mrow><mn>10</mn></mrow><mrow><mn>6</mn></mrow>
</msup>
</mrow></math>, then <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi><mo>=</mo><mn>20</mn></mrow></math>. This is a quite modest number
of iterations even for a very high degree of refinement.

<div class="p"><!----></div>
There are iterative methods of root finding that converge faster than
bisection for well behaved functions. One is "Newton's
method"<a 
id="Newton_method32194"></a>, which may succinctly be stated as
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>=</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>k</mi></mrow>
</msub>
<mo>-</mo><mi>f</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>s</mi></mrow><mrow><mi>k</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo>
<msub><mrow><mo> </mo><mi mathvariant="italic">df</mi><mo stretchy="false">/</mo><mi mathvariant="italic">ds</mi><mo>|</mo></mrow><mrow>
<msub><mrow><mi>s</mi></mrow><mrow><mi>k</mi></mrow>
</msub>
</mrow>
</msub>
</mrow></math>. It converges in a
few steps when the starting guess<a 
id="guess_initial32195"></a> 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
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">df</mi><mo stretchy="false">/</mo><mi mathvariant="italic">ds</mi><mo>=</mo><mn>0</mn></mrow></math>, 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<a 
id="robustness32196"></a> is in practice
usually more important than speed.<a 
id="false-position___method32197"></a><a href="footnote.xml#tthFtNtABG" id="tthFrefABG"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>16</mn></mrow>
</msup>
</mrow></math></a>

<div class="p"><!----></div>
In the context of our shooting solution of a two-point problem, the
function <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi></mrow></math> is the error in the boundary value at the second point
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></math> of the inital-value solution <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math> that takes
initial-value <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math> for its derivative at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>. The bisection generally
adjusts the initial-value <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math> until <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">&verbar;</mo><mi>y</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">&verbar;</mo></mrow></math> is less than some
tolerance<a 
id="tolerance32198"></a> (rather than requiring some tolerance on <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>s</mi></mrow></math>).

<div class="p"><!----></div>
 <a id="tth_sEc3.3"></a><h2>
3.3&nbsp;&nbsp;Direct Solution</h2>

<div class="p"><!----></div>
The shooting method, while sometimes useful for situations where
adaptive
step-length<a 
id="adaptive_step-length33199"></a><a 
id="step-length_adaptive33200"></a> is
a major benefit, is rather a back-handed way of solving two-point
problems. It is very often better to solve the problem by constructing
a finite difference system to represent the differential equation
<em>including</em> its boundary conditions, and then solve that system
directly.

<div class="p"><!----></div>
     <a id="tth_sEc3.3.1"></a><h3>
3.3.1&nbsp;&nbsp;Second-order finite differences</h3>

<div class="p"><!----></div>
<a 
id="second-order_differences33201"></a><a 
id="discrete33202"></a> 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)<a 
id="mesh33203"></a><a 
id="grid33204"></a> of values of the independent variable
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></math> such that <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>=</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow></math>. The natural definition of the
first derivative<a 
id="first_derivative33205"></a><a 
id="first_derivative_discrete33206"></a> is
<a id="2pt7">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dy</mi></mrow>
<mrow><mi mathvariant="italic">dx</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>=</mo>
<mfrac><mrow><mi mathvariant="italic">&Delta;</mi><mi>y</mi></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow>
</mfrac>
<mo>=</mo>
<mfrac><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
</mfrac>
<mo>;</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>7</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


and this should be regarded as an estimate of the value at the
midpoint <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>=</mo><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mn>2</mn></mrow></math>, which we denote via a
half-integral index <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math>. The second 
derivative<a 
id="second_derivative_discrete33207"></a><a 
id="second_derivative33208"></a> 
is the derivative of the derivative. Its most
natural definition, therefore is
<a id="2pt8">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>=</mo>
<mfrac><mrow><mi mathvariant="italic">&Delta;</mi><mo stretchy="false">(</mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo stretchy="false">)</mo></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow>
</mfrac>
<mo>=</mo>
<mfrac><mrow><mrow><mo>(</mo>
<msub><mrow><mo> </mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>|</mo></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mo> </mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>|</mo></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>)</mo></mrow></mrow>
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow>
</mfrac>
<mo>,</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>8</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


as illustrated in Fig.&nbsp;<a href="chap3.xml#l2ndDerivative">3.5</a>.

<div class="p"><!----></div>
<a id="tth_fIg3.5">
</a>   <img src="figures/2ndDerivative.png" alt="figures/2ndDerivative.png" /><a id="2ndDerivative">
</a>
  
<div style="text-align:center">Figure 3.5: Discrete second derivative at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math> is the difference between
    the discrete derivatives at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
</mrow></math>. In a
    uniform mesh, it is 
    divided by the same <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow></math>.<a id="l2ndDerivative">
</a></div>

<div class="p"><!----></div>
Because the first derivative is the value at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math>, the second
derivative (the derivative of the first derivative) is the value at a
point mid way between <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math>, i.e.&nbsp;at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math>. Substituting
from the previous equation (<a href="chap3.xml#2pt7">3.7</a>) we
get<a 
id="binomial33209"></a><a href="footnote.xml#tthFtNtABH" id="tthFrefABH"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>17</mn></mrow>
</msup>
</mrow></math></a>:
<a id="2pt9">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>=</mo>
<mfrac><mrow><mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi><mo>-</mo><mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow>
</mfrac>
<mo>=</mo>
<mfrac><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo><mn>2</mn>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>9</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>



<div class="p"><!----></div>
Now think of the entire mesh stretching from <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow></math> to <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mi>N</mi></mrow></math>. The
values <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></math> at all the nodes can be considered to be a column vector
of length <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>. The second derivative can then be considered to be a
matrix operating on that column vector, to give the values of
eq.&nbsp;(<a href="chap3.xml#2pt9">3.9</a>).  So, written in matrix form we have:
<a id="2pt10">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mo> </mo>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi><mo stretchy="false">/</mo>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mo>|</mo></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mo> </mo>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi><mo stretchy="false">/</mo>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mo>|</mo></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mo> </mo>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi><mo stretchy="false">/</mo>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mo>|</mo></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>=</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>,</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>10</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


where the square <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi><mo>&times;</mo><mi>N</mi></mrow></math> matrix has diagonal elements equal to <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo>-</mo><mn>2</mn></mrow></math>. On the
adjacent diagonals, sometimes called subdiagonals, (indices <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>,</mo><mi>n</mi><mo>+</mo><mn>1</mn></mrow></math> and
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>,</mo><mi>n</mi><mo>-</mo><mn>1</mn></mrow></math>) it has <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mn>1</mn></mrow></math>; and everywhere else it is zero. This overall form is
called tridiagonal<a 
id="tridiagonal33210"></a>.

<div class="p"><!----></div>
If we are considering the equation<a id="generic2pt">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>=</mo><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>11</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math> is
some function (for example <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>g</mi><mo>=</mo><mo>-</mo><mi mathvariant="italic">&rho;</mi><mo stretchy="false">/</mo>
<msub><mrow><mi mathvariant="italic">&epsi;</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math> for our electrostatic
example) then the equation is represented by putting the column vector
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">(</mo>
<msub><mrow><mo> </mo>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi><mo stretchy="false">/</mo>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mo>|</mo></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></math> equal to the column vector <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">(</mo>
<msub><mrow><mi>g</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mi>g</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>x</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow></math>.

<div class="p"><!----></div>
     <a id="tth_sEc3.3.2"></a><h3>
3.3.2&nbsp;&nbsp;Boundary Conditions</h3>
<a id="2ptBCs">
</a>

<div class="p"><!----></div>
<a 
id="boundary_condition33211"></a><a 
id="boundary_condition_discrete33212"></a> However,
in eq.&nbsp;(<a href="chap3.xml#2pt10">3.10</a>), 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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></math> are determined not
by the differential equation and the function <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>g</mi></mrow></math>, 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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>L</mi></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>R</mi></mrow>
</msub>
</mrow></math>
at the left and right-hand ends is to write the equation as:
<a id="2pt11">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>=</mo><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn>
<msub><mrow><mi>y</mi></mrow><mrow><mi>L</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>N</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn>
<msub><mrow><mi>y</mi></mrow><mrow><mi>R</mi></mrow>
</msub>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>12</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


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
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold">h</mi></mrow></math>) uses for the first and last rows the boundary values, and
for the others the elements of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold">g</mi><mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></math>. These adjustments
enforce that the first and last values of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi></mrow></math> are always the boundary
values <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>L</mi></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>R</mi></mrow>
</msub>
</mrow></math>.<a href="footnote.xml#tthFtNtABI" id="tthFrefABI"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>18</mn></mrow>
</msup>
</mrow></math></a>

<div class="p"><!----></div>
Once we have constructed this matrix form of the differential
equation<a 
id="matrix_equation33213"></a>, which we can write:
<a id="2pt12">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mi mathvariant="bold">D</mi><mi mathvariant="bold">y</mi><mo>=</mo><mi mathvariant="bold">h</mi><mo>,</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>13</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


it is obvious that we can solve it by simply inverting the matrix
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold">D</mi></mrow></math> and finding
<a id="2pt13">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mi mathvariant="bold">y</mi><mo>=</mo>
<msup><mrow><mi mathvariant="bold">D</mi></mrow><mrow><mo>-</mo><mn>1</mn></mrow>
</msup>
<mi mathvariant="bold">h</mi><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>14</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


(Or we can use some other appropriate matrix equation solution technique.) 

<div class="p"><!----></div>
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<a 
id="Dirichlet_boundary___condition33214"></a><a 
id="boundary_condition_Dirichlet33215"></a> (value is specified),
we are given Neumann<a 
id="boundary_condition_Neumann33216"></a><a 
id="Neumann___boundary_condition33217"></a> conditions, that is, the <em>derivative</em> (e.g.&nbsp;<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mo> </mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>|</mo></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>) 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
<a id="2pt14">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mo>-</mo><mn>1</mn><mi>&emsp;&emsp;&emsp;</mi><mn>1</mn><mi>&emsp;&emsp;&emsp;</mi><mn>0</mn><mi>&emsp;&emsp;&emsp;</mi><mo>&#x2026;</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><mi mathvariant="bold">y</mi><mo stretchy="false">)</mo><mo>=</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>=</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi><mo stretchy="false">(</mo>
<msub><mrow><mo> </mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>|</mo></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>15</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


However, this choice does not calculate the derivative at the right
place. The expression <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow></math> is the derivative at
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>3</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></math> rather than <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>, which is the boundary<a href="footnote.xml#tthFtNtABJ" id="tthFrefABJ"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>19</mn></mrow>
</msup>
</mrow></math></a>. So the scheme (<a href="chap3.xml#2pt14">3.15</a>) is not properly
centered<a 
id="centered33218"></a> and will give only first
order<a 
id="first-order_accuracy33219"></a> accuracy.<a href="footnote.xml#tthFtNtACA" id="tthFrefACA"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>20</mn></mrow>
</msup>
</mrow></math></a>  A better
extrapolation of the derivative to the boundary is to write instead
for the first row
<a id="2pt15">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>(</mo><mo>-</mo>
<mfrac><mrow><mn>3</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi>&emsp;&emsp;&emsp;</mi><mn>2</mn><mi>&emsp;&emsp;&emsp;</mi><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi>&emsp;&emsp;&emsp;</mi><mn>0</mn><mi>&emsp;&emsp;&emsp;</mi><mo>&#x2026;</mo><mo>)</mo></mrow><mo stretchy="false">(</mo><mi mathvariant="bold">y</mi><mo stretchy="false">)</mo><mo>=</mo><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>3</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>+</mo>
<mfrac><mrow><mn>3</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>=</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi><mo stretchy="false">(</mo>
<msub><mrow><mo> </mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>|</mo></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>16</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>

 
This is a discrete form of the expression <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi>
<msub><mrow><mo>'</mo></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>&ap;</mo><mi>y</mi>
<msub><mrow><mo>'</mo></mrow><mrow><mn>3</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>-</mo><mi>y</mi>"<msub><mi></mi><mrow><mn>2</mn></mrow></msub>
<mo>.</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow></math>, 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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></math> (but of
course using the mirror image of the row given in eq.&nbsp;(<a href="chap3.xml#2pt15">3.16</a>)).

<div class="p"><!----></div>
If the boundary condition is of a more general form (the
so-called Robin<a 
id="boundary_condition_Robin33220"></a><a 
id="Robin_boundary_condition33221"></a> condition)
<a id="2pt16">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mi mathvariant="italic">Ay</mi><mo>+</mo><mi mathvariant="italic">By</mi><mo>'</mo><mo>+</mo><mi>C</mi><mo>=</mo><mn>0</mn><mo>,</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>17</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


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 
<a id="2pt17">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>[</mo><mi>A</mi><mrow><mo>(</mo><mn>1</mn><mi>&emsp;&emsp;&emsp;</mi><mn>0</mn><mi>&emsp;&emsp;&emsp;</mi><mn>0</mn><mi>&emsp;&emsp;&emsp;</mi><mo>&#x2026;</mo><mo stretchy="false">)</mo><mo>+</mo>
<mfrac><mrow><mi>B</mi></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow>
</mfrac>
<mo stretchy="false">(</mo><mo>-</mo>
<mfrac><mrow><mn>3</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi>&emsp;&emsp;&emsp;</mi><mn>2</mn><mi>&emsp;&emsp;&emsp;</mi><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi>&emsp;&emsp;&emsp;</mi><mn>0</mn><mi>&emsp;&emsp;&emsp;</mi><mo>&#x2026;</mo><mo>)</mo></mrow><mo>]</mo></mrow><mo stretchy="false">(</mo><mi mathvariant="bold">y</mi><mo stretchy="false">)</mo><mo>=</mo><mo>-</mo><mi>C</mi><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>18</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>C</mi><mo>=</mo><mn>0</mn></mrow></math>, the boundary condition is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>d</mi><mo stretchy="false">(</mo><mi>ln</mi><mi>y</mi><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>=</mo><mi>y</mi><mo>'</mo><mo stretchy="false">/</mo><mi>y</mi><mo>=</mo><mo>-</mo><mi>A</mi><mo stretchy="false">/</mo><mi>B</mi></mrow></math>.
This form (with <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>A</mi><mo stretchy="false">/</mo><mi>B</mi><mo>=</mo><mn>1</mn></mrow></math>) is the condition that one might apply to the
potential due to a spherically symmetric electrostatic charge at the
outer boundary, for example.

<div class="p"><!----></div>
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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo>-</mo><mn>2</mn></mrow></math>. This is done by multiplying all the row's
elements of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold">D</mi></mrow></math>, and the corresponding entry of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="bold">h</mi></mrow></math> by a
factor <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo>-</mo><mn>2</mn><mo stretchy="false">/</mo>
<msub><mrow><mi>D</mi></mrow><mrow><mn>11</mn></mrow>
</msub>
</mrow></math>, or <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo>-</mo><mn>2</mn><mo stretchy="false">/</mo>
<msub><mrow><mi>D</mi></mrow><mrow><mi mathvariant="italic">NN</mi></mrow>
</msub>
</mrow></math> respectively. This can improve the
conditioning<a 
id="conditioning33222"></a><a 
id="matrix_conditioning33223"></a> of the
matrix, making inversion easier and more accurate.

<div class="p"><!----></div>

<div class="p"><!----></div>
<a id="tth_fIg3.6">
</a>   <img src="figures/periodicBC.png" alt="figures/periodicBC.png" /><a id="periodicBC">
</a>
  
<div style="text-align:center">Figure 3.6: Periodic boundary conditions apply when the independent
    variable is, for example, distance around a periodic domain.<a id="periodic">
</a></div>

<div class="p"><!----></div>
A final type of boundary condition worth discussing is called
"periodic"<a 
id="periodic_boundary_condition33224"></a><a 
id="boundary_condition_periodic33225"></a>. This expression means that the end of the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>x</mi></mrow></math>-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 <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>. See Fig.&nbsp;<a href="chap3.xml#periodic">3.6</a>. They are the same point; so
the values at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>x</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></math> are the same. There are then <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>
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
<a id="2pt18">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&#x2026;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&#x2026;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&#x2026;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&#x2026;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>=</mo><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>N</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
<mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>,</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>19</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


which maintains the pattern <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mn>1</mn><mo>,</mo><mo>-</mo><mn>2</mn><mo>,</mo><mn>1</mn></mrow></math> for every row, without exception.
For the first and last rows, the subdiagonal <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mn>1</mn></mrow></math> 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.<a href="footnote.xml#tthFtNtACB" id="tthFrefACB"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>21</mn></mrow>
</msup>
</mrow></math></a>

<div class="p"><!----></div>
 <a id="tth_sEc3.4"></a><h2>
3.4&nbsp;&nbsp;Conservative Differences, Finite Volumes</h2>

<div class="p"><!----></div>
<a 
id="conservative_form34226"></a>In our cylindrical fuel rod example, we had what one might call a
"weighted derivative": something more complicated than a
Laplacian. One might be tempted to write it in the following way:
<a id="2pt19">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow><mi>d</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mrow><mo>(</mo><mi>r</mi><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>)</mo></mrow><mo>=</mo><mi>r</mi><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>T</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dr</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>+</mo>
<mfrac><mrow><mi>d</mi><mo stretchy="false">(</mo><mi>r</mi><mi mathvariant="italic">&kappa;</mi><mo stretchy="false">)</mo></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>

<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>,</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>20</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


and then use the discrete forms for the first and second derivative in
this expression. The problem with that approach is that first
derivatives are at half-mesh-points (<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math> etc.), while second
derivatives are at whole mesh points (<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math>). So it is not clear how
best to express this multiple term formula discretely in a consistent
manner. In particular, if one adopts an asymmetric form, such as
writing <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dT</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dr</mi>
<msub><mrow><mo stretchy="false">&verbar;</mo></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>&ap;</mo><mo stretchy="false">(</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow></math>, (just ignoring the
fact that this is really centered at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math>, not <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math>), then the
error will be of second-order in <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&Delta;</mi><mi>x</mi></mrow></math>. The scheme will be
accurate only to first-order. That's bad. 

<div class="p"><!----></div>
We must avoid that error. But even so, there are various <em>different</em> ways
to produce schemes that are second-order accurate. Generally the best
way is to recall that the differential form arose as a
<em>conservation equation</em>. It was the conservation of energy that
required the heat flux through a particular radius cylinder <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mn>2</mn><mi mathvariant="italic">&pi;</mi><mi>r</mi><mi mathvariant="italic">&kappa;</mi><mi mathvariant="italic">dT</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dr</mi></mrow></math> to vary with radius only so as to account for the power
density at radius <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi></mrow></math>. It is therefore best to develop the
second-order differential in this way. First we form <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dT</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dr</mi></mrow></math> in the
usual discrete form at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math> and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math>. Then we multiply those
values by <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mi mathvariant="italic">&kappa;</mi></mrow></math> <em>at the same half-mesh positions <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math> and
  <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math></em>.  Then we take the difference of those two fluxes writing:
<a id="2pt20">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mtable>
<mtr><mtd columnalign="right"><mrow>
<mfrac><mrow><mi>d</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mrow><mo>(</mo><mi>r</mi><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>)</mo></mrow></mrow></mtd><mtd columnspan="2" columnalign="left"><mrow><mo>=</mo><mrow><mo>(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<mfrac><mrow>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>r</mi></mrow>
</mfrac>
<mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<mfrac><mrow>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>r</mi></mrow>
</mfrac>
<mo>)</mo></mrow>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi><mi>r</mi></mrow>
</mfrac>
</mrow></mtd></mtr>
<mtr><mtd columnalign="right"><mrow></mrow></mtd><mtd columnalign="right"><mrow><mo>=</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>r</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo stretchy="false">[</mo>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<mi>&ensp;</mi>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></mtd><mtd columnalign="left"><mrow><mi>&ensp;&ensp;</mi>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="right"><mrow></mrow></mtd><mtd columnalign="right"><mrow><mi>&emsp;&emsp;&emsp;</mi><mo>-</mo><mo stretchy="false">(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo stretchy="false">)</mo></mrow></mtd><mtd columnalign="left"><mrow><mi>&ensp;&ensp;</mi>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="right"><mrow></mrow></mtd><mtd columnalign="right"><mrow><mi>&emsp;&emsp;&emsp;</mi><mo>+</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></mtd><mtd columnalign="left"><mrow><mi>&ensp;&ensp;</mi>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mi>&ensp;</mi><mo stretchy="false">]</mo><mo>.</mo></mrow></mtd></mtr></mtable>

</mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>21</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


The big advantage of this expression is that it exactly conserves the
heat flux<a 
id="heat_flux34227"></a>. This property can be seen by considering
the exact heat conservation in integral form<a 
id="integral_form34228"></a> over
the cell consisting of the range <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>&lt;</mo><mi>r</mi><mo>&lt;</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></math>:
<a id="htcons">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mn>2</mn><mi mathvariant="italic">&pi;</mi>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dT</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>-</mo><mn>2</mn><mi mathvariant="italic">&pi;</mi>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dT</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>=</mo><mo>-</mo>
<msubsup><mrow><mo>&int;</mo></mrow><mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
 </mrow>
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></msubsup>
<mi>p</mi><mn>2</mn><mi mathvariant="italic">&pi;</mi><mi>r</mi><mo>'</mo><mi mathvariant="italic">dr</mi><mo>'</mo><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>22</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


Then adding together the versions of this equation for two adjacent
positions <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mi>k</mi><mo>,</mo><mi>k</mi><mo>+</mo><mn>1</mn></mrow></math>, the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dT</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>k</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></math> terms
cancel, provided the expression for <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow><mi mathvariant="italic">dT</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
</mrow></math> is the same at the
same <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math> value regardless of which adjacent cell (<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>k</mi></mrow></math> or <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow></math>) it
arises from. This symmetry is present when using <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dT</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>=</mo><mo stretchy="false">(</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi mathvariant="italic">&Delta;</mi><mi>r</mi></mrow></math> and the half-mesh
values of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mi mathvariant="italic">&kappa;</mi></mrow></math>. The sum of the
equations is therefore the exact total conservation for the region
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>k</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>&lt;</mo><mi>r</mi><mo>&lt;</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>k</mi><mo>+</mo><mn>3</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></math>, 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"<a 
id="finite_volumes34229"></a><a href="footnote.xml#tthFtNtACC" id="tthFrefACC"><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow></mrow><mrow><mn>22</mn></mrow>
</msup>
</mrow></math></a>. The finite volume
in our illustrative case is the annular region between <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></math> and
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow></math>.

<div class="p"><!----></div>
A less satisfactory alternative which remains second-order accurate
might be to evaluate the right hand side of eq.&nbsp;(<a href="chap3.xml#2pt19">3.20</a>) using
double distance derivatives that are centered at the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math> mesh as
follows
<a id="2pt21">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mtable>
<mtr><mtd columnalign="right"><mrow>
<mfrac><mrow><mi>d</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mrow><mo>(</mo><mi>r</mi><mi mathvariant="italic">&kappa;</mi>
<mfrac><mrow><mi>d</mi><mi>T</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>)</mo></mrow></mrow></mtd><mtd columnspan="2" columnalign="right"><mrow><mo>=</mo><mrow><mo>(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<mfrac><mrow>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo><mn>2</mn>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>r</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>+</mo>
<mfrac><mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow>
<mrow><mn>2</mn><mi mathvariant="italic">&Delta;</mi><mi>r</mi></mrow>
</mfrac>

<mfrac><mrow>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow>
<mrow><mn>2</mn><mi mathvariant="italic">&Delta;</mi><mi>r</mi></mrow>
</mfrac>
<mo>)</mo></mrow></mrow></mtd></mtr>
<mtr><mtd columnalign="right"><mrow></mrow></mtd><mtd columnalign="right"><mrow><mo>=</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi>
<msup><mrow><mi>r</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo stretchy="false">[</mo><mi>&ensp;</mi><mo stretchy="false">(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">/</mo><mn>4</mn><mo>+</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">/</mo><mn>4</mn><mo stretchy="false">)</mo></mrow></mtd><mtd columnalign="left"><mrow><mi>&ensp;&ensp;</mi>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="right"><mrow></mrow></mtd><mtd columnalign="right"><mrow><mo>-</mo><mn>2</mn>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd><mtd columnalign="left"><mrow><mi>&ensp;&ensp;</mi>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="right"><mrow></mrow></mtd><mtd columnalign="right"><mrow><mo>+</mo><mo stretchy="false">(</mo><mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">/</mo><mn>4</mn><mo>+</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>

<msub><mrow><mi mathvariant="italic">&kappa;</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">/</mo><mn>4</mn><mo stretchy="false">)</mo></mrow></mtd><mtd columnalign="left"><mrow><mi>&ensp;&ensp;</mi>
<msub><mrow><mi>T</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mo stretchy="false">]</mo><mo>.</mo></mrow></mtd></mtr></mtable>

</mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>23</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


None of the coefficients of the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>T</mi></mrow></math>s in this expression is the same as
in eq.&nbsp;(<a href="chap3.xml#2pt20">3.21</a>) unless <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mi mathvariant="italic">&kappa;</mi></mrow></math> is independent of
position. This is true even in the case where <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mi mathvariant="italic">&kappa;</mi></mrow></math> is known only
at whole mesh points so the half-point values in (<a href="chap3.xml#2pt20">3.21</a>) are
obtained by interpolation. Expression (<a href="chap3.xml#2pt21">3.23</a>) does not exactly
conserve heat flux, which is an important weakness. Expression
(<a href="chap3.xml#2pt20">3.21</a>) is usually to be preferred.

<div class="p"><!----></div>

<h2>Worked Example: Formulating radial differences</h2>

<div class="p"><!----></div>
<a 
id="radial_differences34230"></a>Formulate a matrix scheme to solve by finite-differences the equation
<a id="ch3wkd1">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow><mi>d</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mrow><mo>(</mo><mi>r</mi>
<mfrac><mrow><mi>d</mi><mi>y</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>)</mo></mrow><mo>+</mo><mi mathvariant="italic">rg</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>24</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


with given <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>g</mi></mrow></math> and two-point boundary conditions <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dr</mi><mo>=</mo><mn>0</mn></mrow></math> at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow></math>
and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo>=</mo><mn>0</mn></mrow></math> at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mi>N</mi><mi mathvariant="italic">&Delta;</mi></mrow></math>, on an <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi></mrow></math>-grid of uniform spacing <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">&Delta;</mi></mrow></math>.

<div class="p"><!----></div>
<br />We write down the finite difference equation at a
generic position:
<a id="ch3wk2">
</a><math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dy</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>=</mo>
<mfrac><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi></mrow>
</mfrac>
<mo>.</mo></mrow></math>
Substituting this into the differential equation, we get
<a id="ch3wkd3">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mtable displaystyle="true" align="right" width="80%">
<mtr><mtd columnalign="right" columnspan="1"><mrow><mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<msub><mrow><mi>g</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>=</mo>
<mfrac><mrow><mi>d</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>

<msub><mrow><mo>(</mo><mi>r</mi>
<mfrac><mrow><mi mathvariant="italic">dy</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>)</mo></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
</mtd><mtd columnalign="left">
<mrow><mo>=</mo></mrow>
</mtd><mtd columnalign="left">
<mrow><mrow><mo>(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dy</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mo> </mo>
<mfrac><mrow><mi mathvariant="italic">dy</mi></mrow>
<mrow><mi mathvariant="italic">dr</mi></mrow>
</mfrac>
<mo>|</mo></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
<mo>)</mo></mrow>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi></mrow>
</mfrac>
</mrow>
</mtd></mtr>
<mtr><mtd columnalign="right" columnspan="1"><mrow></mrow>
</mtd><mtd columnalign="left">
<mrow><mo>=</mo></mrow>
</mtd><mtd columnalign="left">
<mrow><mrow><mo>(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<mfrac><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi></mrow>
</mfrac>
<mo>-</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<mfrac><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow>
<mrow><mi mathvariant="italic">&Delta;</mi></mrow>
</mfrac>
<mo>)</mo></mrow>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mi mathvariant="italic">&Delta;</mi></mrow>
</mfrac>
</mrow>
</mtd></mtr>
<mtr><mtd columnalign="right" columnspan="1"><mrow></mrow>
</mtd><mtd columnalign="left">
<mrow><mo>=</mo></mrow>
</mtd><mtd columnalign="left">
<mrow><mrow><mo>(</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo><mn>2</mn>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>

<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>+</mo>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>

<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mo>)</mo></mrow>
<mfrac><mrow><mn>1</mn></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">&Delta;</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>.</mo></mrow>
</mtd><mtd columnalign="right">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>25</mn><mo stretchy="false">)</mo></mtd></mtr>
</mtable>
</mrow>
    </mstyle></math>
</td></tr></table>
<br />

It is convenient (and improves matrix conditioning<a 
id="matrix_conditioning34231"></a>) to divide this
equation through by <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo stretchy="false">/</mo>
<msup><mrow><mi mathvariant="italic">&Delta;</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></math>, so that the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math>th equation reads
<a id="ch3wkd4">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>(</mo>
<mfrac><mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow>
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
</mfrac>
<mo>)</mo></mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow>
</msub>
<mo>-</mo><mn>2</mn>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>+</mo><mrow><mo>(</mo>
<mfrac><mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow>
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
</mfrac>
<mo>)</mo></mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
<mo>=</mo><mo>-</mo>
<msup><mrow><mi mathvariant="italic">&Delta;</mi></mrow><mrow><mn>2</mn></mrow>
</msup>

<msub><mrow><mi>g</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>26</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>


For definiteness we will take the position of the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math>th grid point to
be <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
<mo>=</mo><mi>n</mi><mi mathvariant="italic">&Delta;</mi></mrow></math>, so <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi></mrow></math> runs from <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mn>0</mn></mrow></math> to <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>. Then the coefficients become 
<br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi><mo>&PlusMinus;</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
</msub>
</mrow>
<mrow>
<msub><mrow><mi>r</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow>
</mfrac>
<mo>=</mo>
<mfrac><mrow><mi>n</mi><mo>&PlusMinus;</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow>
<mrow><mi>n</mi></mrow>
</mfrac>
<mo>=</mo><mn>1</mn><mo>&PlusMinus;</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn><mi>n</mi></mrow>
</mfrac>
<mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>27</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>



<div class="p"><!----></div>
The boundary condition at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mi>N</mi></mrow></math> is <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
<mo>=</mo><mn>0</mn></mrow></math>. At <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow></math> we want
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dr</mi><mo>=</mo><mn>0</mn></mrow></math>, but we need to use an expression that is centered<a 
id="centered34232"></a> at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow></math>,
not <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mn>1</mn><mo stretchy="false">/</mo><mn>2</mn></mrow></math>, to give second-order accuracy<a 
id="second-order_accuracy34233"></a>. Therefore following eq.&nbsp;(<a href="chap3.xml#2pt15">3.16</a>) we write the equation at <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow></math>
<a id="ch3wkd5">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mi mathvariant="italic">&Delta;</mi>
<msub><mrow><mo> </mo><mi mathvariant="italic">dy</mi><mo stretchy="false">/</mo><mi mathvariant="italic">dx</mi><mo>|</mo></mrow><mrow><mn>0</mn></mrow>
</msub>
<mo>=</mo><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>2</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>+</mo>
<mfrac><mrow><mn>3</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mo stretchy="false">(</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>-</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
<mo stretchy="false">)</mo><mo>=</mo><mrow><mo>(</mo><mo>-</mo>
<mfrac><mrow><mn>3</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi>&emsp;&emsp;&emsp;</mi><mn>2</mn><mi>&emsp;&emsp;&emsp;</mi><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mi>&emsp;&emsp;&emsp;</mi><mn>0</mn><mi>&emsp;&emsp;&emsp;</mi><mo>&#x2026;</mo><mo>)</mo></mrow><mo stretchy="false">(</mo><mi mathvariant="bold">y</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn><mo>.</mo></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>28</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>

 
Gathering all our equations into a matrix we have:
<span class="small"><a id="ch3wkd6">
</a><br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow><mo>-</mo>
<mfrac><mrow><mn>3</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>1</mn><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn><mo>+</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn><mi>n</mi></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn><mo>+</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn><mi>n</mi></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mo>&dtdot;</mo></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn><mo>-</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn><mo stretchy="false">(</mo><mi>N</mi><mo>-</mo><mn>1</mn><mo stretchy="false">)</mo></mrow>
</mfrac>
</mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>1</mn><mo>+</mo>
<mfrac><mrow><mn>1</mn></mrow>
<mrow><mn>2</mn><mo stretchy="false">(</mo><mi>N</mi><mo>-</mo><mn>1</mn><mo stretchy="false">)</mo></mrow>
</mfrac>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd><mtd columnalign="center"><mrow><mo>-</mo><mn>2</mn></mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>N</mi></mrow>
</msub>
</mrow></mtd></mtr></mtable>

<mo>)</mo></mrow><mo>=</mo><mo>-</mo>
<msup><mrow><mi mathvariant="italic">&Delta;</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mrow><mo>(</mo>
<mtable>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>n</mi></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>:</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow>
<msub><mrow><mi>g</mi></mrow><mrow><mi>N</mi><mo>-</mo><mn>1</mn></mrow>
</msub>
</mrow></mtd></mtr>
<mtr><mtd columnalign="center"><mrow><mn>0</mn></mrow></mtd></mtr></mtable>

<mo>)</mo></mrow></mrow>
    </mstyle></math></td><td width="1">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow><mo stretchy="false">(</mo><mn>3</mn><mo>.</mo><mn>29</mn><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>

</span>
Fig.&nbsp;<a href="chap3.xml#lcyldiff">3.7</a> shows the solution of an illustrative case.

<div class="p"><!----></div>
<a id="tth_fIg3.7">
</a>   <img src="figures/cyldiff.png" alt="figures/cyldiff.png" /><a id="cyldiff">
</a>
  
<div style="text-align:center">Figure 3.7: Example of the result of a finite difference solution for
    <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi></mrow></math> of eq.&nbsp;(<a href="chap3.xml#ch3wkd1">3.24</a>) using a matrix of the form of
    eq.&nbsp;(<a href="chap3.xml#ch3wkd6">3.29</a>). The source <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>g</mi></mrow></math> is purely
    illustrative, and is plotted in the figure. The boundary points at
    the ends of the range of solution are <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow></math>, and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>r</mi><mo>=</mo><mi>N</mi><mi mathvariant="italic">&Delta;</mi><mo>=</mo><mn>4</mn></mrow></math>. A
    grid size <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi><mo>=</mo><mn>25</mn></mrow></math> is used.</div><a id="lcyldiff">
</a>

<div class="p"><!----></div>

<h2>Exercise 3. Solving 2-point ODEs.</h2>

<div class="p"><!----></div>
 1.
Write a code to solve, using matrix inversion, a 2-point ODE of the form 
<br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>=</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>
<br />
 on the <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>x</mi></mrow></math>-domain <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mn>1</mn><mo stretchy="false">]</mo></mrow></math>, spanned by an equally spaced mesh of
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math> nodes, with Dirichlet boundary conditions <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo stretchy="false">(</mo><mn>0</mn><mo stretchy="false">)</mo><mo>=</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>y</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>. 

<div class="p"><!----></div>
When you have got it working, obtain your personal expressions for
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math>, and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math> from
<a href="http://silas.psfc.mit.edu/22.15/giveassign3.cgi"><tt>http://silas.psfc.mit.edu/22.15/giveassign3.cgi</tt></a>. (Or use
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>a</mi><mo>+</mo><mi mathvariant="italic">bx</mi></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>a</mi><mo>=</mo><mn>0</mn><mo>.</mo><mn>15346</mn></mrow></math>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>b</mi><mo>=</mo><mn>0</mn><mo>.</mo><mn>56614</mn></mrow></math>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi><mo>=</mo><mn>44</mn></mrow></math>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
<mo>=</mo><mn>0</mn><mo>.</mo><mn>53488</mn></mrow></math>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
<mo>=</mo><mn>0</mn><mo>.</mo><mn>71957</mn></mrow></math>.) And solve the
differential equation so posed. Plot the solution. 

<div class="p"><!----></div>
Submit the following as your solution:

<ol type="1">
<li> Your code in a computer format that is capable of being
  executed.
<div class="p"><!----></div>
</li>

<li> The expressions of your problem <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math>, and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>
<div class="p"><!----></div>
</li>

<li> The numeric values of your solution <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mi>j</mi></mrow>
</msub>
</mrow></math>.
<div class="p"><!----></div>
</li>

<li> Your plot.
<div class="p"><!----></div>
</li>

<li> Brief commentary (<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo>&lt;</mo><mn>300</mn></mrow></math> words) on what problems you faced and how you solved them.
<div class="p"><!----></div>
</li>
</ol>

<div class="p"><!----></div>
<br /><br /> 2.
Save your code and make a copy with a new name. Edit the new code so
that it solves the ODE
<br />
<table width="100%"><tr><td align="center">
    <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mstyle displaystyle="true"><mrow>
<mfrac><mrow>
<msup><mrow><mi>d</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi></mrow>
<mrow>
<msup><mrow><mi mathvariant="italic">dx</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow>
</mfrac>
<mo>+</mo>
<msup><mrow><mi>k</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
<mi>y</mi><mo>=</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow>
    </mstyle></math>
</td></tr></table>
<br />

on the same domain and with the same boundary conditions, but with the
extra parameter <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow><mi>k</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></math>. Verify that your new code works correctly for
small values of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup><mrow><mi>k</mi></mrow><mrow><mn>2</mn></mrow>
</msup>
</mrow></math>, yielding results close to those of the previous
problem. 

<div class="p"><!----></div>
Investigate what happens to the solution in the vicinity of <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>k</mi><mo>=</mo><mi mathvariant="italic">&pi;</mi></mrow></math>. 

<div class="p"><!----></div>
Describe what the cause of any interesting behavior is.

<div class="p"><!----></div>
Submit the following as your solution:

<ol type="1">
<li> Your code in a computer format that is capable of being
  executed.
<div class="p"><!----></div>
</li>

<li> The expressions of your problem <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mi>N</mi></mrow></math>, <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>0</mn></mrow>
</msub>
</mrow></math>, and <math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msub><mrow><mi>y</mi></mrow><mrow><mn>1</mn></mrow>
</msub>
</mrow></math>
<div class="p"><!----></div>
</li>

<li> Brief description (<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow><mo>&lt;</mo><mn>300</mn></mrow></math> words) of the results of your
  investigation and your explanation.
<div class="p"><!----></div>
</li>

<li> Back up the explanation with plots if you like.
<div class="p"><!----></div>
</li>
</ol>

<div class="p"><!----></div>


<hr /><table width="100%"><tr><td>
 <a href="index.xml">HEAD</a></td><td align="right">
<a href="chap4.xml">NEXT
</a></td></tr></table>
</div></body></html>
