Lusares Notes Ra#9

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

NOTES ON RA#9: PARTIAL DIFFERENTIAL EQUATIONS

For a function F(x,y) that depends on more than one independent variable, the partial
derivative of the function with respect to a particular variable is the derivative of the function
with respect to that variable while holding the other variables constant. For a function of two
independent variables x and y, the partial derivatives are 𝜕𝐹(𝑥, 𝑦)/𝜕𝑥 (y held constant) and
𝜕𝐹(𝑥, 𝑦)/𝜕𝑦 (x held constant). There are three second-order partial derivatives for the function
F(x,y): 𝜕 2 𝐹(𝑥, 𝑦)/𝜕𝑥 2 , 𝜕 2 𝐹(𝑥, 𝑦)/𝜕𝑥𝜕𝑦 and 𝜕 2 𝐹(𝑥, 𝑦)/𝜕𝑦 2.
Elliptic, Parabolic and Hyperbolic Partial Differential Equations
A general form of the partial differential equation (up to the second order) is

where the coefficients a . . .f are functions of x and y. Of course, a particular differential


equation may be much simpler than equation 12-1. Depending on the values of the coefficients
a, b and c, a partial differential equation is classified as elliptic, parabolic, or hyperbolic. A
partial differential equation is elliptic if b2 – 4ac < 0, parabolic if b2 – 4ac = 0, hyperbolic if b2
– 4ac > 0.
In many physical models, x represents space and y represents time. The partial
differential equation known as Laplace's equation (equation 12-2) is an example of an elliptic
partial differential equation.

Elliptic equations are often used to describe the steady-state value of a function in two
dimensions. Parabolic partial differential equations are often used to describe how a quantity
varies with respect to both distance and time. The onedimensional thermal diffusion equation

describing the temperature T = F(x,t) at position x and time t in a material with thermal
diffusion coefficient K is an example of a parabolic equation (a = b = 0, c = K, thus b 2 – 4ac =
0). A similar equation, Fick's Second Law, describes the diffusion of molecules or ions in
solution, diffusion of dopant atoms into a semiconductor, and so on.
Hyperbolic partial differential equations, involving the second derivative with respect
to time, are used to describe oscillatory systems. The wave equation in one dimension,
describes the vibration of a violin string. Equation 12-4 is an example of a hyperbolic partial
differential equation (a = -k, b = 0, c = 1, thus b2 – 4ac = 4k). Other applications include the
vibration of structural members or the transmission of sound waves.
Elliptic Partial Differential Equations
Elliptic equations describe the value of a function in two spatial dimensions. Elliptic
partial differential equations have boundary conditions which are specified around a closed
boundary, while hyperbolic and parabolic partial differential equations have at least one open
boundary. Since the values are specified around a closed boundary, the equation describes a
steady-state condition.
Solving Elliptic Partial Differential Equations: Replacing Derivatives with Finite
Differences
In Chapter 6 we used the following approximation for a derivative

where h was a suitably small value. Equation 12-5 is the forward difference equation. The
corresponding backward difference equation is

For a partial derivative involving two independent variables, the finite difference
equation will involve suitable small differences in both x and y. We will use h and k to represent
these differences. The forward and backward difference equations corresponding to 12-5 and
12-6 are

Since we have used the forward difference equation 12-9 to calculate the partial derivative, we
can use backward differences for dF/dx in order to eliminate bias. The result is
Thus, for example, Laplace's equation (12-2) is rewritten as

Our approach for solving these problems will be to subdivide the region of interest into
a lattice of mesh size h x k and write the difference equations that correspond to the lattice
points, to obtain values of the function at each lattice point. For the general lattice point x i, yi
the derivative expression is

