Professional Documents
Culture Documents
ii
c December 28, 2014 Ian W. Knowles
Contents
Preface
vii
1 Mathematical Models
1.1 What is a Mathematical Model? . . . . . . . . . . . . .
1.2 SI Units . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Some PDE Models . . . . . . . . . . . . . . . . . . . .
1.3.1 Heat Flow . . . . . . . . . . . . . . . . . . . . .
1.3.2 Steady State Temperature Distributions . . . .
1.3.3 Diffusion . . . . . . . . . . . . . . . . . . . . . .
1.3.4 Groundwater Flow . . . . . . . . . . . . . . . .
1.3.5 Guitar/Violin Strings: Waves . . . . . . . . . .
1.3.6 Spectral Theory . . . . . . . . . . . . . . . . . .
1.3.7 Vibrating Membranes: The 2-D Wave Equation
.
.
.
.
.
.
.
.
.
.
1
1
3
4
4
10
11
13
16
19
23
.
.
.
.
.
.
.
.
.
.
.
31
31
35
39
45
48
48
50
52
53
56
57
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
iv
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Layers
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
59
59
60
61
61
61
61
63
64
65
66
67
67
68
68
69
71
75
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
77
78
81
82
84
86
87
87
93
96
97
99
101
104
111
113
CONTENTS
5 Classical Electrodynamics
5.1 Electrostatics . . . . . . . . . . . . .
5.1.1 The Electric Field E . . . . .
5.1.2 The Gauss Law . . . . . . . .
5.1.3 Macroscopic Media . . . . . .
5.1.4 Electric Current . . . . . . . .
5.2 Magnetostatics and Faradays Law .
5.2.1 The Biot-Savart-Amp`ere Laws
5.2.2 Macroscopic Magnetostatics .
5.2.3 Stokes Theorem . . . . . . . .
5.2.4 Faraday Law of Induction . .
5.3 The Maxwell Equations . . . . . . .
5.3.1 Vector and Scalar Potentials .
6 Finance
6.1 Random Variables . . . . . . . . . . .
6.1.1 Normal Distribution . . . . .
6.2 Brownian Motion and Diffusion . . .
6.2.1 A Special Diffusion Property .
6.3 Stochastic Processes . . . . . . . . .
6.4 The Ito Integral . . . . . . . . . . . .
6.4.1 Properties of the Ito Integral .
6.4.2 The Ito Formula . . . . . . .
6.5 Asset Prices . . . . . . . . . . . . . .
6.5.1 The Asset Price Model . . . .
6.6 Options and the Black-Scholes PDE .
6.6.1 The European Call Option . .
6.6.2 The Black-Scholes PDE . . .
6.6.3 The Greeks . . . . . . . . . .
6.6.4 Implied Volatility . . . . . . .
6.7 Local Volatility and the Dupire PDE
6.8 Bonds . . . . . . . . . . . . . . . . .
6.8.1 Calculating v with r Known .
6.8.2 Bond Futures . . . . . . . . .
6.8.3 Stochastic Interest Rates . . .
6.8.4 The Bond Pricing Equation .
6.8.5 Bond Options . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
115
. 116
. 117
. 119
. 121
. 123
. 123
. 124
. 129
. 130
. 130
. 132
. 134
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
137
. 137
. 140
. 141
. 144
. 145
. 146
. 149
. 150
. 151
. 153
. 154
. 154
. 155
. 161
. 162
. 164
. 167
. 167
. 169
. 170
. 170
. 171
vi
7 Modeling Projects
7.1 The Planting Box . . . . . . . . . .
7.2 The Mridangam . . . . . . . . . . .
7.3 The Nutwrecker2000 . . . . . . . .
7.4 The Frozen CIDS Problem . . . . .
7.5 Cooling a Computer Chip . . . . .
7.6 Groundwater Modelling . . . . . .
7.7 The Fuel Spill . . . . . . . . . . . .
7.8 The Soap Bubble Problem . . . . .
7.9 Blood Flow . . . . . . . . . . . . .
7.10 The Skin Effect in a Circular Wire
7.11 Hurricanes and Soap Bubbles . . .
7.12 A Rectangular Waveguide . . . . .
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
173
. 173
. 175
. 176
. 178
. 183
. 185
. 187
. 187
. 189
. 192
. 195
. 197
Preface
This course is intended to provide an introduction to the mathematical and
computational skills required to build computer models of practical importance. MA227 (Calculus III) is a prerequisite; the courses MA360/560 (Scientific Programming) and MA455/555 (Partial Differential Equations) are
encouraged but not required.
While mathematical models of many different types are worthy of consideration (discrete, ordinary differential equation models from MA252, and
statistical models as considered in MA486/586, come immediately to mind),
we concentrate here exclusively on those involving a partial differential equation (PDE). In particular, we consider a variety of practical examples in
which we follow the trail of
problem formulation, including statement of relevant physical laws and
discussion of relevant material properties,
derivation of the applicable PDE,
solution of the PDE, and
display and processing of solution data.
The initial examples that we consider are the classical favourites: parabolic
equations like the heat equation, the diffusion equation, and the groundwater
flow equation; elliptic equations as exemplified by the steady state heat problem with sources, and hyperbolic equations in the form of the classical wave
equation and the acoustic wave equation. These equations are solved using
the finite element routines in the MATLAB PDE Toolbox and COMSOL.
In chapter 2 we discuss the various classifications of partial differential equations and look at the finite difference solution method for elliptic
equations and, briefly, the finite element solution method that is used by
vii
viii
PREFACE
Chapter 1
Mathematical Models
1.1
design (very big airplanes, very fast yachts, for example the New Zealand
AC72 class catamaran which is the favorite for the 2013 Americas Cup
trials in San Francisco);
1.2. SI UNITS
In the pages below we gather and discuss in detail some of the classical examples of mathematical models that appear in the form of partial differential
equations or PDEs. But first, a short digression is needed to discuss systems
of units.
1.2
SI Units
1.3
1.3.1
temperature u(x, y, t) at any point (x, y) in the plate, at any later time t.
To do this we must first investigate the relationship between how much
heat energy (joules) it takes to cause a given temperature change in a particular body. The reason for this is that we are interested in the temperature
u, but heat energy is the quantity that actually flows around the plate. The
required connection is given by
Q = c.m.T
(1.1)
where Q is the amount of heat (joules) added, c is the specific heat of the
material (J kg1 K1 ), m is the mass of the body (kg), and T is the temperature change (K). Here, the specific heat of a body is the amount of heat
energy needed to raise unit mass of the material one degree of temperature.
So a lower specific heat means that, for a given mass of material, less heat is
So, you can see that NASA made a big mistake in not making the Space
Shuttle heat shield out of cucumber!
Joseph Fourier 1768-1830, French mathematician and physicist; he came up with the
idea of expanding arbitrary functions in a series of sines and cosines, today known as a
Fourier series in his honor
2
from the Latin word fluxus meaning flow
area of a plane perpendicular to the x-axis in unit time; the SI units are
J m2 s1 . If u is the temperature then the temperature gradient in the x
direction is u/x. So the above law may be written
Fx = x
u
x
(1.2)
where the positive constant of proportionality x is called the thermal conductivity of the body; its SI units are J m1 K1 s1 . The minus sign indicates
that the heat energy moves oppositely to the temperature gradient, i.e. heat
moves from hot areas to cold areas. This law has been obtained experimentally, and is valid often, but not always. Some typical thermal conductivities
appear in the table below:
Material
Thermal Conductivity (W m1 K1 )
water at 20 C
0.56
steel
50.2
copper
401
glass
0.8
air
0.024
wood
0.04-0.12
The Heat Equation
To derive the PDE satisfied by the temperature function u we consider a
small box surrounding a point P (x, y, z) as shown in Figure 1.3. Given that
ABCD and ABCD are the faces perpendicular to the x-axis, the rate at
which heat enters through the face ABCD is
4dy dz (Fx
Fx
dx),
x
where Fx /x.dx is the change in Fx back to the face ABCD, and the rate
at which heat exits through the face ABCD is
4dy dz (Fx +
Fx
dx),
x
So, the net rate at which heat enters the box through these two faces is
8dx dy dz
Fx
.
x
In similar fashion the net rate at which heat enters the box through the faces
perpendicular to the y- and z-axes are, respectively,
8dx dy dz
Fz
Fy
and 8dx dy dz
.
y
z
In addition, heat can enter the box by way of internal sources, such as the
Bunsen burner in our case. For the moment we let all such internal sources
be represented by the function S(x, y, t) with units of J m3 s1 (heat source
per unit volume per unit time). So the total rate at which the heat energy
increases in the box is
Fx Fy Fz
8dxdydz (
+
+
) + 8dxdydz S(x, y, z, t).
(1.3)
x
y
z
Let (x, y, z) denote the density (mass per unit volume) of the material (the
metal in our case). From (1.1) the rate at which the amount of heat energy
increases in the box is
Q
u
= c.m.
t
t
where m is the mass of material in the box; as m = 8 dxdydz the rate at
which heat increases in the box is
u
8c dxdydz
,
t
u
Fx Fy Fz
+(
+
+
) = S(x, y, z, t).
t
x
y
z
Finally, if we use (1.2) and assume the isotropic3 case in which we have
x = y = z = (which may still be a function of x, y, z) we obtain the
heat equation:
c
u
u
u
u
( ( ) +
( ) + ( )) = S(x, y, z, t)
t
x x
y y
z z
(1.4)
This is the equation you would use for three-dimensional heat flow. It is of
parabolic type (see Chapter 2). In our case we can reasonably assume that for
a thin plate the temperature u does not vary appreciably in the z direction,
so u/z = 0, and the functions and S do not depend on z as well. This
leads us to the two-dimensional heat equation for our metal plate:
c
u
u
u
( ( ) +
( )) = S(x, y, t).
t
x x
y y
(1.5)
One could represent the effect of the Bunsen burner with the source function
1 (x, y) in B
S(x, y, t) =
0 (x, y) not in B
where B is a small ball with center (a, b).
If the metal in the plate is uniform we can assume that the coefficients c,
, and K are constants. The equation may then be written
S(x, y, t)
u
ku =
t
c
(1.6)
2u 2u
+
x2 y 2
(1.7)
for (x, y) in the boundary and all time t, and a given g, is called a Dirichlet4
boundary condition. A condition of the form
u n + au = g
is called a generalized Neumann5 (or Robin) condition. Here, n = (n1 , n2 )T is
10
ary, and
u
x
u =
u
y
is the gradient of u, and the outward normal derivative (this is just the
directional derivative from Calculus III) is
u
u
u
= u n = n1
+ n2 ;
n
x
y
from (1.2) u n represents the outward heat flux in a direction normal
to the boundary. A variant of this boundary condition takes the form
u n = h.(Te u).
This represents the physical situation in which the heat flux is proportional
to the difference between the fixed temperature, Te , of the exterior and the
current temperature, u, of the heated body; h is called a heat transmission
coefficient.
We also know that at time t = 0
u(x, y, 0) = 0
(1.8)
at all points (x, y) in the plate. This is called an initial condition. Again,
the use of different values here would also lead to a different u. It is a
mathematical fact that the two additional conditions (1.7) and (1.8) are
enough to guarantee unique solutions for these parabolic equations.
1.3.2
If the heat source function S and the boundary conditions do not depend
on time, i.e. S = S(x, y) in 2-D, then it is reasonable to expect that, after
a sufficiently long time, the temperature at each point (x, y) in our plate
should settle down to some steady value. Mathematically, we expect that
lim u(x, y, t) = U (x, y)
where the function U represents the so-called steady state temperature distribution. We can obtain the partial differential equation representing the
11
U
U
(
)
(
) = S(x, y),
x x
y y
(1.9)
an example of an elliptic equation (see Chapter 2). Such equations also occur
in gravitational potential theory, and in electrostatics and magnetostatics, to
name but a few application areas.
Unique solutions are ensured by applying either Dirichlet or Neumann
boundary conditions in the manner discussed above for parabolic equations.
Notice that as time has in effect disappeared here, initial conditions are no
longer needed.
1.3.3
Diffusion
12
respondingly less intensely colored. After a sufficiently long time the iodine
molecules move so as to become uniformly distributed throughout the vessel.
The transfer of heat by conduction is also due to random molecular motions and there is an obvious analogy between the two processes, as was
recognized by Fick7 who, around 1855, adapted the ideas Fourier used in
deriving the equation of heat conduction given above. The relevant physical
law in this case is the
Fick Law of Diffusion:
Diffusive flux is proportional to the concentration gradient.
Here, if we restrict attention for the moment to diffusion in the x-direction,
the diffusive flux, Fx , is the amount of diffusing substance moving through
unit area of a plane perpendicular to the x-axis in unit time; the SI units are
mol m2 s1 . If C is the concentration then the concentration gradient in the
x direction is C/x. So the above law may be written
Fx = Dx
C
x
(1.10)
where the positive constant of proportionality Dx is called the diffusion coefficient of the diffusive material; its SI units are m2 s1 . The minus sign
indicates that the diffusive material moves oppositely to the concentration
gradient. This law has been obtained experimentally, and is valid often, but
not always. Some diffusion coefficients appear in the table below:
Material
Diffusion Coefficient in Water (m2 s1 )
Iodine I2 (20 C)
1.0 109
Oxygen O2
1.97 109
Benzene
1.10 109
Ethylene Dichloride
9.90 1010
Using an analogous, but simpler (no temperature here) argument to that
used in the heat flow problem, we can see that the partial differential equation
for diffusion in 2-D is
C
C
=
(D
)+
(D
)
t
x
x
y
y
7
(1.11)
13
C
=
(D
)+
(D
) + (D
)
t
x
x
y
y
z
z
(1.12)
1.3.4
(1.13)
Groundwater Flow
Much of the potable8 water on the planet lies underground in large and small
geologic formations called aquifers. A common situation of interest occurs
when the groundwater is trapped in a porous medium between two (more
or less) horizontal impervious layers; such a groundwater system is called
a two-dimensional confined aquifer, as is illustrated in Figure 1.6 below.
Sources of water for an aquifer include rainfall, and subsequent seepage under
the influence of gravity, and underground streams. These sources cause the
8
14
water to move through the aquifer under pressure. In a well penetrating the
aquifer, the water level will rise to a height in the well, called the piezometric
head, that depends on the pressure of the groundwater in the aquifer at that
point. Analogous to heat flow and diffusion we have
The Experimental Law of Darcy
The discharge per unit width of aquifer is proportional to the
hydraulic gradient.
Here the discharge in say the x-direction, qx , is the volume of water per unit
time crossing unit area of the aquifer normal to the x-direction. If we denote
the piezometric head by , then Darcys Law becomes
qx = Tx
(1.14)
x
where the constant of proportionality, Tx , is called the transmissivity; it
represents the ease with which the water passes through the aquifer region.
Storativity
As the pressure increases in an aquifer, the porous medium tends to expand
somewhat and absorb additional water; conversely, as the pressure decreases,
15
w
.
A
(1.15)
where b is the aquifer thickness and F (x, y, t) (with units of volume per unit
time) represents external recharge (averaged over z) into the system from
various subsurface sources, as well as above ground sources such as rainfall.
If we divide by the product dx dy dt and let each factor tend to zero, we
obtain
=
(Tx ) +
(Ty ) + F.
t
x
x
y
y
(1.16)
A common assumption (often unjustified, but made anyway) is that the water
always flows in the direction of the pressure gradient; the porous medium
is then called isotropic and Tx = Ty = T (x, y), so that the flow equation
becomes
S
=
(T ) +
(T ) + F.
(1.17)
t
x x
y y
16
More generally, for an anisotropic aquifer the generalized Darcy Law holds:
q = T
(1.18)
Here q is the specific flux vector, is the pressure gradient vector, and
T11 T12
T=
.
T12 T22
is the transmissivity matrix. The groundwater flow equation then takes the
form
S
= (T) + F.
t
1.3.5
Figure 1.8: The Stones: Wyman, Jones, Watts, Jagger, Richards circa 1963
17
18
2u
(
x, t)
t2
(1.19)
Now if h(x, t) denotes the magnitude of the horizontal component of TL (x, t),
then h(x, t) = T (x, t) cos . As we assume that there is no net horizontal motion of the segment, it follows that h(x, t) = h(x + dx, t), and thus h is
independent of x. In fact, as we are assuming only small string displacements, cos 1 and h(x, t) T (x, t), where, again because of the small
displacements, the tension in the string T (x, t) T , a constant. So to a
reasonable approximation we have
v(x, t) = h(x, t) tan = T
u
.
x
(1.20)
19
0 x L;
0 x L.
It is a mathematical fact that these two conditions, together with the wave
equation and suitable boundary conditions uniquely determine the solution
u.
1.3.6
Spectral Theory
20
with the aim of finding a solution vector x that is not the zero vector. One
learns in Linear Algebra that the values for which this can be done are
quite exceptional. There are at most n such and we call them eigenvalues
of A; the corresponding solutions x are the associated eigenvectors. If we
write the linear system as
(A I)x = 0,
where I denotes the n n identity matrix, from a theorem in Linear Algebra,
if the determinant |A I| =
6 0 we know that the (unique) solution x must
be the zero vector; so
|A I| = 0
is an equation for the eigenvalues of A. One can see that this is a polynomial
equation in of degree n, and so it follows from the Gauss theorem that a
matrix of order n has n eigenvalues, counted according to multiplicity, so
repeated roots are counted separately.
If we regard the matrix A as a linear operator on Rn that takes the vector
x to the vector Ax, then the set of eigenvalues is called the spectrum of this
linear operator. The word spectrum comes originally from physical optics
wherein visible light was separated into a color spectrum by a prism (or, in
the case of the rainbow above, by small droplets of water). We connect these
ideas below.
Eigenvalues and Vibration Modes
Consider a guitar string stretched between x = 0 and x = 1. As we saw
earlier, if the string is plucked and we denote the displacement at time t of
the part of the string located at x by u(x, t), then the function u satisfies
(assuming appropriate units are chosen for the string density and tension)
the wave equation
utt = uxx .
We now look for musical (see below) solutions of the form
u(x, t) = U (x).eit .
Our wave equation above now becomes
Uxx = (i)2 U (x) = 2 U (x) = U (x),
(1.21)
21
n = 0, 1, 2, . . .
These are the eigenvalues (in this case, of the differential operator A that
takes a function U to minus its second derivative) and for each n the corresponding eigenfunction is
Un (x) = sin(nx).
It is instructive to look at the first three eigenfunctions, using n = 1, 2, 3,
listed in order below. The first eigenfunction motion can be seen by plucking
the string exactly at its midpoint. If you touch (i.e. dampen) a moving string
exactly at the midpoint, you will see a vibration like the second eigenfunction.
If you repeat this by touching the string exactly at the one-third point, you
will see the third eigenfunction in the resulting vibration.
Figure 1.10: The first three eigenfunctions
(a) n = 1
(b) n = 2
(c) n = 3
22
int
Cn Un (x)e
n=1
Cn sin(nx)eint .
n=1
2
2
2
= .
=
n
n
n
Now, as one cycle takes n seconds, one second corresponds to 1/n cycles,
so that the frequency fn = 1/n . So the frequencies fn are
fn =
n
,
2
n = 1, 2, 3, . . .
1.3.7
23
(x, y) in .
A Wave Animation
We use the MATLAB PDE Toolbox to produce an animation of a membrane
wave. Specifically, consider the equation
2u
u = 0
t2
on the square region with opposite corners at (1, 1) and (1, 1). The
membrane is assumed to be fixed on the left and right sides and free on the
upper and lower sides:
u(1, y) = u(1, y) = 0
u
u
(x, 1) =
(x, 1) = 0.
y
y
We assume initial conditions of the form
24
(a) u(x, y, 0)
(b) ut (x, y, 0)
with the menu choice PDEPDE Specification and select the hyperbolic type and set the PDE coefficients c = 1, a = 0, f = 0, and d = 1.
Then go the solve menu and select the SolveSolve Parameters dialog
box and enter, as a list of times, linspace(0,5,31) and also enter, as initial
functions,
atan(cos(pi/2*x))
for u, and
3*sin(pi*x).*exp(sin(pi/2*y))
for ut (take careful note of the dot-star separating the two functions here if you omit the dot, MATLAB will bite you). Finally, press the plot button
and select Color, as well as Height (3-D plot), and Animation and
Plot in x-y grid and close the dialog box.
Press the button to solve and animate the membrane wave. You will
notice that first each frame of the animation is computed separately, and
then they are sequenced, and then the movie is played a number of times
specified in the animation Options.
This demonstration shows clearly that the wave equation really does represent certain types of wave motion.
Musical and Non-musical Sounds
When we hear a sound, our eardrums pick up the alternate compressions and
rarefactions of air produced by the vibrations of the source. For this sound
to be musical (melodious) it must possess two characteristics: pitch and
timbre.
25
(b) Clarinet
26
2
U,
T
=
.
f=
2
2
These eigenvalues can be found with the MATLAB PDE Toolbox as follows. The general form is
cU + aU = dU.
The above problem is solved with c = 1, a = 0, and d = 20 to simulate a
constant areal density function = 20.
This can be seen from the theory given in MA455 using the zeros of
Bessel functions, or by using the Eigenmodes option in the MATLAB PDE
Toolbox as follows. First start MATLAB and then PDE Toolbox as indicated
earlier. Choose OptionsGrid and then OptionsSnap to set a drawing
27
grid which locks any boundary curve to a nearby grid point. Then click on
the circle+ icon (fourth from left at the top) and, by clicking on the point
(0, 0), and holding, you can drag out a circular domain
= {(x, y) : x2 + y 2 1}.
We do not need to set the boundary condition here as we use u = 0 on
and that is the default. Next, we set the PDE type and coefficients. To
do this click the PDE button and choose Eigenmodes and set d to be 20
and press OK; we use the default c=1 and a=0 here, by the way. Next, to
set the computational grid (also called a mesh), click the mesh button (next
to PDE with a triangle on it); this sets up a coarse triangular grid over
our circular region . Refine this grid by pressing the refine mesh button
(look for a triangle in a triangle) once. This makes the computations more
accurate, at the expense of greater calculation time. You may now press the
button to compute the eigenmodes. From the MATLAB menus at the
top choose SolveExport Solution... and click OK in the dialog box
that appears. Among other things, this sends the eigenvalues to the main
MATLAB screen in the form of the column vector l (this is an ell here)
as you can check by typing l at the MATLAB prompt in the Command
Window. Again at the MATLAB prompt enter
f = sqrt(l)/(2 pi)
to see the associated vibration frequencies, and
f = f/f(1)
28
to check for the existence of harmonics. It should be clear that in this case
the higher frequencies are not integer multiples of the lowest frequency f(1),
so there are no harmonics in this case.
The Mridangam Drum
The mridangam drum from southern India consists of a radially variable density membrane stretched tightly over a circular frame as pictured below. It
has the unusual property of being harmonic, i.e. the frequencies of vibration of the membrane are integer multiples of the lowest, or fundamental,
frequency.
There are several approximate forms of with which one can investigate
the harmonic properties of the mridangam. Consider first using a two-part
density function
(r) =
1
2
for 0 r < a,
for a r < b,
a
k= ,
b
29
1 for 0 r < a
2 for a r < b
(r) =
3 for b r < l.
30
r
=
2
,
3
b
k= .
l
Chapter 2
Partial Differential Equations
2.1
Introduction
A partial differential equation or PDE is an equation for an unknown multivariable function in terms of its partial derivatives. There are many approaches to classifying different types of PDEs. As with ODEs one primarily
has the order of the equation which is the order of the highest derivative
appearing. An example of a first order PDE is
L[u] =
u u
+
=1
x y
(2.1)
for the unknown function u = u(x, y). Another first order equation is
2 2
u
u
+
=1
(2.2)
N [u] =
x
y
While these equations share a common order, they are quite different in
another important respect. In the first equation the operator L describing
the left side has the following property:
(u + v) (u + v)
+
x
y
= L[u] + L[v].
L[u + v] =
We call such an operator linear, and the equation (2.1) is said to be a linear
partial differential equation. The operator N is not linear, and the equation
(2.2) is an example of a nonlinear partial differential equation.
31
32
(2.3)
(2.4)
and governs heat flow in one space dimension. Finally, the wave equation in
one space variable is given by
2u
2u
=
t2
x2
(2.5)
arises in connection with waves in one space dimension, for example a guitar
string.
While these equations share linearity and order and the number of independent variables, their properties differ markedly when one considers the
kinds of boundary and initial conditions needed to assure unique solutions.
These equations are also special in that if we concentrate on second order
linear equations in two variables, essentially all such equations behave like
one of these.
Classification of Second Order Linear PDEs
Consider the more general second order linear differential equation
A
2u
2u
u
u
2u
+
B
+
C
=D
+E ,
2
2
t
xt
x
t
x
(2.6)
where A, B, C, D, and E are given constants, and investigate the consequences of making the transformation of coordinates
= x + t,
= x + t.
1
2
2.1. INTRODUCTION
33
(2.7)
from which the solution is seen to be u(x, y) = p() + q(), for arbitrary
differentiable functions of one variable p and q. So it is reasonable to seek a
similar simplification for the general equation (2.6).
Now, setting U (, ) = u(x, t), the above coordinate change applied to
(2.6) produces
2U
2U
+
(2A
+
B(
+
)
+
2C)
2
2
U
U
U
+ (D + E)
.
+ (A 2 + B + C 2 ) 2 = (D + E)
(A 2 + B + C2 )
We need
A 2 + B + C2 = 0,
A 2 + B + C 2 = 0,
(2.8)
1 h
=
B + B 2 4AC ,
2A
i
1 h
=
B B 2 4AC .
2A
There are now three cases. If
B 2 4AC > 0,
34
the transformation of (2.6) to (2.7) exists; in this case we say that the equation (2.6) is of hyperbolic type. The transformation is given by
= 2Ax + [B + B 2 4AC]t,
= 2Ax + [B B 2 4AC]t.
and all of these equations behave similarly to the wave equation. If B 2
4AC = 0, we say that the equation (2.6) is of parabolic type. In this case
/ = B/2A makes the coefficient of 2 u/ 2 vanish, and from the identity B/2A = 2C/B the coefficient of 2 u/ also vanishes and so the
transformation
= 2Ax Bt,
= t,
basically turns (2.6) into a heat equation,
2U
U
U
= A 2 + D
.
(2AD EB)
If
B 2 4AC < 0
we say that equation (2.6) is of elliptic type. Here there are no real solutions
of the quadratic equations and no real choice of / or / makes the coefficients of 2 u/ 2 and 2 u/ 2 both vanish. It is true however that the
transformation
2Ax Bt
,
=
4AC B 2
= t,
turns (2.6) into the Laplace equation
2u 2u
+ 2 = 0.
2
35
2.2
36
Here, the last term, which is usually called the remainder term, R(h, k), is
of order h4 + k 4 ; i.e. there is a constant K such that
|R(h, k)| K.(h4 + k 4 ).
Observe that, on replacing h by h and k by k, we find that
u(x h, y k) = u(x, y) hux (x, y) kuy (x, y)
+ 2!1 [h2 uxx (x, y) + 2hkuxy (x, y) + k 2 uyy (x, y)]
3!1 [h3 uxxx (x, y) + 3h2 kuxxy (x, y)
+3hk 2 uxyy (x, y) + k 3 uyyy ] + O(h4 + k 4 ).
(2.10)
From a rearrangement of equation (2.9) first with k = 0, and then with
h = 0, we find the
Forward Difference Formulae:
u(x + h, y) u(x, y)
+ O(h)
h
u(x, y + k) u(x, y)
uy (x, y) =
+ O(k)
k
ux (x, y) =
(2.11)
(2.12)
ux (x, y) =
(2.13)
(2.14)
37
ux (x, y) =
(2.16)
(2.17)
uxx (x, y) =
(2.19)
(2.20)
38
39
denote the PDE solution values at the node points (see Figure 2.1), then at
the node point (xr , ys ) we have from (2.19) and (2.20)
ur1,s 2urs + ur+1,s
+ O(h2 )
h2
ur,s1 2urs + ur,s+1
uyy (xr , ys ) =
+ O(k 2 )
k2
uxx (xr , ys ) =
2.2.1
(2.25)
(2.26)
Elliptic Equations
40
Problem 1
Consider first the following boundary value problem. Find the solution u of
the Laplace equation
uxx + uyy = 0
(2.27)
0 x 1,
= u1,0
= u0,2
= u2,4
= u3,2
=0
= u2,0
= u0,3
= u2,3
= u4,2
and we ignore the exterior grid points (x5 , y1 ), (x1 , y1 ),(x1 , y2 ), and (x1 , y3 ),
for the moment. The unknown grid values are u1,3 , u1,2 , u1,1 , u2,1 , u3,1 ; at each
of these grid points we substitute the derivative approximations (2.25) and
41
:
:
:
:
:
=0
=0
=0
=0
= 0.
Notice that at each of the five grid points one can obtain the equation by
considering the so-called five-point stencil (see Figure 2.3) and using a weight
of 1 at each of the blue nodes, and -4 at the center.
Using the boundary values (2.28), we arrive at the system
u1,2 + u2,1 4u1,1
u1,1 + u3,1 4u2,1
u2,1 4u3,1
u1,3 + u1,1 4u1,2
u1,2 4u1,3
=
=
=
=
=
100
100
100
0
0.
Notice that the solutions urs of these equations are now (in general) only
approximations of the solutions values u(xr , ys ).
If we make the assignments (using row ordering)
u1 u1,1 ,
u2 u2,1 ,
u3 u3,1 ,
u4 u1,2 ,
u5 u1,3 ,
(2.29)
100
4
1
0
1
0
u1
1 4
1
0
0
u2 100
0
1 4
0
0
(2.30)
u3 = 100
1
0
0 4
1 u4
0
u5
0
0
0
0
1 4
and this system can be solved with MATLAB.
Problem 2
Consider next the problem of finding the solution u of the Laplace equation
uxx + uyy = 0
(2.31)
42
over the same region as above and subject to the mixed Dirichlet and
Neumann boundary conditions
u(x, 0)
u
(0, y)
x
u
(1, y)
x
u
= 100,
0 x 1,
(2.32)
= 0,
0 y 1,
(2.33)
= 0,
0 y 0.5,
(2.34)
= 0,
(2.35)
(2.36)
In addition to the internal unknown solution values u1,1 , u1,2 , u1,3 , u2,1 , and
u3,1 , we now have to determine approximations for the solution at the bound-
43
ary points u0,1 , u0,2 , u0,3 , u4,1 , and the ghost grid values u1,1 , u1,2 , u1,3 ,
and u5,1 , thirteen unknowns in all.
At the grid point (x4 , y1 ) we use a central difference approximation of the
derivative ux (x4 , y1 ) to satisfy the Neumann condition (2.34):
ux (x4 , y1 )
u5,1 u3,1
= 0.
2h
This formula is O(h2 ) accurate, in line with the other approximations that
we are making. In similar fashion, using the Neumann data at the grid points
(x0 , y1 ), (x0 , y2 ), and (x0 , y3 ) we obtain the equations
u5,1
u1,1
u1,2
u1,1
=
=
=
=
u3,1
u1,1
u1,2
u1,3
(2.37)
44
=
=
=
=
=
=
=
=
=
100
0
0
100
0
0
100
100
100
(2.38)
in the nine (non-ghost) unknowns u0,1 , u0,2 , u0,3 , u1,1 , u1,2 , u1,3 , u2,1 , u3,1 , u4,1 .
To produce a matrix system, we make the (column ordered) assignments
u0,1 = u1 ,
u1,1 = u4 ,
u2,1 = u7 ,
u0,2 = u2 ,
u1,2 = u5 ,
u3,1 = u8 ,
u0,3 = u3 ,
u1,3 = u6 ,
u4,1 = u9 .
=
=
=
=
=
=
=
=
=
100
0
0
100
0
0
100
100
100
4
1
0
2
0
0
0
0
0
1 4
1
0
2
0
0
0
0
0
1 4
0
0
2
0
0
0
1
0
0
4
1
0
1
0
0
0
1
0
1 4
1
0
0
0
0
0
1
0
1
4
0
0
0
0
0
0
1
0
0 4
1
0
0
0
0
0
0
0
1 4
1
0
0
0
0
0
0
0
2 4
45
u1
u2
u3
u4
u5
u6
u7
u8
u9
100
0
0
100
0
0
100
100
100
(2.39)
2.2.2
Parabolic Equations
(2.40)
for (x, y) in ,
(2.42)
46
This ODE initial value system can now be solved with standard ODE solver
routines.
In the case that Neumann boundary conditions are present, one can employ the technique of ghost boundary points, as in the elliptic case, and then
proceed as above.
This approach to solving parabolic equations is called the Method of Lines
and is the recommended technique for the following reason. The typical alternative method involves approximating the time derivative ut in the parabolic
equation by a finite difference formula using a uniform t-mesh. One then
finds that, in certain situations (generally unknown in advance) the method
requires very small time steps for stability of the algorithm.
The reason for this is not hard to find. It is known (and should be expected anyway) that some ODE solutions have small gradients in parts of
their domain, intermixed with regions where the solution gradient is very
large. In the latter region, one must use small time-steps to ensure an accurate solution. The problem here is that if the time-step is uniform on
the whole domain, you will be wasting computing resources in those regions
that have small gradient, because a larger time-step is permissible for those
regions.
The good ODE solvers have long ago solved this problem by employing
adaptive stepsize control, i.e. the solver uses large time-steps when it can,
and small time-steps when it must. These solvers are very robust and have
been working well for decades. So they are exactly the correct resource for
these parabolic problems.
As an example, consider the above equation with the square domain
overlain with the grid shown in Figure 2.5 below and assuming the Dirichlet
boundary condition given by,
u(x, 0) = 100, 0 x 1
u(x, y) = 0, elsewhere on the boundary of .
47
the equations
du1,1
dt
du
1,2
h2
dt
du
2,1
h2
dt
du2,2
h2
dt
h2
u1,2 (0) = 0,
u2,1 (0) = 0,
u2,2 (0) = 0.
This ODE system can be solved with, for example, the subroutine xodeint.f
used in MA360, or the ODE subroutines available in MATLAB.
48
2.2.3
Hyperbolic Equations
The method of lines may also be applied to hyperbolic equations. For example, the hyperbolic equation
utt = uxx + uyy
(2.43)
for (x, y) in ,
for (x, y) in .
(2.44)
(2.45)
(2.47)
(2.48)
and Br,s again denotes the contributions from the Dirichlet boundary data
(if any). This ODE initial value system can now be solved with standard
ODE solver routines, after first transforming each second order equation to
a subsystem of two first order equations (see MA360, for example).
2.3
If the PDE domain boundary is not a polygon with sides parallel to the
coordinate axes, finite difference methods tend to be not only more cum-
49
bersome, but more inaccurate. In some situations, such as the lake region
shown below, the use of finite differences would be something of a nightmare
to implement. A better choice under these circumstances is the finite element method (FEM). We content ourselves here with a brief overview of the
essential ideas involved in the 2-D case.
In the finite element approach, we first approximate the computational
domain with a union of simple geometrical objects, usually either triangles
(see Figure 2.6) or rectangles; in the MATLAB PDE Toolbox for example,
triangles are used. The triangles form a mesh, and each triangle vertex is
called a node. If greater accuracy is desired, the mesh can be refined by
further subdividing each triangle into smaller triangles, either uniformly on
the domain, or adaptively in appropriate sub-domains, until the mesh is fine
enough to achieve the desired accuracy.
Next, the approximate solution is chosen to take a simple form on each
triangle. Polynomials are a widely favored choice; they are easy to evaluate,
and have good approximation properties on small domains. MATLAB uses
functions that are linear on each triangle, and continuous across each triangle
boundary, as can be seen in Figure 2.6; such functions are called continuous
50
2.3.1
For a vector function F(x, y) = (F1 (x, y), F2 (x, y))T defined on a plane region
= B with boundary = C having parametric form (x(t), y(t)), a t b,
we have from Greens theorem in Calculus III,
51
Z
B
F1 (x, y) F2 (x, y)
+
dxdy =
x
y
Z
F2 (x, y) dx + F1 (x, y) dy
C
Z b
p
F(x(t), y(t)) n x0 (t)2 + y 0 (t)2 dt.
where
F1 F2
+
x
y
is the divergence of the vector function F, and
F=
(y 0 (t), x0 (t))
n(x, y) = p
x0 (t)2 + y 0 (t)2
is the unit outward normal vector located at each point (x, y) in the boundary
C = of B = . Here, one can see that n is outward by checking the four
cases
x0
x0
x0
x0
> 0, y 0
> 0, y 0
< 0, y 0
< 0, y 0
>0
<0
>0
<0
52
follows.
If we use this formula with F = v.cu then as
F = (v.cu) = cu v + v (cu),
we have
Z
Z
v(x, y)c(x, y)u n ds = (c(x, y)u v + v(x, y) (c(x, y)u)) dxdy,
so that
Z
v (cu) =
Z
vcu n
cu v.
(2.49)
2.3.2
where F(x, y, z) = (F1 (x, y, z), F2 (x, y, z), F3 (x, y, z))T , and
F=
F1 F2 F3
+
+
x
y
z
is the divergence of the vector function F, and n(x, y, z) is the unit outward
normal vector at each point (x, y, z) in the boundary, , of .
If we use this formula with F = v.cu then as
F = (v.cu) = cu v + v (cu),
53
we have
Z
Z
v(x, y, z)c(x, y, z)un dS = (c(x, y, z)uv+v(x, y, z)(c(x, y, z)u)) dxdydz,
so that
Z
v (cu) =
2.3.3
Z
vcu n
cu v.
(2.50)
(2.51)
(2.52)
on the boundary.
The FEM rests upon the mathematical idea of a weak solution of a PDE,
which is a cornerstone of the modern theory of partial differential equations.
54
The idea here is that one can take a function v (often called a test function)
and multiply it through equation (2.51) and integrate the result over the
region to get
Z
( (c(x, y)u) + au f ).v(x, y) dxdy = 0.
(2.53)
Z
n (cu)v ds
f v dxdy = 0.
Any function u such that (2.54) holds for all test functions v is said to
be a weak solution of the above elliptic boundary value problem. Notice
that as long as the function c is bounded all is well. In particular c can
be discontinuous. This is important in many modeling situations involving
material interfaces.
55
If we restrict the solution u and the test functions v to lie in a finitedimensional space of functions then we can use the above weak formulation
of the boundary value problem to obtain an approximate solution. There
are many choices that one can make for the finite dimensional space of test
functions. The MATLAB PDE Toolbox uses the set of piecewise linear hat
functions i , 1 i N , where N is the number of mesh nodes. Each function
i (x, y) is linear (i.e. of the form i (x, y) = ai + bi x + ci y) on each triangle
containing the i-th vertex and takes the value 0 at all nodes (xj , jj ) except
for the node (xi , yi ) where the value is 1. In particular, i is identically zero
on all triangles that do not contain the node (xi , yi ).
Setting v = i in (2.54) gives (for 1 i N )
f i dxdy = 0. (2.55)
gi ds
qui ds
u(x, y) =
N
X
Uj j (x, y).
j=1
Notice that
u(xi , yi ) =
N
X
Uj j (xi , yi ) = Ui ,
j=1
i.e. the values Ui are exactly the nodal values of the approximate solution of
the boundary value problem.
On substituting this u into (2.55) we obtain the system of equations
Z
N Z
X
( cj i + ai j dxdy +
j=1
Z
qj i ds)Uj =
Z
f i dxdy +
gi ds
56
Z
Mij =
aj i dxdy, (Mass matrix)
Z
qj i ds
Qij =
Z
Fi =
f i dxdy
Z
Gi =
gi ds.
2.3.4
As in the analogous finite difference case, we can again make use of the
method of lines. For the equation
d(x, y)
u
(c(x, y)u) + a(x, y)u = f (x, y)
t
(2.56)
(2.57)
(x, y) in ,
and using the hat functions i (x, y) defined in the elliptic case above, we seek
a solution u(x, y, t) in the form
X
u(x, y, t) =
Ui (t)i (x, y).
i
57
If this expression is substituted into the PDE (2.56) and the FEM is applied
as in the elliptic case, one arrives at the ODE system
dU
+ KU = F.
dt
The initial values for this system are given by
M
Ui (0) = u0 (xi , yi ),
1 i N,
where the points (xi , yi ) are the mesh nodes. The ODE system is solved by
the MATLAB ODE Suite which uses adaptive stepsize control to control the
ill conditioning in the ODE system.
2.3.5
cu n + qu = g
(2.58)
(2.59)
If this expression is substituted into the PDE (2.58) and the FEM is applied
as above, one arrives at the ODE system
d2 U
+ KU = F.
dt2
The initial values for this system are given by
M
d
Ui (0) = v0 (xi , yi )
dt
where the points (xi , yi ) are the mesh nodes. The ODE system is again solved
by the MATLAB ODE Suite.
Ui (0) = u0 (xi , yi ),
58
Chapter 3
MATLAB and COMSOL
3.1
MATLAB
60
in the MacBook Dock. If you need MATLAB on your home machine, check
out the Student Edition its cheap1 (relatively speaking) and fully functional.
You can download the MATLAB tutorial, written by David F. Griffiths
of the University of Dundee, Scotland, from the class website
http://people.cas.uab.edu/iknowles/ma461/matlab/MatlabNotes.pdf
We will work through parts of this now. First, start MATLAB. You will
notice a rather busy scene with lots of windows. Find the one marked Command Window. At the top left of this window click the rectangle (marked
Maximize Command Window) to temporarily get rid of the rest (you can
click the same switch to restore things if you like the clutter). You can type
MATLAB commands at the >> prompt, followed by pressing the return
key. It is important to notice that one can always suppress MATLAB output
by typing ; at the end of your command. You will need this for example
when you create a vector or matrix that is too large to display on your screen,
and you wish to keep things tidy.
3.1.1
The command
>> diary freddie
will cause all subsequent text that appears on the screen to be written to a
file called freddie in the current directory. Terminate the session with
>> diary off
1
down the road they hope to recoup their losses from your eventual employer!
3.1. MATLAB
61
The file freddie is a text file and may be edited with jedit if you need to
do some clean up.
3.1.2
Keyboard Shortcuts
You can recall previous MATLAB commands by using the key, and reverse
your path through the command list with the key. Once a prior command
has been recalled, it can be edited (if needed) and then re-executed.
3.1.3
MATLAB as a Calculator
The basic arithmetic symbols are +,-,*,/, and the usual rules of precedence apply. So, by way of example, 2+3/4*5 really means 2+(3/4)*5 as
can be checked by typing either at the MATLAB prompt:
>> 2+3/4*5
ans =
5.7500
3.1.4
Standard Functions
3.1.5
Vectors in MATLAB
62
Row Vectors
MATLAB treats row vectors (1 n matrices) quite differently from column
vectors (n 1 matrices). Consider the 1 3 row vector v is defined by
>> v = [1,3,sqrt(5)]
v =
1.0000
3.0000
>> length(v)
ans =
3
2.2361
Here the elements of the row vector can be separated by spaces, if you prefer.
Vectors of the same type and length can be added; vectors can also multiplied
by scalars. One can also build row vectors from existing pieces:
>> u=[-1,v,-2]
u =
-1.0000 1.0000 3.0000 2.2361 -2.0000
The colon notation provides a shortcut for making certain row vectors:
>> z = 0.32:0.1:0.8
z =
0.3200 0.4200 0.5200 0.6200 0.7200
Here, the row vector has first element 0.32 and this is incremented by 0.1
up to 0.72 (it will not go beyond 0.8 in this case). Negative increments also
work. One can also extract parts of a vector as in
>> z(3:4)
ans =
0.5200 0.6200
or
>> z(1:2:5)
ans =
0.3200 0.5200 0.7200
Consider also the linspace command. For example linspace(a,b,n) produces a linearly spaced row vector of length n with first element a and last
element b. For example
3.1. MATLAB
63
>> v=linspace(1,2,5)
v =
1.0000
1.2500
1.5000
1.7500
2.0000
Column Vectors
The construction is similar to row vectors, except that semicolon (or newline)
is used as the separator for the elements. So we have
>> c = [1; 3; sqrt(5)]
c =
1.0000
3.0000
2.2361
>> c1 = [3
4
5]
c1 =
3
4
5
To convert a row vector to a column vector (or vice versa) use the transpose
operator as in
>> c
ans =
3
>> v
ans =
1.0000
3.0000
2.2361
3.1.6
On p. 10 of Griffiths, may be found various useful ways to combine two vectors. Included here are the standard dot product, with more subtle variations
64
such as elementwise products (with .*), elementwise division (with ./) and
elementwise powers (with . ). Check them out.
3.1.7
To plot (for example) the function y = sin(3x) over [0, 1] we first sample
the function at a large enough number of points, and then get MATLAB to
make a plot by joining these points consecutively by straight lines. This is
done so
>> N=10; h=1/N; x=0:h:1;
where the row vector x contains the values x = 0, h, 2h, . . . , 1, and the corresponding row vector y of y-values is made thus
>> y = sin(3*pi*x);
Notice that the constant in MATLAB is pi and that when the sin function
acts on a row vector, it produces another row vector. This is an important
trick to absorb here. The plot is now carried out with
>>
plot(x,y)
You can improve the plot by increasing the value of N to 100 and re-executing
the above steps (use the key!) You can print on your local printer by using
the command print (for other plotting options see Griffiths p. 6).
One can also plot surfaces, for example graphs of function of two variables.
First create a grid of x and y points:
>> points=linspace(-1,1,40);
>> [X,Y]=meshgrid(points,points);
Then define the function Z = f (X, Y ) noting the use of .* for function
multiplication
>> Z=3*sin(pi*X).*exp(sin(pi/2*Y));
Finally create the surface plot using first figure to make the plot appear in
a new window, and then the surf command
>> figure;
>> surf(X,Y,Z)
to produce
3.1. MATLAB
65
3.1.8
Matrices
[1
4
2
5
1
4
3
6]
2
5
3
6
or even
>>
[1
3;
6]
[1:5;
1
6
11
2
7
13
6:10;
3
8
15
11:2:20]
4
9
17
5
10
19
66
3.1.9
Special Matrices
>>
>>
>>
>>
ans
n=5;
l = -(2:n+1); d = (1:n); u = ((n+1):-1:2);
B = spdiags([l,d,u],-1:1,n,n);
full(B)
=
1
5
0
0
0
-2
2
4
0
0
0
-3
3
3
0
0
0
-4
4
2
0
0
0
-5
5
Here, the second argument -1:1 in the spdiags() call makes ` the -1 (i.e.
the lower) diagonal, d the 0 (i.e. the main) diagonal, and u the 1 (upper)
diagonal. The last two arguments indicate the size of the resulting matrix.
One can modify this command to produce matrices with any chosen diagonal
structure. The command full() converts the sparse matrix output coming
from spdiags() to standard row/column matrix notation. This is used here
only for cosmetic reasons, and would not normally be needed for m-file (see
later) code.
3.1. MATLAB
3.1.10
67
r=
1
0
0
0
2
B\r
-0.4167
-0.1167
-0.1500
0.0333
-0.3667
3.1.11
Loops
Not surprisingly, MATLAB also allows various looping constructs. The most
common is the for loop. For example f30 , the thirtieth member of the
Fibonacci sequence {fn }
n=0 defined by f1 = 0, f2 = 1, and
fn = fn1 + fn2
for n 3, may be computed by populating the vector f via
>>
>>
>>
f(1)=0; f(2)=1;
for i=3:30
f(i)=f(i-1)+f(i-2);
end
f(30)
68
One can also employ while loops (see p. 22 of Griffiths) and MATLAB also
has if ... then ... else ... end constructs as well.
3.1.12
m-files
MATLAB allows you to place a collection of commands into a file, and then
execute them with one command. Such a file must be given a .m extension,
and if the file is called freddie.m the commands in the file can be executed
by typing freddie at the MATLAB prompt. For example, create such a file
containing the commands below
n=5;
l = -(2:n+1); d = (1:n); u = ((n+1):-1:2);
B = spdiags([l,d,u],-1:1,n,n);
r = zeros(3,1);
r = [-1;r;-2];
x = B\r
and save the file as freddie.m (or some other name, if you prefer, but it
must also end with .m). If you now type freddie at the MATLAB prompt,
you should then see the above solution x of the system Bx=r.
3.1.13
m-functions
Function m-files (or m-functions) are a combination of the ideas of m-file and
mathematical functions. We are now going to turn the last example into an
m-function. Here we have the variables n (the size of the square matrix B),
the columns `, d, and u of length n making up the diagonals of the matrix B,
and the right hand side column r, also of length n. The solution x of Bx=r
depends on these five variables. We make a function m-file (m-function)
called trisolve.m with the following content:
function [x]=trisolve(n,l,d,u,r)
% This function solves the tridiagonal system Bx=r
% with vectors l,d,u as the diagonals of B.
B = spdiags([l,d,u],-1:1,n,n);
x = B\r;
3.1. MATLAB
69
Here the lines that begin with % are comment lines; it is always a good idea
to write these letters to your later self. You can then solve the system above
with the single function call
>>
trisolve(n,l,d,u,r)
3.1.14
In general it is infeasible to use the screen and keyboard when large amounts
of data, e.g. thousands, or even millions, of numbers resulting from measurements accumulated in scientific experiments, are involved. MATLAB
has several commands for handling data. First, if the data is in array form,
the importdata() command is useful for reading the contents of a data file
into MATLAB. Consider the file dump (see the matlab directory in the class
website)containing two columns of (x, y) function data output from the ODE
solver odeint.f in MA360. We have (using right quotes around the filename
dump)
>> A
A =
0
0.1000
0.2000
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
importdata(dump)
0
0
0.0002
0.0018
0.0072
0.0200
0.0450
0.0882
0.1569
0.2597
0.4072
70
>> size(A)
ans =
11
2
>> plot(A(1:11,1),A(1:11,2))
The same data can be written to a file dump.dat via
>> fid = fopen(dump.dat,w);
>> for i=1:11
fprintf(fid,%f%f\n,A(i,1),A(i,2));
end
>> fclose(fid);
Note here the right single quotes around both the filename and the w; the
latter indicates that the file is being opened for writing. This usage of
fprintf() here is very similar to that in C; perhaps not surprising as MATLAB is written in C.
Is is quite common for data to arrive in the form of an Excel (spreadsheet,
or *.xls) file and our MATLAB does not handle these very well. Fortunately,
inside Excel one can use the Save as ... facility and produce a new file in
the Comma Separated Values (.csv) format which MATLAB does handle
readily. This latter file format (unlike Excel) is a universally useful way
to store scientific data, by the way. To load the file cpi.csv (containing
Consumer Price Index data, obtainable from the class website, or FRED,
the Federal Reserve Economic Database) into MATLAB proceed as follows:
type in
>> A=cvsread(cpi.csv,11,0)
and MATLAB responds with
A =
207.6030
207.6670
..
.
217.4630
219.0160
71
Here, MATLAB reads the file starting at the spreadsheet position (row 12,
column 2) and one has to note that the first row is labelled 0 and the first
column is labelled 0; this is an unfortunate holdover from the C language
convention of using zero to label the first component of a vector ). There is
a similar MATLAB command csvwrite() for writing MATLAB data out to
a csv file.
3.2
The PDE Toolbox in MATLAB provides a convenient GUI interface for solving 2D linear partial differential equations of parabolic, elliptic, or hyperbolic
type. You may download the PDE Toolbox manual from
http://people.cas.uab.edu/iknowles/ma461/matlab/pde.pdf
Problem Types
The PDE Toolbox can handle the following problem types:
1. Elliptic PDE
(c(x)u) + a(x)u = f (x),
x ,
u
(c(x)u) + a(x)u = f (x),
t
2u
(c(x)u) + a(x)u = f (x),
t2
72
Solving a Problem
As an example we will use the MATLAB PDE Toolbox to solve one of the
problems studied earlier via finite differences. Specifically consider the elliptic
PDE
uxx + uyy = 0, x ,
over the L-shaped region given below in Figure 3.2 and subject to the
mixed Dirichlet and Neumann boundary conditions
u(x, 0)
u
(0, y)
x
u
(1, y)
x
u
= 100,
0 x 1,
(3.1)
= 0,
0 y 1,
(3.2)
= 0,
0 y 0.5,
(3.3)
= 0,
(3.4)
In order to numerically solve a given PDE with the MATLAB PDE Toolbox
one must carry out the following sequence of steps:
Create the 2D region using the Draw mode.
Specify the boundary conditions using Boundary mode.
Specify and refine the FEM computational grid using Mesh mode.
Specify the PDE coefficients using the PDE mode.
73
74
3.3. COMSOL
3.3
75
COMSOL
76
Not all of these steps are always necessary when building a model. The order
is also variable depending on the complexity of the model. As an example
try constructing a heat flow model by following the detailed instructions in
http://www.math.uab.edu/knowles/ma461/comsol/tutorial.pdf
Be aware here that on Mac machines, right-click means control -click while
left-click means click, and in the setting of boundary conditions, if you
wish to set a common condition for several boundary pieces at once, you
should click on the first piece (it should turn red) and then command -click
on the rest to add them to the first piece.
Chapter 4
Continuum Mechanics
We present here a basic introduction to the mechanics of continuous matter.
In modelling certain behaviours of matter it is advantageous to regard the
matter as a continuum, i.e. a material that is divisible down to the smallest
length scales, a point of view that originated with the philosophers of ancient
Greece. Science has of course since embraced the atomistic view of matter,
a theory that also dates back to the Greeks! Nonetheless, for many areas of
interest including such macroscopic concerns as fluid flow and the defor-
78
4.1
Equations of Motion
The basic equation of motion governing the flow of solids and fluids is embodied in Newtons second law: the rate of change of momentum equals the
sum of the applied forces.
The applied forces separate into two categories. There are body forces
b, like gravity, with units of force per unit mass, acting on each continuum
volume element: the force per unit volume is b where is the mass density
(mass per unit volume). The second category of force for a continuum is
that which acts on surface elements. The idea here is that one can imagine a
blob of material acted upon, and surrounded by, the rest of the material.
This action takes place at the surface of our blob, directed toward the interior
of the blob. By Newtons third law there is an equal reactive force directed
outwardly, away from the blob. Such effects are expressed as force per unit
surface area and can be directed normally to the surface, as in the inflation
of a balloon, but need not be, as one can see when a cylinder is immersed
and rotated in different fluids. The stickier (more viscous) fluid requires
more torque to achieve the same angular velocity.
In general the surface force per unit area acting on a surface with normal
n has both normal and tangential components. One can describe the force
per unit area through any surface passing through a point x by means of the
stress matrix (tensor)
11 12 13
= 21 22 23 .
31 32 33
Here, T(e1 ) = 11 (x)e1 +12 (x)e2 +13 (x))e3 represents the components (one
normal and two shear) of the force per unit area acting on the plane through
x normal to the x-axis, T(e2 ) = 21 (x)e1 +22 (x)e2 +23 (x))e3 represents the
79
components of the force per unit area acting on the plane through x normal
to the y-axis, and T(e3 ) = 31 (x)e1 + 32 (x)e2 + 33 (x))e3 represents the
components of the force per unit area acting on the plane through x normal
to the z-axis. Then, the force per unit area acting on the plane through x
with unit normal n is T(n) = T n and
!
3
3
3
X
X
X
(n)
(e1 )
(e2 )
(e3 )
T = n1 T +n2 T +n3 T
=
ni
ij ej =
(j n)ej (4.1)
i=1
j=1
j=1
(m)
1 0 0
(m)
2 0 ,
= (ij ) = 0
0 0
3
80
Also, as b is the force per unit volume (the force density) the total body
force on our volume V is
Z
b dxdydz.
V
Finally, from (4.1) the j-th component of the total stress (i.e. internal) force
acting on the boundary of V is
Z
Z
j n dS =
j dxdydz
V
v dxdydz =
(v) dxdydz = ( + b) dxdydz.
t V
V t
V
81
where, we have assumed that the density does not depend on time, and
set a = v/t as the acceleration vector. The above can only happen if the
integrand is identically zero at all points of our material. So we have the
following equation of motion:
a = + b.
(4.2)
This is a crucially important equation for us, but at this stage of the
development, it is not very practical. Even if we assume that the body force
b is known, we have twelve unknown functions ( has nine components and
a has three) and there are only three equations here.
Further physical properties and principles are needed. For example, if
angular momentum is conserved1 , then one can show that = T , which
reduces somewhat the number of unknown functions. For further progress, we
have to be more specific about what sort of material we are modelling. This
is usually accomplished by specifying a constitutive law of the material.
These cannot be given arbitrarily, as possible forms of the stress tensor are
limited by, for example, frame indifference, the principle that the results of
any experiment should be independent of the coordinate axes used to make
the measurements.
The fact that we cannot proceed further until a constitutive law has been
specified indicates that at this point our general continuum theory begins to
separate along different branches. In the sequel we explore separately the
theories for elastic solids and fluids.
4.2
Linear Elasticity
The basic idea here is that when a solid is deformed by the application of
a force, the change in a characteristic length in the solid is proportional to
the applied force, a principle commonly known as Hookes law. For small
deformations, this law has a solid experimental foundation.
1
it need not be so; volumetric body torque can exist, for example, in ferromagnetic
liquids
82
l l0
=
l0
l0
4.2.1
83
from a number of short straight line segments dw (we can call these line
elements), each of which has resulted from the deformation of a line element
dx as in Figure 4.5. Each line element dx is both stretched and rotated to
its final form dw. Notice the vector equation
u1 u1 u1
x x x
1
2
3
u u u
2
2
2
u =
.
x1 x2 x3
u u u
3
3
3
x1 x2 x3
We assume in this section that all elements of the deformation gradient matrix u are considerably smaller than one in absolute value. So we have
the vector identity (accurate to first order terms)
dw = dx + u dx.
(4.3)
84
4.2.2
very short length l0 and with direction specified by the unit vector m = (mi )
as shown in Figure 4.6. The engineering strain e of the specimen is given by
e =
l l0
.
l0
l
e (m) = 1 = 1 + 2u m m 1 = u m m
l0
3
X
j=1
mj [u m]j =
3
X
j=1
mj
3
X
uj
i=1
xi
mi
85
and
m u m =
3
X
mi [u m]i =
i=1
3
X
i=1
3
X
ui
mi
mj .
xj
j=1
So
3
3
X
1X
uj
ui
m u m =
mj mi (
+
)=
mj mi ij
2 i,j=1
xi xj
i,j=1
then the engineering strain e = 11 ; i.e. in Figure 4.7 xx = 11 , with a similar
interpretation for 22 ; these are called the direct strains. The shear strain,
denoted as the angle xy complementary to the angle between OA0 and OB 0 ,
satisfies
xy
yx
12 = 21 =
=
.
2
2
86
)
2 xj
xi
then it can be shown that
dw = dx + u dx = Edx + (dx + Wdx)
where Edx is a pure strain, and dx + Wdx is a pure rotation.
4.2.3
Principal Strains
The strain matrix E is symmetric, so one can always find a new basis m =
{m1 , m2 , m3 } of three dimensional space so that E becomes
e1 0 0
(m)
E(m) = (ij = 0 e2 0 ,
0 0 e3
a diagonal matrix. The quantities e1 > e2 > e3 are called principal strains.
The principal strains are the eigenvalues of the matrix E.
87
4.2.4
Plane Strain
4.2.5
Stress-Strain Relations
3
X
k,l=1
Cijkl kl
(4.4)
88
(4.5)
unchanged with respect to all rotations of the coordinate axes (i.e with respect to all choices of orthogonal basis sets in three dimensional space). We
now show that isotropy combined with the symmetry from (4.5) reduces the
effective number of components in the elasticity tensor to two.
Notice first that if we change from the Cartesian coordinate system generated by the standard unit vectors {e1 , e2 , e3 } to a new one generated by the
orthogonal matrix A (whose columns constitute the new basis set), then the
new coordinates of a point x would be x0 = Ax. Furthermore, for any unit
normal vector n the stress force at a point x in a surface with normal n is
T = n. Under the above change of coordinates the stress force at x0 = Ax
(the same point, but with the new coordinates) relative to the new normal
n0 = An is T0 = 0 n0 . Physical reality dictates that the stress force does not
depend on our choice of Cartesian coordinate system, so for all choices of n,
we have (in the new coordinates)
An = AT = T0 = 0 n0 = 0 An.
This leads to the matrix identity A = 0 A or 0 = AAt , where At = A1
is the transpose of the orthogonal change of basis matrix A. If A = (aij )
89
then the components ij0 of in the new coordinate system are given by the
formula
3
3
3
X
X
X
0
ij =
air
rs ajs =
air ajs rs .
r=1
s=1
r,s=1
3
X
p,q,r,s=1
3
X
(4.6)
p,q,r,s=1
(4.7)
1 0 0
A1 = 0 0 1
0 1 0
which corresponds to rotating the original axes through /2 about the e1
axis. Then for = (ij ) we have
11
13 12
33 23
0 = A1 At1 = 13
12 23 22
90
so that
011 = 11 ,
022 = 33 ,
033 = 22 ,
023 = 23 ,
031 = 12 ,
012 = 31 .
(4.8)
(4.9)
p11
p12
P1 =
p13
p12 p13
p11 p13 p12
p22 p23 = p13 p33 p23
p23 p33
p12 p23 p22
so that p12 = p13 and p12 = p13 , which means that p12 = p13 = 0, and
p23 = p23 , so that p23 = 0 as well. We also have p22 = p33 and p11 is free,
so P1 has the form
0 0
P1 = 0 0
0 0
where and are free parameters. A similar argument
0 0 1
0 1
1 0
0 1 0
A2 =
and A3 =
1 0 0
0 0
using
0
0
1
gives, successively,
0 0
0 0
P2 = 0 0 and P3 = 0 0 .
0 0
0 0
Next we equate the terms in 23 in (4.10) to get A1 Q1 At1
that
= Q1 . This means
q12
q23 .
q22
91
So, q11 = q11 and thus q11 = 0. Also q12 = q13 and q12 = q13 so that
q12 = q13 = 0. Finally q22 = q33 and q23 is free, giving Q1 the form
0 0 0
Q1 = 0 ,
0
where and are again free parameters. In like manner, using the coordinate
rotations A2 and A3 one obtains, respectively,
0
0
Q2 = 0 0 0 and Q3 = 0 .
0
0 0 0
Finally, equating the
from which it follows
0 0
0 0
Q1 =
0
0
0 0
0
0 0 0 , Q3 =
, Q2 =
0
0 0
0
Q2 = A1 Q3 At1
0
0 0 .
0 0
cos sin 0
A = sin cos 0 .
0
0
1
From (4.9) we have that
0
11
= (A At )11
= 11 cos2 + 212 sin cos + 22 sin2
= (11 + 22 + 33 ) cos2 + 212 sin cos
+(11 + 22 + 33 ) sin2 .
92
Equating the terms in 12 in the previous two identities we see that =
and we have now reduced the effective number of components in the elasticity
tensor to two, as we can replace with +. We set = 2 and = . Here,
is the Lame modulus and is the shear modulus; these two parameters are
collectively known as the Lame parameters. The stress-strain relation then
takes the matrix form
11
+ 2
0 0 0
11
22
+ 2
0 0 0
22
33
+ 2 0 0 0
33
12 =
0
0
0
2 0 0 12
13
0
0
0
0 2 0 13
23
0
0
0
0 0 2
23
assuming that no change in temperature takes place in the material. Alternately, this may be written in component form as
ij = ij
3
X
kk + 2ij ,
(4.11)
k=1
where
ij =
1 if i = j,
0 if i 6= j
are the components of the identity matrix, also called the Kronecker delta.
In practical problems, other elastic parameters that can appear include
Youngs modulus
(3 + 2)
E=
+
and with units of Nm2 and the dimensionless Poissons ratio
=
.
2( + )
Youngs modulus is the slope of the stress-strain curve in uniaxial tension and
represents the stiffness of the solid with larger values for more stiff materials.
The Poisson ratio is the ratio of lateral to longitudinal strain in uniaxial
tensile stress, and typically ranges from 0.2 to 0.49. It is a measure of the
compressibility of the solid, with = 0.5 representing an incompressible
solid. If = 0 then stretching the solid causes no lateral contraction; there
are some bizarre materials with < 0, so that on stretching a round bar of
the material, the bar increases in diameter!
93
4.2.6
X ji
2 ui
,
2 = i + bi = bi +
t
xj
j=1
where from (4.11) for 1 j 3,
ji = ji
3
X
k=1
kk + 2ji = ji
3
X
uk
k=1
xk
+
ui uj
+
xj
xi
.
So
(
)
3
3
X
X
2 ui
uk
ui uj
2 =
ji
+
+
+ bi
t
x
x
x
x
j
k
j
i
j=1
k=1
( 3
)
3
X
X
uk
ui uj
=
+
+ bi
xi
xk
xj
xj
xi
j=1
k=1
3
3
X
X
uj
uj
ui
=
(
(
)+
(
)) +
(
) + bi(4.12)
xi xj
xj xi
xj xj
j=1
j=1
94
4( + )2
4( + )2 2
4( + )2
( + 2)(3 + 2)
and
( + 2)(11 + 22 + 33 ) = ( + 2)(11 + 22 ) (11 + 22 ) = 2(11 + 22 ),
so that
(11 + 22 + 33 ) =
2
E
(11 + 22 ) =
(11 + 22 ).
+ 2
1 2
= 2,
1+
+
3 + 2
we have
ij = 2ij +
2
E
E
ij (11 + 22 ) =
ij +
ij (11 + 22 )
+ 2
1+
1 2
95
or
11
2 +
0
11
22 =
2 + 0 22
12
0
0
2
12
1
0
11
E
1
0 22 ,
=
1 2
0 0 1
12
(4.13)
2 u1
= 1 + b1
t2
2
X
j1
=
+ b1
x
j
j=1
u1
u2
u1 u2
=
((2 + )
+
)+
((
+
)) + b1
x1
x1
x2
x2
x2 x1
Similarly,
2 u2
u1 u2
u2
u1
=
((
+
)) +
((2 + )
+
) + b2
2
t
x1
x2 x1
x2
x2
x1
(4.14)
(4.15)
where
c11 =
2 + 0
0
c12 =
0
0
c21 =
0
0
c11 =
0
0 2 +
.
This is the form used by the PDEToolbox in the application mode called
Structural Mechanics - Plane Stress. Here the shear modulus is written
as G, and the quantity that we have called is written as in the form
96
G/(1 ) where is the Poisson ratio; the body force term b is given as
k and the equilibrium form of the equation is written in the tensor form
(c u) = k
(4.16)
c u =
4.3
c11 c12
c21 c22
c11 u1 + c12 u2
c21 u1 + c22 u2
.
Fluid Mechanics
We are quite literally surrounded by fluids, from the atmosphere above to the
rivers, lakes and oceans that we are so dependent upon; moreover, given that
human beings are approximately ninety percent H2 O, in a very real way, we
are fluids! So it should come as no surprise that a significant fraction of all
PDE modeling involves some kind of fluid flow.
97
4.3.1
It is known that in a fluid at rest, the stress (force per unit area) exerted
on a blob of fluid by the surrounding fluid across a plane surface with unit
normal n is pn where the scalar function
1
p = (11 + 22 + 33 )
3
(4.17)
pij
| {z }
ij
|{z}
where the term ij is called the deviatoric, or viscous, part of the stress tensor
and bears further investigation.
From many experimental observations it has been noted that the terms
ij vary linearly with the imposed velocity and inversely with the length scale
of the apparatus used to study various flows. In such a case, it is reasonable
2
there are other ways to do this, for example via the concept of thermodynamic pressure
98
to infer that the ij are linear functions of the velocity gradients ui /xj , in
which case we call the fluid a Newtonian fluid, and we can write
ij =
3
X
Aij
,=1
u
x
3
X
uk
k=1
xk
+ (
ui uj
+
)
xj
xi
(4.18)
that we have been seeking. The dynamic shear viscosity measures the
response of the fluid to shearing forces, and the bulk viscosity indicates the
response to changes of volume. Using the definition of pressure as average
normal stress as given in (4.17) we see that the trace of the tensor must be
zero. We therefore also have
(3 + 2)
3
X
uk
k=1
xk
= 11 + 22 + 33 = 0.
ui uj
2 X uk
+
)
ij
ij = pij + (
| {z }
xj
xi
3
xk
k=1
normal stress
|
{z
}
viscous stress
(4.19)
4.3.2
99
w
Z
(4.20)
Dp =
p ds for 2d,
where p is the fluid pressure, the viscosity pressure drag Dvp defined by
ZZ
w
Z
(4.21)
Dvp =
w
Z
Df =
(4.22)
where t is normal to n (and horizontal, in the 3d case). The total drag D (at
a certain fixed time and for a given velocity) is
D = Dp + Dvp + Df .
100
In earlier times, naval architects and ship designers were forced to construct scale models of proposed hulls and tow them in water tanks4 to ascertain the drag resistance of a hull. This was expensive and time consuming, and often produced poor results when the process did not scale up
properly (compare your bathtub rubber ducky with a battleship). The
modern approach is to make a life-size hull in the computer, work out the
flow around the hull by solving the Navier-Stokes PDE (see below) and then
compute the drag from something like the above formulae. For example,
in the 2D case, once u = (u(x, y), v(x, y))T , n = (nx(x, y), ny(x, y))T , and
t = (ny(x, t), nx(x, y))T are known we have
11 12
n t = (11 nx + 12 ny)ny (12 nx + 22 ny)nx
12 22
= (11 22 )ny.nx + 12 (ny 2 nx2 ).
Here
u v
4 u 2 v
+
,
=
11
x y
3 x
3 y
u v
12 =
+
,
y x
2 u 4 v
22 =
+
,
3 x
3 y
so that 11 22 = 2(ux vy) and the 2D friction drag Df becomes
Z
.(2(ux vy)nx.ny + (uy + vx)(ny 2 nx2 )) ds.
u 2
= 2
x
3
In like fashion,
11 12
n n = (11 nx + 12 ny)nx + (12 nx + 22 ny)ny
12 22
= 11 nx2 + 22 )ny 2 + 212 nx.ny
4
2
= .[nx2 ( ux vy)
3
3
2
4
2
+ny ( ux + vy) + 2(uy + vx)]
3
3
4
We will adopt much the same approach in the Aussie Cup class boat race later in the
course.
101
2
2
4
4
.[nx2 ( ux vy) + ny 2 ( ux + vy) + 2(uy + vx)] ds.
3
3
3
3
We note here that for water the shear (or dynamic) viscosity = 8.90 104
Pa-s, so both Df and Dvp are expected to be quite small relative to the
pressure drag.
This process can be done repeatedly to optimize certain design variables
(such as maximizing speed by minimizing drag in the case of Americas
Cup yachts). Similar techniques were used to design the Boeing and Airbus jumbo-sized jets. We note in passing that the main reason that we do
not have a supersonic version of these airplanes is that the Navier-Stokes
equations break down in the transonic region between subsonic and supersonic, and the modeling fails. This is a decades-old unsolved problem looking
for some genius to come forth and crack it.
4.3.3
Before we appeal to the continuum equation of motion found earlier, an important issue regarding the acceleration of a fluid particle has to be resolved.
Because we are using the Eulerian approach to fluid motion, the term u/t
is, in general, not the acceleration of the fluid particle at x at time t. This
102
u
+ (u ) u.
t
(4.23)
From (4.19) and (4.23) substituted into the equation of motion (4.2) and
assuming that u = (ui ) we have for 1 i 3 the equations
3
p X
ui
ui uj
2
+ (u ) ui ) =
(
+
((
+
))
( u) + bi .
t
xi j=1 xj
xj
xi
3 xi
(4.24)
This system of three equations originates in Newtons second law. If we
presume that the body force b and the shear viscosity are known, we seek
five unknowns: u1 , u2 , u3 , the pressure p, and the density .
Another equation, the conservation of mass equation is found by the
following argument. Consider a blob of fluid that occupies the region V , with
surface S. The total mass of fluid in V at time t is
Z
(x, t) dxdydz.
V
If we presume that fluid material is not added to, or subtracted from, the
interior of V through the presence of source or sink points, then all
material must leave or enter V through the surface S of V . Let us calculate
the amount of material that would pass through a small piece of surface
S in time t. To do this we must first recognize that the component of u
tangential to the surface cannot contribute to fluid particles moving through
S, so we restrict attention to the normal component of u, u n. In this time a
103
fluid particle would travel a distance u nt, and you can imagine a cylinder
of fluid particles with base area S and height u nt being filled with these
particles. The total mass of these particles is u ntS and the rate of exit
through S is u nS. The rate at which fluid material exits V is then
Z
Z
u n dS =
(u) dxdydz
V
Z
(x, t) dxdydz =
(u) dxdydz.
V
This rewrites to
Z
(
V
+ (u)) dxdydz = 0
t
which must hold for all blobs V . This leads to the conservation of mass
equation
+ (u) = 0.
(4.25)
t
The two equations (4.24) and (4.25) are called the Navier-Stokes equations
for compressible viscous fluid flow for the five unknown scalar functions u, p,
and .
As they stand these four equations are still incomplete. At this level
of generality, one must make further assumptions. For example one could
assume the perfect gas law
p = RT
where R is the universal gas constant and T is the temperature. If T is constant, one can then solve this system; if not, one must add another equation,
the energy equation to complete the system.
As an alternative to the approach of the last paragraph, one can also
choose to make further simplifying assumptions, and these can take many
forms, as we see below.
104
4.3.4
Incompressible Fluids
(4.26)
3
3
X
2u
X uj
u
+ (u )u) = p +
+ ( u) + b
+
2
t
x
x
x
i
j
j
j=1
j=1
= p + ( + )( u) + 2 u + b
where
2 =
and
u = u1
2
2
2
+
+
.
x21 x22 x23
+ u2
+ u3
.
x1
x2
x3
(4.27)
105
Hagen-Poiseuille Flow
The flow of an incompressible viscous fluid through a pipe of uniform circular
cross-section is known as Hagen-Poiseuille flow after Gotthilf Hagen5 and
Jean Louis Marie Poiseuille6 who independently investigated this type of
flow experimentally; the latter was interested in the flow of human blood in
narrow tubes.
One usually makes the following assumptions. Consider cylindrical polar
coordinates, and u = (ur , u , uz )T . Furthermore
the flow is steady, so u/t = 0;
the radial and swirl components are zero, so ur = u = 0;
the flow is axisymmetric, so uz / = 0, and fully developed in the
sense that uz /z = 0 as well.
also p/r = p/ = 0, so p = p(z) and b = 0.
Under these conditions and using the cylindrical polar form of the Laplacian
we have that
uz
1 p
1
,
r
=
r r
r
z
from which we see that
uz
r
c1
=
pz +
r
2
r
and hence
1 p 2
r + c1 log r + c2 .
4 z
Given that uz is finite at r = 0 we have c1 = 0 and from the no-slip
condition at the boundary r = R we see that c2 = (p/z)R2 /(4), so that
uz =
uz =
1 p 2
(R r2 ).
4 z
In particular, as one might expect, the maximum velocity occurs at the pipe
centerline (r = 0):
R2
p
uz,max =
.
4
z
5
6
106
The average pipe velocity can be obtained by integrating over the pipe crosssection C:
ZZ
1
uz,avg =
uz dS
R2
C
Z 2 Z R
1
uz r drd
=
R2 0
0
Z R
2
=
uz .r dr
R2 0
Z R
pz
=
(R2 r2 )r dr
2R2 0
R
pz 2
(R r2 )2 0
=
2
8R
uz,max
=
.
2
Assume now that the pressure decreases linearly down the length of the pipe,
so that if p represents the pressure change down a pipe of length L we have
(p/z) = p/L and, setting D = 2R as the pipe diameter we get
uz,avg =
D2 p
,
32 L
which rearranges to
32Luz,avg
.
D2
This is known as the Hagen-Poiseuille formula (or law) which was derived
experimentally. It is a nice confirmation of the validity of the Navier-Stokes
equations in this case.
p =
(4.28)
107
Equations (4.26) and (4.28) are usually known as the Euler equations. The
Euler equation of motion (4.28) may be expanded as the system
u1
u1
u1
u1
1 p
+ u1
+ u2
+ u3
=
+ b1
t
x1
x2
x3
x1
u2
u2
u2
u2
1 p
+ u1
+ u2
+ u3
=
+ b2
t
x1
x2
x3
x2
1 p
u3
u3
u3
u3
+ u1
+ u2
+ u3
=
+ b3
t
x1
x2
x3
x3
of three non-linear first order partial differential equations.
These equations are simpler than the full Navier-Stokes equations, but
their use requires careful attention to their sometimes fatal deficiencies. It is
a general fact that the act of omitting terms that may appear small but that
result in a lowering of the order in a differential equation is an inherently risky
proposition, and the omission of the viscosity terms in the Navier-Stokes to
obtain the Euler equations further underlines this. For example, one can no
longer insist on the no-slip boundary condition in the Euler case; instead, one
can at best insist that there is no flow normal to the boundary. This means
that one cannot in general extract, for example, lift and drag information for
air- and hydro-foils from the Euler equation formulation. As a working rule,
one should be careful in interpreting the results of Euler equation calculations
in the parts of the domain that are in close proximity to a boundary.
If the body force is that of gravity (the most common choice) then we
have that
b = ()
where = gx3 , provided that we take x3 to be the vertical direction. Here, in
writing the gravity force in this way, we are observing that it is a conservative
force, i.e. it can be written as the gradient of a scalar function, called a
potential function.
A streamline is a curve that is everywhere parallel the the velocity vector
u of the fluid. We say that the fluid is undergoing steady flow if the velocity
u does not depend on time. Then the Euler equation becomes
p
(u )u + ( + ) = 0.
108
(4.29)
p 1
+ uu+
2
(4.30)
(4.31)
109
Again, one cannot impose no-slip boundary conditions here; typically one
imposes conditions amounting to enforcing no flow through the boundary.
As an example consider Newtonian fluid flow through the tapered pipe
or bottleneck shown below: it is assumed that the flow is incompressible,
inviscid, irrotational, and steady. In this case there exists a scalar function
such that the fluid velocity vector u may be written as
u =
and the Navier-Stokes equations reduce to
2 2 2
+
+
= 0.
x21 x22 x23
Assuming that the axis of the tapered pipe is x1 , we convert to cylindrical
coordinates defined by (x1 , r, ) where x2 = r cos and x3 = r sin and
1 2
2 2 1
+
+
+
= 0,
x21
r2
r r r2 2
and we continue to use to represent the velocity potential. It may be
assumed that the flow is symmetric with respect to the axis x1 so that there
is no variation of the potential function in . The cylindrical Laplace
equation then becomes
2 2 1
+ 2 +
= 0,
x21
r
r r
110
which rearranges to
x1
r
+
r
= 0.
x1
r
r
111
holding here. Finally, at the vertical exit boundary on the right side of
the region, we do not know the velocity, but we may assume laminar flow
away from the bottle-neck and we can fix the potential to any constant; it is
convenient to choose the Dirichlet condition = 0 here.
For inviscid, incompressible, irrotational, but unsteady flow we note that
p 1
+ + ||2
t
2
is a function of time only. This may be used to compute p from in an
analogous fashion.
4.3.5
Compressible Fluids
Because of the difficulties associated with solving the full system for compressible viscous flow, which generally means that one has to include temperature and internal energy effects, it is often convenient to make further
simplifying assumptions.
Compressible Inviscid Fluids
As the viscosities of gases tend to be a great deal lower that those of liquids,
and gases tend to be compressible while most liquids are incompressible, the
assumption of compressible inviscid flow is frequently quite acceptable in the
gas case. The Navier-Stokes equations (4.24) become
1
u
+ (u )u = p + b,
t
(4.32)
+ (u) = 0.
t
(4.33)
112
where is the ratio of specific heats at constant pressure and constant volume, respectively. For air 1.4. Such an equation is called an equation
of state and we now have five equations for the five unknowns u1 , u2 , u3 , p, ;
these are the equations of compressible inviscid flow.
In general, we can assume that p = f (), or even p = f (, S) where S
is the specific entropy; although we do not treat the latter case specifically,
the approach is essentially the same. In the case of sound moving in air, for
example, we can make further simplifications.
The Acoustic Wave Equation
Sound is a compression and rarefaction disturbance that can travel through
a fluid medium such as air. This disturbance can be modeled by determining
the pressure variations p0 around a base pressure p0 :
p = p0 + p0
In the same way we can represent the density in terms of variations 0 around
a base density 0 , = 0 + 0 . In line with the fact that most sound disturbances involve very small variations, we may assume that p0 and 0 and the
velocity u0 = u are all small functions, together with their derivatives. If we
substitute these forms into the Euler equation (4.32) and ignore products of
small terms and set b = 0, we obtain the linearized Euler equation
u0
+ p0 = 0.
0
t
In similar fashion, the linearized mass equation (4.25) becomes
0
+ 0 u0 = 0.
t
Finally, if we differentiate the equation of state p = f () at = 0 we get
p0
f
0
=
(0 )
t
t
Then if we define the speed of sound c by
c2 =
f
(0 )
113
we have
2 0
2 p0
u0
u0
2
2
2
= c 0
= c2 p0
=c
= c 0
t2
t2
t
t
If we now ignore the base pressure p0 and rewrite p for p0 we arrive at the
acoustic wave equation
2p
= c2 p.
(4.34)
t2
for the pressure variations in a sound wave travelling through a gas.
4.3.6
L 0
t,
U
x = Lx0 ,
u = U u0 ,
p = U 2 p0 .
where the new variables t0 , x0 , u0 , p0 are dimensionless. Then the NavierStokes equations (4.26) and (4.27) become, after dropping the primes on the
new variables,
u = 0
u
1 2
+ (u )u = p +
u,
t
Re
where the Reynolds number Re is defined by
Re =
LU
.
114
This change to dimensionless variables has many uses. One can see that
once a solution for a particular flow field is known and expressed in dimensionless form, a triply-infinite family of solutions may be obtained from it
by choosing values of , L, U, in such a way that Re is unchanged. All
those flows that satisfy the same boundary and initial conditions when expressed in non-dimensional form and for which the values of , L, U , and
differ without the combination LU/ being different, are described by the
same non-dimensional solution; such flows are said to be dynamically similar.
This observation is quite useful in practice. For example hydraulic engineers
might wish to predict the rate at which small solid particles would settle in
water, but is it difficult to perform such measurements. One can however
perform such an experiment with a larger sphere falling in say glycerine or
motor oil, with the size of the sphere so chosen that the value Re is the same
as that for the small solid particle falling in water.
Experiments have shown that at low Reynolds number, the flows are
smooth and stable, a regime usually called laminar flow. As the speed
(Reynolds number) increases there reaches a point, depending on the fluid,
when the flow becomes highly eddied and unstable, usually termed turbulent
flow and generally present when the Reynolds number is a few thousand, or
so.
For flows with Reynolds number values much greater than one, but still
laminar, it has been shown that the flow is essentially inviscid, unless we
are within a distance of the order of L/ Re of a solid boundary. In this
regime, the boundary layer, viscous effects are extremely important and
cannot be ignored. This knowledge allows the Navier-Stokes equations to be
simplified in many case of interest, including the important case of obtaining
drag information on slender bodies such as aerofoils as was done by Prandtl
in 1904 when he introduced the concept of a boundary layer. The idea has
since been applied to many problems, including shock waves and chemical
reactions.
Chapter 5
Classical Electrodynamics
While electrical and magnetic events have been observed in various forms, including lightning and magnetic rocks such as lodestone, since ancient times,
the precise quantitative electromagnetic theory that we have today is of relatively recent origins. From the remarkable experiments of Cavendish in
electrostatics, dating from around 1771, to the appearance of the equations
of Maxwell in 1862 and the experimental confirmation by Hertz in 1888 of
It is worth a note in passing that in the period following this remarkable century,
there followed perhaps the most productive era of scientific discovery in human history.
115
116
gives us the equations that are used to describe most of the macroscopic2
electrical and magnetic properties that we generally encounter.
In this chapter, we consider first electrostatics and then magnetostatics,
finally reaching the objective of the equations of Maxwell for time-varying
electromagnetic systems. A good reference for this material is the book
Classical Electrodynamics, Third Edition, by J. D. Jackson (Wiley, 1999).
5.1
Electrostatics
The theory of electricity begins with the study of single charges and their effects on other charges. The experiments of first Cavendish and later Coulomb
indicated that the force between two small charged bodies separated by a dis-
5.1. ELECTROSTATICS
117
In addition, the total force produced on one small charged body by several
small charged bodies is the vector sum of the individual two-body forces
between the first body and each of the others.
These empirical properties are collectively known as Coulombs Law. The
second of the properties, the inverse square property, has been the subject of
extensive experimental verification over the last two centuries or so and is now
known to be true to an extraordinarily small degree of error. Theoretically,
its truth is equivalent to the mass of a photon of light being zero, an assertion
of great importance in quantum contexts. Collectively Coulombs Law may
be written in formula form as follows: let F be the force on a point charge
q coulombs located at x due to another point charge q1 coulombs located at
x1 . Then
x x1
F = kqq1
|x x1 |3
where in SI units the constant k = (40 )1 and 0 = 8.854 1012 farads
per meter is called the permittivity of free space (or vacuum).
5.1.1
E = lim
In effect the idea here is that E is like a force per unit charge density, so
that to find the force, one integrates Edq.
From Coulombs law the electric field due to a point charge q1 at x1 is
E(x) =
3
1
x x1
q1
.
40 |x x1 |3
(5.1)
Technically speaking, this limit cannot be taken because electric charge is quantized,
i.e. there is a smallest charge; this is an example of a mathematical idealization not unlike
the type used in continuum mechanics that we saw earlier.
118
1 X x xi
qi
.
40 i
|x xi |3
(5.2)
Note that, for positions x not occupied by a charge, and any i, we have from
the divergence product rule for a scalar function and a vector function F,
(F) = . F + F,
that
x xi
= |x xi |3 (x xi ) 3|x xi |5 (x xi ) (x xi )
|x xi |3
= 0
(5.3)
(
).
x
|x x0 |3
|x x0 |
(5.6)
5.1. ELECTROSTATICS
119
where
Z
(x0 )
1
dx0
(x) =
40
|x x0 |
is said to be a potential function for E. Notice also that, as A = 0 for
any vector A, we have
E=0
(5.7)
5.1.2
The Gauss Law is a formula for the total flux of the vector field E due to
a point charge q across a closed surface S. There are two cases. First, if
the charge is located outside the region D enclosed by S, we have from the
On the other hand, if the charge is located inside the region enclosed by S
(as in the figure below) then one can find a small sphere centered on the
charge with boundary Se completely contained in D. Then , by (5.3) again,
if we denote the sphere with boundary Se by B,
Z
Z
Z
Z
E n ds =
Edx =
Edx =
E n ds
S
Se
120
coordinates over Se
r(, ) = (R sin cos , R sin sin , R cos ),
0 2,
0 ,
ds =
.R2 sin dd = .
3
2
|x|
0
Se 40 |x|
Se
0
0 40 R
Hence
q
0 if q is inside S,
E n da =
0 if q is outside S.
S
5.1. ELECTROSTATICS
121
( E ) dV = 0
0
V
for all volumes V . In consequence we arrive at the so-called differential form
of the Gauss law:
E=
(5.8)
0
valid for charges and thin conductors in a vacuum.
5.1.3
Macroscopic Media
Thus far we have only considered electrostatic fields in the presence of charges
and conductors either in vacuo, or something close thereto, such as air; in
general, the presence of a ponderable medium complicates matters.
When an electric field is applied to a medium made up of a large number of atoms or molecules, the charges associated with each molecule will
respond to the applied field and will execute perturbed motions. The most
common situation involves molecular dipoles, i.e. molecules that carry a
positive charge at one end and a negative charge at the other and that consequently tend to line up parallel with an applied field. The general effect is
that there is produced in the medium an electric polarization P representing
the dipole moment per unit volume in the dielectric medium.
The end result is that the Gauss law becomes
E=
1
0
[ P]
| {z }
(5.9)
We shall see later that this is the first of the Maxwell equations. Note that
to proceed further, one needs a constitutive relation connecting D and E. It
122
is common here to assume that the medium is isotropic and linear5 , so that
P is parallel to E with a coefficient of proportionality that is independent of
direction:
P = 0 e E.
Then
D = E
where = 0 (1 + e ) is the electric permittivity. If the dielectric medium is
not only isotropic but also uniform, then the Gauss law becomes
E=
and in such cases, electrostatic problems may be treated in much the same
way as the vacuum case, except that 0 is replaced with .
As we discuss in detail presently, magnetic fields may be generated by
moving charges. So a short digression to consider time varying electric currents is in order.
5.1.4
123
Electric Current
I=
a
+ J = 0,
t
(5.10)
5.2
At least none have ever been detected, despite the best efforts of many experimental
physicists over the last two centuries.
124
5.2.1
The Biot-Savart-Amp`
ere Laws
In 1819 Oersted observed that wires carrying electric currents produced deflections of permanent magnet needles placed nearby. Thus the currents were
7
125
d` x
|x|3
(5.11)
where the terms are shown in the figure below. In particular, Id` is the
current element. The corresponding law for forces on charged particles, also
determined empirically and known as Amp`eres first law, is given by
dF(x) = kId` B(x).
(5.12)
c = (0 0 ) 2
(5.13)
126
that
x
J(x0 )
|x x0 |
= x
and hence
0
B(x) =
x
4
1
|x x0 |
J(x0 ),
J(x0 )
dx0 .
|x x0 |
127
128
x
)
dx
) dx0
J(x ) x (
J(x
)
(
x
4
|x x0 |
4
|x x0 |
The two standard identities stated below are now crucial. First,
x (
1
1
) = x0 (
),
0
|x x |
|x x0 |
and then
1
) = 4(x x0 ).
|x x0 |
The latter property involves the Dirac delta function9 . This function has
the interesting property that for any function f
Z
f (x0 )(x x0 ) dx0 = f (x).
x (
(5.14)
Actually, it is not a function, but a measure, so its properties are a little weird when
first seen.
5.2.2
129
Macroscopic Magnetostatics
Thus far the magnetic phenomena have been assumed to occur in a vacuum
or at least a medium that does not contribute magnetic effects. When this
is not the case, one must go through a similar process to that used in the
electrostatic case. An appropriate argument indicates that the equation
B=0
still holds for a ponderable medium.
With regard to the other equation, we note that the atoms in matter
have electrons that give rise to effective atomic currents, the current density
of which is a rapidly fluctuating quantity. These electrons also contribute
intrinsic magnetic moments in addition to those from their orbital motion. It
can be deduced that the end result is that there is macroscopic magnetization
or magnetic moment density M due to the medium and this contributes an
effective current density
JM = M,
in such a way that Amp`eres second law becomes
B = 0 [J + M].
If we define an new macroscopic field H called the magnetic field by
H=
1
BM
0
(5.15)
(5.16)
130
5.2.3
Stokes Theorem
Before considering the full Maxwell equations, we need to first discuss the
justifiably famous
5.2.4
As far as we know the first quantitative observations of note relating timedependent electric and magnetic fields were made by Michael Faraday in
1831. Faraday was perhaps the finest and most accurate of the early experimentalists. He was described by Ernest Rutherford10 as one of the greatest
scientific discoverers of all time. After many experiments Faraday concluded
that a transient current is induced (started) in a circuit if
the steady current flowing in an adjacent circuit is turned on or off; or
the adjacent circuit with a steady current flowing is moved relative to
the first circuit; or
10
131
132
change of flux through the circuit. For SI units k = 1. It follows from the
above comments that
Z
Z
Z
d
B n da =
E dl =
E n da
dt S
C
S
by Stokes theorem. Thus
Z
( E +
S
B
) n da = 0
t
5.3
(5.18)
We have dealt thus far with steady-state problems in electricity and magnetism as more or less separate topics. As may be inferred from the Faraday
133
law, the move to time-varying problems signals an entirely new regime: timevarying magnetic fields give rise to electric fields, and time-varying electric
fields produce magnetic fields. In this case we must speak of electromagnetic
fields rather than separate electric or magnetic fields.
The basic laws of electricity and magnetism discussed above are summarized by the following four (not yet Maxwell) equations:
D=
Coulomb law
H=J
Faraday law
E + B = 0
t
Absence of free magnetic poles
B=0
`re law
Ampe
There is of course no reason to believe that, with the exception of the Faraday
law, these equations continue to hold for time dependent problems. The
interesting part of the story here is that they are actually not far from the
correct equations, but it took the genius of James Clerk Maxwell11 to notice
that there was a slight inconsistency with these laws and the continuity
equation
= 0.
J+
t
What Maxwell noticed was that while
J = ( H) = 0
must hold for steady-state problems by the Ampere law, this is inconsistent
with the continuity equation in the time-varying case. More importantly, he
also noticed that if one appeals to Coulombs law it follows that
D
= (J +
)=0
t
t
and the continuity equation is thereby written in a vanishing-divergence form.
So, he reasoned, to arrive at the appropriate form for the time-varying equations, one should merely replace the term J in the system above with its
generalization
D
JJ+
,
t
J+
11
Yet another Scotsman, joining a distinguished band of 19th century Scottish visionaries that included the likes of James Watt, Alexander Graham Bell, and John Logie Baird,
each of whose work changed the world.
134
H = J + D
t
B=0
E + B = 0
t
(5.19)
are known as the Maxwell equations; they form the basis of all classical electromagnetic phenomena. When combined with the Lorentz force equation
F = q(E + v B)
and Newtons second law of motion, these equations provide a complete description of the classical dynamics of interacting charged particles and electromagnetic fields.
In many instances it is valid to assume the constitutive relations
D = E
B = H
5.3.1
A
) = 0.
t
135
A
= ,
t
A
.
t
E =
0
1 E
B 2
= 0 J.
c t
where c2 = (0 0 )1 from (5.13). Then, in terms of the scalar and vector
potentials and A, the free space Maxwell equations become
( A) =
t
0
2
1 A
1
A 2 2 ( A + 2
) = 0 J.
c t
c t
+
In this fashion, the original system has now been reduced to two coupled
equations for the potentials A and .
These equations may be uncoupled by taking advantage in the fact that
the potential functions are not uniquely defined. For example, the magnetic
induction B is unchanged by replacing A by
A0 = A +
where is, for now, any (differentiable) scalar function whatsoever! Under
this change in A, for the electric field to remain unchanged as well, the scalar
potential must be transformed to
0 =
.
t
136
c2 t2
0
2 0
1 A
A0 2
= 0 J.
c t2
0
(5.20)
(5.21)
Chapter 6
Finance
In financial circles it is currently popular to use probability theory1 , specifically the theory of so-called random variables, to model the behavior of
macroeconomic quantities such as equities (stocks) and associated financial
derivatives. We study some of these ideas now, with our main target the
justifiably famous, and Nobel prize winning, equation of Fischer Black and
Myron Scholes for the fair price of an option contract.
6.1
Random Variables
If we roll a fair die, each of the six possible results, called outcomes, is equally
Some of the randomness in economics is likely better modeled using chaos and differential equations; in particular the current probabilistically-based mainstream economic
theory has little predictive capability they are substantially worse than the weather guys
who can at least tell you if a hurricane is coming, even if their timing is a tad off!
137
138
CHAPTER 6. FINANCE
likely, and thus each has probablity 1/6. If we denote the individual outcomes
by i , 1 i 6 (so that i is the outcome that an i is thrown), then the
set
= {i , 1 i 6}
is called the sample space. The die throwing activity is represented mathematically by a discrete random variable X : {i : 1 i 6} with the
property that
X(i ) = i, 1 i 6.
A subset of is called an event and each event has a certain probability of
occurring. By way of example, if the event is X is even then the probability
of this happening is 1/2.
In general, a discrete random variable X takes values values {x1 , x2 , . . . , xm }
(i.e. = {1 , . . . , m } where X(i ) = xi ) and the probability of X being xi
is pi where
pi 0, 1 i m,
m
X
pi = 1.
i=1
m
X
xi p i ,
i=1
and, as its name indicates, is the X-value one might expect to see on average
after a large number of trials. For our dice above,
E(X) =
6
X
i=1
7
1
= .
6
2
The variance of X is
var(X) = E (X E(X))2 .
Continuous Random Variables
In many situations, we encounter the need for our random variable X to
have more than a finite number of values, i.e. infinitely many outcomes are
139
(6.1)
(6.2)
E(X) =
xf (x) dx,
140
CHAPTER 6. FINANCE
6.1.1
Normal Distribution
x2
1
f (x) = e 2
2
we say that X has the standard normal distribution, and we write this in
the famous bell curve; to some, including the philosopher and one-time securities
trader Nassim Taleb, inventor of the Black Swan, its pre-eminent position in financial
modeling is greatly overblown, even dangerous.
141
the form X N (0, 1). Notice that for such X one can show that E(X) = 0
and var(X) = 1. The graph of f is given above, with its maximum at
(2)1/2 0.4. If X has the more general density function
f (x) =
1
2 2
(x)2
2 2
6.2
Robert Brown3 was a Scottish Botanist who in 1827 observed the irregular
motion of pollen particles suspended in water. He observed that
the paths are very irregular, in fact continuous but non-differentiable;
the motions of distinct particles appear to be independent.
This form of transport is known as molecular diffusion. In one dimension,
one can imagine a long thin tube parallel to the x-axis and filled with pure
water into which we inject, at time t = 0, a unit amount of ink at the location
x = 0. The diffusion of these ink particles has the same molecular origins as
the pollen movement observed by Brown.
If f (x, t) is the density of ink particles at a location x and time t 0 we
have that
f (x, 0) = (x),
3
He was quite adventurous he accompanied the explorer Matthew Flinders who was
the first to circumnavigate Australia and, in his expedition of 1801, mapped much of the
coastline of southern Australia using not much more than a large rowboat.
142
CHAPTER 6. FINANCE
x2
1
e 2Dt .
1/2
(2Dt)
Sutherland, who was born in Scotland but emigrated to Australia as a child, found it
before Einstein, but his work went unnoticed.
143
Figure 6.4: Louis Bachelier, 1870-1946; William Sutherland, 1859-1911; Albert Einstein 1879-1955
predates5 both Sutherland and Einstein. In fact his ideas, completely underappreciated for much of his life, predate many others. For example, his idea
that one can find a deterministic PDE (the diffusion equation) for the time
evolution of probability distributions representing various physical systems
later became known as the Fokker-Planck (or forward Kolmogorov) equation.
Bachelier was attempting to model the erratic behavior of stock and
derivative prices on the Paris Stock Exchange. The asset price model that
we consider presently is a direct result of his work. We mention in passing
that Einstein found that the diffusion constant D may be computed via the
formula
D=
RT
,
NA h
Bachelier is today known as the father of modern mathematical finance; the Bachelier
Society was formed in his honor.
144
CHAPTER 6. FINANCE
6.2.1
Consider again ink diffusing in water. An ink molecule is much6 larger than
a water molecule. The water molecules bombard an ink molecule randomly,
so that the ink molecule movement is the sum of a large number of random
collisions.
Suppose that in a small time t the ink molecules typically move a small
distance s. Then we have
s2 2Dt,
(6.3)
so that the distance moved is proportional to the square root of the time.
To see this we define C(x) to be the concentration of ink molecules (the
number of molecules per unit length of tube) and J(x) to be the flow per unit
time (the number of ink molecules crossing x, to the right, per unit time).
We also assume Ficks Law:
J(x) = DC 0 (x).
Consider the perpendicular plane P passing through a point x0 and across
which diffusion is occurring. Let xr and xs be points chosen so that
xr < x0 < xs
and x0 xr = xs x0 = s. As the ink molecule movement is random, particles
move either left or right with equal probability. Thus half the particles in
the left zone [xr , x0 ] cross P . Let the concentration in this zone be Cr , so
that the number of ink particles is
cCr
.
2
Now, the total flow across from the left zone to the right zone is the flow per
unit time Jr time the time t. So
Jr =
sCr 1
.
2
t
sCs 1
.
2
t
145
Thus the net flow to the right per unit time across P is
Cs Cr
2t
Cs Cr
s2
.
=
t
s
2
s
.(C 0 (x0 ).
J = Js Jr = s.
6.3
Stochastic Processes
If, for each t 0 we are given a random variable Xt defined on a fixed sample
space for all t, we call the collection
{Xt }t0
a stochastic process. For each the mapping
t 7 Xt ()
is a sample path.
The idea here is that if we run an experiment and observe the random
values of Xt as time evolves, we are actually looking at a sample path {Xt () :
t 0} for some fixed . If we re-run the experiment, we will in general
observe a different path {Xt (
) : t 0} represented by, say,
.
While there are many stochastic processes, we only concern ourselves with
one:
The Wiener (Brownian Motion) Process
Let Bt () be the position at time t of the pollen grain . Then {Bt ()}t0
forms a stochastic process. Here
= {pollen grains}.
It is not uncommon for the phrase Brownian motion to refer to the physical
experiment, while Wiener process refers to the mathematical model that
we develop below. We choose not to make such distinction here.
146
CHAPTER 6. FINANCE
While we shall not formally construct our Brownian motion process, there
are some properties that are worth listing and we do so here. First, for
t s 0 we expect that the displacement Bt Bs to be the sum of a
huge number of small independent identically distributed collisions. By the
central limit theorem from probability theory, Bt Bs should be normal.
Also, there is no reason that collisions in one direction should be more likely
than in another, so
E(Bt Bs ) = 0
for all t s 0. Finally, the probability distribution for Bt Bs should not
depend separately on t, s, only on their difference t s. So we must have
Bt Bs N (0, t s).
There is no reason that the displacements imparted over non-overlapping
time intervals should be related. So, for times
0 < t0 < t1 < < tk ,
the increments
{Bt1 Bt0 , Bt2 Bt1 , . . . , Btk Btk1 }
are independent. Also, as the subtraction of B0 does not change any of the
above increments, we can assume that B0 = 0. Finally, we assume that each
sample path is continuous.
6.4
The It
o Integral
INTEGRAL
6.4. THE ITO
147
f (ti )(ti+1 ti ),
i=0
where, for each i, ti ti ti+1 , and provided that such a limit exists.
For a function f defined on an interval [a, b] and a function g we define the
Riemann-Stieltjes integral of f over [a, b] with respect to g,
Z b
f (t) dg(t),
a
i=0
where, for each i, ti ti ti+1 , and provided once again that such a limit
exists.
Here, it is known that if the function g is continuously differentiable, then
Z b
Z b
f (t) dg(t) =
f (t)g 0 (t) dt
a
148
CHAPTER 6. FINANCE
f (t, ) dBt ()
a
i=0
Here is where it gets a little weird. For Riemann integrals it is known that
the result does not depend on the choice of the values ti where
ti ti ti+1 .
In the stochastic case this is no longer true. In fact we get different limits if
we set ti = ti (this gives the Ito integral below) compared to ti = (ti +ti+1 )/2,
which gives the so-called Stratonovich integral.
We also need to be careful which stochastic integrands f (t, ) we use.
In particular, a stochastic process gt is called non-anticipating if its value
at time t depends only on information available at or before time t. So,
for any deterministic function F : R2 R the process gt = F (t, Bt ) is
non-anticipating, whereas gt = B2t is not. We now have
INTEGRAL
6.4. THE ITO
149
i=0
6.4.1
Properties of the It
o Integral
(iii)
Z
E
f (t, ) dBt
= 0.
We also have
Definition 6.2 Let u(t, ) and v(t, ) be non-anticipating functions.
stochastic process Xt of the form
Z t
Z t
Xt = X0 +
u(s, ) ds +
v(s, ) dBs
0
150
CHAPTER 6. FINANCE
6.4.2
The It
o Formula
Observe that if the deterministic function X(t) satisfies the differential equation
dX
= u(t, X)
dt
and Y (t) = g(t, X(t)) then by the chain rule
dY
g g dX
g
g
=
+
=
+
u,
dt
t x dt
t X
or, in differential form,
dY =
g
g
+
u
t X
dt.
(6.4)
Given this, the next theorem is quite surprising; it is the basis of much of
modern financial mathematics.
Theorem 1 (It
o formula) Let Xt be an Ito process,
dXt = u dt + v dBt ,
where u and v are non-anticipating, and let g(t, x) be twice continuously
differentiable. Then
Yt = g(t, Xt )
is also an Ito process and
g
1 2g 2
g
g
+
u+
v dt +
v dBt .
dYt =
2
t X
2 x
x
(6.5)
151
6.5
Asset Prices
An asset refers to a financial object whose value is known in the present, but
is liable to change in the future. By way of examples we have
one share in a company;
a fixed amount of a commodity: one ounce of gold, one barrel of oil,
one gross of soybeans;
currencies: the value of one euro in US dollars.
We shall be interested in other financial instruments, called options, that are
derivatives of (i.e. depend on) these assets; such an asset is then called an
underlying security or more simply, an underlying.
The asset model we consider rests upon several assumptions, principal
among these being the Efficient Market Hypothesis that
The current asset price reflects all past information.
In general the asset price is a measure of investor confidence, which in turn
depends on news (good and bad), rumor and suchlike, so this is not unreasonable if one believes that the market responds instantaneously to external
influences and there would be no advantage from reading the charts, and
our model need only use the asset price at time t to predict the price at time
t + t. We mention in passing that many7 believe that this hypothesis is
flawed, but it does give us a start!
Other assumptions include
the asset price may take any non-negative value;
buying and selling may take place at any time;
7
The market is quick to digest earnings data but grossly inefficient in valuing stuff
Michael Lewis, author and sometime bond trader, 1989
152
CHAPTER 6. FINANCE
Figure 6.6: Daily IBM share price May 2012 to April 2013
can begin to ascertain the underlying statistical behaviour by computing the
numbers
S(ti+1 ) S(ti )
ridaily =
S(ti )
153
that are known as the daily returns. Over a fixed time frame one could
compute the mean and variance of the returns and then normalize the
data to
ridaily
daily
ri
=
When this normalized data is compared to data from an N (0, 1) pseudorandom number generator, as may be seen from the quantile plots below, the
match is least accurate at the extremes, i.e for low probability events; this is
the famous fat tail problem wherein the use of Gaussian distributions seems
to be incorrect for certain financial events of low probability. Nonetheless,
by assuming our daily stock return data is normally distributed we appear
to be in something like the correct ball park, at least some of the time.
6.5.1
Let the asset price at time t be S(t). Over a small time interval [t, t + dt] the
asset price S(t) changes by dS. The relative change (i.e. the daily or weekly
154
CHAPTER 6. FINANCE
= dt + dBt ,
| {z }
|{z}
asset return
drift
(6.6)
fluctuations
Also
(log S(t))0 =
S 0 (t)
,
S(t)
so that the Brownian motion statistics really apply to log S(t) rather than
S(t) itself. It is for this reason that we say the asset prices follow a log-normal
distribution. One can show that if and are constant, then the stochastic
differential equation (6.6) has solution
S(t) = S(0)e(
6.6
2
)t+Bt
2
We are concerned here with the fair value of certain financial entities called
derivatives. These are financial instruments that depend on a base asset in
various, possibly complicated, ways. As an example we have
6.6.1
This is a contract that gives the holder the right, but not the obligation, to
purchase from the writer a prescribed asset for a prescribed price (the strike,
or exercise, price) at a prescribed future time (the maturity).
As an example, suppose that Professor A (the writer) creates a European
call option contract that gives you (the holder) the right to buy 100 shares
of IBM stock (the underlying asset) for US$1000 three months from now on
June 17. At that time
155
(i) if the actual value of 100 IBM shares is greater than US$1000, you
would exercise the option, and then sell for a profit; or
(ii) if the value is less than or equal to US$1000, do nothing.
Because you are not obliged to purchase the shares, you either gain (possibly
substantially) in (i), or neither gain nor lose in (ii). Professor A, in contrast,
who has to give you the shares at the exercise price, would incur a loss,
possibly huge, in (i). To compensate for this risk imbalance you would pay
Professor A an amount of money now, called the price of the option.
The key question is: how does Professor A work out how much he should
charge, i.e. what is the fair value now of this option? Here fair means
that Professor A neither makes, nor loses, money; he is a very altruistic
fellow!
Assume now that the prevailing risk-free interest rate is r > 0 for a call
option on an asset with price S(t) and strike price p and maturity T . In this
situation, $1 placed in the bank at time t = 0 becomes erT at time t = T , or
$1 at t = T is worth only erT at t = 0.
As a first guess should not the price of our call option be
erT E((S(T ) p)+ )?
The rationale here is that if S(T ) p the option is worthless. On the other
hand, if S(T ) > p we can buy the asset at p and sell at S(T ) and make a
profit (S(T ) p)+ ; so one should average this over all sample paths to get
the value.
Unfortunately this is wrong in general. In particular, the important missing factor concerns the possibility of arbitrage, the generation of risk-free profits. So, one must price the option so as to not create arbitrage opportunities
for others. This is done by hedging, in that one creates a portfolio consisting
of one option and a (continually changing) number of asset shares. The idea
here is that the hedge instrument duplicates the gains in a bank line-of-credit
used to finance the hedge under a no arbitrage assumption. This is the core
of the idea of Black and Scholes for solving the pricing problem via a certain
deterministic PDE of parabolic type.
6.6.2
For 0 t T and s 0 let u(t, s) denote the price of a call option at time t,
given that S(t) = s. So we seek u(0, S(0)). The function u(t, s) must satisfy
156
CHAPTER 6. FINANCE
Figure 6.8: Economists Fisher Black, 1938-1995 and Myron Scholes, 1941the following conditions. First the final condition
u(T, s) = (s p)+
(6.7)
(6.8)
(6.9)
for 0 t T . The first of these follows because if the asset price is zero,
so is the option price; as for the second, if the asset price increases without
bound, the value of the exercise price p becomes irrelevant.
The Hedge Portfolio
Let the underlying asset have value S(t), where 0 t T , and consider
the value H(t) of a portfolio constructed with one call option with value
C(t) = u(t, S(t)) and N (t) asset shares:
H(t) = C(t) + N (t).S(t)
where this is financed by a line of credit. The N (t) will be chosen below.
Noting that from (6.6) we have that in the time interval [t, t + dt] the change
in the asset price ds is given by
ds = s dt + s dBt
157
and from the Ito theorem (6.5) the corresponding change in the option price
dC is
1
dC = (ut + sus + 2 s2 uss ) dt. + sus dBt
2
It follows that in the time interval [t, t+dt] the gain (which could be negative)
in this portfolio is
1
dC + N (t)ds = (ut + sus + 2 s2 uss ) dt + sus dBt
2
+ N (t)(s dt + s dBt ).
If we choose N (t) = us (t, S(t)) then we have that the gain is
1
dC + N (t)ds = (ut + 2 s2 uss ) dt,
2
which is riskless (no dBt ) and thus must be the same as the gain in the
line of credit account over the same period. So, as
rH(t) dt = r[u(t, S(t)) + N (t)S(t)] dt = r[u(t, S(t)) us (t, S(t)).S(t)] dt
and
1
r[u(t, S(t)) us (t, S(t)).S(t)] dt = (ut + 2 s2 uss ) dt,
2
it follows that
u 1 2 2 2 u
u
+ s
+ rs
ru = 0.
(6.10)
2
t
2
s
s
This is the equation of Black and Scholes. We note in passing that the
equation does not explicitly involve the drift , and the volatility need
not be a constant for this derivation to hold. However, if both and r are
constant, then the equation can be solved explicitly as we demonstrate next.
Solving the Constant Coefficient Black-Scholes PDE
We solve (6.10) under the final condition (6.7) and the boundary conditions
(6.8) and (6.9), assuming and r are positive constants. By the variable
change (t, s) (, x) defined by
s = pex
t=T 1 2
2
u(t, s) = pv(, x),
(6.11)
158
CHAPTER 6. FINANCE
(6.12)
1
1
s
u(T, s) = max (s p, 0) = max ( 1, 0) = max (ex 1, 0).
p
p
p
x2
where
(6.13)
x2
1
e 4
4
w(, x) =
(xy)2
4
e
w0 (y)
dy,
(6.14)
159
then
w
=
[f (, x y)] dy =
and
2
2w
[f
(,
x
y)]
dy
=
,
x2
x2
w0 (y)(x y) dy = w0 (x).
w(0, x) =
y)/
2 for
1
2
w0 (x 2 z)ez /2 dz
w(, x) =
2
Z x/2
1
1
1
2
=
(e 2 (k1 +1)(x 2 z) e 2 (k1 1)(x 2 z) ) ez /2 dz
2
= I1 I2 ,
where on noting that
!2
(k1 + 1) 2
z+
,
2
1
1
1
(z 2 + (k1 + 1) 2 z) = (k1 + 1)2
2
4
2
I1
1
=
2
x/ 2
e 2 (k1 +1)(x
1 1
= e 2 (k1 +1)x
2
x/ 2
2 z) z 2 /2
e 2 (k1 +1)
1
1 1
2
= e 2 (k1 +1)x+ 4 (k1 +1)
2
1
1 1
2
= e 2 (k1 +1)x+ 4 (k1 +1)
2
x/ 2
2 z 12 z 2
e 2 (z+
x
2
dz
(k1 +1)
2 )2
2
(k1 +1)
2
2
dz
1 02
e 2 z dz 0
dz
(k1 + 1)
2 ,
2
x
(k1 + 1)
d1 = +
2 ,
2
2
(6.15)
160
CHAPTER 6. FINANCE
and
1
N (x) =
2
ez
2 /2
dz
1
=
2
x/ 2
e 2 (k1 1)(x
1 1
= e 2 (k1 1)x
2
x/ 2
2 z) z 2 /2
e 2 (k1 1)
1
1 1
2
= e 2 (k1 1)x+ 4 (k1 1)
2
1
1 1
2
= e 2 (k1 1)x+ 4 (k1 1)
2
x/ 2
2 z 12 z 2
e 2 (z+
x
2
dz
(k1 1)
2 )2
2
(k1 1)
2
2
dz
1 02
e 2 z dz 0
dz
(k1 1)
2 ,
2
(k1 1)
x
d2 = +
2 .
(6.16)
2
2
Having obtained w we now work our way back through the variable
changes to obtain the option price u. First,
v(, x)
1
= e 2 (k1 1)x 4 (k1 +1) (e 2 (k1 +1)x+ 4 (k1 +1) N (d1 ) e 2 (k1 1)x+ 4 (k1 1) N (d2 ))
= ex N (d1 ) ek1 N (d2 ).
Finally, using (6.11), we have
u(t, s) = p{ex N (d1 ) ek1 N (d2 )}
= sN (d1 ) per(T t) N (d2 ).
This means that
u(0, S(0)) = S(0)N (d1 ) perT N (d2 ),
(6.17)
161
where
x
(k1 + 1)
d1 = +
2
2
2
r
log(s/p) ( 12 2 + 1)
=
+
2
2
2
log(s/p) + ( 1 r2 + 1) 12 .2
2
=
2
log(s/p) + (r + 21 2 )(T t)
=
T t
and
log(s/p) + (r 12 2 )(T t)
d2 =
.
T t
6.6.3
(6.18)
The Greeks
No, we are not talking about struggling European economies, but interestingly enough, due to the likes of Goldman-Sachs the these particular Greeks
did have a role to play in that saga8 .
The value of a European call option u derived above depends not only on
s and t, but also on the strike price p, the interest rate r, and the volatility
of the underlying and also, as we see later, the maturity T . So, ignoring T
for the moment,
u = u(t, s; p, r, ) = sN (d1 ) per(T t) N (d2 ).
The financial sector is interested in the sensitivity of the option value u to
changes in each of these parameters, and this can be determined by calcu8
Goldman-Sachs created certain complicated derivative instruments that cleverly allowed the Greek government to circumvent EU deficit spending rules, leading directly to
their current predicament
162
CHAPTER 6. FINANCE
u
vega : vega =
= s T tN 0 (d1 ).
Delta : =
(6.19)
(6.20)
(6.21)
(6.22)
(6.23)
We have already met Delta in the hedging formula used to derive the BlackScholes formula, and we run into vega in the next section on implied volatilities.
6.6.4
Implied Volatility
163
0+
Now, from the previous section, vega = u > 0, so the function u() is
increasing and, for 0 < the values of u() satisfy
max (s per(T t) , 0) u() < s.
In particular the equation u() = u if the above inequality holds, and the
solution is unique if it exists.
164
CHAPTER 6. FINANCE
A major assumption underlying the Black-Scholes theory is the the volatility is constant. In reality, this is rarely so, as the graph below indicates
and this behavior is quite typical. We note that the derivation of the BlackScholes PDE in fact does not require the constancy of , although the nice
formula (6.17) is no longer valid. We explore what happens when we assume
= (t, s),
in the asset price stochastic equation (6.6) in the next section.
6.7
Assume now that the asset price S(t) satisfies the stochastic equation
dS
= (t, S(t)) dt + (t, S(t)) dBt ,
S(t)
(6.24)
where the drift = (t, s) relates to the trend of the asset and = (t, s)
is the volatility. If we consider a European call option on this underlying,
the corresponding Black-Scholes PDE for the fair price u(t, s) of the option
is
u 1
2u
u
+ (t, s)2 s2 2 + rs
ru = 0.
(6.25)
t
2
s
s
subject to the conditions (6.7), (6.8), and (6.9) as before.
Now, without the benefit of the Black-Scholes formula (6.17) it is a much
more difficult problem to recover the volatility (now a function) from a
knowledge of the option prices u. This is the so-called inverse volatility
problem which we discuss next. The recovered volatility function is called
165
the local volatility, in order to distinguish it clearly from the implied volatility
discussed above.
First we observe that the option price u depends here on the four variables,
s the asset price, t the current time, K the strike price, and T the maturity
or time to expiry,
u = u(t, s; T, K).
(6.26)
Typically one knows at a certain time t0 and asset price s0 = S(t0 ) the option
prices u(t0 , s0 ; T, K) for a number of strikes K and maturities T . Now while
the volatility appears in the Black-Scholes equation (6.25) it is not clear
how it might be extracted, as the data involves K and T and the PDE uses
the variables s and t. What is needed here is a differential equation for u
that involves the other variables K and T in (6.26). In 1994 such an equation
was found by Bruno Dupire, a French mathematician then working for the
banking and financial services giant Societe General in Paris.
1
[u(t, s; T, K + ) u(t, s; T, K)] .
Then u1, also satisfies the PDE (6.25) in the variables s, t for any 6= 0.
166
CHAPTER 6. FINANCE
Observe also that from (6.7), u1, satisfies the final condition
if s (0, K]
0
1
(K
s)
if
s (K, K + )
u1, (T, s; T, K) =
1
if s [K + , )
If we let 0 we have that u1, tends to uK , and
uK (T, s; T, K) = H(s K),
where H(s) is the Heaviside step function. In like fashion, set
u2, =
1
[u(t, s; T, K + ) 2u(t, s; T, K) + u(t, s; T, K )]
2
Again, u2, also satisfies the PDE (6.25) in the variables s, t for any 6= 0.
Observe also that from (6.7), u2, satisfies the final condition
0
if s (0, K ]
1
( + s K) if s (K , K]
2
u2, (T, s; T, K) =
1
( s + K) if s (K, K + )
2
0
if s [K + , )
where the right hand side is a hat function. If we let 0 we have that
u2, tends to uKK , and
uKK (T, s; T, K) = (s K),
where (s) denotes the Dirac delta function. This means that
G(t, s; T, K) = uKK (t, s; T, K)
is a so-called fundamental solution for the parabolic PDE (6.25). Such solutions have the special property that, as a function of the variables K, T , the
function G satisfies the so-called adjoint equation
1 2
G
=
(K 2 (K, T )2 G)
(rKG) rG.
2
T
2 K
K
So we know that the function u(t, s; T, K) satisfies
1 2
uKK
2
2
=
(K
(K,
T
)
u
)
(rKuKK ) ruKK .
KK
T
2 K 2
K
6.8. BONDS
167
u
2 d = K
2 dd =
+
d = K
u.
K K
K
K
K
We then arrive at the Dupire PDE for the call price function u(t, s; T, K) in
the variables K, T :
u
1
2u
u
= K 2 (K, T )2
rK
.
2
T
2
K
K
6.8
(6.27)
Bonds
A bond is a contract, paid for up-front, that pays a known amount on a known
date in the future, called the maturity date. The bond may also pay a known
cash dividend, called the coupon at fixed times during the life of the contract;
if there is no coupon the bond is known as a zero-coupon bond. Bonds are
issued by both governments and companies typically with the intention of
raising capital, and the up-front premium should be considered a loan to the
issuer.
The problem of valuing/pricing a bond boils down to answering the following question: how much should one pay now to receive a guaranteed $1 in
T years time? The fair value v of such a contract at any given time t depends
upon t, the maturity time T , and also the prevailing short-term interest rate
r(t); so v = v(r, t; T ). As the maturity time T can be large, T = 10 years is
not uncommon, one can no longer assume a constant interest rate as we did
above. We begin first by assuming that r = r(t) is a deterministic function
known in advance; later we study a stochastic interest rate model.
6.8.1
We now calculate v = v(r, t; T ), assuming that the interest rate r(t) and the
coupon payment schedule k(t) are both known in advance. We assume also
that
v(r, T ; T ) = Z,
(6.28)
168
CHAPTER 6. FINANCE
the nominal, principal, par, or face amount of the bond. At time t < T the
change of value of the bond over the time interval [t, t + dt] is
v
+ k(t) dt,
t
given that the coupon payment over this time interval is k(t)dt. To avoid
arbitrage possibilities, this must equal the corresponding return on a short
term bank deposit, r(t)v.dt, so that
v
r(t)v = k(t).
t
This first order linear equation may be solved using (6.28) and an integrating
factor to give
Z T
R
R
pT r( ),d
tT r( ),d
v(r, t; T ) = e
Z+
k(p)e
dp .
t
r( ) d = log(
t
v(r, t; T
),
v(r, T ; T )
(6.29)
6.8. BONDS
169
v
1
.
v(r, t; T ) T
Taking a cue from (6.29) we define the yield Y (t; T ) to be
r(T ) =
Y (t; T ) =
log(v(r, t : T )/v(r, T ; T ))
.
T t
For fixed t (the present) the yield is a measure of the future value, r(T ),
of interest rates. The plot of Y against Tt is known as a yield curve; the
dependence of the yield on the time to maturity T t is called the term
structure of interest rates. Actual market data tends to produce yield curves
that are increasing, indicating that future interest rates will be higher than
shorter term rates, since it should be more rewarding to tie up money for the
longer periods. Occasionally, the yield curve will be decreasing (or humped);
such curves are called inverted yield curves. An example of this can seen in
the figure below. Strongly inverted yield curves have historically preceded
6.8.2
Bond Futures
170
CHAPTER 6. FINANCE
occurring at a specified future date T , the delivery date. If the interest rate
r(t) is known, the futures price is
F (t) = v(r, t; T )e
RT
t
r( ) d
Who purchases a futures contract? Buying a futures contract is an indirect method of buying (going long in) the underlying and conversely, selling
a futures contract allows one to indirectly sell (short) the underlying. The
traditional idea is that, for example, an airline could buy a jet fuel futures
contract to guard against a catastrophic future rise in fuel prices. Who would
sell such a contract? A speculator might see a future with fuel prices falling
(due insider knowledge about a future oversupply, for example), which would
support the selling of such a futures contract to lock in a profit. In general
hedgers seek to reduce risk, and speculators seek to take advantage of it.
When a party establishes a position in (buys) a futures contract, it can
either run this position to maturity or close out the position between the
trade date and the maturity date. If a position is closed out the party will
have either a profit or loss to book. If a position is held until maturity, the
party who is long futures will take delivery of the underlying asset (bond) at
the settlement price; the party who is short futures will deliver the underlying
asset. This is referred to as physical settlement.
6.8.3
In practice the interest rate r is not known in advance, but we can try to
model it using a similar random variable technique to that used above for
stock prices. In particular we assume that the short-term spot interest
rate r is determined by a stochastic equation
dr = u(r, t) dt + w(r, t) dBt ,
(6.30)
where u and w are to be determined, and Bt is the Brownian motion stochastic process considered earlier.
6.8.4
6.8. BONDS
171
v1 1 2 2 v1 v1 /r
+ w
t
2
r2
v1 /r
v2 1 2 2 v2
+ w
t
2
r2
dt
v1
= r v1
r
v2
r
dt.
Rearranging gives
v2 1 2 2 v2
v1 1 2 2 v1
v1
v2
+ w
rv1
=
+ w
rv2
= a(r, t),
2
2
t
2
r
r
t
2
r
r
as the first term above is a function of T1 but not T2 , and the second term is a
function of T2 and not T1 . It follows that the price v(r, t; T ) of a zero-coupon
bond satisfies the partial differential equation
v 1 2 2 v
v
+ w
+ a(r, t)
rv = 0,
2
t 2 r
r
(6.31)
6.8.5
(6.32)
Bond Options
A European bond call (put) option is a contract that gives the owner the
right, but not the obligation, to purchase (sell) one bond (maturing at TB )
at a specified price K (the exercise, or strike, price) at a specified future
172
CHAPTER 6. FINANCE
date T < TB (the expiry date). In common with its equity analogue the
fair (arbitrage free) price c = c(r, t; K, T ; TB ) satisfies a partial differential
equation that we now derive.
Notice first that one can apply the above bond pricing argument with a
portfolio consisting of one bond v1 maturing at T1 together with options.
Again eliminating the random part gives
v1 c
,
=
r
r
followed by
c 1 2 2 c
c
v1 1 2 2 v1
v1
+ w
rv1
=
+ w
rc
= a(r, t).
2
2
t
2
r
r
t 2 r
r
It follows that the price c(r, t; K, T ; TB ) of a zero-coupon bond satisfies the
partial differential equation
c 1 2 2 c
c
+ w
+ a(r, t) rc = 0,
2
t 2 r
r
(6.33)
together with the final condition for the payoff at maturity given by
max(v(r, T ; TB ) K, 0) for a European bond call option
c(r, T ; K, T ; TB ) =
max(K v(r, T ; TB ), 0) for a European bond put option,
and appropriate boundary conditions.
Chapter 7
Modeling Projects
The questions raised in each of the projects listed below are only a guide;
you are free to ask and answer your own questions (or not).
7.1
Density
Specific Heat Thermal conductivity
3
(lbm ft ) (Btu lbm1 F1 )
(Btu hr1 ft1 F1 )
489.01
0.11
30.62
150.00
0.25
0.79
8.5
0.18
0.03
85.0
0.21
0.90
Assume that the temperature of the steam on the inner surface of the
pipe is 400 F and that the pipe has an inner diameter of 10 inches and an
outer diameter of 11.5 inches. The insulation around the pipe is 2 inches
thick and is assumed to be in place for both calculations. There is a concrete
walk over the area which is 4 inches thick; the concrete box is 5 inches thick
and 40 inches wide on a side as an outside dimension. The center of the
173
174
pipe is 36 inches from the outer edge of the side of the box and 36 inches
from the surface of the concrete walk. The insulation used as a lining of
the one side and bottom of the box is 6 inches thick. The temperature of
the air is 90 F and the coefficient of thermal convection into the air is 0.88
Btu hr1 ft2 F1 .
This is a steady-state heat conduction problem for the temperature T (x, y)
over the region given in the Figure. The equation is
kT = 0
175
7.2
The Mridangam
The mridangam drum from southern India consists of a radially variable density membrane stretched tightly over a circular frame as pictured below. It
has the unusual property of being harmonic, i.e. the frequencies of vibration of the membrane are integer multiples of the lowest, or fundamental,
frequency.
There are several approximate forms of with which one can investigate
the harmonic properties of the mridangam. The alternate continuous density
function
176
7.3
The Nutwrecker2000
A tool manufacturer has given you the specifications of their new spanner,
the Nutwrecker2000, shown below, and they are requesting your input as to
whether the spanner should be put into production. Specifically, assuming
that a typical mechanic could exert at most a downward pressure of 150 psi
(pounds per square inch) on the handle, would the Nutwrecker2000 be liable
177
OptionsAxes Limits with [-1 5] for the x-axis and [-1 1] for the yaxis. Next, make the selection OptionsGrid Spacing and set the x-axis
extra points to [-1 0 0.2 0.4 0.7657 5] and the y-axis extra points to
[-0.4 0 0.4 0.4828]. From the Draw menu create the rectangle R1 with
opposite corners at (0, 0) and (5, 0.4). Create the circle C1 with center
(0, 0) and radius 0.2, and the circle C2 with the same center and radius
0.4. The rectangle R2 is first formed with opposite corners at (0.2, 0) and
(0.2, 0.4828). This rectangle is then rotated 45 using DrawRotate; type
the angle into the dialog box, and also the rotation point, which is typed as 0
0 representing the origin (do not use center of mass rotation here). Draw
the square SQ1 with opposite corners at (0, 0) and (0.4, 0.4), and then rotate it about 0 0 by 45 . The rectangle R3 has opposite corners (0.4, 0)
and (0.7657, 0.4828). Finally, turn off the snap option with OptionsSnap
again, and form the circle E1 with center (0.7657, 0.4828) with radius such
178
7.4
179
Figure 7.6: Exxon Mobil CIDS platform Orlan drilling off the coast of Russia
mounted on one of the two deck storage barges and is designed with a 25, 000foot drilling capability. There are quarters for 80 people and 10 months of
supplies for long-term operations. The entire system, with drilling rig intact,
can be relocated by pumping out the saltwater ballast and towing the CIDS
to a new site. A drilling contractor using a CIDS in the Arctic Ocean is
concerned that the water ballast in the outer ring of cells in the barge will
freeze and fracture the concrete walls of the honeycomb module. An insulation salesperson suggests insulating the outer walls of each of the cells with
roughly 10 inches of insulation, as illustrated in Figure 7.8. The water in the
cells that do not border on the perimeter of the barge is kept warm by the
drilling activity.
180
181
You can assume that the temperature function u(x, y) satisfies the 2D steady
state (elliptic) heat equation
((x, y)u) =
u
((x, y) ) +
((x, y) ) = 0
x
x
y
y
182
to bring up a dialog box. You do not need to set conditions on any of the
internal boundaries.
Specifying the PDE
Choose PDEShow Subdomain Labels. This command places numbers
on the various sub-domains in the domain you have drawn. We can now give
our various coefficient functions different values in the different sub-regions.
For example, choose PDEPDE Specification and select the elliptic
option. Notice that the ballast water region is actually marked as regions
1 and 2 here. In the sub-region marked as 1, first click on that sub-region
to select it; then double-click on it to bring up the dialog box. You will set
a = 0, f = 0, and set c to the value of thermal conductivity determined by
the table above. Repeat this process for all of the sub-regions.
Specifying the Mesh
Press the initialize-mesh button, and do two refinements by pressing the
refine-mesh button twice; you should have around 2928 triangles in this mesh.
Solving and Plotting
First set the plot options by pressing the plot button, or choosing PlotParameters;
press the Contour button (and release the Color button if necessary). This
will give you a contour plot with equal temperature values in the final steady
state appearing on colored lines. Now press the solve button (it looks like
) to solve the problem.
The Report
Write a report detailing your choice of equation and boundary conditions;
explain precisely why in this case there was no problem with the material
properties being given in SI units, while the cell dimensions were given in
inches and degrees centigrade. Include a copy of the contour plot of the 32 F
contour. You can print the contour plot by choosing FilePrint... from
the File menu in PDETool; when the print dialog box comes up check the
Print to File box and print the file as usual.
183
Note that If you wish to just plot one contour, this is a little more difficult. You must first export the mesh and the solution to the main MATLAB workscreen using SolveExport Solution... and MeshExport
Mesh... and in the MATLAB workscreen type
pdeplot(p, e, t,0 xydata0 , u,0 contour0 ,0 on0 ,0 levels0 , [32, 32])
to plot the 32 F isotherm, for example; here each of the quote marks above
is a right quote.
Discuss the soundness of the salesmans suggestion. What effect, if any,
will increasing the thickness of the insulation have?
We studied above the difficulties encountered in deploying a concrete
island drilling system (CIDS) off-shore in the arctic ocean. The problem
stated that the seawater was at a temperature of -60 F and we found using
the steady-state version of the heat equation that the ballast in the platform
became a solid lump of ice.
Re-do this problem using the standard heat equation and determine precisely when the ballast begins to freeze after the CIDS is deployed.
There is some question as to whether the arctic ocean can reach a temperature of -60 F. Find how low the seawater temperature actually gets
in practice, and re-do the problem with more reasonable estimates of the
seawater temperature. You may wish to employ the additional fact that the
seawater temperature is in practice not constant, but varies sinusoidally with
the seasons.
7.5
Computer chips work faster if they are not too hot, but operating them
creates heat. In order to dissipate the heat, designers can surround the
(silicon) processing units by a high-conductivity material like copper to act
as a heat sink to conduct the heat away. The cross-section of a typical
configuration is shown in the figure below:
184
185
The Report
(a) Initialize the mesh and then refine 4 times. Plot the temperature distribution in the domain at time t = 100 when the thickness b = 2 mm.
(See figure above.) Label the plot with the maximum temperature and
identify the point at which it occurs.
(b) Plot the maximum temperature at t = 100 as a function of b [1, 6]
and determine (to 2 significant figures) the smallest thickness for which
the temperature is at most 500K. How accurate do you believe your b
value is? Justify your answer.
Submit your plots, your program, your minimal b value, and your justification.
7.6
Groundwater Modelling
A two-dimensional aquifer system is rectangular, with dimensions 3000 meters by 1500 meters. The aquifer is replenished from a surface-water supplied
swamp area P1 that is 50 meters wide on the eastern side of the line between
(1200, 1500) and (1800, 0) in the Figure below. In addition to the aquifer
area R1, the square areas SQ1 and SQ2 represent pumping regions that are
50 meters square located to the north and east of the points (600, 500) and
(2400, 1000), respectively. In PDE Toolbox the proper set combination is
(R1-(P1+SQ1+SQ2))+P1+SQ1+SQ2.
The piezometric head u(x, y, t) represents the height, in meters above
some standard datum level often taken to be the mean sea water level, of
water in the aquifer at position (x, y) at time t days. The PDE that governs
groundwater flow is
u
(T u) = Q,
S
t
where S is the storativity, which is dimensionless, T is the transmissivity
measured in units of m2 /day, and Q is the inflow or aquifer recharge term,
in units of m3 /day/m2 .
We assume that at the eastern and western boundaries, the head is fixed
at u = 100 and that the remaining boundaries are impervious, so that there
is no groundwater flow across them. The transmissivity in the aquifer is
186
7.7
187
You live on a long 10 meter wide boat canal, and your neighbor 200 meters
upstream spills one kilogram of boat fuel onto a circular patch of the canal
water surface S of area one square meter. Suppose that at first the current
in the canal is negligible and the fuel is transported on the canal surface only
by diffusion, so that the concentration C(x, y, t) of fuel at position (x, y) in
the canal from the spill at time t seconds later satisfies
C
= D.C,
t
(x, y) R2 ,
t > 0,
(7.1)
Find the first time at which the fuel concentration reaches 5105 Kg/m2 .
Find also the maximum surface concentration reached by the fuel in the
vicinity of your house.
Later you find that, due to upstream run-off, the canal water surface was
actually moving at 0.01 m/s. In this case the concentration C(x, y, t) actually
satisfies the convective diffusion equation
C
= D.C v C,
t
(x, y) R2 ,
t > 0,
where v denotes the velocity of the canal water, together with the same
initial condition (7.1). Redo the above calculations in this case.
If one assumes that the canal current is reversed and actually flows from
your house toward the spill point, is it possible that the fuel never reaches
your house in the sense that the concentration at your house never exceeds
5 105 Kg/m2 ?
7.8
A soap film bounded by a wire frame has the shape determined by the minimization of its internal energy. The shape of the film is described by the
height u(x, y) over a given domain in the xy-plane, assuming that the
height is fixed at the domain boundary. So a wire fram consisting of parallel
188
0.9
1
0.8
0.8
0.7
0.6
0.6
0.5
0.4
0.4
0.2
0.3
0
1
0.2
1
0.5
0.8
0.6
0.1
0.4
0.5
0.2
1
189
p
p
g(0, y) = 1 y 2 ; on the line x = 2 let g(2, y) = 1 y 2 ; on the remaining lines let g(x, 1) = g(x, 1) = 0. Under PDE Specification choose
elliptic and set c to be
1./sqrt(1.+ ux.^2 + uy.^2)
and a=f=0. Under SolveParameters... select Use nonlinear solver
and set the Jacobian option to Full.
Experiment with this film: does it break if the length is increased beyond
two? Can you make other films? For example you can set up concentric
circles as the wire boundaries, and have the wires at different heights.
7.9
Blood Flow
interesting flows, include that of blood flow through arteries and veins in the
human body.
190
The PDE
As always denote the fluid velocity vector by u = (u1 , u2 , u3 ). We assume
that the flow is uni-directional, so that u2 = u3 = 0. We also assume that
the velocity is independent of distance in the flow direction, and thus the
acceleration of a fluid particle is u/t, which now has just one non-zero
component. If the flow is steady (i.e. independent of time), the NavierStokes equations then reduce to the single equation
0=
2 u1 2 u1
p
+ ( 2 +
).
x1
x2
x23
If the flow is in the direction of the positive x1 axis and there is a constant
pressure gradient resulting from a pressure p1 at the exit end of the tube and
p2 at the tank end, then we may set
p
p1 p2
=
= G,
x1
l
where G > 0. The Navier-Stokes equation now reduces to the single elliptic
equation
G
2 u1 2 u1
+
=
2
2
x2
x3
over the circular region of radius r for the velocity u1 across any crosssection of the tube.
Use the MATLAB PDEToolbox to compute u1 for three tubes of radius
r = 1, 2, 3 millimetres. You may assume that l is one meter, and that the
pressure drop is 0.01 atmospheres (one atmosphere is 105 Pascals, or about
15 pounds per square inch, if you need some perspective). Assume that the
viscosity of the fluid is 0.001 Nsm2 . Dont forget to change everything to
SI units before starting to set up your geometry in PDEToolbox (see 1.2 in
the notes). Use the no-slip condition
u1 = 0
at the boundary of your circle of radius r.
The Volume Flux
An interesting quantity to compute is the rate at which fluid comes out of the
tube, the volume flux, measured in m3 s1 (cubic meters per second). If we
191
consider the volume of fluid that flows through a small part A of in time
t, we can see that it is the amount of fluid in a cylinder of height Ru1 t and
base area A. So the total volume of fluid through in time t is t u1 dA.
Consequently the volume flow rate (volume flux) of fluid coming out of the
pipe is
Z
u1 (x2 , x3 ) dx2 dx3 .
You can compute this quantity for each of the choices of radius r as follows.
When you compute the u1 in PDEToolbox you can choose SolveExport
Solution from the Solve menu and the solution is exported to the MATLAB
screen from which you called PDEToolbox as the array u. Before going
back to the MATLAB screen you need to also export the mesh, by choosing
MeshExport Mesh; the arrays p, e, and t representing, respectively, the
mesh node points, the triangle edges, and the triangle vertices. Now return
to the MATLAB window; you should see at least four new arrays, u, p, e, and
t listed in the top left window. To integrate u over the region (represented
by p and t) we first note that in the finite element method,
u(x2 , x3 ) =
N
X
Ui i (x2 , x3 )
i=1
where N is the number of mesh points in and the functions i are the FEM
hat functions. So
Z
u1 (x2 , x3 ) dx2 dx3 =
N
X
i=1
Z
Ui
192
where c,a,f are the PDE coefficients, p,t are the mesh vectors discussed
above, and the output arrays K,M,F are, respectively, the FEM stiffness matrix, the mass matrix, and the vector of right hand side integrals Fi that we
need here. So at the MATLAB prompt >> type
[K,M,F]=assema(p,t,1,0,1)
and then type F*u to form the scalar product of u and F , thereby computing
the integral of u over . Repeat this for each of the three radii r.
Find the volume flux in each of the three cases, in each case converting
to units of cubic centimeters per second (otherwise known as millilitres per
second). It is known that the volume flux is proportional to a positive integer
power of the radius. Use your data to estimate this power.
7.10
where E is the electric field with units of volts per meter (V m1 ), H is the
magnetic field with units of amperes per meter (A m1 ), J is the current
density with units of amperes per square meter (A m2 ), is the magnetic
permeability measured in henrys per meter, or m kg s2 A2 , and is the coefficient of dielectrics (or electric permittivity) measured in farads per meter
or s4 A2 m3 kg1 .
193
E
2E
2 = 0.
t
t
jt
One then assumes
that E = Ec e so that the electric field is periodic in
time; here j = 1 is typically used instead of i which is often used for the
current in engineering books. In the PDE toolbox we further assume that
Ec = (0, 0, Ec ) is only varying in one dimension; in consequence we also have
J = (0, 0, Jejt ), where J = Ec , and
H = (Hx , Hy , 0) =
1
Ec .
j
194
2*pi*50
4*pi*1E-7
57E6
8.8E-12
7.11
195
film of air that constitutes our own atmosphere. Based upon these soap
bubble experiments, the team developed a promising forecasting model for
predicting the paths of real hurricanes. Rather than using soap, we will
try to use COMSOL to create vortices in a realistically sized hemispherical
shell of air heated sinusoidally at the equator. The COMSOL model file
hurricane3d.mph is available on the class website. Here we use the multiphysics capabilities of COMSOL in that we model air movement with the
Navier-Stokes equations for compressible flow (under Laminar Flow), together with a convective diffusion equation to model the critically important
temperature effects (under Heat Transfer in Fluids). For the fluid flow
we use slip (no flow) conditions on the upper and lower sides of the shell
which is set up as Wall boundary. The flat equatorial side is used as an
Inlet boundary with a set normal velocity of 20 m/s. At the vertical North
Pole boundary (see below) we have an Outlet boundary where the pressure is set at zero. For the temperature conditions, we set the North Pole
boundary to 293.14K and the walls as Thermal Insulation boundaries.
The equatorial boundary temperature is set to
196
mean*amp*sin(af*t)*sin(atan2(y,x))
to incorporate the night/day heating cycle at the equator. Here, the mean
temperature is set at 333[K], the temperature variation amp is 10[K] and the
angular frequency af is 2/[(24)(3600)] = 0.00007272. The spherical angle
= atan2(y, x), where atan2(y,x) calculates arctan(y/x), but is sensitive
to both the different quadrants involved, and even to the possibility of x being zero. We note that the parameters like mean and amp are defined in the
Global Definitions node under Parameters. One must be quite careful here in naming such parameters. In particular COMSOL uses reserved
names such as u,v,w,x,y,x,t for the Cartesian coordinates and time, and
the fluid velocity components, and combinations like ux,uy,uz,ut and so on
for derivatives, and uxx, ... for higher derivatives. You must not inadvertently use any of these names for one of your parameters (as I have done!).
COMSOL does not do any checking for this kind of stuff, but does give weird
errors like Pointwise constraints for time derivatives are not supported ...
while crashing your program run. Be aware that the time run is currently
set to 104 seconds (about 3 hours) with a computer run time of 47 minutes,
and one really needs to reset this to run for several model days.
It is not clear at this stage whether on not this will work ...
197
7.12
A Rectangular Waveguide
198
(a) Waveguide 1
199
(b) Waveguide 2
(c) Waveguide 3
200
[x,index]=sort(x);
v=v(index);
plot(x,abs(v))
If you save the three bends in vectors v1,v2,v3 they can all be plotted on
one graph. At this stage x and v are vectors containing the grid points and
values in the usual order. The energy of each wave at exit is the integral
Z 0.8
|u|2 (x, 0.8) dx.
0.4
As the energy of each wave on entry to the waveguide is 0.4 (why?), the
energy loss may be computed in MATLAB using the trapezoid quadrature
rule:
N=length(x);
w=abs(v).^2;
E=sum(0.5*(w(2:N)+w(1:N-1).*diff(x))/0.4
Here the MATLAB function diff(x) applied to a vector x=[x(1),x(2),...,x(n)]
gives the (n-1)-vector of differences [x(2)-x(1),...,x(n)-x(n-1)]. Comment on the effectiveness of each waveguide in transmitting energy. Investigate what happens if the wave number k changes.
Appendix A
Typesetting with TEX
From the earliest cave hieroglyphs to the present time it is evident that
we as a society depend in a fundamental way upon the written word, not
just for mere communications, but as the main storage medium for much
of our accumulated knowledge. An important, even crucial, aspect of the
effectiveness of a written document as a vehicle for transmitting information
is the connection between the logical structure of the ideas being presented
in the document and the visual layout of the characters on the pages of
the document. This is especially true when it comes to presenting technical
scientific and engineering material containing a lot of mathematical notation.
202
ment of formulae, chapter and section headings, quotations, and the like,
to produce a pleasing and visually effective look to the documents. This
rather loose process was brought strongly into focus by the introduction of
the printing press by Johann Gutenberg (pictured above, with his press) in
the fifteenth century. Now the visual presentation of documents was in the
hands of a new breed of artisans the typographers whose job it was to set
the heavy lead typefaces into a type-rack which was then used to print the
document. If you look at technical books produced in the pre-computer era1
you will see that many of them were beautiful examples of the printed word.
Over the centuries, the typographers had developed to a high art techniques
for the effective visual presentation of complex ideas on the printed page.
Then the computer era dawned, bringing with it word-processing programs like Word Perfect and (ugh!) Word. These programs of course allowed each user to be their own typographer. The user could place characters anywhere they chose on their computer screen and then print the
result. Of course, without much knowledge of the art of typography or help
from the computer program, the results were generally rather shabby, and
only suitable for very simple applications like letters and memos and the
like. Computer programs of this type are called WYSIWYG2 (pronounced
wizzywig) programs, and they
rapidly took over the world of publishing. The old-time typographers
were, it seemed, no longer relevant.
Worse, all their accumulated knowledge as to how to place characters on
the printed page to achieve the beautiful and effective presentation of the
books of their era is not a part of
the WYSIWYG world, and this is all
too apparent in the poor typographical quality of many of the technical books published today. This was
certainly the case in the late 1970s
when this all-too-bleak typographical future became apparent to Donald Knuth, a Stanford computer scientist
1
2
203
who was in the process of writing his seven volume epic The Art of Computing. He tried to have one of the early volumes computer typeset and the
effort was, in his view, a dismal failure. Fortunately for the rest of us, rather
than just admitting defeat, as one of the worlds pre-eminent computer scientists he was in a position to actually do something about the problem.
Over about a ten year period, he read old books on typography, and even
interviewed some of the old typographers. He found that they had lots of
clever tricks, like kerning, ligatures, and adjustable interword spacing. Then
he coded all of this knowledge into a computer typesetting program that he
called TEX (pronounced tek). Finally, he gave the program away! This
last act makes it possible for anyone to download and freely use what is still
today the finest computer typesetting program available. In particular, the
TEX system is installed on the Mac Lab machines in HHB221 (look for the
LATEX icon in the MacBook Dock).
A useful reference for the version that we will use is LATEX: A Document
Preparation System (2nd Edition) by L. Lamport, Addison-Wesley, 1994; you
can obtain used copies easily on Amazon. These very notes you are reading,
by the way, are written in LATEX on my Mac.
A.1
Getting Started
The TEX program is in fact a compiler. It converts files with a .tex extension to
corresponding files with a .pdf extension that contain the formatting information needed
to preview the final printed page on the screen, or to print.
204
in the Mac Dock. The TexShop editor window (which is basically a frontend to the TEX system) is TEX literate in that it recognizes and highlights
many of the TEX commands. Type the following into a file that you should
save as texample.tex in your USB directory:
% Simple source file texample.tex
% All source files must end in .tex
% Anything on a line after a % symbol is ignored by TeX
\documentclass{article}
\begin{document}
This is a somewhat minimal \TeX\ source file.
It contains this blurb
as well
as the finest formula known
to
the mathematical world.
The great mathematician Leonhard Euler (pronounced
Oiler) discovered the formula $$ e^{i\pi } + 1 = 0 $$
that connects
five of the most interesting quantities
in mathematics, $e$, $\pi$,
$i=\sqrt{-1}$, $1$, and $0$.
Rumour has it that he had this formula inscribed on his
tombstone!
\end{document}
On a Mac running TexShop, to save the file and call up the TEX compiler
(and send a preview version to the screen), just click the Typeset button at
205
the top left of the TexShop editor screen. The output should look something
like the following:
This is a somewhat minimal TEX source file. It contains this blurb as well
as the finest formula known to the mathematical world.
The great mathematician Leonhard Euler (pronounced Oiler) discovered
the formula
ei + 1 = 0
thatconnects five of the most interesting quantities in mathematics, e, ,
i = 1, 1, and 0. Rumour has it that he had this formula inscribed on his
tombstone!
206
that indicate to TEX the beginning and the end of your document contents.
Now to the actual contents of the document. The first paragraph is
typeset in 12 point computer modern font as specified in the article style
file. One can change much of this via options to the \documentclass{}
statement. A blank line in the source indicates a new paragraph. Notice that
TEX ignores most of the actual layout of the characters in this paragraphit
is only interested in the words themselves. The formatting command \TeX
produces the name TEX itself; notice that this is followed by a blank space
here which is accomplished via \ i.e. a backslash followed by a blank
character. In the second paragraph we first note Oiler in which to form a
correct pair of double quotation marks, we use two left quotes at the front
and two right quotes at the end.
Further on we have our first mathematical formula. The typographic rules
for mathematical material is a world unto itself and the rules of TEX reflect
this. By enclosing the formula between a pair of double dollar signs, we are
telling TEX that this is not only a mathematical formula, but a displayed
mathematical formula. As such, it must appear centered on a line by itself
with a certain amount of white space above and below. We do not need
to concern ourselves with the details, as TEX will take care of all of this for
us. By enclosing a formula with a pair of single dollar signs, one would be
instructing TEX to treat this as
an inline formula and typeset it as inline
mathematics. The formula i = 1 is one such example.
Finally the formula itself involves the TEX command \pi which is the
Greek letter . The exponent is written in the form
e^{i\pi}
where the hat symbol represents exponentiation with the exponent enclosed in the curly braces. It is important to note that in TEX curly braces
are used as scope delimiters and are only typeset by the TEX compiler
when directly ordered.