+ All Categories
Home > Documents > PDE Modeling Notes

PDE Modeling Notes

Date post: 24-Sep-2015
Category:
Upload: brendan-farris-turner
View: 114 times
Download: 44 times
Share this document with a friend
Description:
Notes for Modeling with Partial Differential Equations
214
Class Notes MA461/561 Spring 2015 PDE Modeling Ian Knowles Department of Mathematics University of Alabama at Birmingham Birmingham AL 35294 December 28, 2014
Transcript
  • Class NotesMA461/561 Spring 2015

    PDE Modeling

    Ian KnowlesDepartment of Mathematics

    University of Alabama at BirminghamBirmingham AL 35294

    December 28, 2014

  • ii

    c December 28, 2014 Ian W. Knowles

  • Contents

    Preface vii

    1 Mathematical Models 1

    1.1 What is a Mathematical Model? . . . . . . . . . . . . . . . . . 1

    1.2 SI Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    1.3 Some PDE Models . . . . . . . . . . . . . . . . . . . . . . . . 4

    1.3.1 Heat Flow . . . . . . . . . . . . . . . . . . . . . . . . . 4

    1.3.2 Steady State Temperature Distributions . . . . . . . . 10

    1.3.3 Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    1.3.4 Groundwater Flow . . . . . . . . . . . . . . . . . . . . 13

    1.3.5 Guitar/Violin Strings: Waves . . . . . . . . . . . . . . 16

    1.3.6 Spectral Theory . . . . . . . . . . . . . . . . . . . . . . 19

    1.3.7 Vibrating Membranes: The 2-D Wave Equation . . . . 23

    2 Partial Differential Equations 31

    2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    2.2 Finite Difference Methods . . . . . . . . . . . . . . . . . . . . 35

    2.2.1 Elliptic Equations . . . . . . . . . . . . . . . . . . . . . 39

    2.2.2 Parabolic Equations . . . . . . . . . . . . . . . . . . . 45

    2.2.3 Hyperbolic Equations . . . . . . . . . . . . . . . . . . . 48

    2.3 Finite Element Methods . . . . . . . . . . . . . . . . . . . . . 48

    2.3.1 Gauss Divergence Theorem in 2D . . . . . . . . . . . . 50

    2.3.2 Gauss Divergence Theorem in 3D . . . . . . . . . . . . 52

    2.3.3 Elliptic Equations and the FEM . . . . . . . . . . . . . 53

    2.3.4 Parabolic Equations and the FEM . . . . . . . . . . . 56

    2.3.5 Hyperbolic Equations and the FEM . . . . . . . . . . . 57

    iii

  • iv CONTENTS

    3 MATLAB and COMSOL 59

    3.1 MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    3.1.1 Keeping a Session Record . . . . . . . . . . . . . . . . 60

    3.1.2 Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . 61

    3.1.3 MATLAB as a Calculator . . . . . . . . . . . . . . . . 61

    3.1.4 Standard Functions . . . . . . . . . . . . . . . . . . . . 61

    3.1.5 Vectors in MATLAB . . . . . . . . . . . . . . . . . . . 61

    3.1.6 Products, Division and Powers of Vectors . . . . . . . . 63

    3.1.7 Plotting Elementary Functions . . . . . . . . . . . . . . 64

    3.1.8 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    3.1.9 Special Matrices . . . . . . . . . . . . . . . . . . . . . . 66

    3.1.10 Solving Systems of Linear Equations . . . . . . . . . . 67

    3.1.11 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    3.1.12 m-files . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

    3.1.13 m-functions . . . . . . . . . . . . . . . . . . . . . . . . 68

    3.1.14 Reading and Writing Data Files . . . . . . . . . . . . . 69

    3.2 MATLAB PDE Toolbox . . . . . . . . . . . . . . . . . . . . . 71

    3.3 COMSOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

    4 Continuum Mechanics 77

    4.1 Equations of Motion . . . . . . . . . . . . . . . . . . . . . . . 78

    4.2 Linear Elasticity . . . . . . . . . . . . . . . . . . . . . . . . . 81

    4.2.1 The Displacement Field . . . . . . . . . . . . . . . . . 82

    4.2.2 The Strain Tensor . . . . . . . . . . . . . . . . . . . . . 84

    4.2.3 Principal Strains . . . . . . . . . . . . . . . . . . . . . 86

    4.2.4 Plane Strain . . . . . . . . . . . . . . . . . . . . . . . . 87

    4.2.5 Stress-Strain Relations . . . . . . . . . . . . . . . . . . 87

    4.2.6 The Elasticity Equations . . . . . . . . . . . . . . . . . 93

    4.3 Fluid Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . 96

    4.3.1 The Stress-Strain Relation . . . . . . . . . . . . . . . . 97

    4.3.2 Application to Hull Design . . . . . . . . . . . . . . . . 99

    4.3.3 The Navier-Stokes Equations . . . . . . . . . . . . . . 101

    4.3.4 Incompressible Fluids . . . . . . . . . . . . . . . . . . . 104

    4.3.5 Compressible Fluids . . . . . . . . . . . . . . . . . . . 111

    4.3.6 The Reynolds Number and Boundary Layers . . . . . . 113

  • CONTENTS v

    5 Classical Electrodynamics 1155.1 Electrostatics . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

    5.1.1 The Electric Field E . . . . . . . . . . . . . . . . . . . 1175.1.2 The Gauss Law . . . . . . . . . . . . . . . . . . . . . . 1195.1.3 Macroscopic Media . . . . . . . . . . . . . . . . . . . . 1215.1.4 Electric Current . . . . . . . . . . . . . . . . . . . . . . 123

    5.2 Magnetostatics and Faradays Law . . . . . . . . . . . . . . . 1235.2.1 The Biot-Savart-Ampe`re Laws . . . . . . . . . . . . . . 1245.2.2 Macroscopic Magnetostatics . . . . . . . . . . . . . . . 1295.2.3 Stokes Theorem . . . . . . . . . . . . . . . . . . . . . . 1305.2.4 Faraday Law of Induction . . . . . . . . . . . . . . . . 130

    5.3 The Maxwell Equations . . . . . . . . . . . . . . . . . . . . . 1325.3.1 Vector and Scalar Potentials . . . . . . . . . . . . . . . 134

    6 Finance 1376.1 Random Variables . . . . . . . . . . . . . . . . . . . . . . . . . 137

    6.1.1 Normal Distribution . . . . . . . . . . . . . . . . . . . 1406.2 Brownian Motion and Diffusion . . . . . . . . . . . . . . . . . 141

    6.2.1 A Special Diffusion Property . . . . . . . . . . . . . . . 1446.3 Stochastic Processes . . . . . . . . . . . . . . . . . . . . . . . 1456.4 The Ito Integral . . . . . . . . . . . . . . . . . . . . . . . . . . 146

    6.4.1 Properties of the Ito Integral . . . . . . . . . . . . . . . 1496.4.2 The Ito Formula . . . . . . . . . . . . . . . . . . . . . 150

    6.5 Asset Prices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1516.5.1 The Asset Price Model . . . . . . . . . . . . . . . . . . 153

    6.6 Options and the Black-Scholes PDE . . . . . . . . . . . . . . . 1546.6.1 The European Call Option . . . . . . . . . . . . . . . . 1546.6.2 The Black-Scholes PDE . . . . . . . . . . . . . . . . . 1556.6.3 The Greeks . . . . . . . . . . . . . . . . . . . . . . . . 1616.6.4 Implied Volatility . . . . . . . . . . . . . . . . . . . . . 162

    6.7 Local Volatility and the Dupire PDE . . . . . . . . . . . . . . 1646.8 Bonds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

    6.8.1 Calculating v with r Known . . . . . . . . . . . . . . . 1676.8.2 Bond Futures . . . . . . . . . . . . . . . . . . . . . . . 1696.8.3 Stochastic Interest Rates . . . . . . . . . . . . . . . . . 1706.8.4 The Bond Pricing Equation . . . . . . . . . . . . . . . 1706.8.5 Bond Options . . . . . . . . . . . . . . . . . . . . . . . 171

  • vi CONTENTS

    7 Modeling Projects 1737.1 The Planting Box . . . . . . . . . . . . . . . . . . . . . . . . . 1737.2 The Mridangam . . . . . . . . . . . . . . . . . . . . . . . . . . 1757.3 The Nutwrecker2000 . . . . . . . . . . . . . . . . . . . . . . . 1767.4 The Frozen CIDS Problem . . . . . . . . . . . . . . . . . . . . 1787.5 Cooling a Computer Chip . . . . . . . . . . . . . . . . . . . . 1837.6 Groundwater Modelling . . . . . . . . . . . . . . . . . . . . . 1857.7 The Fuel Spill . . . . . . . . . . . . . . . . . . . . . . . . . . . 1877.8 The Soap Bubble Problem . . . . . . . . . . . . . . . . . . . . 1877.9 Blood Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1897.10 The Skin Effect in a Circular Wire . . . . . . . . . . . . . . . 1927.11 Hurricanes and Soap Bubbles . . . . . . . . . . . . . . . . . . 1957.12 A Rectangular Waveguide . . . . . . . . . . . . . . . . . . . . 197

    A Typesetting with TEX 201A.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . 203

  • Preface

    This course is intended to provide an introduction to the mathematical andcomputational skills required to build computer models of practical impor-tance. MA227 (Calculus III) is a prerequisite; the courses MA360/560 (Sci-entific Programming) and MA455/555 (Partial Differential Equations) areencouraged but not required.

    While mathematical models of many different types are worthy of con-sideration (discrete, ordinary differential equation models from MA252, andstatistical models as considered in MA486/586, come immediately to mind),we concentrate here exclusively on those involving a partial differential equa-tion (PDE). In particular, we consider a variety of practical examples inwhich we follow the trail of

    problem formulation, including statement of relevant physical laws anddiscussion 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: parabolicequations like the heat equation, the diffusion equation, and the groundwaterflow equation; elliptic equations as exemplified by the steady state heat prob-lem with sources, and hyperbolic equations in the form of the classical waveequation and the acoustic wave equation. These equations are solved usingthe finite element routines in the MATLAB PDE Toolbox and COMSOL.

    In chapter 2 we discuss the various classifications of partial differen-tial equations and look at the finite difference solution method for ellipticequations and, briefly, the finite element solution method that is used by

    vii

  • viii PREFACE

    both MATLAB and COMSOL. The method of finite differences is covered ingreater detail in the course MA465/565 Numerical PDE: Finite DifferenceMethods. Chapter 3 provides an introduction to software packages MATLAB(including the PDE Toolbox) and COMSOL.

    In chapter 4 we provide a introduction to the theory of continuum me-chanics, which includes parts of the theory of linear elastic solids as wellas a brief sortie into fluid mechanics to derive the Euler and Navier-Stokesequations that are central to the modelling of fluid flow; the latter topic iscovered more fully in the course MA467/567 Gas Dynamics. In chapter 5 weconsider the Maxwell equations and electromagnetic waves and in chapter 6we look at the mathematics behind financial derivatives.

    Finally, in chapter 7 are given outlines of possible class projects.

  • Chapter 1

    Mathematical Models

    1.1 What is a Mathematical Model?

    The tenets of the Scientific Method, as espoused by Galileo for example,hold that one should formulate scientific theories and then test them with

    Galileo Galilei 1564-1642

    measurement based experiments. A funda-mental underpinning to all of this is therecognition that natural phenomena can berepresented by mathematical equations. Aprime, and simple, example of such an equa-tion is Galileos formula

    s =1

    2gt2

    governing the distance s travelled by afalling body in time t. This is also a niceexample of a mathematical model. In com-mon with most mathematical models of nat-ural phenomena, it comes with underlyingassumptions: here for example, the effectsof air resistance are taken to be negligible.

    On an even more fundamental level, Isaac Newton discovered that naturalphysical laws, such as his second law of motion for a particle

    F = ma,

    1

  • 2 CHAPTER 1. MATHEMATICAL MODELS

    lead to differential equations:

    mx(t) = F.

    By solving these differential equations Newton was able, amongst otherthings, to precisely model the solar system, confirming and providing a math-ematical underpinning for earlier theories of Nicolaus Copernicus and Jo-hannes Kepler that rested upon astronomical data gathered by Tycho Brahe.

    Since that time differential equations have become omnipresent in theworld of mathematical modeling. Such models are of central importance in,for example,

    predicting future events (hurricane/typhoon impact zones, such as thatof Katrina in 2005 and Haiyan in 2013 and other weather related trau-mas, asteroid collisions, and tsunamis, such as the one that destroyedNatori City in Japan in 2011, earthquakes);

    design (very big airplanes, very fast yachts, for example the New ZealandAC72 class catamaran which is the favorite for the 2013 Americas Cuptrials in San Francisco);

    testing theories (high energy physics, epidemiology).

  • 1.2. SI UNITS 3

    In the pages below we gather and discuss in detail some of the classical ex-amples of mathematical models that appear in the form of partial differentialequations or PDEs. But first, a short digression is needed to discuss systemsof units.

    1.2 SI Units

    SI units (otherwise known as Syste`me Internationale dunites) are now theinternationally accepted system of units for the measurement of physicalquantities. In this system the unit of length is the meter (m), the unit ofmass is the kilogram (kg), the unit of time is the second (s), the unit ofelectric current is the ampere (A), thermodynamic temperature is measuredin kelvins (K), the unit of amount of material is the mole (mol), and the unitof luminous intensity is the candela (cd).

    From these seven base units many derived units appear:

    Frequency: hertz, Hz=s1; Force: newton, N=m kg s2; Pressure: pascal, Pa=N/m2=kg m1 s2; Energy, work, quantity of heat: joule, J=N m; Power: watt, W=J/s=m2kg s3, 1 horsepower 750 watts; Quantity of electricity, electric charge: coulomb, C=s A; Capacitance: farad, F=s4A2m2kg1; Electric potential: volt, V=W/A; Electric resistance: ohm, =V/A; Electrical conductivity: siemens, S=A/V=kg1m2s3A2. Magnetic flux: weber, Wb=V s; Magnetic flux density: tesla, T=Wb m2; Inductance: henry, H=Wb/A.

    We use this system exclusively throughout these notes.

  • 4 CHAPTER 1. MATHEMATICAL MODELS

    1.3 Some PDE Models

    1.3.1 Heat Flow

    Consider the following problem. A thin metal plate, initially at 0 C (273.15K) everywhere, is heated with a Bunsen burner at the point (a, b) while theedge of the plate is kept at 0 C in an ice bath. Our task is to determine the

    Figure 1.1: Heating a thin metal plate

    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 partic-ular body. The reason for this is that we are interested in the temperatureu, but heat energy is the quantity that actually flows around the plate. Therequired 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 thematerial (J kg1K1), m is the mass of the body (kg), and T is the tem-perature change (K). Here, the specific heat of a body is the amount of heatenergy 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

  • 1.3. SOME PDE MODELS 5

    required to cause a given temperature change. A table of specific heat valuesfor some common materials is given below:

    Material Specific Heat (J kg1K1)water at 25 C 4181steel 466glass 840copper 385cucumber 4060

    So, you can see that NASA made a big mistake in not making the SpaceShuttle heat shield out of cucumber!

    Figure 1.2: Joseph Fourier

    Next, we need the physical law that describes the movement of heat in abody. This may be stated as the Fourier1

    Heat Flux Law:

    The heat flux is proportional to the temperature gradient.

    Here, if we restrict attention for the moment to heat flowing in the x-direction, the heat flux2, Fx, is the amount of heat moving through unit

    1Joseph Fourier 1768-1830, French mathematician and physicist; he came up with theidea of expanding arbitrary functions in a series of sines and cosines, today known as aFourier series in his honor

    2from the Latin word fluxus meaning flow

  • 6 CHAPTER 1. MATHEMATICAL MODELS

    area of a plane perpendicular to the x-axis in unit time; the SI units areJ m2s1. If u is the temperature then the temperature gradient in the xdirection is u/x. So the above law may be written

    Fx = xux

    (1.2)

    where the positive constant of proportionality x is called the thermal con-ductivity of the body; its SI units are J m1K1s1. The minus sign indicatesthat the heat energy moves oppositely to the temperature gradient, i.e. heatmoves from hot areas to cold areas. This law has been obtained experimen-tally, and is valid often, but not always. Some typical thermal conductivitiesappear in the table below:

    Material Thermal Conductivity (W m1K1)water at 20 C 0.56steel 50.2copper 401glass 0.8air 0.024wood 0.04-0.12

    The Heat Equation

    To derive the PDE satisfied by the temperature function u we consider asmall box surrounding a point P (x, y, z) as shown in Figure 1.3. Given thatABCD and ABCD are the faces perpendicular to the x-axis, the rate atwhich heat enters through the face ABCD is

    4dy dz (Fx Fxx

    dx),

    where Fx/x.dx is the change in Fx back to the face ABCD, and the rateat which heat exits through the face ABCD is

    4dy dz (Fx +Fxx

    dx),

    So, the net rate at which heat enters the box through these two faces is

    8dx dy dzFxx

    .

  • 1.3. SOME PDE MODELS 7

    Figure 1.3: Local heat flow in a box

    In similar fashion the net rate at which heat enters the box through the facesperpendicular to the y- and z-axes are, respectively,

    8dx dy dzFyy

    and 8dx dy dzFzz

    .

    In addition, heat can enter the box by way of internal sources, such as theBunsen burner in our case. For the moment we let all such internal sourcesbe represented by the function S(x, y, t) with units of J m3s1 (heat sourceper unit volume per unit time). So the total rate at which the heat energyincreases in the box is

    8dxdydz (Fxx

    +Fyy

    +Fzz

    ) + 8dxdydz S(x, y, z, t). (1.3)

    Let (x, y, z) denote the density (mass per unit volume) of the material (themetal in our case). From (1.1) the rate at which the amount of heat energyincreases in the box is

    Q

    t= c.m.

    u

    twhere m is the mass of material in the box; as m = 8 dxdydz the rate atwhich heat increases in the box is

    8c dxdydzu

    t,

  • 8 CHAPTER 1. MATHEMATICAL MODELS

    which we can equate to (1.3), and then divide by 8dxdydz to obtain

    cu

    t+ (

    Fxx

    +Fyy

    +Fzz

    ) = S(x, y, z, t).

    Finally, if we use (1.2) and assume the isotropic3 case in which we havex = y = z = (which may still be a function of x, y, z) we obtain theheat equation:

    cu

    t (

    x(u

    x) +

    y(u

    y) +

    z(u

    z)) = S(x, y, z, t) (1.4)

    This is the equation you would use for three-dimensional heat flow. It is ofparabolic type (see Chapter 2). In our case we can reasonably assume that fora 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. Thisleads us to the two-dimensional heat equation for our metal plate:

    cu

    t (

    x(u

    x) +

    y(u

    y)) = S(x, y, t). (1.5)

    One could represent the effect of the Bunsen burner with the source function

    S(x, y, t) =

    {1 (x, y) in B0 (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

    u

    t ku = S(x, y, t)

    c(1.6)

    where k = /c is called the thermal diffusivity with units of m2s1, and

    u =2u

    x2+2u

    y2

    is the two-dimensional Laplace operator.

    3i.e. material properties are independent of direction

  • 1.3. SOME PDE MODELS 9

    Initial and Boundary Conditions

    The parabolic equations above do not by themselves uniquely specify a so-lution, as we now make clear from our physical example. More precisely, inthe metal plate problem described above, we are assuming that

    u(x, y, t) = 0

    for all points (x, y) on the boundary of the metal plate for all time t. Thisis called a boundary condition. It seems reasonable that if the values on theboundary were different, we would end up with a different solution u.

    In general, a condition of the form

    u(x, y, t) = g(x, y) (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

    Figure 1.4: Dirichlet and Neumann

    a unit length column vector outwardly normal (perpendicular) to the bound-

    4German mathematician Gustav Lejeune Dirichlet 1805-18595German mathematician Carl Neumann 1832-1925

  • 10 CHAPTER 1. MATHEMATICAL MODELS

    ary, and

    u =

    u

    xu

    y

    is the gradient of u, and the outward normal derivative (this is just thedirectional derivative from Calculus III) is

    u

    n= u n = n1u

    x+ n2

    u

    y;

    from (1.2) u n represents the outward heat flux in a direction normalto 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 proportionalto the difference between the fixed temperature, Te, of the exterior and thecurrent temperature, u, of the heated body; h is called a heat transmissioncoefficient.

    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 amathematical fact that the two additional conditions (1.7) and (1.8) areenough to guarantee unique solutions for these parabolic equations.

    1.3.2 Steady State Temperature Distributions

    If the heat source function S and the boundary conditions do not dependon time, i.e. S = S(x, y) in 2-D, then it is reasonable to expect that, aftera sufficiently long time, the temperature at each point (x, y) in our plateshould settle down to some steady value. Mathematically, we expect that

    limt

    u(x, y, t) = U(x, y)

    where the function U represents the so-called steady state temperature dis-tribution. We can obtain the partial differential equation representing the

  • 1.3. SOME PDE MODELS 11

    steady state distribution U by allowing t to approach infinity in (1.5), andassuming that

    limt

    u

    t= 0.

    This gives

    x

    (U

    x)

    y(U

    y) = S(x, y), (1.9)

    an example of an elliptic equation (see Chapter 2). Such equations also occurin gravitational potential theory, and in electrostatics and magnetostatics, toname but a few application areas.

    Unique solutions are ensured by applying either Dirichlet or Neumannboundary conditions in the manner discussed above for parabolic equations.Notice that as time has in effect disappeared here, initial conditions are nolonger needed.

    1.3.3 Diffusion

    Diffusion is the process by which matter is transported from one part of asystem to another as a result of random molecular motions. It is an important

    Figure 1.5: Adolf Fick

    and fundamental physical effect. In groundwatermodeling, for example, one is often interested inquantifying the movement of contaminants, and itis generally assumed that such movement is drivenin part6 by molecular diffusion of the contaminantspecies.

    Molecular diffusion can be illustrated by theclassical experiment in which a tall cylindrical glassvessel has its lower part filled with an iodine so-lution, and a column of clear water is poured ontop, carefully and slowly, so that no convection cur-rents are started. At first the lower colored part isseparated from the upper clear portion by a sharp,well-defined boundary. Later it is found that the up-per part becomes colored, the color getting faintertowards the top, while the lower part becomes cor-

    6the other mechanism is that of advective dispersion

  • 12 CHAPTER 1. MATHEMATICAL MODELS

    respondingly less intensely colored. After a sufficiently long time the iodinemolecules move so as to become uniformly distributed throughout the vessel.

    The transfer of heat by conduction is also due to random molecular mo-tions and there is an obvious analogy between the two processes, as wasrecognized by Fick7 who, around 1855, adapted the ideas Fourier used inderiving the equation of heat conduction given above. The relevant physicallaw 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 throughunit area of a plane perpendicular to the x-axis in unit time; the SI units aremol m2s1. If C is the concentration then the concentration gradient in thex direction is C/x. So the above law may be written

    Fx = DxCx

    (1.10)

    where the positive constant of proportionality Dx is called the diffusion co-efficient of the diffusive material; its SI units are m2s1. The minus signindicates that the diffusive material moves oppositely to the concentrationgradient. This law has been obtained experimentally, and is valid often, butnot always. Some diffusion coefficients appear in the table below:

    Material Diffusion Coefficient in Water (m2s1)Iodine I2 (20

    C) 1.0 109Oxygen O2 1.97 109Benzene 1.10 109Ethylene Dichloride 9.90 1010

    Using an analogous, but simpler (no temperature here) argument to thatused in the heat flow problem, we can see that the partial differential equationfor diffusion in 2-D is

    C

    t=

    x(D

    C

    x) +

    y(D

    C

    y) (1.11)

    7Adolf Eugen Fick 1829-1901, a German-born physician and physiologist

  • 1.3. SOME PDE MODELS 13

    where D = D(x, y) is the diffusion coefficient. In 3-D the equation is

    C

    t=

    x(D

    C

    x) +

    y(D

    C

    y) +

    z(D

    C

    z) (1.12)

    with D = D(x, y, z).In vector notation both of these equations may be written as

    C

    t= (DC). (1.13)

    1.3.4 Groundwater Flow

    Much of the potable8 water on the planet lies underground in large and smallgeologic formations called aquifers. A common situation of interest occurswhen the groundwater is trapped in a porous medium between two (moreor less) horizontal impervious layers; such a groundwater system is calleda two-dimensional confined aquifer, as is illustrated in Figure 1.6 below.

    Figure 1.6: Confined 2-D Aquifer

    Sources of water for an aquifer include rainfall, and subsequent seepage underthe influence of gravity, and underground streams. These sources cause the

    8this basically means drinkable

  • 14 CHAPTER 1. MATHEMATICAL MODELS

    Figure 1.7: Confined 2-D Aquifer Flow

    water to move through the aquifer under pressure. In a well penetrating theaquifer, the water level will rise to a height in the well, called the piezometrichead, that depends on the pressure of the groundwater in the aquifer at thatpoint. Analogous to heat flow and diffusion we have

    The Experimental Law of Darcy

    The discharge per unit width of aquifer is proportional to thehydraulic gradient.

    Here the discharge in say the x-direction, qx, is the volume of water per unittime crossing unit area of the aquifer normal to the x-direction. If we denotethe piezometric head by , then Darcys Law becomes

    qx = Txx

    (1.14)

    where the constant of proportionality, Tx, is called the transmissivity; itrepresents the ease with which the water passes through the aquifer region.

    Storativity

    As the pressure increases in an aquifer, the porous medium tends to expandsomewhat and absorb additional water; conversely, as the pressure decreases,

  • 1.3. SOME PDE MODELS 15

    water is expelled from the porous medium matrix. This absorptive/elasticproperty of the aquifer material is called the storativity which is defined moreprecisely to be the volume of water released from (or added to) storage inthe aquifer per unit horizontal area of the aquifer per unit change in the(vertically averaged) piezometric head. Thus, if a volume of water w isreleased from (or added to) storage in an area A due to a change inthe head, the storativity S is

    S =w

    A. (1.15)

    The Groundwater Flow Equation

    Consider the box in (b) of Figure 1.6. As we are assuming that the aquiferis 2-D, we only study flow in the horizontal xy-plane. In a time dt the netvolume of water entering the box is

    dt{b dy[qx(x dx2, y) qx(x+ dx

    2, y)] +

    b dx[qy(x, y dy2

    ) qy(x, y + dy2

    )]}+ F (x, y, t).b.dxdydt= bS dx dy [(x, y, t+ dt) (x, y, t)],

    where b is the aquifer thickness and F (x, y, t) (with units of volume per unittime) represents external recharge (averaged over z) into the system fromvarious 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, weobtain

    b.F b. x

    (qx) b. y

    (qy) = bS

    t,

    so that from (1.14)

    S

    t=

    x(Tx

    x) +

    y(Ty

    y) + F. (1.16)

    A common assumption (often unjustified, but made anyway) is that the wateralways flows in the direction of the pressure gradient; the porous mediumis then called isotropic and Tx = Ty = T (x, y), so that the flow equationbecomes

    S

    t=

    x(T

    x) +

    y(T

    y) + F. (1.17)

  • 16 CHAPTER 1. MATHEMATICAL MODELS

    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

    T =

    (T11 T12T12 T22

    ).

    is the transmissivity matrix. The groundwater flow equation then takes theform

    S

    t= (T) + F.

    1.3.5 Guitar/Violin Strings: Waves

    When a guitar or violin string is plucked the subsequent rather complicatedoscillatory motion of the string is typically restricted to a single plane con-taining the fixed string end-points. It is an example of a one dimensionalwave motion.

    Figure 1.8: The Stones: Wyman, Jones, Watts, Jagger, Richards circa 1963

    Assume that a string at rest is fastened at the points x = 0 and x = Lon the x-axis as shown in Figure 1.9 and then undergoes movement in the

  • 1.3. SOME PDE MODELS 17

    y direction in an xy-plane so that the displacement of the part of the stringlocated at (x, 0) when the string is at rest, is given by y = u(x, t) at asubsequent time t. Our task here is to determine the partial differential

    Figure 1.9: Vibrating string

    equation satisfied by the function u.

    A number of additional assumptions are to be observed. First, we neglectthe damping effects of air resistance and the weight of the string. We alsoassume that the string is so flexible that it takes no effort to bend it; so thetension forces in the string always act tangentially. Finally we assume thatthe motion of the string always involves only small displacements and thatthe linear density (mass per unit length) is (x).

    Consider now a small part of the string, that between x and x + dx attime t, as shown in the right hand part of Figure 1.9. At the x end of thestring segment, i.e. the point (x, u(x, t)), there is a tension TR(x, t) pullingto the right that is balanced9 by the tension force TL(x, t) pulling to the left;the tension shown is really TL(x, t). Similarly the tension force shown atthe other end, i.e. at the point (x+ dx, u(x+ dx, t)), is really TR(x+ dx, t).Let T (x, t) = |T(x, t)|. Then the magnitude of the vertical component ofTL(x, t) is v(x, t) = T (x, t) sin and the magnitude of the vertical component

    9assuming that the string does not break!

  • 18 CHAPTER 1. MATHEMATICAL MODELS

    of TR(x + dx, t) is v(x + dx, t) = T (x + dx, t) sin( + d). The net verticalforce on the string segment is

    v(x+ dx, t) v(x, t).If we assume that the length of the segment is dx (here the small displace-ment assumption enters) then the mass of the segment is .dx. By Newtonssecond law, the net vertical force on the segment equals the mass times theacceleration of the center of mass of the segment. Thus

    v(x+ dx, t) v(x, t) = dx 2u

    t2(x, t)

    where x x x+ dx. Thenv(x+ dx, t) v(x, t)

    dx=

    2u

    t2(x, t).

    If we let dx 0 we arrive atv

    x=

    2u

    t2(x, t). (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 mo-tion of the segment, it follows that h(x, t) = h(x + dx, t), and thus h isindependent of x. In fact, as we are assuming only small string displace-ments, cos 1 and h(x, t) T (x, t), where, again because of the smalldisplacements, the tension in the string T (x, t) T , a constant. So to areasonable approximation we have

    v(x, t) = h(x, t) tan = Tu

    x.

    Thus from (1.19) we have the 1-D wave equation:

    2u

    t2= a2

    2u

    x2(1.20)

    where a2 = T/. This is an example of a hyperbolic PDE (see MA455/555).If we allow for an external force of magnitude F units per unit length

    acting parallel to the y-axis then a similar derivation leads to the equation

    2u

    t2= a2

    2u

    x2+F

  • 1.3. SOME PDE MODELS 19

    Initial and Boundary Conditions

    The boundary conditions to be applied at the boundary of the space regionare as discussed in the section on the parabolic heat equation. Becausethe equation has two time derivatives, two initial conditions are required touniquely determine the solution u(x, t). On physical grounds, one needs toknow the initial shape of the string:

    u(x, 0) = f(x) 0 x L;

    one also needs the initial velocity of the string:

    ut(x, 0) = g(x) 0 x L.

    It is a mathematical fact that these two conditions, together with the waveequation and suitable boundary conditions uniquely determine the solutionu.

    1.3.6 Spectral Theory

    Matrices and Eigenvalues

    Let A be an nn matrix and consider solving, for a given scalar , the linearsystem

    Ax = x,

  • 20 CHAPTER 1. MATHEMATICAL MODELS

    with the aim of finding a solution vector x that is not the zero vector. Onelearns in Linear Algebra that the values for which this can be done arequite exceptional. There are at most n such and we call them eigenvaluesof A; the corresponding solutions x are the associated eigenvectors. If wewrite the linear system as

    (A I)x = 0,

    where I denotes the nn identity matrix, from a theorem in Linear Algebra,if the determinant |A I| 6= 0 we know that the (unique) solution x mustbe the zero vector; so

    |A I| = 0is an equation for the eigenvalues of A. One can see that this is a polynomialequation in of degree n, and so it follows from the Gauss theorem that amatrix of order n has n eigenvalues, counted according to multiplicity, sorepeated roots are counted separately.

    If we regard the matrix A as a linear operator on Rn that takes the vectorx to the vector Ax, then the set of eigenvalues is called the spectrum of thislinear operator. The word spectrum comes originally from physical opticswherein visible light was separated into a color spectrum by a prism (or, inthe case of the rainbow above, by small droplets of water). We connect theseideas below.

    Eigenvalues and Vibration Modes

    Consider a guitar string stretched between x = 0 and x = 1. As we sawearlier, if the string is plucked and we denote the displacement at time t ofthe 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)2U(x) = 2U(x) = U(x), (1.21)

  • 1.3. SOME PDE MODELS 21

    if we set = 2. As we assume the ends of our guitar string are permanentlyfixed, we can also assume that U(0) = U(1) = 0. It follows from (1.21) that

    U(x) = A cos(x) +B sin(x),

    for some constants A and B. Inserting the condition U(0) = 0 forces A = 0;from U(1) = 0 we then see that B sin() = 0, so, in order to obtain non-trivial solutions (B 6= 0) we must have = npi, i.e.

    = n2pi2, n = 0, 1, 2, . . .

    These are the eigenvalues (in this case, of the differential operator A thattakes a function U to minus its second derivative) and for each n the corre-sponding eigenfunction is

    Un(x) = sin(npix).

    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 pluckingthe string exactly at its midpoint. If you touch (i.e. dampen) a moving stringexactly 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, youwill see the third eigenfunction in the resulting vibration.

    Figure 1.10: The first three eigenfunctions

    (a) n = 1 (b) n = 2 (c) n = 3

    Solving the Wave Equation

    The eigenfunctions found above can be used to predict the future motion ofthe guitar string, given an initial shape and velocity. One accomplishes this

  • 22 CHAPTER 1. MATHEMATICAL MODELS

    by solving the above wave equation with initial conditions

    u(x, 0) = f(x),

    ut(x, 0) = g(x).

    We look for the solution u(x, t) in the form

    u(x, t) =n=1

    CnUn(x)einpit =

    n=1

    Cn sin(npix)einpit.

    Notice that we automatically satisfy the boundary conditions

    u(0, t) = u(1, t) = 0

    for all time. The complex numbers Cn can be found using a Fourier se-ries technique (see MA455/555). As the eventual motion of the string iscompletely determined by the eigenfunctions Un we naturally call these thefundamental vibration modes. The eigenvalues n = n

    2pi2 are related tofrequencies as follows. The angular frequency n = npi is related to theperiod n of the sine function by

    n =2pi

    n=

    2pi

    npi=

    2

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

    These frequencies correspond to pure notes.

    The Color Spectrum

    In the same way, a prism breaks natural light into its constituent pure colors.Light is basically an energy wave motion. Each fundamental color representsa simple wave motion with a fixed frequency.

  • 1.3. SOME PDE MODELS 23

    1.3.7 Vibrating Membranes: The 2-D Wave Equation

    In similar fashion, if one considers the vibrations of a drum, or more generally,any vibrating elastic membrane, we end up with the wave equation on a 2-Dregion :

    2u

    t2= a2(

    2u

    x2+2u

    y2) = a2u, (1.22)

    where a2 = T/ and now is the mass per unit area of the drum membraneand T is again the constant magnitude of tension. The initial and boundaryconditions for the 2-D wave equation are specified in an analogous mannerto the above in that Dirichlet or Neumann conditions are applied at theboundary of the membrane region, and the initial shape and velocity mustalso be specified:

    u(x, y, t0) = u0(x, y), ut(x, y, 0) = v0(x, y), (x, y) in .

    A Wave Animation

    We use the MATLAB PDE Toolbox to produce an animation of a membranewave. Specifically, consider the equation

    2u

    t2u = 0

    on the square region with opposite corners at (1,1) and (1, 1). Themembrane is assumed to be fixed on the left and right sides and free on theupper and lower sides:

    u(1, y) = u(1, y) = 0u

    y(x,1) = u

    y(x, 1) = 0.

    We assume initial conditions of the form

    u(x, y, 0) = tan1(cos(pi

    2x))

    ut(x, y, 0) = 3 sin(pix)esin(pi

    2y)

    Draw the region and set the boundary conditions in the MATLAB PDEToolbox. Initialize the mesh. Open the PDE Specification dialog box

  • 24 CHAPTER 1. MATHEMATICAL MODELS

    (a) u(x, y, 0) (b) ut(x, y, 0)

    with the menu choice PDEPDE Specification and select the hyper-bolic 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 dialogbox and enter, as a list of times, linspace(0,5,31) and also enter, as initialfunctions,

    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 buttonand select Color, as well as Height (3-D plot), and Animation andPlot in x-y grid and close the dialog box.

    Press the button to solve and animate the membrane wave. You willnotice that first each frame of the animation is computed separately, andthen they are sequenced, and then the movie is played a number of timesspecified in the animation Options.

    This demonstration shows clearly that the wave equation really does rep-resent certain types of wave motion.

    Musical and Non-musical Sounds

    When we hear a sound, our eardrums pick up the alternate compressions andrarefactions of air produced by the vibrations of the source. For this soundto be musical (melodious) it must possess two characteristics: pitch andtimbre.

  • 1.3. SOME PDE MODELS 25

    (a) Non-periodic (i.e. no pitch) (b) Periodic waveform

    Figure 1.12: Pitch

    For the sensation of pitch the waveform must be periodic, and then thepitch is the frequency, i.e. the rate at which the waveform repeats itself,measured in cycles per second. Timbre refers to the quality of the sound,and depends on the shape of the individual periods of the waveform. Most

    (a) Tuning fork (b) Clarinet

    Figure 1.13: Timbre

    complex waveforms are combinations (superpositions) of waves of one funda-mental frequency and of higher frequencies called overtones. For the resultantwaveform to be periodic the overtones should be integral multiples of the fun-damental frequency, and they are then called harmonics. Thus, for a note tobe musical to our ears the overtones must be harmonic.

    Drums like the western Bongo drum, consisting of a circular membranewith constant density are not harmonic. To explain this in more detail,recall first that the displacement u(x, y, t) of the circular membrane satisfiesthe wave equation

    utt =T

    u,

    on the circle = {(x, y) : x2 + y2 1}, where T is the tension in themembrane, a constant, and is the areal density function (mass per unit

  • 26 CHAPTER 1. MATHEMATICAL MODELS

    area), assumed here to be a function only of the radius r. If we look forsolutions vibrating with (angular) frequency they take the form

    u(x, y, t) = U(x, y)eit

    If this is substituted into the above wave equation we find that the functionU satisfies the reduced wave equation or Helmholz equation

    U = T2U,

    where U , like u, must vanish on the boundary of the circle . It is a deepmathematical fact that for most values of , U = 0 is the only solution ofthis boundary value problem; the exceptions, an infinite sequence of valuesn, give non-trivial solutions U that determine the allowed vibration modesof the membrane.

    We assume for convenience that T = 1 and set = 2. Then we seekvalues such that

    U = Uwhere U = 0 on the boundary. Values for which there is a non-zerosolution U are called eigenvalues and the corresponding solutions U are calledeigenfunctions. Notice that these eigenvalues are related to the actualfrequencies of vibration as follows. As eit = cost + i sint the angularfrequency satisfies = 2pi where is the period of the trigonometricfunction cost (and sint). As the period is the reciprocal of the frequencyf = 1/ , we have that

    f =

    2pi=

    2pi.

    These eigenvalues can be found with the MATLAB PDE Toolbox as fol-lows. The general form is

    cU + aU = dU.

    The above problem is solved with c = 1, a = 0, and d = 20 to simulate aconstant areal density function = 20.

    This can be seen from the theory given in MA455 using the zeros ofBessel functions, or by using the Eigenmodes option in the MATLAB PDEToolbox as follows. First start MATLAB and then PDE Toolbox as indicatedearlier. Choose OptionsGrid and then OptionsSnap to set a drawing

  • 1.3. SOME PDE MODELS 27

    grid which locks any boundary curve to a nearby grid point. Then click onthe 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 + y2 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. Todo this click the PDE button and choose Eigenmodes and set d to be 20and press OK; we use the default c=1 and a=0 here, by the way. Next, toset the computational grid (also called a mesh), click the mesh button (nextto PDE with a triangle on it); this sets up a coarse triangular grid overour circular region . Refine this grid by pressing the refine mesh button(look for a triangle in a triangle) once. This makes the computations moreaccurate, at the expense of greater calculation time. You may now press the

    button to compute the eigenmodes. From the MATLAB menus at thetop choose SolveExport Solution... and click OK in the dialog boxthat appears. Among other things, this sends the eigenvalues to the mainMATLAB 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 CommandWindow. Again at the MATLAB prompt enter

    Figure 1.14: The mridangam drum from Southern India

    f = sqrt(l)/(2 pi)to see the associated vibration frequencies, and

    f = f/f(1)

  • 28 CHAPTER 1. MATHEMATICAL MODELS

    to check for the existence of harmonics. It should be clear that in this casethe 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 den-sity membrane stretched tightly over a circular frame as pictured below. Ithas the unusual property of being harmonic, i.e. the frequencies of vibra-tion of the membrane are integer multiples of the lowest, or fundamental,frequency.

    There are several approximate forms of with which one can investigatethe harmonic properties of the mridangam. Consider first using a two-part

    Figure 1.15: Two-part density mridangam

    density function

    (r) =

    {1 for 0 r < a,2 for a r < b,

    as illustrated above. Here we define

    =

    12, k =

    a

    b,

    and note that real world drums usually have

    3 < < 4,

    0.45 < k < 0.55.

  • 1.3. SOME PDE MODELS 29

    The values = 3.15 and k = 0.401 are optimal.

    In order to use this function with the PDE Toolbox, you have to makeit into a MATLAB function. This is done via a source file rho.m that youwrite and store in the directory from which you are running MATLAB. Onecan set b = 1, and a = k = 0.401, and 2 = 1 and 1 =

    2 = 9.9225. The fileshould thus contain the following MATLAB code:

    function [y]=rho(x)

    % radial density function

    a=0.401;

    rho1=9.9225;

    y = ones(size(x));

    idx = find( (0.0

  • 30 CHAPTER 1. MATHEMATICAL MODELS

    Figure 1.16: Three-part density mridangam

    illustrated above. Here, we define

    =

    12, =

    23,

    q =a

    b, k =

    b

    l.

    The values = 2.74, = 1.14, k = 0.476, and q = 0.513 appear to produceexcellent results.

  • Chapter 2

    Partial Differential Equations

    2.1 Introduction

    A partial differential equation or PDE is an equation for an unknown mul-tivariable function in terms of its partial derivatives. There are many ap-proaches to classifying different types of PDEs. As with ODEs one primarilyhas the order of the equation which is the order of the highest derivativeappearing. An example of a first order PDE is

    L[u] =u

    x+u

    y= 1 (2.1)

    for the unknown function u = u(x, y). Another first order equation is

    N [u] =

    (u

    x

    )2+

    (u

    y

    )2= 1 (2.2)

    While these equations share a common order, they are quite different inanother important respect. In the first equation the operator L describingthe left side has the following property:

    L[u+ v] =(u+ v)

    x+(u+ v)

    y

    = L[u] + L[v].

    We call such an operator linear, and the equation (2.1) is said to be a linearpartial differential equation. The operator N is not linear, and the equation(2.2) is an example of a nonlinear partial differential equation.

    31

  • 32 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    We have already encountered some second order linear partial differentialequations. The equation

    2u

    x2+2u

    y2= g(x, y) (2.3)

    is called the Poisson1 equation in two variables; if g = 0 it is called theLaplace2 equation and describes the steady state temperature distribution ina metal plate. The heat equation in one space variable is

    u

    t=2u

    x2(2.4)

    and governs heat flow in one space dimension. Finally, the wave equation inone space variable is given by

    2u

    t2=2u

    x2(2.5)

    arises in connection with waves in one space dimension, for example a guitarstring.

    While these equations share linearity and order and the number of inde-pendent variables, their properties differ markedly when one considers thekinds of boundary and initial conditions needed to assure unique solutions.These equations are also special in that if we concentrate on second orderlinear equations in two variables, essentially all such equations behave likeone of these.

    Classification of Second Order Linear PDEs

    Consider the more general second order linear differential equation

    A2u

    t2+B

    2u

    xt+ C

    2u

    x2= D

    u

    t+ E

    u

    x, (2.6)

    where A, B, C, D, and E are given constants, and investigate the conse-quences of making the transformation of coordinates

    = x+ t,

    = x+ t.

    1French mathematician and physicist Simeon Denis Poisson, 1781-18402French mathematician and astronomer Pierre-Simon Laplace, 1749-1827

  • 2.1. INTRODUCTION 33

    It is known that using = 2, = 2, = 2, and = 2 the wave equation(2.5) transforms to the simple equation

    2u

    = 0, (2.7)

    from which the solution is seen to be u(x, y) = p() + q(), for arbitrarydifferentiable functions of one variable p and q. So it is reasonable to seek asimilar simplification for the general equation (2.6).

    Now, setting U(, ) = u(x, t), the above coordinate change applied to(2.6) produces

    (A2 +B + C2)2U

    2+ (2A +B( + ) + 2C)

    2U

    + (A2 +B + C2)2U

    2= (D + E)

    U

    + (D + E)

    U

    .

    We need

    A2 +B + C2 = 0, (2.8)

    A2 +B + C2 = 0,

    and if A = C = 0 we are already there via = x and = t. So assumethat A 6= 0 (with a similar argument if C 6= 0). Here we must look to 6= 0 because if = 0 then = 0 and there is no transformation of thedesired type. Similarly we assume 6= 0. On dividing the above equationsby 2 and 2 respectively, we get identical quadratic equations for the ratios/ and / and given that these ratios must be different in order that thetransformation be non-singular, we end up with

    =

    1

    2A

    [B +

    B2 4AC

    ],

    =

    1

    2A

    [B

    B2 4AC

    ].

    There are now three cases. If

    B2 4AC > 0,

  • 34 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    the transformation of (2.6) to (2.7) exists; in this case we say that the equa-tion (2.6) is of hyperbolic type. The transformation is given by

    = 2Ax+ [B +B2 4AC]t,

    = 2Ax+ [B B2 4AC]t.

    and all of these equations behave similarly to the wave equation. If B2 4AC = 0, we say that the equation (2.6) is of parabolic type. In this case/ = B/2A makes the coefficient of 2u/2 vanish, and from the iden-tity B/2A = 2C/B the coefficient of 2u/ also vanishes and so thetransformation

    = 2AxBt, = t,

    basically turns (2.6) into a heat equation,

    (2AD EB)U

    = A2U

    2+D

    U

    .

    IfB2 4AC < 0

    we say that equation (2.6) is of elliptic type. Here there are no real solutionsof the quadratic equations and no real choice of / or / makes the co-efficients of 2u/2 and 2u/2 both vanish. It is true however that thetransformation

    =2AxBt4AC B2 ,

    = t,

    turns (2.6) into the Laplace equation

    2u

    2+2u

    2= 0.

    as 4AC B2 > 0 and A 6= 0.We note finally that, after a completing of the square process on the

    second order terms, the quadratic equation

    At2 +Bxt+ Cx2 = t+ x+

  • 2.2. FINITE DIFFERENCE METHODS 35

    plots in the xt-plane as a hyperbola, parabola, or ellipse according as thediscriminant B24AC is positive, zero, or negative, and motivates the namesof the above classes of partial differential equations.

    For further material on the theory of PDE and for explicit solution tech-niques you should look to the course MA455. Given that most PDEs cannotbe solved explicitly we now turn to a brief review of the commonly usedmethods for the computer solution of these equations.

    2.2 Finite Difference Methods

    In order to approximate solutions of partial differential equations one mustconvert the differential equations into a form more amenable to the computer,typically a system of algebraic equations. In finite difference methods, oneoverlays a rectangular grid on the domain,and then approximates (some or all of) thederivatives in the PDE with difference ex-pressions that involve values of the solutionof the PDE at the grid points. We illustratethe ideas in the two dimensional case; the 3-D case is analogous but more complicated.The starting point for the finite differenceformulae is the 2-D Taylor3 theorem statedhere with a fourth-order remainder term:

    Taylor Theorem.

    For a function u with continuous fifth or-der partial derivatives, and assuming thatwe have 0 < C1 h/k C2 (no skinnyrectangles)

    u(x+ h, y + k) = u(x, y) + hux(x, y) + kuy(x, y)+ 1

    2![h2uxx(x, y) + 2hkuxy(x, y) + k

    2uyy(x, y)]+ 1

    3![h3uxxx(x, y) + 3h

    2kuxxy(x, y)+3hk2uxyy(x, y) + k

    3uyyy] +O(h4 + k4).

    (2.9)

    3named after the English mathematician Brook Taylor, 1685-1731

  • 36 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    Here, the last term, which is usually called the remainder term, R(h, k), isof order h4 + k4; i.e. there is a constant K such that

    |R(h, k)| K.(h4 + k4).

    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)+ 1

    2![h2uxx(x, y) + 2hkuxy(x, y) + k

    2uyy(x, y)] 1

    3![h3uxxx(x, y) + 3h

    2kuxxy(x, y)+3hk2uxyy(x, y) + k

    3uyyy] +O(h4 + k4).

    (2.10)From a rearrangement of equation (2.9) first with k = 0, and then withh = 0, we find the

    Forward Difference Formulae:

    ux(x, y) =u(x+ h, y) u(x, y)

    h+O(h) (2.11)

    uy(x, y) =u(x, y + k) u(x, y)

    k+O(k) (2.12)

    Similiarly, from (2.10), we have

    Backward Difference Formulae:

    ux(x, y) =u(x, y) u(x h, y)

    h+O(h) (2.13)

    uy(x, y) =u(x, y) u(x, y k)

    k+O(k). (2.14)

    We can also subtract the identities (2.9) and (2.10) to obtain

    u(x+h, y+k)u(xh, yk) = 2hux(x, y)+2kuy(x, y)+O(h3 +k3). (2.15)

    If we again first set k = 0 and later h = 0, we obtain the more accurate

  • 2.2. FINITE DIFFERENCE METHODS 37

    Central Difference Formulae:

    ux(x, y) =u(x+ h, y) u(x h, y)

    2h+O(h2) (2.16)

    uy(x, y) =u(x, y + k) u(x, y k)

    2k+O(k2). (2.17)

    Difference formulae for second order derivatives may also be determined.First, by adding (2.9) and (2.10) we find that

    u(x+ h, y + k) + u(x h, y k)= 2u(x, y) + (h2uxx(x, y) + 2hkuxy(x, y) + k

    2uyy(x, y)) +O(h4 + k4).

    (2.18)from which we obtain

    Second derivative difference formulae

    uxx(x, y) =u(x+ h, y) 2u(x, y) + u(x h, y)

    h2+O(h2) (2.19)

    uyy(x, y) =u(x, y + k) 2u(x, y) + u(x, y k)

    k2+O(k2). (2.20)

    Finally, from (2.9) replacing h with h we getu(x h, y + k) = u(x, y) hux(x, y) + kuy(x, y)

    + 12!

    [h2uxx(x, y) 2hkuxy(x, y) + k2uyy(x, y)]+ 1

    3![h3uxxx(x, y) + 3h2kuxxy(x, y)

    3hk2uxyy(x, y) + k3uyyy] +O(h4 + k4),(2.21)

    and, replacing k with k,u(x+ h, y k) = u(x, y) + hux(x, y) kuy(x, y)

    + 12!

    [h2uxx(x, y) 2hkuxy(x, y) + k2uyy(x, y)]+ 1

    3![h3uxxx(x, y) 3h2kuxxy(x, y)

    +3hk2uxyy(x, y) k3uyyy] +O(h4 + k4).(2.22)

    On adding (2.21) and (2.22) we have

    u(x h, y + k) + u(x+ h, y k)= 2u(x, y) + (h2uxx(x, y) 2hkuxy(x, y) + k2uyy(x, y)) +O(h4 + k4).

    (2.23)

  • 38 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    Then from (2.18) and (2.23) we have

    u(x+ h, y + k) u(x h, y + k) u(x+ h, y k) + u(x h, y k)= 4hkuxy(x, y) +O(h

    4 + k4)

    From this we finally have (assuming h/k and k/h are O(1)) the

    Second mixed derivative difference formula

    uxy(x, y)

    =u(x+ h, y + k) u(x h, y + k) u(x+ h, y k) + u(x h, y k)

    4hk+O(h2 + k2). (2.24)

    In general, finite difference methods are best applied when the boundarydomain of the PDE is a polygon with sides parallel to the coordinate axes.This, of course includes squares and rectangles, but as we see below, alsoell-shaped regions, and the like. For regions with curved boundaries thefinite element method is recommended (see the next section). If the PDE

    Figure 2.1: Rectangular grid

    region is overlain with a Cartesian grid formed by vertical lines x = xr,0 r n, and horizontal lines y = ys, 0 s m, and we let ur,s = u(xr, ys)

  • 2.2. FINITE DIFFERENCE METHODS 39

    denote the PDE solution values at the node points (see Figure 2.1), then atthe node point (xr, ys) we have from (2.19) and (2.20)

    uxx(xr, ys) =ur1,s 2urs + ur+1,s

    h2+O(h2) (2.25)

    uyy(xr, ys) =ur,s1 2urs + ur,s+1

    k2+O(k2) (2.26)

    2.2.1 Elliptic Equations

    We illustrate the general approach by means of some examples based uponthe following two dimensional region :

    Figure 2.2: Grid for region

  • 40 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    Problem 1

    Consider first the following boundary value problem. Find the solution u ofthe Laplace equation

    uxx + uyy = 0 (2.27)

    satisfying the boundary condition

    u(x, 0) = 100, 0 x 1,

    and u = 0 on the remaining sides of the L-shaped region shown above inFigure 2.2.

    We use the grid shown in which h = k = 0.25; we take

    u0,0 = u1,0 = u2,0 = u3,0 = u4,0 = 100

    u0,1 = u0,2 = u0,3 = u0,4 = 0

    u1,4 = u2,4 = u2,3 = 0

    u2,2 = u3,2 = u4,2 = 0

    u4,1 = 0 (2.28)

    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 eachof these grid points we substitute the derivative approximations (2.25) and

    Figure 2.3: Five point stencil

  • 2.2. FINITE DIFFERENCE METHODS 41

    (2.26) into the PDE (2.27) to obtain the equations:

    (x1, y1) : u1,2 + u1,0 + u0,1 + u2,1 4u1,1 = 0(x2, y1) : u2,2 + u2,0 + u1,1 + u3,1 4u2,1 = 0(x3, y1) : u3,2 + u3,0 + u2,1 + u4,1 4u3,1 = 0(x1, y2) : u1,3 + u1,1 + u0,2 + u2,2 4u1,2 = 0(x1, y3) : u1,4 + u1,2 + u0,3 + u2,3 4u1,3 = 0.

    Notice that at each of the five grid points one can obtain the equation byconsidering the so-called five-point stencil (see Figure 2.3) and using a weightof 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 = 100u1,1 + u3,1 4u2,1 = 100

    u2,1 4u3,1 = 100u1,3 + u1,1 4u1,2 = 0

    u1,2 4u1,3 = 0.Notice that the solutions urs of these equations are now (in general) onlyapproximations 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)equivalent to providing an ordering for the unknowns, the above system oflinear equations may be written in matrix form as

    4 1 0 1 01 4 1 0 00 1 4 0 01 0 0 4 10 0 0 1 4

    u1u2u3u4u5

    =100100100

    00

    (2.30)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 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    over the same region as above and subject to the mixed Dirichlet andNeumann boundary conditions

    u(x, 0) = 100, 0 x 1, (2.32)u

    x(0, y) = 0, 0 y 1, (2.33)

    u

    x(1, y) = 0, 0 y 0.5, (2.34)

    u = 0, elsewhere on the boundary. (2.35)

    The presence of the Neumann conditions necessitates some non-trivial changesin our approach. First, we introduce the ghost grid points at (x5, y1),(x1, y1), (x1, y2), and (x1, y3) as shown in Figure 2.4. As before

    Figure 2.4: ghost grid points for

    u0,0 = u1,0 = u2,0 = u3,0 = u4,0 = 100

    u0,4 = u1,4 = u2,4 = u2,3 = 0

    u2,2 = u3,2 = u4,2 = 0. (2.36)

    In addition to the internal unknown solution values u1,1, u1,2, u1,3, u2,1, andu3,1, we now have to determine approximations for the solution at the bound-

  • 2.2. FINITE DIFFERENCE METHODS 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 thederivative ux(x4, y1) to satisfy the Neumann condition (2.34):

    ux(x4, y1) u5,1 u3,12h

    = 0.

    This formula is O(h2) accurate, in line with the other approximations thatwe 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 = u3,1 (2.37)

    u1,1 = u1,1u1,2 = u1,2u1,1 = u1,3

    At the non-ghost grid points, we also approximate the differential equation.For example, at (x4, y1) we have

    uxx(x4, y1) + uyy(x4, y1) =u3,1 2u4,1 + u5,1

    h2+u4,0 2u4,1 + u4,2

    k2= 0,

    which, when combined with (2.37) gives

    u4,2 + u4,0 + 2u3,1 4u4,1 = 0.

    In similar fashion we obtain from (x0, y1), (x0, y2), and (x0, y3)

    u0,2 + u0,0 + 2u1,1 4u0,1 = 0u0,3 + u0,1 + 2u1,2 4u0,2 = 0u0,4 + u0,2 + 2u1,3 4u0,2 = 0

    When the boundary conditions (2.36) are incorporated, we have nine equa-

  • 44 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    tions for the non-ghost grid points:

    u0,2 + 2u1,1 4u0,1 = 100u0,3 + u0,1 + 2u1,2 4u0,2 = 0

    u0,2 + 2u1,3 4u0,3 = 0u1,2 + u0,1 + u2,1 4u1,1 = 100u1,3 + u1,1 + u0,2 4u1,2 = 0

    u0,3 + u1,2 4u1,3 = 0u1,1 + u3,1 4u2,1 = 100u2,1 + u4,1 4u3,1 = 100

    2u3,1 4u4,1 = 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, u0,2 = u2, u0,3 = u3,

    u1,1 = u4, u1,2 = u5, u1,3 = u6,

    u2,1 = u7, u3,1 = u8, u4,1 = u9.

    The above equations then become

    u2 + 2u4 4u1 = 100u3 + u1 + 2u5 4u2 = 0

    u2 + 2u6 4u3 = 0u5 + u1 + u7 4u4 = 100u6 + u4 + u2 4u5 = 0

    u3 + u5 4u6 = 0u4 + u8 4u7 = 100u7 + u9 4u8 = 100

    2u8 4u9 = 100

  • 2.2. FINITE DIFFERENCE METHODS 45

    or, in matrix form

    4 1 0 2 0 0 0 0 01 4 1 0 2 0 0 0 00 1 4 0 0 2 0 0 01 0 0 4 1 0 1 0 00 1 0 1 4 1 0 0 00 0 1 0 1 4 0 0 00 0 0 1 0 0 4 1 00 0 0 0 0 0 1 4 10 0 0 0 0 0 0 2 4

    u1u2u3u4u5u6u7u8u9

    =

    10000

    10000

    100100100

    (2.39)

    and, again, this system is easily solved with MATLAB.

    2.2.2 Parabolic Equations

    Consider the parabolic equation

    ut = uxx + uyy (2.40)

    on a 2-D region bounded by a polygon with sides parallel to the coordinateaxes. We assume an initial condition

    u(x, y, 0) = f(x, y), for (x, y) in ,

    and also that u satisfies a Dirichlet boundary condition. As before we overlaya rectangular grid on . Then, at each grid point (xr, ys) we set

    ur,s(t) = u(xr, ys, t).

    If we approximate the derivatives uxx and uyy in (2.40) at each point (xr, ys)using the formulae (2.25) and (2.26) we obtain the ordinary differential equa-tions

    dur,sdt

    (t) =ur1,s(t) + ur+1,s(t) 2ur,s(t)

    h2

    +ur,s1(t) + ur,s+1(t) 2ur,s(t)

    k2, (2.41)

    whereur,s(0) = f(xr, ys). (2.42)

  • 46 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    This ODE initial value system can now be solved with standard ODE solverroutines.

    In the case that Neumann boundary conditions are present, one can em-ploy the technique of ghost boundary points, as in the elliptic case, and thenproceed as above.

    This approach to solving parabolic equations is called the Method of Linesand is the recommended technique for the following reason. The typical alter-native method involves approximating the time derivative ut in the parabolicequation by a finite difference formula using a uniform t-mesh. One thenfinds that, in certain situations (generally unknown in advance) the methodrequires very small time steps for stability of the algorithm.

    The reason for this is not hard to find. It is known (and should be ex-pected anyway) that some ODE solutions have small gradients in parts oftheir domain, intermixed with regions where the solution gradient is verylarge. In the latter region, one must use small time-steps to ensure an ac-curate solution. The problem here is that if the time-step is uniform onthe whole domain, you will be wasting computing resources in those regionsthat have small gradient, because a larger time-step is permissible for thoseregions.

    The good ODE solvers have long ago solved this problem by employingadaptive 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 havebeen working well for decades. So they are exactly the correct resource forthese 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 Dirichletboundary condition given by,

    u(x, 0) = 100, 0 x 1u(x, y) = 0, elsewhere on the boundary of .

    and the initial condition u(x, y, 0) = 0. If we apply the difference formulaeat the interior grid points (x1, y1), (x1, y2), (x2, y1), and (x2, y2) we obtain

  • 2.2. FINITE DIFFERENCE METHODS 47

    Figure 2.5: Square Domain

    the equations

    h2du1,1dt

    = 4u1,1(t) + u2,1(t) + u1,2(t) + 100

    h2du1,2dt

    = 4u1,2(t) + u2,2(t) + u1,1(t)

    h2du2,1dt

    = 4u2,1(t) + u1,1(t) + u2,2(t) + 100

    h2du2,2dt

    = 4u2,2(t) + u2,1(t) + u1,2(t)

    subject to the initial conditions

    u1,1(0) = 0, u1,2(0) = 0, u2,1(0) = 0, u2,2(0) = 0.

    This ODE system can be solved with, for example, the subroutine xodeint.fused in MA360, or the ODE subroutines available in MATLAB.

  • 48 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    2.2.3 Hyperbolic Equations

    The method of lines may also be applied to hyperbolic equations. For exam-ple, the hyperbolic equation

    utt = uxx + uyy (2.43)

    can be solved on a 2-D region bounded by a polygon with sides parallel tothe coordinate axes. We assume initial conditions

    u(x, y, 0) = f(x, y), for (x, y) in , (2.44)

    ut(x, y, 0) = g(x, y), for (x, y) in . (2.45)

    and that u satisfies a Dirichlet boundary condition. We again overlay arectangular grid on , and at each grid point (xr, ys) we set

    ur,s(t) = u(xr, ys, t).

    If we approximate the derivatives uxx and uyy in (2.40) at each point (xr, ys)using the formulae (2.25) and (2.26) we obtain the ordinary differential equa-tions

    d2ur,sdt2

    (t) =ur1,s(t) + ur+1,s(t) 2ur,s(t)

    h2

    +ur,s1(t) + ur,s+1(t) 2ur,s(t)

    k2+Br,s, (2.46)

    where

    ur,s(0) = f(xr, ys), (2.47)

    dur,sdt

    (0) = g(xr, ys), (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 standardODE solver routines, after first transforming each second order equation toa subsystem of two first order equations (see MA360, for example).

    2.3 Finite Element Methods

    If the PDE domain boundary is not a polygon with sides parallel to thecoordinate axes, finite difference methods tend to be not only more cum-

  • 2.3. FINITE ELEMENT METHODS 49

    Figure 2.6: Triangular mesh and a continuous piecewise linear function

    bersome, but more inaccurate. In some situations, such as the lake regionshown below, the use of finite differences would be something of a nightmareto implement. A better choice under these circumstances is the finite ele-ment method (FEM). We content ourselves here with a brief overview of theessential ideas involved in the 2-D case.

    In the finite element approach, we first approximate the computationaldomain 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 iscalled a node. If greater accuracy is desired, the mesh can be refined byfurther subdividing each triangle into smaller triangles, either uniformly onthe domain, or adaptively in appropriate sub-domains, until the mesh is fineenough to achieve the desired accuracy.

    Next, the approximate solution is chosen to take a simple form on eachtriangle. Polynomials are a widely favored choice; they are easy to evaluate,and have good approximation properties on small domains. MATLAB usesfunctions that are linear on each triangle, and continuous across each triangleboundary, as can be seen in Figure 2.6; such functions are called continuous

  • 50 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    Figure 2.7: Triangular mesh for a lake region

    piecewise linear functions.

    Before we introduce the mathematical basis of the finite element method,we digress to consider (from Calculus III MA227, or Vector Analysis MA444)the

    2.3.1 Gauss Divergence Theorem in 2D

    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,

  • 2.3. FINITE ELEMENT METHODS 51

    Figure 2.8: Unit outward normal n(x, y)

    B

    F1(x, y)

    x+F2(x, y)

    ydxdy =

    C

    F2(x, y) dx+ F1(x, y) dy

    =

    ba

    F(x(t), y(t)) (y(t),x(t)) dt

    =

    ba

    F(x(t), y(t)) nx(t)2 + y(t)2 dt.

    where

    F = F1x

    +F2y

    is the divergence of the vector function F, and

    n(x, y) =(y(t),x(t))x(t)2 + y(t)2

    is the unit outward normal vector located at each point (x, y) in the boundaryC = of B = . Here, one can see that n is outward by checking the fourcases

    x > 0, y > 0

    x > 0, y < 0

    x < 0, y > 0

    x < 0, y < 0

  • 52 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    separately. The 2D Gauss Divergence Theorem

    F(x, y) dxdy =

    F(x, y) n(x, y) ds

    follows.If we use this formula with F = v.cu then as

    F = (v.cu) = cu v + v (cu),

    we have

    v(x, y)c(x, y)u n ds =

    (c(x, y)u v+v(x, y) (c(x, y)u)) dxdy,

    so that

    v (cu) =

    vcu n

    cu v. (2.49)

    This theorem is a multi-dimensional analogue of the familiar integration byparts formula b

    a

    v(cu) = [vcu]ba ba

    cuv

    from Calculus II.

    2.3.2 Gauss Divergence Theorem in 3D

    For a vector function F defined on a region in R3 with boundary wehave

    F(x, y, z) dxdydz =

    F(x, y, z) n(x, y, z) dS,

    where F(x, y, z) = (F1(x, y, z), F2(x, y, z), F3(x, y, z))T , and

    F = F1x

    +F2y

    +F3z

    is the divergence of the vector function F, and n(x, y, z) is the unit outwardnormal 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),

  • 2.3. FINITE ELEMENT METHODS 53

    Figure 2.9: Unit outward normal n(x, y, z)

    we have

    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

    v (cu) =

    vcu n

    cu v. (2.50)

    2.3.3 Elliptic Equations and the FEM

    Consider the solution u of an elliptic equation

    (c(x, y)u) + a(x, y)u = f(x, y) (2.51)on a region satisfying the Neumann condition

    cu n + qu = g (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 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    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 theregion to get

    ( (c(x, y)u) + au f).v(x, y) dxdy = 0. (2.53)

    Then using the integration by parts formula (2.50) we have that

    v(x, y) (cu) dxdy =

    v.cu n ds

    c(x, y)u v dxdy,

    so that (2.53) becomes

    (cu v + auv) dxdy

    n (cu)v ds

    fv dxdy = 0.

    Finally, using the boundary condition (2.52) we arrive at

    (cuv+auv) dxdy+

    quv dxdy

    gv ds

    fv dxdy = 0. (2.54)

    Any function u such that (2.54) holds for all test functions v is said tobe a weak solution of the above elliptic boundary value problem. Noticethat as long as the function c is bounded all is well. In particular c canbe discontinuous. This is important in many modeling situations involvingmaterial interfaces.

    Figure 2.10: hat function

  • 2.3. FINITE ELEMENT METHODS 55

    If we restrict the solution u and the test functions v to lie in a finite-dimensional space of functions then we can use the above weak formulationof the boundary value problem to obtain an approximate solution. Thereare many choices that one can make for the finite dimensional space of testfunctions. The MATLAB PDE Toolbox uses the set of piecewise linear hatfunctions i, 1 i N , whereN is the number of mesh nodes. Each functioni(x, y) is linear (i.e. of the form i(x, y) = ai + bix + ciy) on each trianglecontaining the i-th vertex and takes the value 0 at all nodes (xj, jj) exceptfor the node (xi, yi) where the value is 1. In particular, i is identically zeroon all triangles that do not contain the node (xi, yi).

    Setting v = i in (2.54) gives (for 1 i N)

    (cui+aui) dxdy+

    qui ds

    gi ds

    fi dxdy = 0. (2.55)

    We look for an approximate solution u of (2.55) of the form

    u(x, y) =Nj=1

    Ujj(x, y).

    Notice that

    u(xi, yi) =Nj=1

    Ujj(xi, yi) = Ui,

    i.e. the values Ui are exactly the nodal values of the approximate solution ofthe boundary value problem.

    On substituting this u into (2.55) we obtain the system of equations

    Nj=1

    (

    cj i + aij dxdy+

    qji ds)Uj =

    fi dxdy+

    gi ds

  • 56 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

    over 1 i N for the nodal values Ui of the approximate solution. We set

    Kij =

    cj i dxdy, (Stiffness matrix)

    Mij =

    aji dxdy, (Mass matrix)

    Qij =

    qji ds

    Fi =

    fi dxdy

    Gi =

    gi ds.

    The system can be rewritten in the form

    (K +M +Q)U = F +G

    and solved for U = (Ui).

    2.3.4 Parabolic Equations and the FEM

    As in the analogous finite difference case, we can again make use of themethod of lines. For the equation

    d(x, y)u

    t (c(x, y)u) + a(x, y)u = f(x, y) (2.56)

    on a region satisfying the Neumann condition

    cu n + qu = g (2.57)on the boundary, and the initial condition

    u(x, y, 0) = u0(x, y), (x, y) in ,

    and using the hat functions i(x, y) defined in the elliptic case above, we seeka solution u(x, y, t) in the form

    u(x, y, t) =i

    Ui(t)i(x, y).

  • 2.3. FINITE ELEMENT METHODS 57

    If this expression is substituted into the PDE (2.56) and the FEM is appliedas in the elliptic case, one arrives at the ODE system

    MdU

    dt+KU = F.

    The initial values for this system are given by

    Ui(0) = u0(xi, yi), 1 i N,where the points (xi, yi) are the mesh nodes. The ODE system is solved bythe MATLAB ODE Suite which uses adaptive stepsize control to control theill conditioning in the ODE system.

    2.3.5 Hyperbolic Equations and the FEM

    We again consider the method of lines. For the equation

    d(x, y)2u

    t2 (c(x, y)u) + a(x, y)u = f(x, y) (2.58)

    on a region satisfying the Neumann condition

    cu n + qu = g (2.59)on the boundary, and the initial condition

    u(x, y, 0) = u0(x, y),u

    t(x, y, 0) = v0(x, y) (x, y) in .

    and using the hat functions i(x, y) defined above, we seek a solution u(x, y, t)in the form

    u(x, y, t) =i

    Ui(t)i(x, y).

    If this expression is substituted into the PDE (2.58) and the FEM is appliedas above, one arrives at the ODE system

    Md2U

    dt2+KU = F.

    The initial values for this system are given by

    Ui(0) = u0(xi, yi),d

    dtUi(0) = v0(xi, yi)

    where the points (xi, yi) are the mesh nodes. The ODE system is again solvedby the MATLAB ODE Suite.

  • 58 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS

  • Chapter 3

    MATLAB and COMSOL

    3.1 MATLAB

    MATLAB is commercially available software built around the MATLABlanguage, that provides an easy interface facilitating, among other things,matrix and vector manipulations, the solu-tion of linear systems, and other numeri-cal procedures such as the solution of ordi-nary and partial differential equations andoptimization, together with accompanyinggraphics. MATLAB also permits interfac-ing with other languages such as C andFortran. The first version was written byCleve Moler, one of the authors of the pub-lic domain numerical linear algebra pack-ages LINPACK and EISPACK, in the late1970s as a device to give his students ac-cess to these tools without the need to learnFortran! Needless to say the idea took offbig time, and MATLAB was eventually re-written in C and went commercial in 1984.There are viable free clones of MATLAB available: you can check out Scilabat http://www.scilab.org, or Octave at http://www.octave.org, or FreeMatat http://freemat.sourceforge.net. MATLAB is available on the MacBookPro laptop machines in the mathematics department Mac Lab in HHB221.

    59

  • 60 CHAPTER 3. MATLAB AND COMSOL

    Start MATLAB by double-clicking the MATLAB icon

    in the MacBook Dock. If you need MATLAB on your home machine, checkout the Student Edition its cheap1 (relatively speaking) and fully functional.

    You can download the MATLAB tutorial, written by David F. Griffithsof the University of Dundee, Scotland, from the class website

    http://people.cas.uab.edu/iknowles/ma461/matlab/MatlabNotes.pdfWe will work through parts of this now. First, start MATLAB. You willnotice a rather busy scene with lots of windows. Find the one marked Com-mand Window. At the top left of this window click the rectangle (markedMaximize Command Window) to temporarily get rid of the rest (you canclick the same switch to restore things if you like the clutter). You can typeMATLAB commands at the >> prompt, followed by pressing the returnkey. It is important to notice that one can always suppress MATLAB outputby typing ; at the end of your command. You will need this for examplewhen 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 Keeping a Session Record

    The command

    >> diary freddie

    will cause all subsequent text that appears on the screen to be written to afile called freddie in the current directory. Terminate the session with

    >> diary off

    1down 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 todo some clean up.

    3.1.2 Keyboard Shortcuts

    You can recall previous MATLAB commands by using the key, and reverseyour path through the command list with the key. Once a prior commandhas 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 prece-dence apply. So, by way of example, 2+3/4*5 really means 2+(3/4)*5 ascan be checked by typing either at the MATLAB prompt:

    >> 2+3/4*5

    ans =

    5.7500

    3.1.4 Standard Functions

    MATLAB knows about the trigonometric functions sin,cos,tan, wherearguments must always be in radians:

    >> cos(pi/3)

    ans =

    0.500

    The inverse trigonometric functions are asin, acos, atan. Other standardfunctions include sqrt, exp, log, log10,abs; see Table 2, page 32 of Grif-fiths for more.

    3.1.5 Vectors in MATLAB

    The entries in a vector are usually called elements or components, andthe number of such elements is called the length of the vector. In MATLABvectors are always enclosed with square brackets.

  • 62 CHAPTER 3. MATLAB AND COMSOL

    Row Vectors

    MATLAB treats row vectors (1 n matrices) quite differently from columnvectors (n 1 matrices). Consider the 1 3 row vector v is defined by>> v = [1,3,sqrt(5)]

    v =

    1.0000 3.0000 2.2361

    >> length(v)

    ans =

    3

    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 multipliedby 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.1up to 0.72 (it will not go beyond 0.8 in this case). Negative increments alsowork. 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) pro-duces a linearly spaced row vector of length n with first element a and lastelement 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 transposeoperator as in

    >> c

    ans =

    3 4 5

    >> v

    ans =

    1.0000

    3.0000

    2.2361

    3.1.6 Products, Division and Powers of Vectors

    On p. 10 of Griffiths, may be found various useful ways to combine two vec-tors. Included here are the standard dot product, with more subtle variations

  • 64 CHAPTER 3. MATLAB AND COMSOL

    such as elementwise products (with .*), elementwise division (with ./) andelementwise powers (with . ). Check them out.

    3.1.7 Plotting Elementary Functions

    To plot (for example) the function y = sin(3pix) over [0, 1] we first samplethe function at a large enough number of points, and then get MATLAB tomake a plot by joining these points consecutively by straight lines. This isdone 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 corre-sponding row vector y of y-values is made thus

    >> y = sin(3*pi*x);

    Notice that the constant pi in MATLAB is pi and that when the sin functionacts on a row vector, it produces another row vector. This is an importanttrick 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-executingthe above steps (use the key!) You can print on your local printer by usingthe 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 functionmultiplication

    >> Z=3*sin(pi*X).*exp(sin(pi/2*Y));

    Finally create the surface plot using first figure to make the plot appear ina new window, and then the surf command

    >> figure;

    >> surf(X,Y,Z)

    to produce

  • 3.1. MATLAB 65

    Figure 3.1: f(x, y) = 3 sin(pix)epi2y

    3.1.8 Matrices

    A matrix is a rectangular array of numbers. In particular an n m matrixhas n rows and m columns. To enter a 2 3 matrix

    A =

    [1 2 34 5 6

    ]into MATLAB one would simply use

    >> A = [1 2 3

    4 5 6]

    A =

    1 2 3

    4 5 6

    or even

    >> A = [1 2 3; 4 5 6]

    You can also patch together various vectors as in

    >> B = [1:5; 6:10; 11:2:20]

    B =

    1 2 3 4 5

    6 7 8 9 10

    11 13 15 17 19

  • 66 CHAPTER 3. MATLAB AND COMSOL

    3.1.9 Special Matrices

    The command ones(n,m) makes an nm matrix of ones. This includes ofcourse row vectors (1 n matrices) and column vectors (n 1 matrices).The command zeros(n,m) does the same thing with zeros. For a given rowvector d of length n the command diag(d) creates an nn diagonal matrixwith the elements of d on the main diagonal, and all other elements set tozero. To create a tridiagonal matrix, first make three column vectors `,d,uwith the same length n (only the first n-1 elements in ` are used, togetherwith the last n-1 elements of u). We then use the spdiags() command asshown below:

    >> 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)

    ans =

    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 diagonalstructure. The command full() converts the sparse matrix output comingfrom spdiags() to standard row/column matrix notation. This is used hereonly for cosmetic reasons, and would not normally be needed for m-file (seelater) code.

  • 3.1. MATLAB 67

    3.1.10 Solving Systems of Linear Equations

    Define the column vector r by

    r =

    1

    0002

    .To solve the tridiagonal system of linear equations

    Bx = r

    we set up the column vector r of length 5 with

    >> r = zeros(3,1);

    >> r = [-1;r;-2];

    The solution vector x is now found, as a column vector, from

    >> x = B\r

    x =

    -0.4167

    -0.1167

    -0.1500

    0.0333

    -0.3667

    3.1.11 Loops

    Not surprisingly, MATLAB also allows various looping constructs. The mostcommon is the for loop. For example f30, the thirtieth member of theFibonacci 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 CHAPTER 3. MATLAB AND COMSOL

    One can also employ while loops (see p. 22 of Griffiths) and MATLAB alsohas 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 thenexecute them with one command. Such a file mus


Recommended