For the case where h ≠ k, an expression for F(x,y) can readily be obtained from equation
12- 14.
Note that four lattice points are involved in the calculation of F(x,y) by equation 12-
16, as represented in Figure 12-1. This representation is sometimes referred to as the stencil of
the method.
An Example: Temperature Distribution in a Heated Metal Plate
A typical example of an elliptic partial differential equation involves the solution of a
steady-state heat-flow problem. For example, if a thin steel plate, 10 x 10 cm, has one of the
edges held at 100°C and the other three edges at 0°C, what are the steady-state temperatures
within the plate? For simplicity, we assume that heat is not lost through the faces of the plate.
We subdivide the plate by means of a grid with h = k = 0.5 cm, thus creating a lattice
of size 20 x 20. At equilibrium, heat flows in the x-axis direction into a lattice element at a rate
proportional to the temperature of the adjoining element in the x-axis, and flows out of the
element at a rate proportional to the temperature of the element. The same is true in the y-axis
direction. This model gives rise to an elliptic partial differential equation of the form of
equation 12-2. The time and the thermal conductivity k of the material do not enter into the
equation.
We will use equation 12-16 to calculate the temperature at each lattice point; the
temperature at a lattice point is the average of the temperatures of the four surrounding lattice
points. Thus, we have generated a system of 400 simultaneous linear equations in 400
unknowns. Although most of the terms in a given equation are zero, the problem is still
unmanageable. However, we can solve the system by an iterative method, as described below.
Figure 12-2 shows part of the spreadsheet used to solve the system; each cell of the 20
x 20 array corresponds to a lattice point. The formula in cell B6 is
=(B5+A6+C6+B7)/4
You can Fill Down the formula into 20 rows and then Fill Right into 20 columns to create the
20 x 20 array.
Since cell B6 refers to cell B7 and B7 similarly refers to B6, we have created a circular
reference, a formula that refers to itself, either directly or indirectly. In fact, the spreadsheet
contains a large number of circular references. A circular reference is usually an error; Excel
displays the "Cannot resolve circular references" error message and puts a zero in the cell. In
this case, however, the circular reference is intentional. We can make Excel recalculate the
value in each cell, using the result of the previous iteration.

To "turn on" iteration, choose Tools→Options→Calculation and check the iteration


box. Unless you change the default settings for iteration, Microsoft Excel stops calculating
after 100 iterations or after all values in the circular reference change by less than 0.001
between iterations, whichever comes first. When you press OK the iterative circular reference
calculations will begin.
Parabolic Partial Differential Equations
The previous example showed the steady-state distribution of temperature within a
metal plate. We will now examine how temperature changes with time. This so-called heat
equation is an example of a parabolic partial differential equation.
Consider the flow of heat within a metal rod of length L, one end of which is held at a
known high temperature, the other end at a lower temperature. Heat will flow from the hot end
to the cooler end. We want to calculate the temperature along the length of the rod as a function
of time. We'll assume that the rod is perfectly insulated, so that heat loss through the sides can
be neglected.
Consider a small element dx along the length of the rod. Heat is flowing from the hot
end (x = 0) to the cooler end (x = L). The rate of heat flow into the element at the point x is
given by

where K is the coefficient of thermal conductivity (cal s -1 cm-1 deg-1), A is the cross-sectional
area of the rod (cm2) and dT/dx is the temperature gradient. The minus sign is required because
temperature gradients are negative (heat flows from a higher temperature to a lower). The
material of which the rod is made has heat capacity c (cal g -1 deg-1) and density ρ(g – cm-3).
The heat flow (cal s-1) out of the volume element, at point x + dk, is given by

The rate of increase of heat stored in the element Adx is given by

From equations 12 – 17 and 12 – 18, the rate of increase of heat stored in the element
Adx is Hin – Hout, and this is equal to the expression in 12-19

an example of a parabolic partial differential equation.


Solving Parabolic Partial Differential Equations: The Explicit Method
Using equation 12-2 1 as an example and writing it in the form

we can replace derivatives by finite differences, using the central difference formula for
𝜕 2 𝐹/𝜕𝑥 2

When these are substituted into equation 12-22, we obtain equation 12-25, where 𝑟 =
∆𝑦/(𝑘 (∆𝑥 )2). (Using forward and central differences simplifies the expression.)

Equation 12-25a permits us to calculate the value of the function at time t +l based on
values at time t. This is illustrated graphically by the stencil of the method.
An alternative to the use of equation 12-25 is to choose Δx and Δy such that r = 0.5
(e.g., for a given value of Δx, Δy = k(Δx2)/2), so that equation 12-25 is simplified to

An Example: Heat Conduction in a Brass Rod


Consider an insulated 10-cm brass rod, initially at a temperature of 0°C. One end of the
rod is heated to 100°C. Equation 12-20 describes the heat flow in the rod as a function of time.
(For simplicity, we assume that there is no heat loss through the sides of the rod.) For brass,
the coefficient of thermal conductivity k is 0.26 cal s -1 cm-1 deg-1, the heat capacity c is 0.094
cal g-1 deg-1 and the density ρ is 8.4 g cm-3. From these values, the coefficient k in equation
12-22 is 3.04 s cm-2. Figure 12-5 shows part of the spreadsheet used to calculate the temperature
along the rod, in 1-second and 1-cm intervals. The table extends to t = 100 seconds (row 113).

Cells K3:K9 contain constants used in the calculations; these cells were assigned the
names shown in parentheses in column M. The formulas in cells K6, K7, K8 and K9 are,
respectively
=k/(hcap*rho) (coefficient k in general PDE, equation 12-22)
=D12-C12 (Δx)
=B14-B13 (Δt)
=e*Dt/(Dx^2) (f)
[In the spreadsheet, the range name f was used for the parameter Y in equation 12-26,
since r can't be used as a name in Excel.]
The values in cells on the edges of the table of temperatures (column C and column M)
are the constant temperature values at the ends of the rod; the values in row 13 are the initial
temperature of the interior of the rod. The formula in the remaining cells in the body of the
temperature table (D14:L113) is based on equation 12-22. For example, the formula in cell D14
is
=f*(C13+E13)+(1-2*f)*D13
Experience has shown that the factor f must be less than 1/2 in order to avoid instability
in the calculations. For a given problem, this requires adjustment of both Δx and Δt.

Solving Parabolic Partial Differential Equations: The Crank-Nicholson or Implicit


Method
In the explicit method, we used a central difference formula for the second derivative
and a forward difference formula for the first derivative (equations 12-24 and 12-25). A variant
of equation 12-26 that makes the approximations to both derivatives central differences is
known as the Crank-Nicholson formula
where 𝑟 = ∆𝑦/(𝑘 (∆𝑥 )2 ). Choosing specific values for r and Δx determines the increment Δy.
For r = 1, equation 12-27a simplifies to equation 12-28.

Equation 12-27a or 12-28 shows that Fx,t+1 is a function of yet-to-be calculated values
at t+1 (Fx-1,t+1 and Fx+1,t+1) in addition to known values at time t (the quantities on the right-hand
side of the equation). This is illustrated by the stencil of the method shown in Figure 12-7.
Equation 12-27a results in a set of simultaneous equations at each time step. Again, the solution
procedure is best illustrated by means of an example.

An Example: Vapor Diffusion in a Tube


An air-filled tube 20 cm long allows water vapor to diffuse from a source (liquid water)
to a drying chamber, where the vapors are dissipated. Initially the tube is capped so that the
vapor cannot escape. The temperature of the tube is held at 30°C. The equilibrium vapor
pressure of water at this temperature is 31.8 mm Hg; thus, the vapor pressure inside the tube is
31.8 mm Hg. When the cap is removed, the vapor will diffuse toward the drying chamber,
where the water vapor pressure is zero. We wish to model the vapor pressure along the length
of the tube as a function of time.

where p is the vapor pressure and D is the diffusion coefficient in units of cm2 s-1. For water
vapor, D = 0.115 cm2 s-1 at 30°C.
We subdivide the length of the tube into uniform subintervals and calculate the value
of the function (here the vapor pressure p) at each interior point. Choosing Δx = 4 yields four
x values where the function value needs to be evaluated (at x = 4, 8, 12 and 16 cm) and two
boundary values where it is known (at x = 0 and 20). Also, using Δx = 4 and r = 1 sets Δt = 139
seconds.
Using equation 12-28 yields four simultaneous equations in four unknowns, thus:

For r = 1, the values of the coefficients for the four simultaneous equations are shown
in the spreadsheet in Figure 12-8. They are designated cl, c2, c3 and c4 in the table. These
coefficients will have different values if a different value of r is chosen. The constants (the
values of the right-hand side of the four equations) are also shown in Figure 12-8. The formulas
in cells I15:L15 are
=C15+E15+C15
=D15+F15
=El5+G15
=F15+H15+H15
The set of simultaneous equations can be solved by methods described in Chapter 9. In
this case the solution was found by the matrix inversion method; the array formula in cells
D19:G19 is
{=MMULT(I15: L15,MlNVERSE($D$9:$G$l2))}
A plot of the results, shown in Figure 12-9, indicates that a smaller increment oft is
required. In the preceding example, the parameter r was set equal to 1, which simplifies the
equations but also determines the values oft that were used in the calculations. In most cases it
will probably be desirable to solve the system at specified values oft. Choosing specific values
for Δx and Δt determines the value of r. The following example, using the same data as Example
12-3, illustrates this.

Vapor Diffusion in a Tube Revisited


This example uses formulas that permit the construction of a more general model. In
Figure 12-1 0, the following cells or ranges were defined: D: $G$4; Dx: $G$5; Dt: $G$6; f:
$G$7; coefficients: $D$9:$G$12; constants: $J$15:$M$26; values: $C$15:$H$27. The
formulas in cells G5:G7 are, respectively,
=D14-C14
=B16-B15
=(D*Dt)/Dx^2
In the coefficients table, the formulas =2+2*f, = -f or 0, were entered in the appropriate
cells to create the table. The constants table employs a single formula:
=f*TableValue1+(2-2*f)*TableValue2+f*TableValue3+IF(COLUMN()=MinCol,
f*TableValue1,0)+IF(COLUMN()=MaxCol,f*TableValue3,0)
where TableValuel , TableValue2 and TableValue3 correspond to the function values on the
right-hand side of the general equation 12-27a; the IF function terms add the appropriate
boundary value terms to the first and last constant terms (see the four simultaneous equations
following equation 12-29). The preceding Excel formula uses the following named formulas
(they can be examined by choosing Insert → Name → Define):
For readers unfamiliar with the INDIRECT function, INDIRECT (ref_text, a1) returns
a reference specified by a text string. The optional argument a1 specifies what reference style
is used: if a1 is TRUE or omitted, the reference is in Al style; if a1 is FALSE the reference is
in RlC1-style.
The ValuesTableCol formula returns the column number of the values table that
corresponds to the column in the constants table. This column number is used in the
TableValuel, TableValue2 and TableValue3 formulas to return the appropriate value from the
table of values. (The number 7 in the formula might have to be changed if columns in the
spreadsheet were rearranged.) The MaxCol and MinCol formulas are used in the IF function in
the formula in the constants table so as to add the boundary value terms to the first and last
constant terms.
Vapor Diffusion in a Tube (Again)
This example, using the same data, illustrates the use of a smaller grid size. The
spreadsheet ('Crank-Nicholson 3’), not shown here, can be examined on the accompanying
CD-ROM. The x-increment is 2 cm, thus creating a table of values that is 11 columns wide,
including the boundary values, and requiring a 9 x 9 matrix of coefficients.
The spreadsheet employs a single formula for all cells of the coefficients table:

Thus, a Crank-Nicholson calculation can be set up on a spreadsheet using a single


formula to create the coefficients table, a (different) single formula to create the constants table,
and a single formula for the values table. The results using the smaller grid size are shown in
the following chart.
A Crank-Nicholson Custom Function
Using a smaller increment for Δt improves the accuracy of the calculations. It may be
desirable to employ a variable value for Δt, so as to use smaller Δt near the beginning and use
larger Δt where the function is not changing rapidly. This obviously can't be done with the
spreadsheets in the preceding examples, since Δt determines the value of r and thus the values
in the coefficient matrix. The following VBA code implements the Crank-Nicholson method.
The partial differential equation must be of the form shown in equation 12-29, that is,
𝑎𝜕 2 𝐶/𝜕𝑥 2 − 𝜕𝐶/𝜕𝑦 = 0. The syntax of the function is CrankNichoIson (coeff, delta_x,
delta_t, prev_values). Coeff is the coefficient a in the above partial differential equation.
Delta_x is the size of the x-increment, which must be constant. Delta_y is the size of the y-
increment, which can vary. Prev_values is the range of function values, including the endpoint
values, in the preceding row. The function returns an array of values in a row; the user must
select the appropriate range of cells for the results, then press CTRL+SHIFT+ENTER
(Windows) or CONTROL+SHIFT+RETURN (Macintosh) to enter the formula.
Vapor Diffusion in a Tube Solved by Using a Custom Function
This example, using the same data as the preceding one, illustrates the use of the custom
function. The spreadsheet, not shown here, can be examined on the accompanying CD-ROM.
Unlike the preceding spreadsheets, tables of coefficients and constants are not required. The x-
increment is 2 cm, thus creating a table of values that is 11 columns wide, including the
boundary values. The function returns values identical to those shown in Figure 12-11.
Hyperbolic Partial Differential Equations
Hyperbolic second-order differential equations result from problems involving
vibration processes, and are of the form

describes the vibration (i.e., the lateral displacement y) of a string of length L, weight W,
tension T and weight/unit length w = W/L, as a function of distance x along the length of the
string.
Solving Hyperbolic Partial Differential Equations: Replacing Derivatives with Finite
Differences
Once again, we can solve the problem by replacing derivatives by finite differences.

If we set Tg(Δt)2/w(Δx)2 = 1, equation 12-33 is simplified to equation 12-34.


Interestingly, this simplified expression also yields the most accurate results.
To begin the calculations (i.e., to calculate the value of the function at t 1), equation 12-
34 requires values of the function at t0 = 0 and also a value at t-l. We can get a value for the
function at t-l by making use of the fact that the function is periodic. If the initial value of the
function is zero, we can use the expression 12-36 for the first row of the calculation, and 12-
34 afterwards.

If the value of the function is not zero at t = 0, a different method of beginning the
solution must be used.
An Example: Vibration of a String
A string 50 cm long and weighing 0.5 g is under a tension of 33 kg. Initially the mid-
point of the string is displaced 0.5 cm from its equilibrium position and released. We want to
calculate the displacement as a function of time at 5 cm intervals along the length of the string,
using equation 12-34. From equation 12- 35, the Δt must be 8.8 x 10-5 seconds.
The spreadsheet shown in Figure 12-14 illustrates the solution of the vibrating string
problem. Column B contains time in increments of Δt from zero to 2.8 x seconds (only part of
the spreadsheet is shown). The first row of displacement values (row 12, values shown in bold
on the spreadsheet) are the initial conditions. The values in the second row (row 13, values in
italics) are calculated according to equation 12-36; the formula in cell D13 is
=(C12+E12)/2
Values in subsequent rows (rows 14-27 in Figure 12-14; rows 14-44 on the CD-ROM)
are calculated according to equation 12-34; the formula in cell D14 is
=C13+E13-D12
If you examine the values in the table, you will see that 20-time increments constitute
a complete cycle of vibration. This vibration time, 0.001758 seconds, corresponds to a
frequency of 569 s-1, and agrees exactly with the value calculated by the formula

The above procedure can be expanded to model vibrations in two space dimensions.

You might also like