Applied Numerical Methods - (NAFTI - Ir)
Applied Numerical Methods - (NAFTI - Ir)
4 : :. 3: >a.
&.
Printed and Published by
.,
i-..
' .,/ ' I
- *" f '
-.s,* ,
k~ ; GJ,:t.:,.? .:'2, .:; -.
a u a ~ ~ c~o&~ ~~= -.-& $'3i'::$-~ 1e;:,. T G3~.I L &,, j: ...4-;:i ~i..
$. .
l i
ROBERT E.-E* :
I - .... r*:. ; ee
%.+
- . .<J
.).- . . " "'.*. , , *$. ..<.,:zv- :
-. ., &A
'
,:;:*, ,
K ~ U E G E R D R ~ ~: E. .".
&-
% . .:-.
,+
r,; , *I
, . A
All rights reserved. No part of this bookmay be reproduced inany form or by any means, electronic or mechanical,
including information storage and retrieval systems without permission in writing from the publisher.
No liability is assumed with respect to the use of the information contained herein.
Printed in the United States of America.
vii
Contents
COMPUTER EXAMPLES
CHAPTER 1
Interpolation and Approximation
1.1 Introduction
1.2 Approximating Functions
1.3 Polynomial Approximation-A Survey
The Interpolating Polynomial
The Least-Squares Polynomial
The Minimax Polynomial
Power Series
1.4 Evaluation of Polynomials and Their Derivatives
1.5 The Interpolating Polynomial
1.6 Newton's Divided-Difference Interpolating Polynomial
1.7 Lagrange's Interpolating Polynomial
1.8 Polynomial Interpolation with Equally Spaced Base Points
Forward Differences
Backward Dlfferences
Central Drflerences
1.9 Concluding Remarks on Polynomial Interpolation
1.10 Chebyshev Polynomials
1.1 1 Minimizing the Maximum Error
1.I2 Chebyshev Economization-Telescoping a Power Series
Problems
Bibliography
CHAPTER 2
Numerical Integration
2.1 Introduction
2.2 Numerical Integration with Equally Spaced Base Polnts
2.3 Newton-Cotes Closed Integration Formulas
2.4 Newton-Cotes Open lntegration Formulas
2.5 Integration Error Using the Newton-Cotes Formulas
2.6 Composite Integration Formulas
2.7 Repeated Interval-Halving and Romberg Integration
2.8 Numerical lntegration with Unequally Spaced Base Points
2.9 Orthogonal Polynomials
Legendre Polynomials: P,(x)
Laguerre Polynomials: 5Yn(x)
Chebyshev Polynomials: Tn(x)
Hermite Polynomials: Hn(x)
General Comments on Orthogonal Polynomials
2.10 Gaussian Quadrature
Gauss-Legendre Quadrature
Gauss-Luguerre Quadrature
Gauss-Chebysheu Quadrature
Gauss-Hermite Quadrature
Other Gaussian Quadrature Formulas
2.1 1 Numerical Differentiation
Problems
Bibliography
CHAPTER 3
Solution of Equations
Introduction
Graeffe's Method
Bernoulli's Method
Iterative Factorization of Polynomials
Method of Successive Substitutions
Ward's Method
Newton's Method
Regula Falsi and Related Methods
Rutishauser's QD Algorithm
Problems
Bibliography
CHAPTER 4
Matrices and Related Topics
x Contents
CHAPTER 5
Systems of Equations
Introduction
Elementary Transformations of Matrices
Gaussian Elimination
Gauss-Jordan Elimination
A Finite Form of the Method of Kaczmarz
Jacobi Iterative Method
Gauss-Seidel Iterative Method
Iterative Methods for Nonlinear Equations
Newton-Raphson Iteration for Nonlinear Equations
Problems
Bibliography
CHAPTER 6
The Approximation of the Solution of Ordinary Differential Equations
6.1 Introduction
6.2 Solution of First-Order Ordinary Differential Equations
Taylor's Expansion Approach
6.3 Euler's Method
6.4 Error Propagation in Euler's Method
6.5 Runge-Kutta Methods
6.6 Truncation Error, Stability, and Step-Size Control in
the Runge-Kutta Algorithms
6.7 Simultaneous Ordinary Differential Equations
6.8 Multistep Methods
6.9 Open Integration Formulas
6.10 Closed Integration Formulas
6.11 Predictor-Corrector Methods
6.12 Truncation Error, Stability, and Step-Size Control in
the Multistep Algorithms
6.13 Other Integration Formulas
6.14 Boundary-Value Problems
Problems
Bibliography
CHAPTER 7
Approximation of the Solution of Partial Differential Equations
7.1 Introduction
7.2 Examples of Partial Differential Equations
7.3 The Approximation of Derivatives by Finite Differences
7.4 A Simple Parabolic Differential Equation
7.5 The ~ x ~ l i cForm
i t of the Difference Equation
7.6 Convergence of the Explicit Form
7.7 The Implicit Form of the Difference Equation
7.8 Convergence of the Implicit Form
7.9 Solution of Equations Resulting from the Implicit Method
7.10 Stability
7.1 1 Consistency
7.12 The Crank-Nicolson Method
7.13 Unconditionally Stable Explicit Procedures
DuFort-Frankel Method
Saul'yev Method
Barakat and Clarlc Metlzod
7.14 The Implicit Alternating-Direction Method
7.15 Additional Methods for Two and Three Space Dimensions
7.16 Simultaneous First- and Second-Order Space Derivatives
7.17 Types of Boundary Condition
7.18 Finite-Difference Approximations at the Interface between
Two Different Media
7.19 Irregular Boundaries
7.20 The Solution of Nonlinear Partial Differential Equations
7.21 Derivation of the Elliptic Difference Equation
7.22 Laplace's Equation in a Rectangle
7.23 Alternative Treatment of the Boundary Points
7.24 Iterative Methods of Solution
7.25 Successive Overrelaxation and Alternating-Direction Methods
7.26 Characteristic-Value Problems
Problems
Bibliography
CHAPTER 8
Statistical Metllods
APPENDIX
Presentation of Computer Examples
Flow-Diagram Convention
INDEX
Computer Examples
CHAPTER 1
1.1 Interpolation with Finite Divided Diferences
CHAPTER 2
2.1 Radiant Interchange between Parallel Plates-Composite
Simpson's Rule
CHAPTER 3
3.1 GraefSe's Root-Squaring Method-Mechanical Vibration
Frequencies
CHAPTER 4
4.1 Matrix Operations
CHAPTER 6
6.1 Euler's Method
CHAPTER 7
7.1 Unsteady-State Heat Conduction in an Infnite, Parallel-Sided
Slab (Explicit Method)
In the general case, however, only the base-point func- 1.2 Approximating Functions
tional information is given and little is known about f (x)
The most common approximating functions g(x) are
for other arguments, except perhaps that it is continuous
those involving linear combinations of simple functions
in some interval of interest, a < x < b. The tabulated
drawn from a class of functions (gi(x)) of the form
functional values f (x,), . . ., f (x,), or even the base-point
values x,, . . ., x, may themselves be approximations to
true values, particularly when the table entries are the The classes of functions most often encountered are the
results of experimental measurements.
monomials (xi), i = 0, 1 , . . ., n, the Fourier functions
The synthesis of a new analytical function g(x) that
{sin kx, cos kx}, k = 0, 1, . . ., n, and the exponentials
approximates the original function f(x) depends upon {ebax),i = 0, 1, . . ., n. Linear combinations of the mono-
many factors such as knowledge of the function, the mials lead to polynomials of degree n, pn(x):
source and accuracy of the tabulated functional values,
the intended use of the approximating function g(x), and
accuracy requirements for the approximation. It is in-
tuitively obvious that the more we know about f(x), the
greater is the likelihood of finding a suitable functiong(x).
For example, if a theoretical model suggests that f(x)
should behave as a cubic in x, then we would probably Linear combination of the Fourier functions leads to
begin by attempting to fit the tabulated information approximations of the form
with a third-degree polynomial. If f(x) is a measure of
activity in a process involving radioactive decay, then
f ( x ) = g(x) = a, + a , cosx + a 2cos2x +
it is quite probable that g(x) will be exponential in ' . . f a n cosnx
character. + b, sin x + b, sin 2x f
lnformation about the reliability of the f (xi) values . . . + b, sinnx,
(i = 0, I , . . ., n) is essential. It would be unrealistic to
expect a n approximation g(x) to produce estimates of
f ( x ) accurate to four significant figures, if the values n n
f(xo), f ( x i ) , . . ., f (x,) used to generate g(x) were accurate g(x) = a, -I-
k=1
a k cos kx + k= 1
bk sin kx.
to no more than two figures. Even tabulated values of
"known" functions are normally only approximate Approximations employing exponentials are l~suallyof
values because of rounding, that is, the representation the form
of any real number by a finite number of digits. Num-
erical mathematics is not immune to the laws of thermo-
dynamics. We never get something for nothing (although
~t is often possible to get more than is apparent at first Rational approximations,
glance). a 0 + a , x + a 2 x 2 f . . . + a n x " =-p,(x)
In some cases, the synthesized function will not be used f (x) 2 g(x) =
directly for functional estimation, but instead will be
+
bo b,x + + +
b2x2 . . . h,,xm p , , , ( ~ ) '
manipulated further. For example, suppose that the are also used, although less frequently than are the poly-
integral nomials and Fourier functions.
The algebraic polynomials pn(x) are by far the most
important and popular approximating functions. The
case for their use is strong, although not overwhelming.
is required. Assuming that alternative formulations for The theory of polynomial approximation is well de-
g(x) are possible, the natural choice would be one that is veloped and fairly simple. Polynomials are easy to
easy to integrate. evaluate and their sums, products, and differences are
If the function f (x) is not known precisely, then there is also polynomials. Polynomials can be d ~ k r e n t i a t z dand
certainly no way of evaluating the error committed in re- integrated with little difficulty, yielding other polynomials
placing f ( ~ )by g ( ~ ) .Fortunately, it is often possible to in both cases. In addition, if the origin of the coord~nate
find some order-of-magnitude estimate for the error by system is shifted or if the scale of the independent variable
making reasonable assumptions aboutf(x) (for exa~nple, is changed, the transformed polynomials remain poly-
that f(x) is smooth, that it is monotonic, that its high- nomials, that is, if p , ( ~ )is a polynomial, so are p , ( ~f a)
order derivatives are small, etc.). If the function f(x) is and pn(ax). Some, but not all, of these favorable properties
known precisely o r analytically, then it is often possible * The conventional compact polynomial notation will be used
to establish an upper bound for the error. throughout, it being understood that p,(O) = a,.
Applied Numerical Methods
CHAPTER 1
In the general case, however, only the base-point func- 1.2 Approximating Functions
tional information is given and little is known about f (x) The most common approximating functions g(x) are
for other arguments, except perhaps that it is continuous those involving linear combinations of simple functions
in some interval of interest, a < x < b. The tabulated drawn from a class of functions {gi(x)) of the form
functional values f (xo), . . ., f (xn), or even the base-point
values x,, . . ., x,, may themselves be approximations to
true values, particularly when the table entries are the The classes of functions most often encountered are the
results of experimental measurements. monomials {xi), i = 0, 1, . . ., n, the Fourier functions
The synthesis of a new analytical function g(x) that {sin kx, cos kx), k = 0, 1, . . ., n, and the exponentials
approximates the original function f(x) depends upon {ebix),i = 0, 1, ...,n. Linear combinations of the mono-
many factors such as knowledge of the function, the mials lead to polynomials of degree n, pn(x):
source and accuracy of the tabulated functional values,
the intended use of the approximating function g(x), and
accuracy requirements for the approximation. It is in-
tuitively obvious that the more we know about f(x), the
greater is the likelihood of finding a suitable function g(x).
For example, if a theoretical model suggests that f(x)
should behave as a cubic in x, then we would probably Linear combination of the Fourier functions leads to
begin by attempting to fit the tabulated information approximations of the form
with. a third-degree polynomial. Iff (x) is a measure of
activity in a process involving radioactive decay, then
f(x)&g(x) = a o + a , cosx + a, cos2x +
it is quite probable that g(x) will be exponential in '.-+ an COSnx
character. + b, s i n x + b2 sin2x +
Information about the reliability of the f(xi) values . -+ bn sinnx,
(i = 0, 1, . . ., n) is essential. It would be unrealistic to
expect an approximation g(x) to produce estimates of
f(x) accurate to four significant figures, if the values
f (x,), f (xi), ..., f (x.) used to generate g(x) were accurate g(x) = a, + C akcos kx + kC= bk sin kx.
k= 1 1
to no more than two figures. Even tabulated values of
"known" functions are normally only approximate Approximations employing exponentials are usually of
values because of rounding, that is, the representation the form
of any real number by a finite number of digits. Num-
erical mathematics is not immune to the laws of thermo-
dynamics. We never get something for nothing (although
it is often possible to get more than is apparent at first Rational approximations,
glance). +
a, + a,x a2x2 + + anxn pn(x)
In some cases, the synthesized function will not be used f (x) r g(x) = bo + b,x b2x2 . .. + bmxm=-
+ +
directly for functional estimation, but instead will be pm(x)'
manipulated further. For example, suppose that the are also used, although less frequently than are the poly-
integral nomials and Fourier functions.
The algebraic polynomials pn(x) are by'far the most
important and popular approximating functions. The
case for their use is strong, although not overwhelming.
is required. Assuming that alternative formulations for The theory of polynomial approximation is well de-
g(x) are possible, the natural choice would be one that is veloped and fairly simple. Polynomials are easy to
easy to integrate. evaluate and their sums, products, and differences are
If the function f (x) is not known precisely, then there is also polynomials. Polynomials can be differentiated and
certainly no way of evaluating the error committed in re- integrated with little difficulty, yielding other polynomials
placing f ( ~ )by g ( ~ )Fortunately,
. it is often possible to in both cases. In addition, if the origin of the coordinate
find some order-of-magnitude estimate for the error by system is shifted or if the scale of the independent variable
making reasonable. assumptions about f (x) (for exa~nple, is changed. the transformed polynomials remain poly-
that f(x) is smooth, that it is monotonic, that its high- nomials, tliat is, if p , ( ~ )is a polynomial, so are pn(x + a)
order derivatives are small, etc.). If the function f(x) is and pn(ax). Some, but not all, of these favorable properties
known precisely or analytically, then it is often possible * The conventional compact polynomial notation will be used
to establish an upper bound for the error. throughout, it being understood that p,(O) = ao.
1.3 Polynomial Appro xim mat ion-A Survey 3
are possessed by the Fourier approximations as well. As The Interpolating Polynomial. Given the paired values
we shall see later, most of the other functions considered (xl,f(xl)), i = 0, 1, ..., n, perhaps the most obvious
as potential candidates for approximating functions criterion for determining the coefficients of p,(x) is to
(sines, cosines, exponentials, etc.) must themselves be require that
evaluated by using approximations; almost invariably,
these approximations are given in terms of polynomials
or ratios of polynomials. Thus the nth degree polynomial p,(x) must reproducef (x)
All these obvious advantages of the polynomials would exactly for the n + 1 arguments x = xi. This criterion
be of little value if there were no analytical justification seems especially pertinent since (from a fundamental
for believing that polynomials can, in fact, yield goad theorem of algebra) there is one and only one polynomial
approximations for a given function f (x). Here, "good" of degree n or less which assumes specified values for
implies that the discrepancy between an approximating +
n 1 distinct arguments. This polynomial, called the nth
polynomial p,(x) and ~ ( J c )that
, is, the error in the ap- degree interpolating polynomial, is illustrated schematic-
proximation, can be made arbitrarily small. Fortunately, ally for n = 3 in Fig. 1.1. Note that requirement (1.2)
this theoretical justification does exist. Any continuous
functionf (x) can be approximated to any desired degree
of accuracy on a specified closed interval by Jame poly-
nomial p,(~).This follows from the Weierstrass approxi-
mation theorem stated here without proof [6]:
Iff (x) is continuous in the closed interval [s,b],(that
is, a < x < b) then, given any c: 0, there is some:
polynomial p,(x) of degree n = n(e) such that
f (x) p,(x) -
Qj '
n
qxi. (1.1)
exactly. In addition, it often happens that the desired
polynomial is of low degree, say m, but that there are
many data values available, so that n > m. Since the exact
For a thorough discussion of several other approximating matching criterion of (1.2) for n + 1 functional values can
functions, see Hamming [Z], be satisfied only by one polynomial of degree n or less, it is
generally impossible to find an interpolating polynomial
1.3 P~lynomialApproximation-A Survey of degree m using all n + 1 of the sampled functional
kfter selection of an nth-degree polynomial (1.1) as the values.
approximating function, we must choose the criterion for Some other measure of goodness-of-fit is needed. In-
"fitting the data." This is equivalent to establishing the stead of requiring that the approximating polynomial
procedure for computing the values af the coefficients reproduce the given functional values exactly, we ask only
QO,a,, , . ., a,. that it fit the data as closely as possible. Of the many
4 Inteplation and Approximation
<
Here xo < < x, or, if x < x,, x < 5 < x,. Hence- For xo = .n/4:
forth* this will be written more succinctly as in <
(~9x0).
The parameter 5 in (1.6) is a n unknown function of
x. Hence, except in very special cases (for example, when
f("")(t) is a constant), it is impossible t o evaluate the (x - 7r/4)4
R (x) = cos f,
error or remainder term R(x) exactly. Nevertheless, we 4!
shall see that (1.6) can prove useful in establishing a n We now use (I .8) and (1.9) to estimate cos(~r/2).From (1.8),
upper bound for the error incurred when p,(x) is used to cos(7rl2) = 1 - .n2/8= -0.2337. Since 5 is unknown, but
approximate f(x). Provided that f(x) meets the con- 0 < [ < n/2, an estimate of the error bound is given by
tinuity and differentiability requirements of the formula,
the polynomial p,(x) given by (1.5) may be viewed as
fittingexactly then + 1 paired values(xo,f(xo)),(xo,f'(xo)),
(xo,f "(xo)), . . ., (x,, f("'(x0)), since p2'(xo) =f ( i ) ( ~ o ) . In this case, since the sign of the error is known (because cos f
For the most commonly encountered polynomial is positive for all x, 0 < x < 77/2), we could also write:
approximation problem, in which only the functional
values f(xi) are known at n + 1 distinct base points
x,, i = 0, 1, . . ., n, the Taylor's expansion of (1.5) is of Note that although the error is sizeable [cos(n/2) = 0.01, it is
little use, since it is usually not possible to evaluate the smaller than the predicted upper bound.
required derivatives. However, if the function f(x) is From (1.9),
known analytically and is simply differentiable, then use-
ful approximations p,(x) can be found easily. By estab-
lishing an upper bound foir the magnitude of the remain-
der R (x), and hence of the error in p,(x), we can use the Since cos ( has a maximum value 0.7071 on the interval
approximating polynomial with complete confidence in n/4 < f < 4 2 ,
the region of interest.
Exanlplc. Expand the function f(x) = cos x in a Taylor's
series. Use Taylor's formula with remainder to find a third- As before, the sign of R is known to be positive, and the
degree polynomial approximation p3(x) = cos x. For xo = 0 approximation could be written:
and xo = ~ 1 4estimate
, cos(rr/2) from p3(x); establish bounds
on the errors in the estimated values, using (1.6).
Cos x and its first four derivatives are: The error is again smaller than the upper bound. The approxi-
f (x) = cos x f "'(x) = sin x mation is much better than in the previous case.
f '(x) = -sin x f ' 4 ) ( ~=) cos x The preceding example illustrates the influence of the
polynomial (x - x,)"+' on the remainder term of (1.6),
f "(x) = - cos x. R ( x ) . Normally, to approximate best a function f ( x ) on
Substitution into (1.5) and (1.6) with n =3 yields: the interval [a,b],xo should be chosen near the middle of
* p4x)
CO~(X) = cos xo - (x - xo) sin xo the interval; we can show that the choice x, = ( a + b)/2
minimizes the maximum contribution of the term
--(x - x0l2 cos Xo (X- xol3 (x - x,)"" to the remainder for a < x < b. For a fixed
2!
+ ----
3!
sin xo, (1.7)
value of n (that is, for a fixed number of terms retained in
the series), this is about the only practical way of reducing
the magnitude of the error in the approximating poly-
nomial p , ( ~ ) .The value of f'"+''(t) for a given x in [u,S]
For xo = 0:
cannot be computed, in general, since 5 is an unknown
sin(0) = 0, cos(0) = 1 function of x. Consequently, in estimating the error R (s),
we can only be certain that (f'"+''(<)1 can be n o greater
cos x 5 1 - than the maximum value of 1f '"+"(w)l for x in [a,b].Of
course, if each successive term in the Taylor's expansion
x4
R (x) = - cos t, f in (x,O). is smaller in magnitude than the previous ones (often but
4! not always the case), another way to lower the upper
bound on the magnitude of R (x) is to include additional
+ .
In smral, the notation 6 in ( x , x o , x , , . ., x.) will indicate that
terms in the approximation, that is, to increase the degree
f is in the open interval determined by the smallest and largest of
the enclosed arguments. of the approximating polynomial.
6 Interpolation and Approximation
1.4 Evaluation of Polynomials and Their Derivatives Transcription of these two flow diagrams into two
FORTRAN IV statement sequences is complicated
Efficient evaluation of a polynomial
somewhat by the following restrictions in the FORTRAN
IV language as implemented on most of the digital com-
puters now in use [10,11]:
may be important if pn(x) is to be computed many times 1. Zero is not a permitted subscript for subscripted
for different values of x. Straightforward term-by-term variables.
evaluation is inefficient, particularly for large values of n. 2. Subscripts are limited to simple arithmetic expres-
If each factor Xk is computed by k - 1 repeated multi- sions of the form clv k c2 where c, and c, are non-
+
plications of x, then n(n 1)/2 multiplications and n ad- negative integer constants and v is a nonsubscripted
ditions are required to evaluate pn(x). If each factor xk is integer variable.
calculated by successive multiplications, xxk-', then 3. The initial value, increment, and terminal value of
2n - 1 multiplications and n additions are required. the iteration variable in the iteration (DO) statement
However, if the nesred form of p,(x), must be positive integer constants or variables.
4. The iteration (DO) loop is executed at least once,
even when the upper limit of the iteration variable is
smaller than the initial value of the iteration variable.
is used, then only n multiplications and n additions are Some of these difficulties can be avoided if a different
required per evaluation. The procedure described by subscription convention is used in (1.lo). However, given
(1.10) is called Horner's rule. It has been shown [5] that the subscription convention of (1. lo), assume that
for n < 4, the nested evaluation requires the minimum FORTRAN variables N and X have been assigned the
possible number of arithmetic operations. For poly- values of n and x, respectively; let the values of the co-
nomials of higher degree, other schemes which require efficients a,, . . ., an be assigned in sequence to the ele-
fewer than 2n operations (on the average) are known, ments of the FORTRAN subscripted variable A from
particularly when pn(x) is to be evaluated many times. +
A(l) to A(N 1). Thus coefficient a i is assigned to array
The procedure is generally different for each n [4,19]. For +
element A(I I), where problem variable i is equivalent
most applications, the nested computing scheme of ( I .lo) to program variable I. If J is acounting variableand NP1
is adequate. is a variable assigned the value n + 1, FORTRAN IV
Since the calculations in the innermost parentheses statement sequences which describe algorithms 1 and 2
must be performed first, the computing procedure for and assign the computed value ofpn(x)ta the FORTRAN
variable P are:
Algorithm 1 Algorithm 2
t
Algorithm 1 Algorithm 2
Figure 1.3 Evaharion of a polynomial p,,Q using Horner's rule. Now let us divide pn(x) by the factor (x - t) to yield
X, = x0 + nh, Graphically (see Fig. 1.4), this simply means that if f(x)
is continuous and suitably differentiable on some interval
where h is the constant spacing or stepsize between in x, then there is at least one point x = ( on the interval
adjacent ordered xi values. for which the slope of the line tangent to f (x) [that is, the
In what follows, the two most common forms of the derivative, f1(t)] is the same as the slope of the line
interpolating polynomial for arbitrarily spaced base joining the functional values at the ends of the interval.
points, Newton's divided-diference interpolating poly-
momial and Lagrange's interpolating polynomial will be
developed in some detail. Both permit arbitrary ordering
of the base points x,, x,, x,, . . ., x, as well. Duplicate
base-point values are not permitted, since the Vander-
monde determinant would vanish and the system of equa-
tions in the unknown coefficients would have no unique
solution,
The equal-interval formulas have been developed to
simplify interpolation in tables of functions with evenly
spaced arguments. Some have been developed specifically
for interpolation near the beginning, middle, or end of a
table. All can be derived from either Lagrange's or New-
ton's divided-difference interpolating polynomial. With
the widespread use of high-speed computers, tabular
interpolation of this sort has lost much of its importance.
Almost without exception, functional values needed
for digital computation are generated directly by sub-
routines from the computer's program library. As a con-
Figure 1.4 Zllustration of the differential mean-value theorem.
sequence, only a few of the most important equal-interval
formulas will be shown, primarily because of their use in
the development of numerical integration formulas (see Thus the first finite divided difference of (1.13) is related
Chapter 2). to the first derivative (provided that the continuity and
differentiability restrictions of the theorem are me^) as
1.6 Newton's Divided-Difference Interpolating follows :
Polynomial
Consider the definition of the derivative:
assumed that tabulated sample values at n + 1 discrete where the sequence of integers a,, a,, a,, ..., an is any
base points are available as follows: permutation of n, n - I, n - 2, . . ., 0.
It is also apparent from the definition that
or
f ( 4 =f (xo) -I- (X - x0)f Cx1,xoI
=f Cxol .+ (x - xo)f Cx1,xol
= P~(x>. (1.19)
Since all the elements on the right-hand side of (1.19),
which defines a straight line or first-degree interpolating
polynomial pl(x), can be evaluated from known quanti- Figure 1.7 Linear interpolation-f ( x ) not linear.
ties, the linear interpolant f (x) can be computed directly.
The procedure or algorithm of (1.19) is, of course, the one To account for any discrepancy and to restore the desired
commonly used for linear interpolation, disguised some- equality, an error or remainder term Rl(x) can be ap-
what by the presence of the divided-difference notation. pended to (1.19). Then
Consider linear interpolation between the tabulated
points (I, 1) and (3,5), shown schematically (Fig. 1 . 6 ~and
)
in tabular form (Fig. 1.6b). Solving (1.21) for R,(x) and collecting factors in terms
of the finite divided differences yields
R1(x) = (x -- xo)(f [x,xol -f [x1,xol)
=(x-xO)(X-X~)~[X,X~,XOI. (1.22)
Then (1.21) has the form
f ( 4 =f Cxol + (x - xo)f Cx1,xol
+ (X - XO)(X- x1)f CX,X~,XOI
= P ~ ( x+
> R1(x), (1.23)
where pl(x) [see (1.19)] is, as before, the first-degree inter-
polating polynomial passing through the sample points
(xo,f(xo)) and (x,, f(xl)). Rl(x) is the discrepancy be-
tween f(x) and p,(x) and will be termed the remainder or
error term for the first-degree polynomial approximation
of f(4.
It is, of course, impossible to compute f [x,x,,x,]
exactly sincef(x), required for its evaluation, is unknown
(b) (otherwise there would be no need for interpolation in
Figure 1.6 Numerical e.ramplefor linear interpolation. the first place). However, if an additional value off (x) is
12 Interpolation and Approximation
known, say f (x,) at x = x,, then, on the assumption that hencep,(x) is the second-degree interpolating polynomial
f [x,xl,xo] is not a rapidly changing function on the passing through (x0,f (~011,(x, ,f (XI)),and (x2,f (~2)).
interval containing x,, x,, and x,, that is, Substituting values from Table 1.2 into equation (1.26)
yields
and
Here the nth-degree divided-difference interpolating poly- Now, consider a new function Q ( t ) such that
nomial p , ( ~ )has the forrrt
(1.38)
or, in more compact f m , as We now have a new form for the ermr Rn(x) in terms csf
+
the (a 1)th derivative of f(x), and Newton's funda-
m e 1 formula can be written as
14 Interpolation and Approximation
Ifl tliiS case we know that the functional values are for the
The value of 5 is unknown, except that it is some- fudctibil cos 0. Since we know that the third derivative is the
where on the interval containing x and the base-point function sin B and can establish its upper bound on the interval
values xo, x,, . . ., x,. If the function f (x) is given only in [Bl,03] = [0.2,0.4], an upper bound for the interpolation error
tabular form, then the second form (1.39b) of &(x) is is given by (1.39b) as
of little value since f(""'(5) cannot be determined. How-
ever, if f(x) should be known analytically, then (1.39b) is sin [
(e - e3)(e- e,)(e - el) -
useful in establishing an upper bound for the error. 3!
sin(0.4)
Example. Several values of the cosine function and the cor- < (O.OS)(-0.05)(-0.15) - 3!
= 2.44 x 10- '.
responding divided differences of orders one through five are
shown in Table 1.3. The differences have been computed by
retaining only significant digits (equal to the of digits Since the tl-ue value of cos(0.25) to seven significant figures
in the numerator for each divided difference) at each stage of is 0.9689124, the actual error is 1.77 x lo-*.
the calculation. Notice that each differencing operation tends
to reduce the number of meaningful figures in a divided- Note that (I .39b) shows that i f f (x) is a polynomial of
difference table (see Example 1.1). Evaluate the second-degree degree Or less, then Rn(x) vanishes for This is
xa
interpolating polynomial passing through the functional evidenced by the appearance of zeros in a table of divided
values at B,, 02, and 03, for interpolation argument e = 0.25, differences. For example, consider the divided-difference
that is, estimate the value cos (0.25). table (Table 1.4).
i 8,
Radians f3[ 1 f4[ 1 f ~ 1l
-
0 0.0
-0.09966715
1 0.2 0.98006657 -0.4921 125
-0.2473009 0.0371062
2 0.3 0.95533648 -0.4772700 0.0396700
-0.3427549 0.0609082 -0.0029662
3 0.4 0.92 106099 -0.4529067 0.0375936
-0.4786269 0.0797050
4 0.6 0.82533561 -0.4210247
-0.6049343
5 0.7 0.76484218
In terms of 6' and the three base points B,, B,, and B3, (1.31) The constant third differences and zero higher-order
becomes differences indicate that all six points can be fitted exactly
+
cos 8 =p2(B) = cos 8, (0 - 8,) cos[8,,Bl] with a third-degree polynomial. Without other informa-
+ (0 - B,)(B - 8,) C O S [ ~ ~ , ~ ~ ,tion,
B , ~ however,
. it is not certain that f ( x ) itself is a third-
Then degree polynomial. In this case (1.33) would yield an
+
cos(0.25) = 0.98006657 (0.05)(-0.2473009) estimated error of zero, which is the true error only iff ( x )
+(0.05)(- 0.05)(-0.4772700) is in fact a polynomial of degree three.
or Some comments concerning the relationship of der-
cos(0.25) i-0.9688947. ivatives and the finite divided differences are in order.
1.6 Newton's Divided-Diflerence Interpolating Polynomial 15
Table 1.4 Ditlided-Diflerence Table As before, the third-degree polynomial generated by the
information in the table is given by
The third-degree interpolating polynomial is given (taking ment is near the endpoints xo or x,,, the error is likely to
the upper diagonal path) by (1.29) as be larger than when it is near x,,,, assuming that the base
+ (X - 3)lO + (X - 3)(x - 0)5
p3(x) = 25 points are in algebraic order. It also indicates that when x
is outside the interval [x,, . . ., x,], that is, when the inter-
+ ( x - 3)(x-O)(X -4)l = x 3 -2x2 + 7x - 5. polating polynomial is used for extrapolation, the error
When a divided-difference table for n + 1 base points may be very large.
has been prepared f o ~L! differences of order n or less, The divided-difference form of the interpolating poly-
interpolating polynomials of any degree m where m < n nomial is especially well suited for computing interpolant
may be found. If the full difference table is not used values for polynomials of different degree. Altering the
jm < n), there is a choice of base points. It is intuitively degree of the polynomial from j to j + 1 requires the
obvious that one should use base-point information near evaluation of just one additional term, and no previous
the desired interpolation argument. That this is the case calculations need be repeated or modified. This feature
may be seen by examining the form of the error term is important when the degree of the desired polynomial is
(1.39b). In general, since f ' n + l ' ( { ) is unknown, the best not known at the beginning of the calculation. New terms
that can be done to reduce the error is to make that part can be added one at a time (equivalent to increasing the
of the error term given by the polynomial degree by one) until the bound on the remainder term or
the error estimate given by the first term dropped is small
enough, without invalidating the calculations already
done.
as small as possible in magnitude. Clearly the interpola- In addition, when many interpolations with the same
tion argument should be centered as nearly as possible on data set but different interpolation arguments must be
the interval containing the base points used in the inter- carried out, considerable computing time is saved (over
pojation, that is: the base points should be distributed the Lagrange formulation of the next section), since a
about the interpolation argument as "evenly" as possible. large part of the computation, involved in setting up the
In general, (1.42) shows that when the interpolation argu- divided-difference table, need be done just once.
EXAMPLE 1.1
INTERPOLATION WITH FINITE DIVIDED DIFFERENCES
Problem Statement T as given by (1.1 .I). The program should then read
values for 2 and d, should call on FNEWT to evaluate the
Write a subroutine named DTnaLE that will calculate
all divided of order or less for the paired appropriate divided-difference interpolating polynomial,
values (xi,yi),i = 1 , 2 , . . ., n, where m < n. Elements of and then should compare the interpolant value, J(E),
with the value of cos ? computed by the library function
the divided-difference table should be assigned to the
COS'
first m columns of the first n - 1 rows of the lower
-srangular matrix? T , so that
i = 1 , 2 ,..., n - 1 ,
T , = f C x i + l , x i , . . . , x i + I - J ' [ j = 1 , 2 , ..,,m,
Method of Solution
(1.1.1)
Using (1.1. l), the divided-difference table will have
where f ( x i ) = yi.
the following appearance :
Xl Yl 1 1 =fCxz,xtl
x2 Y2 7 - 2 ~ =~CX~,XZ] Tz,z ' f [X~,~ZIXI]
X3 y3 T3.1 =f[x4rx31 T3,2 = f[ X ~ , X ~ , X Z ]
xm ym T =f [xm+l,xm] 2 !
= S C x m + ~ , x m 3 x m - ~ ITm,m = f[ x m + ~ , - . - , x ~ I
~ n - 1 yn-1 T n - l , l = f [xn,xn-ll Tn-1.2 =f Cxn~xn-1,xn-21 i K-l,m = f Cxn,...,xn-mI
Xn Yn
Note that, unlike the divided-difference tables such as
Assume that the values xi are in ascending algebraic ~ ~ 1.2,b there l is~ no base point (xo,yo = f ( x , ) ) .
order but of arbitrary spacing. Write a function named order to facilitate the simple subscription scheme of
FNEWT that evaluates a divided-difference interpolating (1.1.1), the divided-difference of the table is no
polynomial of degree d for interpolation argument 2 , longer symmetric about the base points near the middle
using the appropriate divided differences from the of the table, All elements of the T matrix, T i , j for
matrix T of (1.1.1' The function should search the x
+
vector? to establlsk which d 1 of the n possible base
, ,
. ,, and n, are unused. The subrolltine
DTABLE assumes that T is a k by k matrix, and
points xi should be used to determine the interpolating for argument consistency to insure that-nl < n.
polynomial, so that is as nearly central to the selected The function FNEWT the vector of base
points as possible. ':his will make (1.42) as small as to find that value of for which I x i ; if %, xn, is
possible and, 'Y, make the error term for assigned the value n. The base points used to determine
the interpolation acc:ptably small. Should ? be smaller the interpolating polynojlial are nornlally max-d, '. .,
than x1 or larger that1 x,,, the base points should be the
first or last d + 1 of the xi, respectively; for these cases,
+
x,,,, where max = i d/2 for d even and max = i +
(d - 1)/2 for d odd. should max be smaller than d + 1
the interpolating polwlmial will be used to extrapolate, or larger than n, then max is reassigned value + I
since i lies outside the ;.inge of available base points. or n, This ins,lres that only given base
To test the two programs, write a main program that points are used to fit the polynomial^
reads values for m , n, an? xi, i = 1 , 2 , . . ., n, computes
terms of the divided the interpolant
the eknents of the y veac'r as Yi = cos xi, and calls on
DTABLE to calculate entries t the divided-difference table
c
value, j(?), is described by the polynomial of degree d:
t The term vector will be used thro ahout to describe alineararray J(%) = Ymax - d + - ~ i r -- d- ) f Cxmox - d + 1, ~ m o x - d l
(a column) of numbers identified i p a common name. Individual
elements of the vector are identifit4 h\ a single subscripr attached
to the name. In this case, the JC and v \ I tors consist of the elements
+ (z - X m ~ ~ - d1x2
+ - xmax-d)
XI, x2, . . ., X. and y,, y 2 , . ..,y n rreqw tively.
The term matrix will describe a rt c i r i rqular array (rows and col- f Cxmas-d+~,X m a x - d + 19 ~ma~--dl
umns) of numbers ldentltied by a c >.?,r ,on name. lnd~vidualele-
ments of the matrix are identified by :) s subscripts, the first to
indicate the row index and the second t ~ , dicate the column index.
+ "'
(x - X m a x - l ) . . . ( ? - x,,,-~)
Thus Tt,, is the element appearing In tile a row and jth column of
the matrix T (see Chapter 4). X f C X ~ .~- .,X xmaX-dl.
, (1.1.2)
18 Interpolation and Approximation
The corresponding error term, from (1.32) and (1.39), is or, from (l.l,l),
< i n ( E , ~ , ~ ,,...,
- ~ xmaJ. (1.1.4) FNEWT uses this nested form to evaluate J(3). Should
there be an inconsistency in the function arguments,
Rewritten in the nested form of (1. lo), (1.1.2) becomes that is, if d > m, the value assigned to FNEWT is zero;
otherwise, the value is J(3).
- xma~-dl(~
J(n) = {{ ' ' ' {f[~max, -3 - XWX- 1) In both DTABLE and FNEWT, a computational switch,
+f [xmax-1, ~max-dl}(~ - xmax-2> trubl, is set to 1 when argument inconsistency is found;
otherwise, trubl is set to 0. FNEWT does not check to
+f [xmax-2, ~max-dI}(~-~max-3)
insure that the elements xi, i = 1,2, . ..,n, are in
+ +f [xmaX-d+1 9 xmax-al> ascending order, although such a test could be incor-
x (E - x,,,-~) + ymax-d, (1.1.5) porated easily.
Flow Diagram
Main Program
---------------------- I
I
I
I
yi 4- COS Xi
0
Return
20 Interpolation and Approximation
F T
Yf
trublt 1
T F T
Y %
d
. , *
max c n maxti+- maxcd+ 1
2
t t t
1
------- - F
I
7 Tmox-l,d
I
I T
I
I
1
I
I
I
I
I
I Evaluate Newton's divided-
I difference polynomial using
I
I
I nested algorithm.
I
I Y 7(2 - xmax - i )
+
I
I + Tmax-i-l,d-i
1
I I
I
I
I
t t
I
------------- Y 8%- xmax-3 + y m a ~ - a
+
trubl + 0
Example 1.1 Interpolation with Finite Divided Di&ences
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
(Main)
I. J, L Slubscripts i, j, I.
lDEG Degree, d, of the interpolating polynomial.
M m, highest-order divided difference to be computed by DTABLE.
N n, the number of paired values (xi, yi =f(xi)).
NM1 n - 1.
TABLE Matrix of divided differences, T i p i .
TRUBL Computational switch: set to 1 if argument inconsistency is encountered, otherwise set to 0.
TRUVAL Value of cos Z computed by the library function cOS.
X Vector of base points, x i .
XARG Interpolation argument, P.
Y Vector of functional values, yi =f(xi).
Y lNTER Iriterpolant value, j(3).
(Subroutine
DTABLE)
SUB Subscript, i + 1 -j.
K Row and column dimensions, k, of matrix T.
(Function
FN EWT)
lDEGMl d ,- 1.
ISUB1,lSUBZ Subscripts, max - i, d i.-
MAX Subscript of largest base point used to determine the interpolating polynomial, max.
Y EST Variable used in nested evaluation of interpolating polynomial, (1.1.6).
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 1.1
C NEWTON'S DIVIDED-DIFFERENCE INTERPOLATING POLYNOMIAL
-
WRITE (6,202)
NM1 = N 1
M
DO 6
L = l
l*l,NMl
I F ( I .GT.M)
WRITE ( 6 , 2 0 3 )
C -
M
(TABLE(I,J), J=l,L)
.. .
, , READ XARG AND IDEF, CALL ON FNEWT TQ \NTERPOLATE ,
WHITE ( 6 , 2 0 4 )
- 9 .
REAP (2,101) XARG, I P E E
Y l NTER = F#EWT( X,Y,TA@LE,N,M, IDEG,XARG,WBL,2O )
END
Subroutine D T 4 B LE
SUBROUTINE DTABLE ( X,Y,TABLE,N,M,TRUBL,K
C
C DTABLE COMPUTES THE F I N I T E D I V I D E D DIFFERENCES OF
C Y(l)...Y(N) FOR A L L ORDERS M OR LESS AND STORES THEM I N
C THE LOWER TRIANGULAR PORTION OF THE F I R S T M COLUMNS OF THE F I R S T
C N - 1 ROWS OF THE MATRIX TABLE. FOR INCQNSISTENT ARGUMENTS,
C TRUBL = 1.0 ON E X I T . OTHERWISE, TRUBL = 0.0 ON E X I T .
C
DIMENSION X(N), Y(N), TABLEtKtY)
i e Interpolation with Finite Diuided Dflerences
~ x a r n ~ 1.1
6 TRUBL = 0.0
RETURN
C
END
Function FNEWT
FUNCTION FNEWT ( X,Y,TABLE,N,M, IDEG,XARG,TRUBL,K )
TRUBL = 0.0
FNEWT = YEST+(XARG
RETURN
-X(ISUB1)) + Y(ISUB1)
C
END
Data
N = 8 M = 6
X(l)...X(S) = 0.0000
X(6)...X(8) = 0.7000
XARG = 0.2500 IDEG =
XARG = 0.2500 IDEG =
XARG= 0.2500 IDEG =
XARG- 0.2500 IDEG =
XARG = 0.2500 IDEG =
XARG= 0.2500 IDEG =
XARG = 0.4500 IDEG =
XARG = 0.4500 IDEG =
XARG= 0.4500 IDEG =
XARG = 0.0500 IDEG =
XARG= 0.0500 IDEG =
XARG = 0.8500 IDEG =
XARG = 0.9500 IDEG =
XARG=
XARG=
XARG =
XARG =
0,9500
0.9500
0.1000
XARG = - 0 . 1 0 0 0
0.5500
IDEG
IDEG
IDEG
IDEG
IDEG
-
=
=
=
=
XARG = 1.1000 IDEG =
XARG= 2.0000 IDEG =
XARG= 2.0000 IDEG =
XARG = 2.0000 IDEG =
XARG = 2.0000 IDEG =
XARG = 2.0000 IDEG =
XARG= 2.0000 IDEG =
Example 1.1 Interpolation with Finite Divided Differences
Computer Output
THE SAMPLE FUNC:TIONAL VALUES ARE
FOR M = 6, THE D I V I D E D D I F F E R E N C E S A R E
In condensed form, (1.47), with the coefficients of (1.48) Example. Use the Lagrange form of (1.43) and (1.44) to find
substituted, yields the Lagrange form of (1.43). the second-degree interpolating polynomial passing through
Note that the Lagrange form involves only the base the three points in Table 1.7 (see Table 1.2).
points xi and the corresponding functional values f (xi). Table 1.7 Functional Values
The divided differences of Newton's fundamental for-
mula need not be computed at all. When only one inter-
polation is to be carried out, the amount of computation
required by the divided-difference and Lagrange formulas
is roughly equivalent. Less computer storage is required
for the Lagrange formula, of course, since there is no
need to save the divided-difference table.
The Lagrange form has two significant disadvantages For this case,
aside from the excessive amount of calculation required
when many interpolations are to be done using the same
data set. Since the divided differences are not computed,
the error estimate of (1.33) has little relevance. Normally,
no estimate of the error can be made, since the error
bound of (1.39b) is not applicable unless high-order der- (x-o)(x-1) x2-x
ivatives can be evaluated (not the usual case). Also, the =-
addition of a new term (that is, increasing the degree of
L'(x)= (3 - 0)(3 - 1) 6 '
the polynomial by one), which is a simple matter when and
using Newton's form, requires complete recomputation + +
p2(x) = -5 Lo(x) Ll(x) 25 L ~ ( x = +
) 2x2 4x - 5 ,
of all the Li(x) values for Lagrange's form. Thus the which is identical with the polynomial found previously for
Lagrange form is not well-suited for cases in which the the same data using the divided-difference form of the inter-
desired polynomial degree is not known a priori. polating polynomial.
EXAMPLE 1.2
LAGRANGIAN INTERPOLATION
emf
(microvolts)
Temperature
03
i = min, min + 1, . .., min + d.
The program that follows is a straightforward imple-
mentation of (1.2.1) and (1.2.2), except that some
calculations (about d2 multiplications and d 2 subtrac-
+
tions, at the expense of d 1 divisions) are saved by
writing (1.2.2) in the form
j = min
j+i
/n,
XI, .. .7 X, ' Z,d, min
Y17 - --,Yn
vf
0 Return
j = m i n , min + 1, i = min,min + 1,
Return
-------- 4
--
FORTRAN Implementation
List of Principal Variables
Program Symbol DeJinition
(Main)
I Subscript, i.
IDEG Degree, d, of the interpolating polynomial.
MIN Smallest subscript for base points used to determine the interpolating polynomial, min.
N n, the number of paired values (xi, yi =f (xi)).
X Vector of base points, x i .
XARG Interpolation argument, x.
Y Vector of functional values, y i =f (xi).
YINTER Interpolant value, J(jS).
(Function
FLAGR)
FACT0 R The factor c (see (1.2.4)).
J ' Subscript, j.
MAX Largest subscript for base points used to determine the interpolating polynomial, min + d.
TERM t , a variable that assumes successively the values Li(jS)yi in (1.2.1).
YEST Interpolant value, jj(Z).
ExampIe 1.2 Lagrangian Interpolation
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 1.2
C LAGRANGE'S INTERPOLATING POLYNOMIAL
C
C TEST PROGRAM FOR THE FUNCTION FLAGR. T H I S PROGRAM READS A
C SET OF N VALUES X(l)...X(N) AND A CORRESPONDING SET OF
C FUNCTIONAL VALUES Y(l)...Y(N) WHERE Y ( I ) = F ( X ( I ) ) . THE
C PROGRAM THEN READS VALUES FOR XARG, IDEG, AND M I N (SEE FLAGR
C FOR MEANINGS) AND CALLS ON FLAGR TO PRODUCE THE INTERPOLANT
C VALUE, Y I NTER.
C
I M P L I C I T REAL*8(A-H, 0-2)
DIMENSION X(100), Y(100)
C
C .....
READ N,
READ (5,100)
X AND Y VALUES, AND PRINT
N, ( X ( l ) , l=l,N)
.....
READ ( 5 , 1 0 1 ) ( Y ( I l 0 l=l,N)
WRITE (6.200)
DO 1 I = ~ , N
1 WRITE (6,201) I, X ( l ) , Y(l)
C
C .....READ INTERPOLATION ARGUMENTS, CALL ON FLAGR,
WRITE (6,202)
AND P R I N T .....
2 READ (5,102) XARG, IDEG, M I N
YINTER = FLAGR ( X,Y,XARG,IDEG,MIN,N )
WRITE ( 6 , 2 0 3 ) XARG, IDEG, MIN, YINTER
GO TO 2
END
Function FLAGR
4 IF (I.KZ.J) -TERM = T E R M / ( X ( I ) - x ( J ) )
5 YEST = YEST + TERM
FLAGR = YEST
RETURN
C
END
Data
N = 13
X(l)...X(5) = 0. 500. 1000. 1500. 2000.
X(6)...X(lO) = 2500. 3000. 3500. 4000. 4500.
X(ll).,.X(l3) = 5000. 5500. 6000.
Y(l)...Y(S) = 32.0 176.0 296.4 405.7 509.0
Y(6)...Y(10) = 608.4 704.7 799.0 891.9 983.0
Y(ll)...Y(l.3) = 1072.6 1160.8 1247.5
XARG = 300. IDEG = 1 MIN = 1
XARG= 300. IDEG = 2 MIN = 1
XARG= 300. IDEG = 3 MIN = 1
XARG= 300. IDEG = 4 MIN = 1
XARG = 1700. IDEG = 1 MIN = 4
XARG = 1700. IDEG = 2 MIN = 3
XARG = 1700; IDEG = 2 MIN = 4
XARG = 1700. IDEG = 3 MIN = 3
XARG -
XARG = 1700.
1700.
IDEG = 4
IDEG 0 4
MIN =
MIN =
2
3
XARG = 2500.
XARG = 2500.
XARG = 2500.
XARG = 2500.
XARG = 2500.
IDEG = 1
IDEG = 1
IDEG = 2
IDEG = 3
IDEG = 3
MIN =
MIN =
MIN
MIN =
MIN =
- 5
6
5
4
5
XARG = 2500. IDEG = 4 MIN = 4
XARG = 3300. IDEG = 1 MIN = 7
XARG = 3300. IDEG = 2 MIN = 6
XARG = 3300. IDEG = 2 MIN = 7
XARG = 3300. IDEG = 3 MIN = 6
XARG = 3300. IDEG = 4 M'IN = 5
XARG = 3300. IDEG = 4 MIN = 6
-
XARG = 3300.
XARG
XARG = 3300.
3300.
IDEG = 5
IDEG = 6
IDEG = 6
MIN =
MIN=
MIN=
5
4
5
XARG = 3300. IDEG = 7 MIN = 4
XARG = 3300. IDEG = 8 MIN = 3
XARG = 3300. IDEG = 8 MIN = 4
XARG = 3300. IDEG = 9 MIN = 3
XARG = 5300. IDEG = 1 MIN = 11
XARG = 5300. IDEG = 2 MIN = 10
XARG = 5300. IDEG = 2 MIN = 11
XARG = 5300. IDEG = 3 MIN = 10
XARG = 5300. IDEG = 4 MIN = 9
XARG = 5900. IDEG = 1 MIN = 12
XARG = 5900. IDEG = 2 MIN = 11
XARG = 5900. IDEG = 3 MlN = 10
XARG = 5900. IDEG = 4 MIN = 9
Example 1.2 Lagrangisn hterpolatien
Computer Output
THE SAMPLE FUNC'TIONAL VALUES ARE
Discussion of Results While the base points used as test data were ordered in
All computations have been carried out using double- ascending sequence and equally spaced, the program is
precision arithmetic (8 byte REAL operands); for the not limited with respect to either ordering or spacing of
test data used, however, single-precision arithmetic would the base points. For greater accuracy, however, one would
have yielded results of comparable accuracy. Since the normally order the base points in either ascending or
true functionf (x), for which y i =f(xi), is unknown, it is descending sequence, and attempt to center the inter-
not possible to determine an upper bound for the inter- polation argument among those base points used to
polation error from (1.39b). However, comparison of the determjne the interpolating polynomial. This tends to
interpolant values with known functional values from keep the polynomial factor
Table 1.2.1 for the arguments used as test data, shows
that interpolation of degree 2 or more when the argu-
ment is well-centered with respect to the base points,
generally yields results comparable in accuracy to the
experimentally measured values. The results for 2 = 300 and hence the error term comparable to (1.39b), as
are less satisfactory than for the other arguments, small as possible. This practice will usually lead to more
possibly because the argument is near the beginning of satisfactory low-order interpolant values as well. The
the table where the function appears to have considerable program does not test to insure that the required base
curvature, and because centering of the argument among points are in fact available, although a check to insure
the base points is not practicable for large d. that min > 0 and max 6 n could be inserted easily.
1.8 Polynomial Interpolation with Equally Spaced Base Points 35
1.8 Polynomial Interpolation with Equally Spaced The relationship between a given forward finite dif-
Base Points ference and the corresponding finite divided difference of
Table 1.1 is a simple one:
When the base-point values are equally spaced so
thatx,-xo=x2-x,==x3-x2=-..=x,-x,-,=h,
then, as we would expect, some simplification of the
divided-difference or Lagrange formulation is possible.
The interpolating polynomial will be developed in terms Similarly,
of the forward (A), backward (V), and central (6) difference
opbrators. These are linear operators, that is,
In general,
+ (x - xo)(x - XI)
(X - Xn- l)f Cxn,xn- l r . ., XOI,
and
R,(x) = (x - xo)(x - x,) ...(x - xn- ,)(x - x,)
Notice that for this third-degree polynomial, the third Rn(4 = (x - xo)(x - x,) ...(x - x,- ,)(x - x,)
forward differences are constant and the fourth forward f '"+
"(5)
difference is zero. X-
(n + I)! ' 5 in (x,x,,x,-, , , .., xo).
36 Interpolation and Approximation
In terms of a and the forward-difference operator, New- Substitution into (1.54) yields
ton's fundamental formula assumes the form
f "(5)
x --
'"+
X, < 5 < x,. (1.60) Since f ( x ) = x 3 - 2 x 2 f 7 x - 5 is a third-degree polynomial,
(n+ I)!' this predicted value is the exact value, that is,'the higher-order
In terms of a and th~ebackward differences, (1.60) differences vanish as before.
becomes Central Differences. In Section 1.6 it was shown that
the interpolation error tends to be smallest when we fit
f (x, + ah) =f (x,) + aV f (x,) + -
2!
v y (x,) +
the interpolating polynomial with base points on both
sides of the interpolation argument. This can be effected
by choosing a path through the divided-difference table
which zizgags about some base point near the interpola-
tion argument. Stated another way, this means that if a
central path is taken across the difference table, more of
the functional value is represented by leading terms in the
difference formulation (the sequence converges faster).
x V"f(xn) + Rn(xn+ ah) Consequently, a low-order central interpolation may pro-
(1.61) duce answers with remainder terms no larger than a
where higher-order fit using the forward or backward paths.
Of course, if the same base points are used to produce
polynomials of equivalent degree, then all paths are
equivalent.
A simple notation which describes differences along a
zigzag path near the center of the difference table is
+
Rn(xn ah) = hn ' a ( a + + l ) ( a + 2). ..( a + n ) needed. The central-diflerence operator ( 6 ) is defined as
X
f-- '"+
"(S)
Xo < 5 < X,.
follows :
(n + I ) ! '
If an additional base point x - , = x, - h should be
available, then the (n + 1) th divided difference may be
approximated by
values xi + h/2, xi - h/2, etc. However, these "fictional" n = 2r + 1 is odd, then the forward formula agrees
values are simply ignored and instead the odd differences exactly with the data at x-,, x-,+,, . .., x,, . . ., xr-,, x,,
are evaluated at mid-interval. Thus the even and odd x,+,, and the backward formula agrees at x-,-,, x-,,
differences are evaluated separately as follows : ,
x-,+ ,, . . ., x,, . . ., x,- , x,. Stirling's formula, occasion-
ally mentioned in the literature, is simply the average of
For 2r = n (even): these two Gauss central-difference formulas:
--
n! hn
-f [xi,xi+ I,. . ., Xi+,,ii-,I.
For 2r + 1 = n (odd):
If the zigzag path along the solid lines is taken, the for- The differences of Table 1.8 with subscripts adjusted as
mulation is termed the Gaussforward formula and is given shown in Table 1.10 are illustrated in Table 1.11.
by
Table 1.! I Central-DifferenceTable
f (xo + ah) =f (xo) + a6f (xo + h/2)
+ @(a- 1)62f(xo)/2!
+ a(a - l)(a + 1)63f(xo + h/2)/3!
+ .. . + R,(x, + ah), (1.65)
The cosine functions, cos 8, cos 26, . . ., cos no, appear Table 1.12 The Chebyshev Polynomials
to be good candidates. Each of the functions has identical
maximum and minimum values distributed regularly over
an arbitrary interval, say 0 C 8 C n; in addition, the
extreme values for two functions cosj8, cos k8, j # k, do
not, in general, occur at the same values of x (see Fig. 1.9).
As shown earlier (1.7), the cosine function requires an
approximation for its numerical evaluation. A simpler
and more useful form results from the transformation of
cos n0 on the interval 0 C 8 C n into an nth-degree poly-
nomial in x on the interval - 1 C x < 1. The set of poly-
Figure 1.11 &(x), the second-degree monic polynomial that deviates least fiom zero on [- 1,1].
roots of the corresponding Chebyshev polynomial argument is straightforward. Suppose that pn(x) =f (x) -
Tn+l(x), given by d(x) is a better approximation to f(x) than is a given
polynomial p,*(x) that exhibits the equal-magnitude
oscillatory behavior for its error (such an error function
is said to possess the equal ripple property). Then
For an arbitrary interval, a < z < b, the appropriate zi -
d*(x) - d(x) = p,(x) pz(x) is evidently a polynomial
values may be computed by transforming these root of degree n, alternately positive and negative at the n + 2
values from [- 1,1] to [a,b], using the inverse of (1.68), or more points where d*(x) passes through its extreme
values, since at these points, by hypothesis, Id(x)l <
Id*(x)(. Since no polynomial of degree n possesses n + 1
roots (changes in sign), the contention that p:(x) is the
This minimization of maximum error is sometimes termed polynomial of degree n that minimizes the maximum de-
the minimax principle. viation from f (x) on the interval of interest is proved by
The application of the minimax principle is poss- contradiction. The polynomial p:(x) is called the mini-
ible only when there is a freedom of choice in selec- max polynomial of degree n.
ting the base points xi. Fortunately, this is often the case We assume that f(x) is a single-valued continuous
in experimental work where one has control over the function on the closed interval [a,b]. Then d*(x) is con-
independent variable values which may be used subse- +
tinuous and p*,(x) must be equal to f (x) at n 1 distinct
quently as base points for polynomial interpolation. For points x,, xi, . . ., x,, where each x i lies between two
example, the sampling time for an experiment may be points at which the error achieves its extreme value. Thus
the independent variable of interest. Then for a fixed total the minimax polynomial p,*(x) is an nth-degree inter-
time interval, during which a fixed number of samples are polating polynomial. When f(x) possesses an (n + 1)th-
to be taken, the best times for taking sample measurements order derivative, the error term (1.39b) applies, and the
are given by the transformed roots of the appropriate problem reverts to that of the early paragraphs of this
Chebyshev polynomial. section. Iff("+ "(x) is a constant, then the interpolating
A more general but related problem is to find that polynomial using the base points given by (1.77) is pre-
approximating polynomial p:(x) of degree n which cisely p $ ( ~ ) if
; not, then the interpolating polynomial so
satisfies generated is only an approximation to p,*(x).
The problem of findingp*,(x) when f '"+''({) in (1.39b)
is unknown or variable in [- 1,1], becomes an iterative
one. The procedures commonly used (see for example
[16]) follow from the work of Remes [15] and are rather
that is, minimizes the maximum deviation from f(x) on complex; they will not be described here.
[ - l,l] (or, in general, on [a,b]). One can show [I41 that Clenshaw [17] shows that if the function f(x) can be
p,*(x) is unique and that the deviation, d*(x) =f(x) expanded in terms of the Chebyshev polynomials as
- pf (x), must attain its maximum magnitude at not less
than n + 2 distinct points in [- 1,1] (or [a,b]) and be
alternately positive and negative at these points. The
1.12 Chebyshev Economizar'ion-Telescoping a Power Series 43
which is in error by no more than 5 x lo-' (see the results some 28 times the specified value. While it would appear
of Example 1.3). The logical starting place is with the at first glance that the original series could be truncated
power series expansion after the term in x6 (since 1/8 ! G 2.5 x 10- ' < 5 x lo-')
44 Interpolation and Approximation
before expansion in the Chebyshev polynomials, this is Table I . 14 Values of F(z), F(z) and 6(z)
not the case. The coefficient of T, in the expanded form from Figure 1 .I2
would have been 4.34 x lo-', and this plus 2.5 x
would have exceeded the specified bound.
Consider another similar problem. Using the econo-
mization procedure, find a linear approximation for the
function
F(z) = z3 (1.88)
on the interval 1 < z < 3.
First, use (1.68) to transform the given function F(z)
on the interval 1 < z ,< 3 to the new function f(x) on the is shown graphically in Fig. 1.13. The local minimum
interval - 1 < x d 1 where x = z - 2. Then (found by equating the derivative to zero) is at z = 2.06
and equals - 3.06. The local maximum error, at z = 3,
equals 3t. In this case, the true maximum error is the
same as the known error bound because T,Cx) and T,(x)
Using Table 1.13, f (x), in terms of the Chebyshev poly- both achieve their maximum values (1.0) at x = 1
nomials, becomes (or z = 3).
where
n
E= C biT(x), (1.3.6) is the binomial coefficient.
i=rn+l The subroutine TRANS computes values for the d:,
and given the d,, n, L,, R,, L2, and R2. A function called
n
NOMIAL evaluates the binomial coefficient of (1.3.13),
when needed by TRANS.
The economized polynomial prn(x)should be rewritten To implement the transformations from (1.3.2) to
as (1.3.4) and from the economized polynomial p,(x) in
terms of the Chebyshev polynomials to (1.3.8), it is
convenient to set up two 10 x 10 matrices X and T,
containing the coeffcients from Tables 1.12 and 1.13.
using Table 1.12. Finally, (1.3.8) should be transformed The matrix X contains the coefficients from Table 1.13
to the original variable z on the interval [L,R], using arranged so that element Xipjcontains the coefficient of
(1.3.3), to yield Tj for the expansion of x i in terms of the Chebyshev
rn
polynomials, as illustrated in Table 1.3.1.
The matrix Tcontains the coefficients from Table 1.12,
The program should print the input data, the coefficients arranged so that is equal to the coefficient of the jth
of the various polynomials as they are computed, and the power of x for the ith Chebyshev polynomial, Ti, and is
value of Ern,,. illustrated by Table 1.3.2. This organization of the
To simplify the transformation from (1.3.1) to (1.3.2) matrices X and T Ieads to rather simple subscription
and from (1.3.8) to (1.3.9), write a general purpose schemes for carrying out the economization process, but
subroutine named TRANS that converts an nth-degree is not essential. To economize on computer memory
Example 1.3 Chebysheu Economization
requirements, the tables could be packed tightly to where Ai = 2 indicates that i is to be incremented by 2;
eliminate all nonzero entries; this would, of course, lead this allows the zero entries in X to be ignored.
to a different subscription scheme. Once the economized polynomial pm(x) has been
Having found the a* in (1.3.2), the coefficients of found, using criterion (1.3.7), the coefficients of (1.3.8)
(1.3.4) can be computed from can be computed from
Flow Diagram
Main Program
Transform the polynomial
a07 ..-,an
on the interval - 1 d x 6 1
to the polynomial I
< R.
on the interval L < z
(Subroutine TRANS) I
Example 1.3 Chebyshev Economizution
calling arguments :
-
n, a, a*, L,R, 1 , 1
[in, c*, c, -1, 1, L, R
I
I
I
I
1
,.----.
I
I
1
I
I I
I
I
I
T I
I
I I
I I
I
I
I
I
Y m Y I
I
I
I
I
d: tdt + (:) kpd, di* c dl I
II
I I
I (Function NOMIAL) II
I I
I I
I I
1
I I
I I
I I
L---,,,-, I
I
I
FORTRAN Implementation
List of Principal Variables
Program Symbol Dejnition
(Main)
A, ASTAR, B, Vectors of polynomial coefficients ai , a,*,bi , ci , and c:.
c, C S T A R ~
AL, AR Lower bound, L, and upper bound, R, for the interval of interest in the variable z.
EMAX Em,, maximum possible error introduced by the economization procedure.
EPS E,maximum allowable error to be introduced by the economization process.
I. ISUB, +
Subscripts, i, n + 2 - i, j, n 1, and m 1. +
J, NP1, M P l t
M m, degree of the economized polynomial.
N n, degree of the starting polynomial.
ONE, ONEM 1.O, - 1.0 (double-precision).
TToxt Matrix of coefficients for converting from a polynomial in terms of Ti(x) to a polynomial ia
terms of xi, TiSj(see Table 1.3.2).
Matrix of coefficients for converting from a polynomial in terms of xi to a polynomial in terms
of Ti(x), XiVj(see Table 1.3.1).
(Subroutine
TRANS)
BlNOM Binomial coefficient calculated by function NOMIAL.
COEFFI, COEFFTt Vectors of coefficients for the initial and transformed polynomials, d, and d,*, respectively.
CON1, CON2 -
Constants k, = (R, L1)/(R2- L,)
and k, = (L, R, - R,L,)/(R, - L,).
ENDLI, ENDLT Lower bounds for the initial and terminal intervals, respectively.
ENDRI, ENDRT Upper bounds for the initial and terminal intervals, respectively.
(Function
NOMIAL)
ICOUNT Counting variable.
K, L Arguments for the binomial coefficient, k, I.
NOM Binomial coefficient g =
Program Listing
Main Program
A P P L l ED NUMERl CAL METHODS, EXAMPLE 1.3
CHEBYSHEV ECONOMlZATlON
I M P L l C l T REAL*8(A-H, 0-2
D I M E N S I O N A ( l O ) , ASTAR(101, B(101, CSTAR(lO), C(10), XTOT(lO,lO),
1 TTOX( 1 0 , l O )
DATA TTOX / 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0,
12.0.0, 1.0, 0.0, -3.0, 0.0, 5.0, 0.0, -7.0, 0.0, 9.0, 2.0.0,
2 2.0, 0.0, -8.0, 0.0, 18.0, 0.0, -32.0, 4.0.0, 4.0, 0.0, -20.0,
3 0.0, 56.0, 0.0, -120.0, 4.0.0, 8.0, 0.0, -48.0, 0.0, 160.0,
4 6.0.0, 16.0, 0.0, -112.0, 0.0, 432.0, 6.0.0, 32.0, 0.0, -256.0,
5 8.0.0, 64.0, 0.0, -576.0, 8*0.0, 128.0, 10.0.0, 256.0 /
C
C
DATA ONE, ONEM / 1.0,
I N T DATA .....
..... READ AND N,P REPS,
-1.0 / ,
.' C
\
,
,>
. "'<
'\
-,
i \*
1 READ (5,100) AL, AR
I F ( N.GT.9 ) CALL E X I T "y,,.\
NP1 a N + 1
k
,.:-r
e.
\+
. -xu
READ ( 5 , 1 0 1 ) ( A ( ! 1, I a 1 , N P l )
/#
WRITE ( 6 , 2 0 0 ) N, EPS, AL, AR, NP1, ( A ( I 1, I=l,NPl) \
\\
-2
"CP
C ~
C
C
..... TOTRANSFORM POLYNOMIAL I N Z ON INTERVAL (AL,AR)
A POLYNOMIAL I N X ON THE INTERVAL (-1,l) .....
C A L L TRANS( N,A,ASTAR,AL,AR,ONEM,ONE )
WRITE ( 6 , 2 0 1 ) NP1, ( A S T A R ( I ) , I = l , N P l )
C
C ..... EXPAND TRANSFORMED POLY. I N TERMS OF CHEBY.
DO 3 J = l , N P l
POLYS. .....
B ( J ) = 0.0
DO 3 I*J,NP1,2
3 B ( J ) = B ( J ) + ASTAR(l)*XTOT(I,J)
WRITE (6,202) NPl, ( B ( I ) , I=l,NPl)
52 Interpolation and Approximation
5
MP1 = N P I - I
EMAX = EMAX + DABS(B(ISUR))
-
I
:
C
6
..... CONVERT ECONOMIZED POLYNOMIAL TO POWERS OF X
M = M P l - 1
.....
DO 7 J = l , M P l
CSTAR( J ) 5 0.0
202
1 5H) ARE/ 1H / ( 1 H .
FORMAT ( 1HO/ 1HO/ 35H THE COEFFICIENTS ASTAR(l)...ASTAR(.Il, -
1P5E16.6))
FORMAT ( 1HO/ 1HO/ 27H THE COEFFICIENTS B(l)...B(,
-
11, 5H) ARE/
1 1H / ( 1 H , 1PSE16.6))
203 FORMAT ( 1HO/ l t i O / 35H THE COEFFICIENTS CSTAR(l)...CSTAR(, 11,
1 5H) ARE/ 1H / ( 1 H , 1P5E16.6))
204 FORMAT ( 1HO/ 1HO/ 49H THE ECONOMIZED PPLYNOMIAL ON THE INTERVAL (
1 AL = ,F10.4,2H4 ,5H AR = ,F10.4,8H I S OF/11H DEGREE M =, 12,ZH.
2 53H THE MAXIMUM ERROR ON THIS INTERVAL I S NO LARGER THAN,lPE15.7,
3 1H./27HOTHE COEFFICIENTS C(1). ..C(, 11, 5H) ARE/ 1H /
4 (1H , lP5E16.6))
C
END
Subroutine TRANS
SUBROUTI NE TRANS( N, COEFF I, COEFFT, ENDLI ,ENDRI ,ENDLTANDRT )
C
TRANS CONVERTS AN N-TH DEGREE WLYNOMIAL I N ONE VARIABLE
(SAY Z) ON THE INTERVAL (ENDLI,ENDRI) HAVING COEFFICIENTS .
.
COEFFI (1). .COEFFI ( N + l ) INTO AN N TH DEGREE POLYNOMIAL
I N A SECOND VARIABLE (SAY X) ON THE INTERVAL (ENDLT,ENDRT)
WITH COEFFICIENTS COEFFT(l)...COEFFT(N+l) WHERE THE TWO
VARIABLES X AND Z ARE RELATED BY THE TRANSFORMATION
I M P L l C l T REAL*8(A-H, 0-2)
REAL*8 COEFF I, COEFFT, ENDLI , ENDR I, ENDLT, ENDRT
DIMENSION COEFFI (101, COEFFT(10)
C .I F....CON2.NE.0.0
(
C H E ~ KFOR C O N 2 1 0 TO A V O I D COMPUTING 0. * * 0
GO TO 2
.....
4 COEFFT(1) a COEFFT(l)*CONl*+(I-1)
RETURN
C
END
Function NOMIAL
F U N C T I O N N O M I A L (K, L )
C
C N O M I A L COMPUTES THE B I N O M I A L C O E F F l C l E N T (K,L).
C
NOM = 1
I F ( K.LE.L .OR. L.EQ.O GO TO 4
DO 3 I C O U N T = l , L
3 NOM = N O M * ( K - I C O U N T + l ) / I C O U N T
4 N O M I A L = NOM
RETURN
C
END
Data
N = 3 E PS
A(l)...A(4) =
N u 3 E PS
A(l)...A(4) =
N = 3 EPS
A(l)...A(4) =
N = 3 E PS
A(l)...A(4) =
N = 3 E PS
A(l)...A(S) =
N = 8 EPS
A(l)...A(4) =
A(5)...A(8) =
A(9) =
N = 8 E PS
A(l)...A(4) =
A(S)...A(8) =
A(9) =
N E 8 EPS
A(l)...A(b) =
A(5)...A(8) =
A(9) =
N u 8 E PS
A(l)...A(4) =
A(S)...A(8) =
A(9) =
N = 2 E PS
A(l)...A(3) =
N = 2 E PS
A(l)...A(3) =
N = 2 E PS
A(l)...A(3) =
Interpolation and Approximation
Computer Output
Results for the 2nd Data Set
N = 3
EPS = 0.32600D 01
AL = 1.0000
AR = 3.0000
1.100000D 01 1.275000D 01
-1.450000D 01 1.275000D 01
.
THE COEFF l C l ENTS ASTAR( 1). .ASTAR( 3 ) ARE
8.210625D 0 0 3.9250000-01
1.0331250 00 7.85OOODD-04
58 Interpolation and Approximation
Discussion of Results
Five different polynomials were used in the twelve test
data sets as follows:
ex = 1 + x, sin x = x
are sometimes employed. In each case, use the error term from
Taylor's expansion to estimate how large a value of x (to the
nearest 0.001) may be employed with the assurance that the
error in the approximation is smaller than 0.01. Check your
conclusions against tables of exponentials and sines. (b) Without renumbering the abscissas, write down the
1.3 Let M be the maximum magnitude of f"(x) on the divided-difference polynomial that uses the elements denoted
interval (xo, xl). Show that the error for linear interpolation by asterisks.
for f (x), using the functional values at xo and xl, is bounded by (c) What is the likely error bound for a fourth-degree inter-
polation with xo < x < x s ?
(d) Find the value of f(x) predicted by the polynomial of
for xo < x < xl. Does this same error bound apply for linear (b) for x = 1.0.
extrapolation, that is, for x < xo or x > XI ? (e) Find the value off (x) predicted by tagrange's second-
1.4 Use the algorithm of (1.12) to evaluate degree interpolating polynomial at x = 1.0, using the three
base points XI, x2, and x3.
1.9 Form the divided-difference table for the data in
Table P1.9.
and each of its derivatives at x = 2.5.
1.5 Write a function, named POLY, that implements the
Table P1.9
algorithm of (1.12) to evaluate an nth-degree polynomial
p.(x) = x7=oa,xi, and each of its derivatives of order 1 X f(4
through n at x = 2. The function should have the dummy
argument list
(N, A, XBAR, DVAL)
1.8 Consider the divided differences in Table P1.8. (d) Estimate the error when the polynomial of part (a) is
(a) What is the significance of the zero at the top of the used for interpolation (or extrapolation) with arguments
seventh column ? x = 1.75, 2.3, and 4.0.
Probler
Table P1.10 first two columns are calculated one column at a time, then
each entry may be evaluated using just two multiplications,
two subtractions, and two divisions.
(b) Generate a table comparable -to that of part (a) for
the functional values of Tables 1.2 and 1.4 with interpolant
value x = 0.5, and compare with the results for various
degrees of interpolation shown in Section 1.6.
1.13 The interpolation method suggested in Problems 1.11
and 1.12 is known as iterated linear interpolation or Aitken's
method. Implement the method by writing a subroutine,
named AITKEN, that could be called from another program
with the statement
CALL AITKEN (X, Y, NMAX, N, ATABLE, XARG)
(e) Given the information that the tabulated function of where the data points (xi,yi) are available in the arrays X
+
Table P1.10 is f(x) = 6x 2 cos x 2 - 4x2 sin x Z --5x-l, find and Y with subscripts 1, 2 , . . ., NMAX, and the X array is
the error bound for quadratic interpolation (interpolating arranged in ascending sequence. The subroutine should scan
polynomials of degree 2) using three successive base points the X array to find the element nearest the argument,
x i , X, + x i + 2, with X, < x < x i + 2. Does the bound change x = XARG, and designate it as x o for Aitken's interpolation.
appreciably over the range of the table? AITKEN should then develop the appropriate entries for
1.11 Let yi = f(xi), i = 0, I , . . ., n. Show that Newton's +
columns 3 through n 2 of Aitken's table in columns 1
fundamental formula (1.30) for the polynomial of degree one through N of the matrix ATABLE, and return to the calling
passing through the points (xi, y,) and (xk,yk)may be written program.
in the form Write a short main program that reads values for NMAX,
X(1). . . ., X(NMAX), and Y(1). . . ., Y(NMAX) just once, and
then repeatedly reads values for N and XP.RG, calls upon
AlTKEN to compute the elements of ATABLE, and prints the
where the vertical bars indicate the determinant (see Chapter matrix ATABLE.
4). Let y,, ,,,, . . . . ,,(x) be the interpolating polynomial of 1.14 When f(x) is a single-valued function of x, and a
degree rn passing through the points p o , p l , .. .,p,. Show that value of x is required for which the dependent variable f(x)
assumes a specified value, the role of independent and dcpen-
dent variable may be interchanged, and any of the appropriate
interpolation formulas may be used. The process is usually
termed inverse interpolation.
Choose the thermocouple emf and temperature data from
Table 1.2.1 corresponding to xo = 0, XI = 500, x 2 = 1000, etc.,
and use inverse interpolation to find approximations of the
emf corresponding to temperatures of 122.4, 118.4, 121.932,
447.6, and 447.02"F for interpolation of degrees I, 2, and 3.
Note that each of the second-degree interpolating polynomials Compare your results with Table 1.2.1 and the computer
can be described in terms of linear interpolation on two output for Example 1.2.
linear interpolating polynomials, and that the third-degree 1.15 Suppose that J ( X ) is the value of the nth-degree inter-
interpolating polynomial can be described in terms of linear polating polynomial passing through the points (xk,yk),
interpolation on two second-degree interpolating polynomials. (XX+I,YX+I), ..., (~k+n,~k+n)rwhere Y I = f (xi) and f(x) is a
1.12 (a) Using the definitions of Problem 1.11, consider single-valued function of x. Carry out an inverse interpolation
Table P1.12: using the same points with J as the argument and let the inter-
polated result be denoted by f*. Comment on the following
statements:
(a) f* will be identical t o P.
(b) the smaller the value of If* - f 1, the better the value of
j; will approximate f (x).
1.16 Show that Lagrange's interpolating polynomial (1.43)
can be written in the form
where
Show that if each of the quantities (xi - x), i = 0, 1, ..., n, is ,, drk)
computed first, and that if entries in the table following the n(x)= n ( x - xl) and nl(x)=-
I=O dx '
62 Interpolation and' Approximation
1.17 In Example 1.1, how would you modify the main 1.22 If the method of Problem 1.21 appears feasible and
program, thesubroutine DTABLE, and the function PNEWf, So can be applied generally, write a subroutine, named CHECK,
that the matrix TABLE could be eliminated and replaced by a that will implement it. Also write a short main program to
vector (one-dimensional array) TABLE? handle input and output and call on the subroutine as follows:
Hint: Only the elements on the appropriate diagonal sf
CALL CHECK (X, F, N, ANSWER, TRUEF)
TABLE are actually used in the evaluation of Newton's
fundamental formula (I,! .6). Here, X and F are the vectors that contain the tabulated values
1.18 How could you modify the function PLAGR of of x and f(x), and N is the subscript corresponding to the last
Example 1.2 so that the function would choose the appropriate entry in the table. ANSWER is a logical vector; according to
base points, and the argument MIN would be unnecessary? whether an entry F(1) is found to be in error or not, the sub-
1.19 The values shown in Table P1.19 are available [24] routine should store the logical value .FALSE. or .TRUE. in the
for the thermal conductivity, k (BTU/hr ft OF), of carbon corresponding element ANSWER(1). The vector TRUEF should
dioxide gas and for the viscosity, p (Ib/ft hr), of liquid ethylene ultimately contain the corrected table of values for/(x). Since
glycol, at various temperatures T("F). it is generally impossible to distinguish between an error in x
Table P1.19
and one in f(x), attempt only to correct the latter if a dis-
crepancy is found.
1.23 Write a function, named STIRL, that uses Stirling's
formula, equation (1.67), to implement an mth-degree central-
difference interpolation on the data values ( x t ,f(x,)), i = 1, 2,
. . ., n. Assume that the x, are evenly spaced and are arranged
in ascending order. The calling sequence should be of the form
FVAL = STIRL (X, F, M, N, TEMP, XVAL. NOGOOD)
Here, we consider linear interpolation. Let XI < x < XI + I , print the interpolated value FXY, and filially return to read
and y, G y < y j + ~as
, shown in Fig. P1.28. The symbol additional pairs of values for XVAL and YVAL.
indicates points at which functional values are available.
Suggested Test Data
(a) The values shown in Table P1.29a are given by Perry
[24] for the specific volume, v (cu ftllb), of superheated
methane, at various temperatures and pressures. Estimate the
specific volume of methane at (56.4"F, 12.7 psia), (56.4, 22.7),
(56.4,100),(411.2,12.7),(411.2,30.1),(-200,10),and (0, 84.3).
To test LlN2D completely, also try a few temperatures and
pressures beyond the scope of the table,
(b) The values shown in Table P1.29b are given by Perry
[24] for the total vapor pressures,p (psia), of aqueous solutions
of ammonia, at various temperatures and molal concentrations
of ammonia.
First, interpolate linearly through frj and fr + and through Temp. Percentage Molal Concentration of Ammonia
fi.j+l and fr + l , j + l , to obtain approximations f, and fa to "F 0 10 20 25 30 35
f (x,y) at the points A and B. Then interpolate linearly through -
fA and fa to obtain the final approximation to f(x,y). If 60 0.26 1.42 3.51 5.55 8.65 13.22
u = ( X - xI)I(xI+~ -XI), and P = (Y-yj)lOIJ+l - yj), show 80 0.51 2.43 5.85 9.06 13.86 20.61
100 0.95 4.05 9.34 14.22 21.32 31.16
that the result is
140 2.89 9.98 21.49 31.54 45.73 64.78
180 7.51 21.65 44.02 62.68 88.17 121.68
220 17.19 42.47 81.91 113.81 156.41 211.24
250 29.83 66.67 124.08 169.48 229.62 305.60
What would be the corresponding formula if the first interpo-
lation were in they direction, to give fc and fD, followed by
interpolation in the x direction? Estimate the total vapor pressure at (126.5"F, 28.8 mole %),
Give a simple graphical interpretation, based on relative (126.5, 6.7), (126.5, 25.0), (60, O), (237.5, 17.6), and (237.5,
areas, to the weight factors assigned in the above formula to 35.0).
Srj,fr.j+~,fr+~.,,
andfr+l.j+l. 1.30 Extend the scheme outlined in Problem 1.28 to two-
1.29 Write a function, named LINZD, that will perform the dimensional cubic interpolation. The known functional values
two-dimensional linear interpolation discussed in Problem 1.28. that will be involved are denoted by thesymbol in Fig. P1.30.
A typical call will be The successive values XI and y, need not be equally spaced.
FXY = LlN2D (F, X, Y, M, N, XVAL, YVAL)
Here, F, X, and Y are the arrays that have been preset with the
tabulated valuesfrj, xi, and yj, M and N have obvious mean-
ings, and XVAL and YVAL correspond to the values x and y
for which f(x,y) is to be estimated. If x and/or y lie outside the
range of the table, the function should print a message to this
effect and return the value zero.
Also, write a main program that will read values for M, N,
the matrix F, the vectors X and Y, and XVAL and YVAL. The
main program should call on LlNZD as indicated above, then
Table P1.29a
Z, the vector containing the several levels zk, P, the number of where 5 and 5' are in (x,xo,xl,. ..,xm) and rl and 7' are in
such levels, and ZVAL, the particular value of z. -..,Y").
CY,YO,Y~,
66 InterpoIation and Approximation
1.39 Write a function, named POLYZD, that evaluates the 1.41 Write a function, named SPLIN2, with dummy
two-dimensional interpolating polynomial p,,.(x,y) of Prob- argument list (IMAX, JMAX, X, Y, F, XBAR, YBAR) that
lem 1.35 for arguments x = 2 and y = 7. The function should evaluates the doubly-cubic spline function developed in
have the dummy argument list Problem 1.40. The arguments have the meanings of like argu-
ments for the function POLYZD described in Problem 1.39.
(IMAX, JMAX, X, Y, F, M, N, XBAR, YBAR)
Write a short main program similar to that outlined in Prob-
Here, F is a matrix having IMAX rows and J M A X columns lem 1.39, and test the function SPLIN2 with the data of
of functional values f(x,,yj), X is a vector containing the Problem 1.29.
corresponding values of x i in ascending sequence in X(l), 1.42 The characteristics in Table P1.42 are available
.. .,X(IMAX), and Y is a vector containing the yj in ascending for the 6J5 triode electronic vacuum tube [23] (v. = anode
sequence in Y (1 ), ...,Y(JMAX) ; F is arranged so that F(1,J) is voltage, v, = grid voltage, .i = anode current, mA).
the functional value corresponding to X(1) and Y(J). The Write a function with three different entries, such that given
function should scan the vectors X and Y to determine which any two of v,, v., and i., the function will compute the third,
+
( M + 1) ( N 1) of the functional values F(1.J) should be using an appropriate two-dimensional interpolation procedure.
selected to make the point (XBAR, YBAR) (that is, the point Let the three function names be VGRID, VANODE, IANODE
(2,jj)) as nearly central as possible to the base points for (real). If VG, VA, and IA (real) are program variables equivalent
evaluating the interpolating polynomial p,,.(f ,?) of degree to v,, ZJ., and i., respectively, then typical statements refer-
M in x and of degree N in y. The value p,,.(z,J) should be encing the function might be
returned as the value of POLYZD. Should XARG or YARG
fall outside the range of base points, the interpolating poly- VG = VGRID (VA, IA)
nomial should be used for extrapolation.
VA = VANODE (VG, IA)
Write a short main program that reads values for IMAX,
JMAX, X ( l ) ,..., X(IMAX), Y ( l ) ,..., Y(JMAX), F(1.1). ..., IA = IANODE (VA, VG)
F(IMAX, JMAX) once, then reads values for M, N, XBAR, and
YBAR, calls on POLYZD to evaluate the appropriate inter- Test the function thoroughly with a short calling program.
polating polynomial, prints the result, and returns to read The functions can be used in Problem 2.48 and Problem 3.20.
another set of values for M, N, XBAR, and YBAR. Test the 1.43 Suppose that you wish to minimize the maximum
function with the data of Problem 1.29 using different com- magnitude of the error-term factor
binations of M and N. Compare the interpolated results with
those found using the functions LlN2D and CUB2D of
Problems 1.29 and 1.31, respectively.
1.40 Using the properties of the cubic spline function in the Lagrange or divided-difference interpolation formulas,
discussed in Problem 1.24, develop a two dimensional doubly- to be used over the interval [a,b]. You are free to choose the
cubic spline function (see [22]) for interpolation in rectangular base points XO,X I ,. .., xn.
regions with base points and functional values arranged as If a = 2, b = 6 , and n = 3, what values would you select for
described in Problem 1.35.
XO,X I ,xz, and x,?
1.44 Find a near-minimax quadratic, and the minimax
Table Pi .42 cubic, polynomial approximations to x4 on the interval [2,8].
1.45 Use the Chebyshev economization procedure to yield
an approximation of the form
Numerical Integration
the location of base points with respect to the interval of Since a different interpolating polynomial p,(x) is used in
integration. The commonly used integration methods can each of the four cases, (2.3) yields four different approxi-
be classified into two groups : the Newton-Cotes formulas mations (the shaded areas) of the true integral. In Fig.
that employ functional values at equally spaced base 2.2a, the polynomial is fitted by using only functional
points, and the Gaussian quadrature formulas that em- values on the interval [a,b], with base points at both
ploy unequally spaced base points, determined by certain a and b. Figure 2.2b illustrates a similar situation,
properties of orthogonal polynomials. except that functional values at base points outside the
integration interval are also used to determine the ap-
2.2 Numerical Integration with Equally Spaced proximating polynomial. In Fig. 2.2c, the polynomial is
Base Points determined by functional values between the integration
Consider the four parts of Fig. 2.2, in which f(x) is limits, with no base points at the ends of the interval; Fig.
known only at the indicated set of equally spaced base 2.2d is similar, except that there is a base point at one
points. end of the interval, x = a. Obviously, many other com-
In each case, the same integral, binations are also possible. For example, a and b could
be arbitrarily located with respect to the base points,
that is, a and/or b need not coincide with base point
values.
is to be evaluated by the approximation The two most frequently used classes of equal-interval
integration formulas are called closed and open. In both
classes, the integration limits a and b are either coincident
a b a b
(c) (dl
Figure 2.2 Numerical integration-four different polynomial approximations o f f (x).
2.3 Newton-Cotes Closed Integration Formulas
+ R.(x, + ah)
,< A n f ( x 0 )
~ d x fo ah) + R,(xo +ah).
Here, as before, ct = ( x - x,)/h, p,(x, + ah) is the nth-
-1 h
1
0
p,(xo + ah) du, (2.6)
where the integral on the right, is given, from (2.4), by
degree interpolating polynomial, and R,(x, + ah) is the
remainder or error term (1.55),
R,(xo + ah) = hn+ 'm(a - l ) ( u - 2). . . ( a - n)
f-'"+"(5)
-
X
(n + I)!' t in ( ~ 9 x 0 9...,xn),
R,(x, + ah) = hn+'n(u- l ) ( a - 2 ) From the definition of the first forward difference,
+
Af(x0) =f (x0 h) -f (xo), (2.7) assumes the final form,
If f(x) is a continuous function of x, then f "(5) or its The trapezoidal rule with error term is then given by
equivalent, 2!f [x,xo,xl] [see (2.5)], is a continuous, but
unknown, function of x, so direct evaluation of (2.9) is
impossible. Since u is simply a transformed value of
x, f"(r) is a continuous function of the integration
variable u; this property simplifies the estimation of (2.9).
The factor f "(r) can be taken outside the integral sign by Thus the error term from the trapezoidal rule is zero only
applying the integral mean-value theorem from the iff"(<) vanishes. If f ( x ) is linear, that is, a first-degree
b
calculus:
polynomial, the trapezoidal rule yields exactly
- -
[ f(x)dx,
Ja
If two functions, q(x) and g(x), are continuous for
as expected (see Fig. 2.3).
a < x < b and g(x) is of constant sign for a < x < b,
A more general problem is illustrated in Fig. 2.4.
then Here, the interpolating polynomial is of degree n ; the
.h -b
+
n 1 evenly spaced base points are xo, x,, . . ., x,. Let a,
the lower limit of integration, coincide with the base
where a < [ < b. point x,. Let b, the upper limit of integration, be arbitrary
since the factor a(u - 1) is negative for all in the for the moment. Then the approximation is given by the
integral
h
0
+ nh) do = hn+' jbb [.(a - ~ ) ( o- 2). . . (u - n) -
a b
Figure 2.4 General' case for closed integration.
width h, (2.14) yields an unexpected dividend which is
illustrated by the choice ii = 2 :
2
jxyf(x) dx = h jf ( x o + ah) du
0
ih 2f(xo) + 2Af(xo)
4-
1
- A2f (x,)
3
+ 0 A3f(a:,) - -1
90
A4f (x,) + . . .
B = 2 (Simpson's rule): On first glance, it would appear that the error for E = 2
is actually smaller than for L = 3. However, allowance
must be made for the fact that for integration over the
sameinterval [a,b],the stepsize (b - a)/E forthesecondcase
is only two-thirds the stepsize for the first. In terms of
B = 3 (Simpson's second rule): a and b, remembering that the values of 5 in the two will
not normally be the same, the error terms become:
E=2:
Since f"(x) = 6x - 4 , the errlor is given by finite-difference polynomial, Newton's forward formula
2 2
(1.54), where the forward differences of f ( x , ) rather than
- -f"(E) = - -(6e- 4), 1 <( <3, off (x,) are used, giving
3 3
which has an extreme value -98. The true error is 20%- 26 =
- 5 3 , smaller than the bound as expected, but still quite large.
For Simpson's rule (see Fig. 2.6b), h = I , x o = 1 , x1 = 2,
x , = 3, f ( x o ) = 1 , f (x,) = 9, and f ( x Z ) = 25. From (2.20),
xz=3
+h
1: p,-2(xo + ah) du. (2.25)
L=, 3
h
dx = - [J'(xo) 4-4 f (XI)+f (xdl- g?jf ' 4 ' ( ( )
f (XI
il5
Here, cr = (x - x,)/h and Z = (b - xo)/h. In terms of the
forward differences o f . f ( x , ) ,p,-,(x0 +
ah) is given by
I h5 2 1
= - (1
3
+ 36 + 25) - -
90
f '4'(6) = 20 - - -j t 4 ' ( [ ) .
3 90 pn-2(xo + ah) = f ( x 1 ) . + ( a - l ) A f ( x ~ )
Since the fourth derivative off (x)vanishes for all x, the error
term vanishes and the result is exact.
approximation is given by
error bound for the partic~~lar formula chosen. In many Assuming that f "(t,) is equal to f"(tz) leads to
practical situations, however, the error formula is of
little direct value since an expression for the derivative
may not be available. In some cases, it might be possible Note that for this case, the open formula is apparently more
to estimate the required derivative value from high-order, accurate than the closed formula of identical degree of pre-
finite divided diflierences of the functional values. cision (not the usual case). Substitution of (2.37) into (2.31)
Even when one has no information about higher-order leads to
derivatives, it may be possible t o estimate the error if the
integral is computed using two different integration
formulas with comparable degrees of precision. For
example, consider the eval~~ation of which is the true value of the integral in this case. Upon closer
examination, (2.38) is seen to reduce to
1b
I* = f (x) dx
a
by u s i ~ gthe three- and four-point dosed formulas of [Simpson's rule (2.21b)l. Thus the expression of the error in
(2.21b) and (2.21c), that is, Simpson's first and second terms of two formulas with degree of precision one has
rules, each of degree of precision three. Let I, and El resulted in a compound formula with degree of precision three.
be the estimate of I*and the error, respectively, resulting
from the use of Simpson's first rule, and let I, and E, be 2.6 Composite Integration Formulas
like quantities, resulting frorn the use of Simpson's second One way to reduce the error associated with a low-
rule. Then order integration formula is t o subdivide the interval of
integration [a,b]into smaller intervals and then to use the
formula separately on each subinterval. Repeated appli-
In terms of the integration limits a and b, we can write cation of a low-order formula is usually preferred to the
single application of a high-order formula, partly because
of the simplicity of the Iow-order formulas and partly
because of computational difficulties, already mentioned
in the previous section, associated with the high-order
formulas. Integration formulas resulting from interval
subdivision and repeated application of a low-order
where t, and 5, are different values of 5 in (a,b). If we formula are called composite integration formulas.
78 Numerical Integration
Although any of the Newton-Cotes or other simple The error term of (2.41) simplifies to that of (2.42) be-
(one-application) formulas can be written in composite cause the continuous function f "(x) assumes all values
form, the closed formulas are especially attractive since, between its extreme values. Therefore, there must be some
except for the base points x = a and x = b, base points r in (a,b) for which
at the ends of each subinterval are also base points for
adjacent subintervals. Thus, althou& one might suspect
that n repeated applic?+ionsof an m-point formula would
-
require nm functional evaluations, in fact only n(m 1) + 1 The error for the composite trapezoidal formula is
such evaluations are needed, a considerable saving, proporlional to l / n z . Therefore, if we double the number
especially when m is small.
of applications, the error will decrease roughly by a factor
The simplest composite formula is generated by re-
of four [f"(t) will usually be different for two different
peated application of the trapezoidal rule of (2.21a). For
values of 111. This form of the error term suggests a tech-
n applications of the rule, each subinterval is of length
nique, similar to that outlined in (2.31) to (2.34), for
h = (b -a)/n. Let xi = x, + ih, i=O, 1, ..., n. Then
estimating the error. In this case, the same composite
formula is used with two different values of n; in (2.31)
to (2.34) two different simple (one-application) formulas
are used.
Let Inand E,, be, respectively, the estimate of the
integral and the associated error for n applications of the
composite trapezoidal formula. Then the true value of
the integral is
In,- I n ,
+
I* = I n ,
.2I:[
1-
(2.46)
In terms of n, the number of applications of the rule, and For n2 = 2n,, (2.46) becomes
a and b, the integration limits, the composite formula is
labf( x ) d x = 1T.f h
(X) d x = - [ f (xo)
3 + 4 f ( x i ) + 2.f ( ~ 2+) 4f ( x , ) + 2 f ( x 4 )
where
b -a
~ ~ < ti
~ < xti,
- 2 h = -2n '
and x i = x 0 + i h , i = O , l , ..., 2n.
- 5+y+4"9+156
91 = 22
XO X1 x2 XO X1 X2 X3 X4
a b a b
(a) (b)
Figure 2.8 Repeated application of the trapezoidal rule. (a) Two applications. (b) Four applications.
EXAMPLE 2.1
RADIANT INTERCHANGE BETWEEN PARALLEL PLATES
COMPOSITE SIMPSON'S RULE
in which a is the Stefan-Boltzmann constant, and in which A, 0 , and N have obvious interpretations, and
F is the name of the function to be integrated.
Figure 2.1.2, corresponding to n = 2, emphasizes that
+
we compute B,, for example, at onlyn 1 points, to which
we can assign subscripts i = 0, 1, . . ., n. From symmetry,
The integral in equation (2.1.1) is the irradiosity, Bl(- i) = B1(.
I, = Il(x,), being the rate per unit area of incident The basic approach is straightforward. As a starting
radiation at a point x, on the lower plate. The integral guess, assume B, = El and B, = E2 everywhere. The
arises because radiation emitted from all points along the
upper plate has been taken into account. Similarly, the
integral in (2.1.2) is 12,the irradiosity at the upper plate.
The net rates at which heat must be supplied to unit
length of the lower and upper surfaces, to keep them at
steady temperatures, are
Plate I
0 1 2
Figure 2.1.2 BI and Bz are computed at discrete points only.
Example 2.1 Radiant Interchange between Parallel Plates-Composite Simpson's Rule 81
right-hand sides of (2.1.1) and (2.1.2) can then be Since the function SIMPS evaluates the integrand at
evaluated, enabling new estimates to be made of the definite values of the continuous variables x, and x,, a
distributions of B, and B,. These values are cycled back translation must be made (achieved in the program by
into the two integrals, giving revised estimates, and so on. the function ISUB) between these continuous variables
Iterations are discontinued either when itmax iterations and the appropriate subscripts for the point values such
have been made or when B, and B, at all points do not as B I i .For this purpose we use, for example, i = jx,/Axl
change by more than a fractional amount 6. This approach + 0.001, rounded down to the next lower integer. Here,
to the solution is an example of a successive substitution the absolute value sign accounts for symmetry, and the
method for solution of simultaneous nonlinear equations. small incrrment of 0.001 avoids any complications of
Successive substitution methods are discussed in Chapter round-off error when x,/Ax is evaluated. There are also
5. other complications in the programming, mainly arising
Note that the number of applications of Simpson's from the fact that SIMPS needs a single function name
rule is n, which is also the number of increments Ax along for the integrand, whereas the integrands of (2.1.11,
each half of the plate. For example, if n = 2, an esti- (2.1.2), (2.1.4), and (2.1.5) involve either the product or
mation of B,, from (2.1 .l) will involve five values of difference of two functions. This difficulty is overcome by
B,: B 2 ( - 2 ) ,BZ(-l),BZ0, BZ1,and B,,, which are just defining additional functions, such as F B I , which stands
enough for two applications of Simpson's rule. for the product of B,(x,) and f(x,,x,,d).
Numerical Integration
Flow Diagram
Main Program
i = o , 1,
..., n
conu
t T
I
.
\
\
x-
w/2
11 i + J- , , ~2Cx2)fCxl~
(evaluate using SIMPS)
Y
B c Bli
t
BI i + EI + (1 - &I)IIi 4 5 + EZ + (1 - &,)Izi
QTI>~
B - Bli
(evaluate using SIMPS)
T F
tf B,(x,)f (XI, x2, d)dx,
conu (evaluate using SIMPS) QI,Qz
+F
FORTRAN Implemenfatiorr
List of Principal Variables
Program Symbol D@nition
(Main)
B1, ~ 2 t Vectors, containing the radiosities Bli and Bli at each point i (BTU/hr sq ft).
CONV Logical variable used in testing for convergence.
13 Separation between the plates, d (ft).
DIF1, DIF2 -
F~lnctions,giving the differences (Bl(xt) Zl(x,)) and (B2(x2)- Z,(x,)), respectively.
DX Spacing, Ax, between points at which radiosities are computed (ft).
El, E2 Ernissive powers, El = e1oTf and B2= e,aT$ (BTU/hr sq ft).
EPSI, EPS2 Ernissivities, el and e,, of the lower and upper plates, respectively.
FBI, FB2 Functions, giving the products B1(xl)f(x,, xz, d) and B2(x2)f(xl, x,, d), respectively.
It Subscript, indicating point at which radiosity is being computed.
INTI, INT2P Vectors, containing the irradiosities I l l and Z2, at each point i (BTU/hr sq ft).
ITER Counter on the number of iterations, iter.
ITMAX Maximum number of iterations allowed, itmax.
N Number of increments, n, into which one half of each plate is subdivided.
Ql, 02 Heat supplied to the lower and upper plates, Q1and Q,,respectively (BTU/hr ft).
SAVE Temporary storage for rdiosities, B.
SIGMA Stefan-Boltzmann constant, a (1,712 x lom9BTU/hr sq ft OR4).
SIMPS Function for implementing Simpson's rule.
T I , T2 Temperatures, T1 and T2 ("R), of the lower and upper plates, respectively.
TO L Tolerance, 6, used in convergence testing,
W Plate width, w (ft),
X Distance from centerline (ft), either xl or xz .
XHIGH, XLOW Upper and lower limits on X,
(Function F B I )
ISUB Function for converting distance to corresponding subscript.
F Function for evaluating equation (2.1.3).
(FunctionSIMPS)
H Stepsize, h.
SUMEND, SUMMID The first and second summations of (2,1.6), S, and S,,,, respectively.
t Because of FORTRAN limitations, we have 1 6 I $ N f I,
corresponding to 0 < i < n:, thus, B,, through B1, in the text
+
correspond to B l (I) through 0 1 ( N 1) in the program.
Numerical Integration
Program Listing
Main Program
A P P L l ED NUMERl CAL METHODS, EXAMPLE 2.1
SIMULTANEOUS l NTEGRAL EQUATl ONS -
COMPOS l TE S IMPSON'S RULE
REAL I N T I , I N T 2
LOG l CAL CONV
COMMON B1, 82, W, N, X, DSQ, I N T I , I N T 2
DIMENSION B 1 ( 1 0 2 5 ) , R 2 ( 1 0 2 5 ) , I N T 1 ( 1 0 2 5 ) , INT2(1025)
EXTERNAL F B I , FB2, D I F 1 , D I F 2
C .... .
READ I N P U T DATA AND COMPUTE E M I S S I V E POWERS .....
-
1 READ ( 5 , 1 0 0 ) T1, T2, EPS1, EPS2, D, W, SIGMA, TOL, N, ITMAX
E l = EPSl*SIGMA+Tl+*k
--
E2 EPS2*SIGMA*T2++S
XHIGH = W/2.
XLOW XHl GH
WRITE ( 6 , 2 0 0 ) T1, T2, EPS1, EPS2, D, W, SIGMA, TOL, N, ITMAX,
1 El, E2, XLOW, XHIGH
C
C .....
DSQ * D*D
COMPUTE CONSTANTS, GUESS I N I T I A L R A O l O S l T l E S .....
DX = W/FLOAT(2*N)
NP1 = N + 1
DO 2 I=l,NP1
Bl(1) = E l
2 B 2 ( 1 ) = €2
C
C ..... PERFORM
DO 5
SUCCESSIVE
I T E R s l , ITMAX
ITERATIONS .....
CONV .TRUE.
C
C .....
DO 3
COMPUTE R A D l O S l T t E S ACROSS S T R I P ONE
t=l,NPl
.....
X = FLOAT(1-l)*DX
SAVE -
I N T l ( 1 ) = SIMPS(XLOW,XHIGH,N,FBZ)
Bl(l)
s i c i ) = E l + (I.O-EPS~)+INT~(I
3 I F ( ABS((SAVE-Bl(I))/Bl(I)) .GT. TOL CONV = .FALSE.
C
C .....
DO 4
COMPUTE R A D I O S I T I E S ACROSS S T R I P TWO
t=l,NPl
.....
X = FLOATCI-1)*DX
I N T 2 ( 1 ) = SIMPS(XLOW,XHIGH,N,FBl)
SAVE + B 2 ( 1 )
B 2 ( I ) = E2 + ( l . O - E P S 2 ) * l N T 2 ( 1 )
4 I F ( ABS((SAVE-B2(I))/B2(1)) .GT. TOL CONV = .FALSE.
C
C .I F....CONV
(
TEST
FOR CONVERGENCE OF I T E R A T I O N SCHEME
GO TO 6
.....
5 WRITE (6,202) ITER, (I,Bl(I),B2(I),INTl(l),lNT2(1), I=l,NPl)
C
C ..... P R I N T OUTPUT .....
WRITE ( 6 , 2 0 1 )
.....
C
ENTRY D I F Z ( Y )
I * ISUB(Y)
D I F 2 = B2(1 1
RETURN
- lNT211)
C
END
Function SIMPS
FUNCTION SIMPS( A, B, N, F
C
C THE FUNCTION SIMPS USES N APPLICATIONS OF SIMPSON'S RULE
C TO CALCULATE NUMERICALLY THE INTEGRAL OF F ( X ) * D X BETWEEN
C UNTEGRATION L I M I T S A AND B. SUMEND I S THE SUM OF A L L F ( X ( 1 ) )
C FOR EVEN I (EXCEPT FOR F ( X ( Z * N ) ) WHILE SUMMID I S THE SUM OF
C A L L F ( X ( 1 ) ) FOR I ODD. H I S THE STEPSIZE BETWEEN ADJACENT
C X ( I ) AN0 TWOH I S THE LENGTH OF THE INTERVAL OF INTEGRATION
i
Numerical Integration
Data
T2 = 500.00 EPSl = 0.80 EPS2 = 0.60
W = 1.00 SIGMA= 1.712E-9 TOL 31. OE-6
ITMAX = 25
T2 = 500.00 EPSI = 0.80 EPS2 = 0.60
W = 1.00 SIGMA= 1.712E-9 TOL =l.OE-6
ITMAX I 25
T2 = 800.00 EPS1 = 0.20 EPS2 = 0.60
W = 1.00 S l GMA= 1.712E-9 TOL =l.OE-6
ITMAX = 25
Computer Output
Resvlts for the 1st Data Set
RADIANT HEAT TRANSFER BETWEEN I N F I N I T E PARALLEL PLATES
TI
T2
EPSl
EPS2
D
W
S l GMA
TO L
N
ITMAX
El
E2
X LOW
XH l GH
Example 2.1 Radiant Interchange between Parallel Plates-Composite Simpson's Rule
ITER = 4
ITER = 5
Partial Results for the 2nd Data Set (Same as 1st Set, with N=8)
ITER a 5
T2
EPS 1
EPS2
D
W
S 1 GMA
TO L
N
l TMAX
E1
E2
XLOW
XHIGH
Numerical Integration
2.7 Repeated Interval-Halving and Romberg Integration assuming that no round-off error enters into the calcula-
tions.
Let T,,, be the computed estimate of an integral
The Richardson extrapolation technique of (2.47) can
now be applied to each pair of adjacent elements in the
[f ( 4 dx
sequence To,,, TI,,, . . . to produce a third (hopefully
by using the composite trapezoidal rule of (2.42) with improved) estimate of the integral. Let I* in (2.47), cor-
n = 2N. Then To,, is the estimate of the integral using the responding to the pair of estimates TN,,,TN+l,l,be de-
simple trapezoidal rule, TI,, the estimate for two appli- noted TNVZ SO that
To.1 =-I-
(b-a) 1
1 2 [ f ( a )+ f ( b ) l )
(2.52a)
J
= (b-a)(/(a) + 4 j (a + q))
+ I /(b), ,
(b - a ) 1
Tt.1 = - 2 (5 [ f ( a ) f(b11 + +f (a + v))
1 6
~ ~ . ~ + ( b - (a+?))]
o)f (2.52b) tion of Simpson's rule. Investigation of the sequence
To,,, .. ., TNV2leads, by induction, to the conclusion
Ta.1 =Y'(:U(~)+
f f(b)l+ = If(a+?)i)] that T,,, is the estimate of the integral which would be
computed by using the composite Simpson's rule of (2.49)
1 with n = 2N. Thus TN,2is the value computed for the
& (a+ V ' i ) )
+?I 1-1
= z ( ~ l , l (2.52~) integral by Simpson's rule after halving the initial interval,
A l r ~ [a,b], N times.
- From (2.49), the error in T ~ , is
, given by
- (b - a)'
f(
1935360(2)6N
) t in (a,b). (2.59)
., Provided that f(x) has a continuous and bounded sixth
Provided that f ( x ) has a continuous and bounded second derivative on the interval (a,b), (2.59) assures that the
derivative on the interval (a,b), (2.54) assures that the sequence To,, . . . TN,, converges to the true integral,
sequence To,, .. . TN,, converges to the true integral, assuming no round-off error.
2.7 Repeated Znrerval-Halving and Romberg Integration 91
The Richardson extrapolation technique can be applied To use this technique, we simply compute the elements
to each pair of adjacent elements in the sequence of the first column using (2.52a) and (2.53), fill out the
To,,,T I , ,. . . to produce another sequence of estimates, remaining elements of the triangular array using (2.61),
and then examine the number sequences down each
column and across each row. Each of the sequences
should converge to the true integral.
which can be shown (see Rauer et al. [6]) to converge to The error corresponding to TNg as defined in (2.61),
the true integral. can be shown [6] to be equal to
The relationships of (2.55), (2.58), and (2.60) are special
cases of the general extrapolation formula,
where f(x) is any single-valued function and a and b are for N = 1,2, . . ., N,,,. The Romberg extrapolation
finite. The program should first use the trapezoidal rule
formula of (2.61),
with repeated interval halving to determine To,,, TI,,, . . .,
TN,,x,l from (2.52a) and the recursion relation (2.53).
Then the Romberg sequences {TNYj} should be computed
from the general extrapolation formula (2.61) for all
j d j,,,. The Rornberg Tableau should be organized as is then employed for j = 2, 3, . . ., j,,,, with N = 0, 1, . . .,
illustrated in Table 2.1. +
N,, - j 1, to fill out the remaining elements in the
To test the subroutine, write a general purpose program first j,,, columns of the matrix T.
that calls on TROMB to evaluate the coefficients of the The integrands for the integrals of (2.2.3) and (2.2.4),
Fourier expansion for any arbitrary function g(x),
periodic with period 2n, such that g(x) = g(x 2kn) for +
integral k. The Fourier expansion may be written [I41
w w
g(x) = C cmcos mx + C dmsin mx, (2.2.2) are evaluated by the functions FUNCTC and FUNCTD,
m=O m=O
respectively, defined in one multiple-entry function. The
where
periodic function g(x), which for the suggested function
1
cm= -
R
1
-n
g(x) cos mx dx (2.2.3) of Fig. 2.2.1 is given by
dm = -
1
71
I"
-n
g(x) sin mx dx. (2.2.4) is also defined in the multiple-entry function.
From (2.2.4), it is clear that for all g(x), do = 0. For the
Write the program so that the coefficients (cm,dm)are periodic function of (2.2.7), the coefficients cmand dmof
calculated in pairs, for m = 0, 1, . ., m,,,.. (2.2.3) and (2.2.4) may be found analytically, and are
As a test periodic function, g(x), use the sawtooth given by
function of Fin. 2.2.1.
I sin 2x sin 3x
Figure 2.2.1 A periodic sawtooth function.
2 +- 3 - ...). (2.2.10)
Method of Solution In the programs that follow, all cmand dmare evaluated
l'he subroutine TROMB is a straightforward implemen- ..., nz,,. Thc Romberg tableaus for em
fur rrr = 0, 1,
tation of the trapezoidal rule of (2.52a), and dmare stored in the matrices C and D respectively.
Example 2.2 Fourier Coefficients using Romberg Integration 93
Flow Diagram
Main Program
C ~ jD
, ~j,
j = 1, 2, ...9jmax, D, =-
71
1
1 h(x) dx
-n
= dm
N = O , 1,..., N m x - j + 1
(Subroutine TROMB)
g(x) cos mx
(Function G)
g(:x) sin mx
(Function G)
0-0
Enter
Return
b-a
To1 +--
2 [f(a) +f (b)l '-- TNl + o
A I
94 Numerical integration
FORTRAN Implementation
List of Principal Variables
Program Symbol Dejinition
(Main)
c, Dt ;.:ztrices C and D, containing the Romberg tableaus for cmand dm,respectively.
J Column subscript for tableaus, j.
JM Maximum column subscript in Nth row of tableau.
JMAX jmax,number of columns in tableau.
M m, index on Fourier coefficients cmand dm.
M MAX m,,, maximum value of m.
Nt Row subscript for tableaus, N.
N MAX Nma,, maximum value of N.
NMAXPl Nmax + 1.
PI IT.
MMAXPl mmax + 1.
MPLUSI m + 1.
(Functions
FUNCTC,
FUNCTD,
G)
X The variable of integration, x.
(Subroutine
TROMB)
A, B Lower and upper limits of integration, a and b.
F The integrand function, j:
FR (b - a)/2N.
FORJMl 4j-1.
H b - a.
I i, index on repeated sum of (2.53).
l MAX 2N- 1 .
N RC n, number of rows and columns in tableau T.
NXMJPZ N, -j 2. +
Tt Matrix containing the Romberg tableau, T.
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 2.2
C FOURIER COEFFICIENTS USING ROMBERG INTEGRATION
C
C T H l S TEST PROGRAM CALLS ON THE SUBROUTINE TROMB TO COMPUTE
c THE INTEGRALS NECESSARY TO DETERMINE THE CORFICIENTS
C OF THE FOURIER EXPANSION FOR A FUNCTION G ( X ) ON THE
C INTERVAL ( - P I , P I ) WHERE THE FUNCTION I S PERIODIC FOR A L L
C X SUCH THAT G ( X ) = G(X + 2 * K * P I ) , K BEING AN
C INTEGER. THE F I R S T MMAX COEFFICIENTS OF THE COSINE AND
C S I N E TERMS (THE C(M) AND D(M) OF THE TEXT) ARE COMPUTED
C US l NG THE TRAPEZOIDAL RULE Wl TH REPEATED l NTERVAL H A L V l NG
C FOLLOWED BY THE ROMBERG EXTRAPOLATION PROCEDURE. THE ROMBERG
C TABLEAUS FOR C(M) AND D(M) ARE STORED I N THE UPPER TRIANGULAR
C PORTIONS OF THE F I R S T N M A X + l ROWS OF THE F I R S T JMAX COLUMNS OF
C THE C AND 0 MATRICES RESPECTIVELY. FOURIER COEFFICIENTS
C FOR ANY ARBITRARY P E R I O D I C FUNCTION CAN BE FOUND BY D E F I N I N G
C G(X) APPROPRIATELY (SEE THE FUNCTIONS FUNCTC AND FUNCTD).
C
I M P L l C l T REAL*8(A-H, 0-2)
DIMENSION C(20,20), D(20,20)
EXTERNAL FUNCTC, FUNCTD
COMMON M
DATA P I / 3 . 1 4 1 5 9 2 6 5 3 5 8 9 8 /
C
C .....
READ DATA, C A L L TROMB TO COMPUTE INTEGRALS
1 READ (5,100) MMAX, NMAX, JMAX
.....
WRlTE (6,200) MMAX, NMAX, JMAX
MMAXPl = MMAX + 1
DO 3 MPLUlSl=l,MMAXPl
M MPLUSl 1 -
CALL TROMBi( NMAX, -PI, PI, FUNCTC, C, JMAX, 20 )
CALL TROMBI( NMAX, -PI, PI, FUNCTD, D, JMAX, 20 )
C
C ..... P R l NIT OUT ROMBERG TABLEAUS
WRlTE ( 6 , 2 0 1 ) M
.....
NMAXPl = NMAX + 1
DO 2 N=l,NMAXPl
JM = JMAX
2
I F ( N.GT.NMAXPl+l-JMAX
WRlTE ( 6 , 2 0 2 ) (C(N,J),
JM = NMAXPl + 1
J=l,JM)
- N
WRlTE ( 6 , 2 0 3 ) M
DO 3 N=l,NMAXPl
JM = JMAX
I F ( N.GT.NMAXPl+l-JMAX JM = NMAXPl + 1 - N
3 WRlTE (6,202) (D(N,J), J=l,JM)
GO TO 1
C
C
100
..... FORMATS FOR I N P U T AND OUTPUT STATEMFNTS
FORMAT( 7X, 13, 2(12X, 1 3 ) )
.....
200 FORMAT( ~ H ~ M M A =X 1 2 / 8H NMAX = , 1 2 1 8H JMAX = , 12 )
201 FORMAT( 1HO/ 1 ~ 0 , 9 i , ~ H C ( , 1 2 , l ~ ) / 1 H
202 FORMAT( 1 H ,
1P7E17.8
,L. 203 FORMAT( 1HO/ 1H0,9X, 2HD(, 12,1H)/ 1H 1
END
Subroutine T R O M B
,. SUBROUTINE TROMS( NMAX, A, B, F, T, JMA.X, NRC
C
3
DO 3
T(N,J)
N=l,NXMJPZ
= ( F O R J M l * T ( N + l , J-1) -
T(N,J-l))/(FORJMl - 1.0)
RETURN
C
END
Data
MMAX = 10 NMAX = 13 JMAX = 7
Example 2.2 Fourier Coeficients using Romberg Integration
VImmmmYIPf
dddddddd
I 1 1 1 1 1 1 1
nnnnnnnn
m m n t m w m d
O f f SQIDhdCD
mocod.(~~mmm
m m d d d h d o
M I D h O d f ;to
h N M f f ma00
........
m m O N d m h h
m d d m m m m n
4lOnmmma m
........
NNNNNNNN
-
1 1 4 1 1 1 1 1
nnnonnnnn
r.OOOOOOOO
m 0 0 0 0 0 0 0 0
m o o o o o o o o
~ O O O O O O O O
m o o o o o o o o
m o o o o o o o o
m o o o o o o o o
m
.........
o o
dNNNNNNNN
o o o o o o
nannnnnnno
m m o o o o o o o o
m m o o o o o o o o
m m o o o o o o o o
~ m o o o o o o o o
o m o o o o o o o o
o m o o o o o o o o
O ~ O O O O O O O O
..........
o m 0 0 0 0 0 0 0 0
NdNNNNNNNN
nnnonnnann0
N m N 0 0 0 0 0 0 0 0
a m 0 0 0 0 0 0 0 0 0
m m o o o o o o o o o
~ O O O O O O O O O O
o a 0 0 0 0 0 0 0 0 0 0
f 0 0 0 0 0 0 0 0 0 0
m o o o o o o o o 0 0
...........
m o o o o o o o o o o
d N N N N N N N N N N
nn0nnonn0nnn
f m m m 0 0 0 0 0 0 0 0
'h?lh00000000
A O m m 0 0 0 0 0 0 0 0
m r - m m o o o o o o o o
o m m m o o o o o o o o
t o a m m o o o o o o o o
m m m m o o o o o o o o
~ m m m o o o o o o o o
9
w
._
D
3
Z
9
9
om,
'44
C1 ~ o o m a m m m m m m m u ~ m
a u n l r oaar.mhmmmmmmmmm
9 xx,
oomwmmmmmmmmmm
8 a s<
ESP
z 2 -3
8
CI
a
Q
8
Numerical Integration
dddrlrlrlrld ddrld*r(dd
00031000 ~ 0 0 0 U 0 0 0
1 1 1 1 1 1 1 1 I I I I I I I I
nnnnonnn onnnnnnn
m h 0 0 0 0 0 0 m n h w w w w w
~ m O O O O O O tmmmmmmm
~ m O O O O O O r.QINNNNNN
~ ~ O O O ~ O O L D N f f t f f t
N m O O o O O O m d d d d d d r l
o m o o o o o o dhhi.r.hhh
0 m 0 0 0 0 0 a
0 m 0 0 0 0 0 0
........
wmmmmmmm
mmmmmmmm
N N N N N N N N
rldrldddddd
000000000
I I l I t t I I I
nnnnnnano
m m t 000000
m w w ~ ~ o o o o
o d m o o o o o o
m w m 0 0 0 0 0 0
f N m 0 0 0 0 0 0
N 0 m o 0 0 0 0 0
m 0 m 0 0 0 0 0 0
m o m o o o o o o
.........
N N N N N N N N N
no0no
rlmmm n
o m mmm
N h d m m
4 m m rlm
mmrl
d t h
fmr.
d m m
Example 2.2 Fourier Coefficientsusing Romberg Integration
2.8 Numerical Integration with Unequally Spaced respect to the weighting function w(x) = 1, that is,
Base Points
All the integration formulas developed in the preceding
sections are of the form given by (2.22)
integration will be changed from [a,b] to [-1,1] by a Note that (2.84) is of the desired form (2.22) and that the
suitable transformation of variable. Assume that all the second integral on the right-hand side of (2.83),
base points are in the interval of integration, that is,
a < xo, x,, . ..,xn,< b. Let the new variable, z, where
- 1 < z < 1, be defined by
is then the error term for the integration or quadrature
2x - (a + b) formula of (2.84). The object is to select the zi in such a
z= (2.79)
b-a way that the error term (2.86) vanishes. The orthogonality
Define also a new function F(z) so that property of the Legendre polynomials of (2.64) will be
used to establish such values zi.
First, expand the two polynomials qn(z) and
n L 0 [ z - zi) in terms of the Legendre polynomials,
as illustrated in Section 2.9:
Then (2.78) becomes
where
will vanish [see (2.64)]. Thus the error term (2.86) for
the quadrature formula of (2.84) may be written
Since the F(zi) are fixed values, the summation operator
can be taken outside the integral sign. Dropping the
right-most integral, (2.83) becomes
= ibici1 [pi(z)I2 dz.
i=O
1
-1
(2.92)
One way to make this expression vanish is to specify that
+
the first n 1 of the bi, i = 0,1,. . .,lt, are zero. The
coefficient b,+l of Pn+,(z) is still unspecified, but from
where
(2.87) it must be given by
2.10 Gaussian Qi~adraturr 103
For example, for n = 3, the coefficient of the high-order base points to be used in the integration formula of (2.84)
(z4) term of Pn+ ,(z) = P,(z) is 3518 [see (2.65)]. Since the +
are the n -t 1 roots of the appropriate [(n 1)th-degree]
high-order coefficient of I11=o(z - zi) is 1, b, + = 8/35. Legendre polynomial. The relative weight assigned each
The important feature of (2.93) is that the polynomial functional value F(zi) is given by (2.85). Values of the
n l Z o ( z- zi)is already in factored form, that is, it has appropriate base points (roots) and weight factors for
t h e n + I roots zi, i=0,1, ...,n.Since bn+,P,+,(z) is the n = 1,2,3,4, 5,9, and 14 (corresponding to the 2, 3,4, 5,
same polynomial, the zi must be the roots of bn+,P,+,(z) 6, 10, and 15-point formulas respectively) are shown in
as well, or equivalently, of Pn+,(z). Thus the n f 1 Table 2.2. The integration formulas of (2.84) with base
Table 2.2. Roots of the Legendre Polynomials P.+,(z) and the Weight
Factors for the Gauss-Legendre Quadrature[4]
-
Roots (zi)
/: F(z) dz = 2 wtF(zt)
1=0
Weight Factors ( w , )
Two-Point Formula
n=l
Three-Point Formula
n=2
Four-Point Formula
n =3
Five-point Formula
n=4
Six-Point Forn~ula
n=5
Ten-Poitit Formula
n-9
~ifieed-pointFormula
n = 14
104 Numerical Integration
Then
J- 1 ~ (d z~ =)
i=O
wi~(zi), (2.97)
The general formulation of the Gauss-Legendre quadra- past. The weight factors and base points for the compu-
ture given by (2.98) is particularly suitable for machine tation are inconvenient numbers for hand calculation. On
computation because it does not require symbolic trans- a digital computer, however, the presence of such numbers
formation offix); instead, the base points zi are trans- makes no difference in calculations, provided that the
formed and the weight factors wj are modified by the function can be 'evaluated at the necessary arguments (if
-
constant (b a)/2. the function is available only in tabulated form, then it
will probably be necessary to interpolate in the table).
Example. Use the two-point Gauss-Legendre quadrature In the derivation of the quadrature formulas, great
formula to evaluate
emphasis has been placed on accurate integration of poly-
J:(x3+x2+x+l)dx=341.
nomial functions, so that (2.84) yields exactly the integral
+
when F(z) is a polynomial of degree 2n 1 or less. In
Using (2.98) with a = 1, b == 3, and the w , and z, from Table most real situations, of course, F(z) is not a polynomiai
2.2 for n = 1, at all; the question of formula accuracy is, as always, of
prime importance. Unfortunately the derivation of the
error term corresponding to (2.84) is quite tedious. The
development is not included here, but a complete des-
cription may be found on pages 314-325 of [2]. The error
term for the Gauss-Legendre quadrature formula of
(2.84) is
To the number of figures retained in the calculation, the Provided that the magnitudes of high-order derivatives
results are exact, as expectled, since f(x) is a polynomial of decrease or do not increase substantially with increasing
+
degree 2n 1.
~ l , the Gauss-Legenhe formulas are signifjcanily mDJE
The preceding example illustrates why the Gauss- accurate than the equal-interval formulas of-the preceding
Legendre quadrature formulas have been little used in the sections for comparable values of n.
EXAMPLE 2.3
GAUSS-LEGENDRE QUADRATURE
Problem Statement Let the magnitudes of the roots and the corresponding
weight factors from Table 2.2 be assigned to elements of
Write a general-purpose function named GAUSS that
two vectors, z and w, as shown in Table 2.3.1.
uses the m-point Gauss-Legendre quadrature formula to
In order to locate the roots and weight factors for the
evaluate numerically the integral
m-point formula, it is convenient to assign the following
.values to two vectors, p and k:
i =J WJ m
for even values of m. For odd values of m, (2.3.2) also
applies except when j = k,.In this case zj has a zero value
and does not occur in a root pair; the factor wjf(d)
should be added just once to the accumulated sum.
In the program that follows, the function GAUSS checks
to insure that m has been assigned one of the legitimate
values 2,3,4, 5,6, 10, or 15. If not, GAUSS returns a
true zero as its value.
A short calling program is included to test GAUSS. It
reads values for a, b, and m, calls on GAUSS to compute
the required integral, and prints the results. The function
f(x) is defined as a function named FUNCTN. In this
example, f(x) = llx, i.e., the integral to be evaluated is
t
b-Q
C+-
2
b+a
dt-
2
s t 0
I
I
I
I
1 -
I
I s + s + wjf(d)
s+s + wj(f (czj + d )
I (Function FUNCTN) +f (- czj + d))
I (Function FUNCTN)
A
I
I
I
I
I
6
I
I
I
I
L ----- -- -- - Return
*The vectors p, k, W, and z are assumed to have appropriate values upon entry (see text).
108 Numerical Integration
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
(Main)
A. Integration limits, a and b.
AREA Computed value of integral (2.3.1), H.
M Number of points in the Gauss-Legendre quadrature formula, m.
(Function
GAUSS)
c c = (b - a)/2.
D d = (b + a)/2.
I Subscript for vectors p and k, i.
J Index on the repeated sum of (2.3.2).
JFIRST Initial value of j, k,.
J LAST Final value of j, ki+l - 1.
KEY Vector k.
NPOINT Vector p.
SUM Repeated sum of (2.3.2).
WEIGHT Vector of weight factors, wi.
z Vector of Legendre polynomial roots, 2,.
(Function
FUNCTN)
x Integration variable, x.
Example 2.3 Gauss-Legendre Quadrature
Program Listing
Main Program
C A P P L l ED NUMERICAL METHODS, EXAMPLE 2.3
C GAUSS-LEGENDRE QUADRATURE
L
C T H I S C A L L I N G PROGRAM READS VALUES FOR A, B, AND M, CALLS
C ON THE FUNCTION GAUSS TO COMPUTE THE NUMERI CAL APPROXIMATION
C OF THE INTEGRAL OF FUNCTN(X)*DX BETWEEN INTEGRATION L I M I T S
C A AND B USING THE M POINT GAUSS-LEGENDRE QUADRATURE FORMULA,
C PRINTS THE RESULTS, AND RETURNS TO READ A NEW SET OF
C
C
DATA VAILU ES .
I M P L I C I T REAL*8(A-H, 0-Z)
EXTERNAL FUNCTN
L
WRITE ( 6 , 2 0 0 )
1 READ ( 5 , 1 0 0 ) A, B, M
AREA = GAUSS ( A, 0, M, FUNCTN
WRITE ( 6 , 2 0 1 ) A, B, M, AREA
GO TO 1
L
C
100
..... FORMATS FOR l NPUT AND OUTPUT STATEMENTS
FORMAT ( ,4:K, F8.4, l o x , F8.4, l o x , 1 3
.....
200 FORMAT ( l H 1 , l O X D l H A D 14X, l H B , 1 0 X D lHM, 9X, 4HAREA / 1 H )
201 FORMAT ( 11-1 , 2F15.6, 17, F15.6 )
C
END
Function FUNCTN
FUNCTION FIJNCTN( X )
C
C .....
REAL*8
T H I S FUNCTlON RETURNS 1 / X AS I T S VALUE
X, FUNCTN
.....
FUNCTN = l . O / X
RETURN
C
END
finction G A U S S
FUNCTION GAUSS( A, 8, M, FUNCTN
C .....
1 CONTINUE
GAUSS
RETURN
-
I N V A L I D M USED
0.0
.....
C
C ..... SET UP l N l T I AL PARAMETERS
JFIRST = K E Y ( I )
.....
2
JLAST KEY(I+1)
C = (0-A)/2.0
- 1
D = (B+A)/2.0
C
C .....
ACCUMULATE THE SUM I N THE M-POINT FORMULA
SUM = 0.0
.....
DO 5 J=JFIRST,JLAST
IF ( Z(J).EQ.O.O ) SUM = SUM + WEIGHT(J)*FUNCTN(D)
5 I F ( Z(JI.NE.O.0 ) SUM = SUM + WEIGHT(J)*(FUNCTN(Z(J)*C + D)
1 + FUNCTNC-Z(J)*C+ D l )
C
C ..... MAKE INTERVAL CORRECTITIN AND RETURN
GAUSS = C*SUM
.....
RETURN
C
END
Data
Example 2.3 Gauss-Legendre Quadrature
Computer Output
AREA
0.692308
0.693122
0.693146
0.693147
0.693147
0.693147
0.693147
1.565217
1.602694
1.608430
1.609289
1.609416
1.609438
1.609438
2.106383
2.246610
2.286970
2.298283
2.301b08
2.302579
2.302585
2.488565
2.779872
2.905192
2.958221
2.980324
2.995311
2.995728
0.0
0.0
0.0
112 Numerical Integration
Gauss-Laguerre Quadrature. The Laguerre polynomials by e-' and integrate both sides :
of (2.68) can be used to generate a Gaussian quadrature
formula to evaluate integrals of the form
.a n
I. m
e-'F(z) d z = fF(zi) l e-'Li(z) d z
i=O
m
n
F(z) = C Li(z)F(zi)+
i= o
q,(z). (2.103) The appropriate base points zi and weight factors wi for
n = 1 , 2 , 3 , 4 , 5 , 9 , and 14(for t h e m = 2 , 3 , 4 , 5 , 6 , 1 0 ,
and 15-point formulas respectively) are shown in Table
e-'F(z) dz, multiply each term of (2.103)
2.4.
Two-Point Formula
.n = 1
.85355 33905 93
.I4644 66094 07
Three-Point Formula
n=2
.71109 3G099 29
.27851 77335 69
.(I) 10389 25650 16
Four-Point Formula
n =3
.60315 41043 42
-35741 86924 38
.(I) 38887 90851 50
.(3) 53929 47055 61
Numerical Integration
Five-Point Formula
n=4
Six-Point Formula
n=5
Ten-Point Formula
n=9
Fifteen-Point Formula
n = 14
(2.106)
and the general formulation of the Gauss-Laguerre quad-
Example. Use the Gauss-Laguerre quadrature formula rature for arbitrary lawer limit of integration a is
to estimate r(2.0) and r(1.8),where .m
j a
e d 7 ( x ) dx = e-. 2wif(zi + a),
i=O
(2.109)
Jo
where the w iand zi are those tabulated in Table 2.4..
For integral arguments, a,
Example. Use (2.109) to evaluate
r(a) := (a - 1) !
P
From (2.1OO), 1
JI e - x x 2dx,
for which the analytical vaiue is 5/e.
r ( a )= :C w i z i a - ' .
1=0
From (2.109), the integral is approximated by
For a = 2, e - 1i=o2 w,(zl + 11'
J- 1
J f L ;2
F(z) dz L (-1 +
n
i7
1
"
i=o
F(zi).
+
transformation x = z a. Then (2.107) becomes (2.1 13)
116 Numerical Integration
Any integral of the form and then use the quadrature appropriate for integrals of
the form on the right of (2.1 17). In some cases, it may be
possible to evaluate integrals in which the integrand has a
singularity on the integration interval by relegating the
where a and b are finite, can be expressed in the form of singular term to the weighting function. For example,
(2.1 11) by a suitable transformation. integrands containing the factor 114 1 - xZ over the
Gauss-Hermite Quadrature. Based upon the ortho- integration interval [ - 1,1] can be handled by using the
gonality property of the Hermite polynomials of (2.74), Gauss-Chebyshev quadrature.
one can develop a useful Gaussian formula, A variety of other quadrature formulas of the Gaussian
type can be generated for particular weighting functions,
limits of integration, and sets of orthogonal polynomials.
Two well-known quadrature formulas of the Gaussian
which is known as the Gauss-Hermiie quadrature. Here, type have been developed that include one or both end
the x i are the roots of the Hermite polynomial of degree points of the integration interval as base points. When
n + 1. The weight factors and appropriate roots for the x, = a and x, = b, the remaining base points x,, . . ., xn-,
first few quadrature formulas are listed in Table 2.6. The are found to be the roots of Pi(x), the derivative of the
corresponding error term [8] is Legendre polynomial of degree n. The formula is called
the Lobatro quadrature and produces exactly the integral
if f(x) is a polynomial of degree 2n - 1 or less. When
only one integration limit is specified to be a base point,
the analogous formula is called the Radau quadraturq and
Table 2.6 Roots of the Hermite Polynomials H.+ l ( x ) and is exact when f(x) is a polynomial of degree 2n or less.
Weight Factors for the Gauss-Hermite Quadrature [3]
The reader interested in the development of many other
Gaussian formulas is referred to [7], which also contains
extensive tabulations of base points and weight factors
Roots ( x i ) Weight Factors ( w l )
for a variety of quadratures. The tabulated values are
accurate to 30 significant figures in all cases. Tables for
Twc~PointFormnh the Legendre, Laguerre, and Hermite formulas are par-
n= 1 ticularly complete (for example, base points and weight
*0.70710 67811 0.88622 69255 factors for the Gauss-Legendre quadrature for over 80
Three-Point Formula values of n from 1 to 51 1).
n=2 The Gaussian quadrature formulas can also be used
& 1.2247448714 0.29540 89752
0.0000000000 1.18163 59006
repeatedly over subintervals of the integration interval to
create composite formulas similar to those of Section 2.6.
Four-Point Formula
n=3 Since most of the Gaussian formulas do not have base
& 1.65068 01239 0.08131 28354 points at the ends of the integration interval, there is
&0.52464 76233 0.8049140900 usually no saving in the number of functional evaluations
Five-Point Formula per subinterval, as occurs when composite formulas are
n=4 constructed from the low-order Newton-Cotes closed
&2.02018 28705 0.01995 32421 formulas. On the other hand, the inconvenient form of
&0.95857 24646 0.39361 93232 values of the weight factors and base points makes use of
0.00000 00000 0.94530 87205
the high-order formulas virtually impossible for hand
calculation; even the preparation of computer programs
Other Gaussian Quadrature Formulas, By a suitable to implement a quadrature for several values of n can be
transformation of the variable of integration or of the tedious, because of the large amount of tabular informa-
function to be integrated, the four Gaussian quadrature tion required (alternatively, we might compute the
formulas developed in this section allow the numerical essential polynomial roots by using methods described in
evaluation of many well-behaved integrals over finite, Chapter 3, and then evaluate the necessary weight factors,
semi-infinite, or infinite intervals of integration. For ex- probably too wasteful of computing time for a fre-
ample, we might write quently used integration program).
EXAMPLE 2.4
where
-- ( ~ ( b- a): b +a)
where v is the mean fluid velocity, D is the inside dia- F(z) = J1 - z2 f . (2.4.12)
meter of the tube, and ,o and p are the density and vis-
cosity of the fluid, respectively, all in compatible units. The Gauss-Chebyshev quadrature formula of (2.1 13)
For smooth circular tubes in the range of Reynolds then becomes
number from 2000 to 50000, f i s adequately represented
[12] by the Blasius equation,
where
Problem Statement
zi = cos
([2(i - 1) + l]n) , i = 1 , 2 ,..., m,
Using an approach suggested by (2.117), derive a 2m
variant of the Gauss-Cfiebyshev quadrature (2.1 11) for
estimating the value of the integral
118 Numerical Integration
Begin
Example 2.4 Velocity Distribution using Gaussian Quadrature
c t eqn. (2.4.2)
I
- .%
(Function FUNCTN)
I
FORTRAN 1mplementatio.n
List of Principal Variables
Program Symbol Definition
(Main)
DUPLUS Atr;, the integral of (2.4.16).
FF Fanning friction factor, 3.
I Subscript, i.
M Number of points to be used in the quadrature formulas, m.
NYPL N,the number of values of y: .
PHI 4, the function of equation (2.4.5).
RE The Reynolds number, NR,.
UPLUS Th~edimensionless axial velocity u l corresponding to dimensionless distance y,?.
YPLUS The dimensionless distance from the tube wall, y:.
YPLUSM Th~edimensionless distance corresponding to the centerline of the tube, 7'.
(Function
FUNCTN)
C, D Pairameters c and d given by (2.4.2) and (2.4.3).
YPL y+, dimensionless distance from the tube wall.
(Function
CHEBY)
A. B Lower and upper limits of integration, a and b, respectively (see (2.4.13)).
F Integrand, f (see (2.4.13)).
SUM s, the repeated sum of (2.4.13).
XI x i , the root zi transformed to the interval [a, b].
ZI z i , a root of the mth-degree Chebyshev polynomial.
120 Numerical Integration
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 2.4
C VELOCI TY D l STR l BUT1 ON US I NG GAUSS I A N QUADRATURE
C
C T H l S PROGRAM COMPUTES D l MENS l ONLESS VELOCI TY D l S T R l BUT1 ONS
C FOR A F L U I D FLOWING I N S I D E A SMOOTH CIRCULAR TUBE BY
C INTEGRATION OF A R E L A T I O N S H I P DEVELOPED BY G I L L AND SCHER (SEE
C A l C H E JOURNAL, VOL 7, NO 1, P 6 1 ( 1 9 6 1 ) ) . RE I S THE REYNOLDS
C NUMBER, YPLUS THE DIMENSIONLESS DISTANCE FROM THE TUBE WALL,
C AND UPLUS THE DIMENSIONLESS VELOCITY I N THE A X I A L D I R E C T I O N A T
C D l STANCE YPLUS. YPLUSM I S THE VALUE OF YPLUS WHl CH CORRESPONDS
C TO THE CENTERLINE DISTANCE. FF, THE FANNING F R I C T I O N FACTOR,
C I S COMPUTED AS A FUNCTION OF RE U S I N G THE B L A S I U S EQUATION.
C PHI I S DESCRIBED I N THE PROBLEM STATEMENT. THE INTEGRAL
C I S EVALUATED U S I N G BOTH THE GAUSS-LEGENDRE AND GAUSS-
C CHEBYSHEV QUADRATURES, PERFORMED BY THE FUNCTIONS GAUSS ( S E E
C EXAMPLE 2.3) AND CHEBY RESPECTIVELY. THE FUNCTI ONAL VALUES FOR
C THE QUADRATURES ARE COMPUTED BY THE FUNCTION FUNCTN. FOR A
C G I V E N RE AND A S E T OF NYPL VALUES OF YPLUS, THE INTEGRATIONS
C ARE CARRIED OUT U S I N G SUCCESSIVE YPLUS VALUES AS THE L I M I T S
C OF INTEGRATION W I T H THE M P O I N T QUADRATURE FORMULA. PHI AND
C YPLUSM ARE ASSIGNED TO COMMON STORAGE TO S I M P L I F Y COMMUNICATION
C AMONG THE PROGRAMS.
C
I M P L I C I T REAL*S(A-H, 0-Z)
DIMENSION Y P L U S ( 1 0 0 )
COMMON PHI, YPLUSM
EXTERNAL FUNCTN
C
C ..... READ DATA, COMPUTE CONSTANT PARAMETERS
READ ( 5 , 1 0 0 ) NYPL, (YPLUS( I ) , I=2,NYPL)
.....
1 READ ( 5 , 1 0 1 ) RE, M
FF = 0 . 0 7 9 / R E * * 0 . 2 5
YPLUSM = RE*DSQRT(FF/2.)/2.
PHI = (YPLUSM-60. ) / 2 2 .
C
C ..... EVALUATE INTEGRAL U S I N G GAUSS-LEGENDRE QUADRATURE
Y P L U S ( 1 ) = 0.
.....
UPLUS = 0.
WRITE ( 6 , 2 0 0 ) RE, YPLUSM, M, Y P L U S ( l ) , UPLUS
DO 3 1 = 2, NYPL
I F (YPLUS(I).GT.YPLUSM) GO TO 4
DUPLUS = GAUSS( Y P L U S ( I - I ) , Y P L U S ( I ) , M, FUNCTN 1
UPLUS = UPLUS + DUPLUS
3 WRITE ( 6 , 2 0 1 ) YPLUS( I), UPLUS, DUPLUS
-
(1
C
4
..... EVALUATE INTEGRAL U S I N G GAUSS-CHEBYSHEV QUADRATURE
UPLUS = 0.
.....
WRITE (6,202) Y P L U S ( l ) , UPLUS
DO 6 1 = 2, NYPL
I F (YPLUS(I).GT.YPLUSM) GO TO 1
DUPLUS = CHEBY( Y P L U S ( I - l ) , Y P L U S ( I ) , M, FUNCTN 1
UPLUS = UPLUS + DUPLUS
6 WRITE ( 6 , 2 0 1 ) Y P L U S ( I ), UPLUS, DUPLUS
GO TO 1
C
100
..... FORMATS FOR I.NPUT AND OUTPUT STATEMENTS
FORMAT ( l o x , 1 2 / t20X, SF10.3)
.....
101 FORMAT ( l o x , F10.3, 20X, 1 2
200 FORMAT ( l O H l R E = ,F10.1/ 1 0 H YPLUSM = ,F11.2/ 10H M -
1 1 8 / 54HOVELOCITY D l S T R l BUTION U S l N G GAUSS-LEGENDRE QUADRATURE'
2 / lHO,SX, 5HYPLUS88X, SHUPLUS,lOX,6HDUPLUS/ lHO,F10.2,F15.7
2 0 1 FORMAT ( 1 H F10.2, 2F15.7
2 0 2 FORMAT ( S S H ~ V E L O C TY
I DISTRIBUTION USING GAUSS-CHEBYSHEV QUADRATUR
1 E / 1H0,5X, 5HYPLUS,8X, 5HUPLUS, 1OX. 6HnUPLUS/ l H 0 , F l O . 2.F15.7
C
END
Example 2.4 Velocity Distribution using Gaussian Quadrature
Function CHEBY
FUNCTION CHEBV( A, 8, M, F 1
C
C THE FUlNCTlON CHERY COPPUTES THE VALUE OF THE INTEGRAL OF
C F ( X ) * D K BETWEEN THE I N T E G R A T I O N L I M I T S A AND R U S I N G THE
C M - P O I N T GAUSS-CHEBYSHEV QUADRATURE FORMULA. Z I I S THE I - T H ROOT
C OF THE CHEBYSHEV POLYNOMIAL OF DEGREE M ON THE I N T E R V A L
C (-1,l) AND X I I S THE VALUE OF Z I TRANSFORMED TO THE I N T E R V A L
C (A,B). SUM I S THE SUM OF THE FUNCTIONAL VALUES A T THE M
C VALUES OF X I CORRECTED FOR THE WEIGHTING FUNCTION. THE
C UNIFORM WEIGHT FACTOR I S THEN A P P L I E D AND THE APPROXIMATED
C VALUE OF THE I N T E G R A L I S RETURNED AS THE VALUE OF THE FUNCTION.
C
I M P L l C l T REAL*B(A-H, 0-2)
REAL*8 CHEBY, A, B, F
C
SUM = 0.
D O 1 I = l , M
ZI DCOS(FLOAT(Z*( 1 - 1 1 + 1)*3.1415927JFbOAT ( 2 r M ) )
XI = (ZI+(B-A) + B + A)/2.
1 SUM = SUM + F ( X l ) * D S Q R T ( l . - Z I * Z I )
CHEBY = ( B - A ) * ~ . ~ ~ ~ ~ ~ ~ ~ * s u M / F L o A T ( ~ * M )
RETURN
C
END
Data
NYPL -
11
YPLUS(2)...YPLUS(6)
RE
RE
RE
RE
RE
RE
RE..
RE
RE
RE
RE
RE
RE
Numerical Integration
Computer Output
Results for the 11th Data Set
RE = 25000.0
YPLUSM = 700.59
M I 2
VELOCITY D l S T R l B U T I O N US l N G GAUSS-LEGENDRE QUADRATURE
0.0 0.0
1.00 0.9992443 0.9992443
2.00 1.9958208 0.9965765
5.00 4.8776166 2.8817958
10.00 8.4823031 3.6046865
20.00 11.8944744 3.4121713
50.00 15.1074984 3.2130241
100.00 16.9996247 1.8921263
200.00 18.7004495 1.7008247
500.00 20.5245821 1.8241326
VELOCITY D I S T R I B U T I O N U S I N G GAUSS-CHEBYSHEV QUADRATURE
0.0 0.0
1.00 1.1098645 1.1098645
2.00 2.2'166574 1.1067930
5.00 5.4059707 3.1893133
10.00 9.4129422 4.0069715
20.00 13.3053378 3.8923955
50.00 17.0892826 3.7839448
100.00 19.2499871 2.1607046
200.00 21.1825355 1.9325484
500.00 23.2999976 2.1174622
V E L O C I T Y D I S T R I B U T I O N U S I N G GAUSS-LEGENDRE QUADRATURE
V E L O C I T Y D I S T R I B U T I O N U S I N G GAUSS-CHEBYSHEV QUADRATURE
m (Gauss-Legendre (Gauss-Chebyshev
Quadrature) Quadrature)
2 20.5245821 23.2999976
4 20.5672100 21.1 692723
6 20.5672992 20.8286561
10 20.5672993 20.66041 13
15 20.5672993 20.6085537
Then
1 1
= -f hf (xo), (2.124a) For x = xj, that is, when x is one of the base points,
h (XI)-
2xo - 4x + 2x1 + 2h For example, (2.124b) can be written with its error term
as :
Notice that the leading factor in the error term for the
Other derivatives follow in obvious fashion, although the derivative at x, is just half that for the error term at xo
formulas quickly become rather cumbersome when and at x,. We would expect that the computed derivative
written in general form. estimate at the midpoint would be more accurate than
Error terms for the differentiation formulas are given those computed at the end points, since functional values
by the appropriate derivative of the remainder term for on both sides of the midpoint are used in the midpoint
the nth-degree interpolating polynomial R,(x), given by formula (2.132b) but not in the end-point formulas. Com-
(1.39b) as parison of the first derivative approximations, using
higher-degree interpolating polynomials (see, for example,
the extensive tables in [9]), shows that the magnitudes of
the coefficients of f'"+"(t) at the base points decrease
where = [(x) is an unknown point on the interval monotonically as x approaches the midpoint of the
(x,xo,. . .,x,). Unfortunately, [(x) may not be single- interval. In addition, the midpoint formula with n
valued or differentiable, although f("+')([) is, provided even is invariably simpler [for example, (2.132b)I than
f(x) itself possesses derivatives of higher order. If we let formulas for other base points. For these reasons, the
~ ( x=) n;=,,(x - xi) and use the finite divided-difference odd-point formulas (n even) are usually favored over the
equivalent off '"+"(t), [see (1.39a)], then R,(x) is given by even-point ones, and the base-point values should, if
possible, lie on both sides of the argument at which
df (x)/dx is to be approximated.
and its first derivative is To determine dmf(x)/dxmfor rn < n, we use (2.120). The
corresponding error term, assuming that f(x) possesses
derivatives of order n + m + 1, is given [9] by the rather
complicated expression
What is the error term for this approximation, and for what
degrees of polynomial will the formula be exact?
has degree of precision three; that is, it is exact if f(x) is a 2.9 What is the formulation of the quadrature given in
polynomial of degree three or less. Pmbkrn 2.6 when using n applications of,the rule in the evalu-
2.3 Find the error term for the improved trapezoidal rule ation of
of Problem 2.2.
2.4 The integral I = J: f(x) dx is to be estimated by a
trapezoidal-type rule, using two base points, x, and x,, that do
not necessarily coincide with the integration limits a and 6.
Show that the required approximation is 2.10 Consider the computation of the integral
where the coefficients ai (see Problem 1.50) are transfer coefficient h is given by
I *
a, = -J
n'o
f(cos e) do,
where
--t +
and T, k, c, and h are defined in Problem 3.43. The program
should also compute the fractional emission, Q/uT4.
Cold
fluid in
( m Ib/hr)
ISI I Condensate
' '
) Hot
tlu~dout
h=-
0.023k 4m
- ( ) 0.8 (pp)0.4
of magnitude). Assume that the value of p , (typically, 1 atm) is
sufficientlylow for the gas to be perfect in the range0 < p < p,,
D rDp so that
0.153 (constant)
erf x = j2 J e-"
7r 0
dt and compare with the true value, .rr/[2 sin(n/4)].
2.24 In a study by Carnahan [17], the fraction fTh of
certain fission neutrons having energies above a threshold
energy E,, (Mev) was found to be
are evaluated using a composite formula, equivalent to repeated can be developed for the case in which two base points are
application of the m-point Gauss-Legendre quadrature over preassigned (xo = - 1, x. = I), that the quadrature is exact
nonoverlapping subintervals of [a,b] of length (b - a)/n. when f(x) is a polynomial of degree 2n - 1 or less, that
2.22 Write a function, named LAGUER, that employs the xl,x2, . . ., x,, - are the zeros of PL(x), and that the weight
m-point Gauss-Laguerre quadrature formula (2.109) to factors are
evaluate numerically an integral of the form
A
write a function, named CHEBZ, with argument list (A, 6,F,
M, R ) that implements the composite version of the quadrature
developed in part (e) of Problem 2.27. Here, A and B are the
lower and upper integration limits, M is the number of points
in the quadrature formula, and R (integer) is the number of 7/',, Figure P2.29 ///A
2.38 Impien~entthe algorithm developed in Problem 2.37 the view factor becomes
as a function named INTZD. Use the function to evaluate the
integral
where the integral is taken over the area A z of the disc. Polar
coordinates should be used to span A 2 ,that is, let dA, = R dR
dB, where X is the radial measure (0 < R & a) and 8 is the
measure (0 < 8 < %n)in Az. , A
Figure P2.41
Suggested Tesi Data
L = 1, with Wl = W zhaving the values 0.5, 1, and 2 in
sequence.
2.42 Repeat Problem 2.41, now with an absorbing (but
not reradiating or scattering) gas intervening between the two
surfaces. :n this case, the integrand will have to be multiplied
by an additional factor e l B ' , where /3 is an attenuation coeffi-
Compute F d A , - 4 2 for all combinat~onsof L/a = 1,2, 3, and cient. Suggested values are PL = 0.5, 1, and 2.
5, a = JOO,60°, and 90°, using the fsnction SIMPC2 from 2.43 Two parallel squares of side L are opposite each other,
Problem 2.36. For a = 90", check the results against the a distance d apart. Starting from the definition given in
known analytical value: Problem 2.41, evaluate FlZ for radiant inte~hangebetween the
two squares for d/k = 0.5, 1, and 2.
2.44 A beam of radiation of intensity rF is incident at an
angle 80 to the normal of the surface of a semiinfinite medium
3.40 Express the integral of Problem 2.39 in terms of Car- that scatters isotropically with an albedo w o (fraction of a
tesian coordinates and use the function INTZD deveioped in pencil of radiation that is scattered at any point). Because of
Problem 2.38 to evaluate the integral for the data of Problem scattering within the medium, some of the radiation will
2.39. Compare the results vvith the analytical solution. reemerge from the surface. It can be shown (see, for example,
2.41 Consider radiant heat transfer between surface 1 and Chandrasekhar [25]) that the intensity of radiation emerging
surface 2, of total areas A, and A2,respectively. The view at an angle 0 to the normal is given by
factor F1l is defined as the fraction of the total radiation
leaving surface 1 that impinges on surface 2 directly. If surface
1is diffuse, radiating uniformly in all directions, it can be shown
that where p = cos B and p o = cos Bo. The function H satisfies the
~1 = -J- j-+,F
following integral equation, which is of general importance in
cos COS
~ ~ nAl A, A2
dAr dAz,
$2
theories of radiation scattering:
in increments of 0.1. Then, evaluate I/Ffor several test values (Eh- Ec), cr = a(X, L, p) = (TI - Ec)I(Eh- Ec), and 4 =
of 6, 60, and w,. $(L) = q/(Eh- Ed.)
2.45 As shown in Fig. P2.45, two infinite black parallel 2.46 Referring to Table 2.7, verify the algebraic approxima-
plates at absolute temperatures Thand T, are separated by an tions to the derivative and their associated error terms.
optical thickness T = L of a gray gas that absorbs and emits 2.47 Jenkins and White [24] give values, reproduced here
(but does not scatter) radiant energy. (Optical thickness in Table P2.47, for the refractive index, n, and the dispersion,
measures the ability of a gas path of length z to attenuate dn/dX, of barium flint glass. The wavelength, A, is in angstrom
radiation, and is defined as T = f', ~p dz, where p = density units.
and K = mass absorption coefficient.)
Table P2.47
7 =0 7=L
Figure P2.45
.................................................
+ 25f (x4)I-t h4f ("(0.
2.50 Show that for rn = 2, n = 4, and xi x0 + ih, (2.120) - x"o0 + Gal + xZa2 + ... + #a. =
n!
------ x:-".
(n - m)!
leads to the following formulations for f"(xi):
Hint: Equation (2.120)must be satisfied exactly iff ( x ) is a
1 polynomial of degree n or less, in particular, if f ( x ) = 1 , x, x Z ,
~ " ( x o=) +
[70f(xo)- 208jP(xI) 228f(xz) - 1 lZf(x3) .. ., x". This approach is known as the method of undetermined
5 h4 coeficients. Note that the formulation does not assume equal
+22f(x,)l- +
h 3 f ' 5 ' ( t ~ ) 15f(6'(Sz)7 spacing for the base points, x i , i = 0 , 1, .... n. (See also
Problem 5.9.).
1 2.52 Write a function, named DSPLIN, with argument list
f"(xl) = 24h2 [22f(xo)- 4 0 f ( x 1 )i- 12f(x2>+ sf(x3)
1 h4 (N, X, Y , XARG)
-2f(x4'1 Ti h 3 f c 5 ' ( ' 1 )- that will evaluate the derivative of the cubic spline function
(see Problems 1.24, 1.25, and 1.26) at x = XARG where the
I
f"(x2) = [-2f(x0) + 32f(x1)- 6 0 f ( x ~+) 32f(x3) +
N 1 base points for the spline fit are available in X('I ), ....
+
X(N I ) , and the corresponding functional values are avail-
1 able in Y (1 ), .... Y (N + 11. The value of S':(Y, XARG) should
- 2 f (x4)1+ g0 h 4 f (6)(5),
be returned as the value of DSPLIN.
140 Numerical Integration
Solution of Equations
the coefficient indicative of the multiplicity of the root Table 3.2 shows uk, vk, tk, v k / ~ ~and
- ~ tk+l/vk
, for values of
cannot vanish. k=3,4 ,..., 16.
It should be borne in nnind that a limit of the form
Table 3.2 Bernoulli's Method-Second Example
(3.11) can correspond to a multiple root. When limits of
the form (3.13) occur, a, and a, are found by solving k uk vk tk ~k/uk-l tk/~k-
- + +
x2 (a1 a2)x ala2 = 0. Here, too, the roots may be
1
multiple.
Note that the numbers formed often exceed the usual
floating-point range. The difficulty can be remedied by
dividing the last n values of the uk by some constant and
then proceeding.
As previously indicated, Graeffe's method may be used
prior to applying Bernoulli"~method in order to increase
the root-separation. Since convergence may be slow, and
since multiple roots must ble considered, we suggest that
as soon as convergence seems to be established, the pro-
cedures of Section 3.4 on the iterative factorization of
polynomials be employed.
A few further remarks concerning both Bernoulli's and
Graeffe's methods will be found in the next chapter when Thus the dominant roots are found as the solution of
companion matrices are discussed. Additional references +
x Z - 0.99993~ 1.0002, as compared with the true factor
to Bernoulli's method are given on page 161 of Henrici [I]. x2-xfl.
EXAMPLE 3.1
Problem Statement
Write a program that implements Graeffe's root-
squaring method for finding real and distinct roots of the
Then, given the initial values for the Ci, where
nth-degree polynomial
Ci = ,Ai = ai, (3.1.4)
the Bi for one iteration may be evaluated from
where the a i are real and a, # 0.
Test the program with several different polynomials, in
particular, the polynomial whose roots are related to the
frequencies of vibration for the mechanical system illus-
trated in Figure 3.1.1 (see Problem 4.23 for details). Con-
sider the horizontal motion of eight equal masses, that is, In (3.1.5), any elements C,, k < 0 or k > n, are arbitrarily
let m, = m2 = - .= m, = m. The spring stiffness coeffi- set to zero. After the computation of the Bi, i = 1,2, ., ..
cient, ki,i = I , 2, . . ., 9, is the force required to extend or n, each Bi is tested to insure that its value is well within the
compress the ith spring by unit length. Find the frequen- floating-point number range. The permitted number
cies of vibration for two cases: range is [-T, - l/T], 0,[I/T, TI. The nonzero Biare
A. m = 1 lb,, and k, = k , = .-.= k, = 1 Ibm/sec2. subjected to two magnitude tests,
B. m = 4 lb,, and ki = i/4 lbm/sec2,i = 1,2, ..., 9. IBiI < T
Method of Solution i=,2, . n. (3.1.6)
Graefle's method. In the program that follows, Graeffe's 141 > B*z. 0,
method as described by (3.3) and (3.4) is implemented.
Data for the program are: n, itmax, T, E , iprint, a,, ..., Should all Bi pass both tests, the root-squaring process
a,. Here, itmax is the maximum number of iterative squar- is continued. The Ci are assigned the newly computed
ing operations permitted. T is the maximum coefficient values of the B,, that is,
magnitude allowed, while 1/T is the minimum coefficient
magnitude allowed (aside from zero); these limits on
magnitude insure that all coefficients remain in the float- Then, the Bi for the next iteration are computed using
ing-point (REAL) number range. & is a small positive (3.1.5).
number used in the root test (3.1.9), and iprint is a The sequence (3.1.5), (3.1.0, and (3.1.7) is repeated
printing control switch. cyclically until at least one Bi fails one of the magnitude
The program first normalizes the coefficients a , tests (3.1.6), at which time the real and distinct roots, a,,
i = 0, 1, . . ., n, by dividing each by a,, that is. of (3.1.1) should be well separated and such that
Mechanical vibration system. Following the method are described in Chapter 4. One such method is to solve
outlined in Problem 4.23, the natural circular frequencies the characteristic equation of the matrix, described on
of vibration o of the above system are given by oZ= A, page 220. Using the method of Danilevski, outlined in
where 1 may be any one of the eigenvalues of the follaw- Section 4.9, the characteristic equations for matrix
(3.1.10) for the twb situations described in the problem
!]
ing matrix:
0 0 . 0 statement are :
k l + k 2 -k2
-kz k2+k3 .-k3 0 * 0 Case A. A* - 16 A7 + 105 i6 - 364 A5 + 715 A4
0 -k3 k 3 + k 4 -k4 0 - 792 A3 + 462 A2 - 120 1 + 9 = 0 (3.1.11)
•
.
0 0 0 0 . -ka ke+k9 Case B. A8 - 20 A' + 157.0625 A6 - 623.4374 A5
(3.1.10) + 1341.4450A4 - 1557.6560A3+ 912.2167A2
Several methods for obtaining the eigenvalues of matrices - 227.9003 A + 15.6643 = 0. (3.1.12)
Flow Diagram
146 Solution of Equations
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
Vector of polynomial coefficients, ai.
Vector of coefficients,B , of the squared polynomial after the current iteration (3.1.3).
ct Vector of coefficients, Cis of the squared polynomial prior to the current iteration (3.1.3).
EPS Small positive number, 6 , used in test (3.1.9) to determine if ai is to be considered a root.
I, IM1, IML, IPL i, i - 1, i - I, i + I, respectively.
IPRlNT Print control variable. If nonzero, coefficients Bi are printed after each iteration.
ITER Iteration counter, j.
ITMAX Maximum number of iterations allowed.
J Subscript (not to be confused with iteration counter).
L 1.
N n, degree of starting polynomial.
NPl n + 1.
PMINUS p-, value of p,( -Zi).
PPLUS p+, value of pn(Zi).
PVAL ~n(~i).
ROOT ui, possibly a root of p,(x).
TOP T, upper limit on the magnitudes of coefficients Bi, produced by the root-squaring process.
Program Listing
A P P L I E D NUCIEHICAL METHODS, EXAMPLE 3 . 1
GRAEFFE'S ROOT-SQUARING METHOD
c c i j = 1,
READ ( 5 , 1 0 0 ) N, ITMAX,TOP,EPS, IPRINT
NP1 = N- + 1
READ ( 5 , 1 0 1 ) (A(l),I=l,NPl)
.....
DO 2
NORMALIZE A C O E F F I C I E N T S , I N I T I A L I Z E C VECTOR
1 = 2, N P 1
.....
A(!) = A(I)/A(l)
C(1) = A(1)
A ( 1 ) = 1.
WRITE ( 6 , 2 0 0 ) N,ITMAX,TOP,EPS,IPRINT,NPl8(A(I~,I=1,NP1)
B ( I ) = B ( I ) + (-l.)**L*Z.*C(IPL)*C(IML)
B(I) = (-l.)+*lMl*B(I
I F ( 1PRIlNT.EQ.O GO TO 6
WRITE ( 6 , 2 0 1 ) ITER,NPl,(B(I),I*l,NPl)
.....
DO 9
HAVE ANY C O E F F I C I E N T S EXCEEDED S I Z E L I M I T S
1 = 2 # NP1
....,
I F ( ABS(M(I)).GT.TOP .OR. A B S ( B ( I ) ) . L T . l , / T O P .AND. 8(I).NE.0.0
1 GOT011
CONTI NUE e
.....
DO 1 0
S H I F T C O E F F I C I E N T S FROM B TO C FOR NEXT I T E R A T I O N
1 = 2, N P l
.....
C(1) = B(U)
WRITE (6,202)
I T E R = ITLdAX
C
C
..... COMPUTE
POLYNOMIAL .....
ESTIMATE OF ROOT FROM COEFFICIENTS OF SQUARED
ROOT= A B S ( B ( ' I ) / B ( I - 1 ) ) * * ( 1 . / 2 . * * l T E R )
Data
N = 2 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-1 IPRINT = 1
A(L)...k(3) = 1.0000 -3.0000 2.0000
N = 2 ITMAX = 3 TOP = 1.OE3O
EPS = 1.OE-1' IPRlNT = 0
A(l)...A(3) = 1.0000 -E.0000 2.0000
N = 3 ITMAX = 25 TOP = 1.llE30
EPS = 1.OE-1 l PRINT = 0
A ( 1 ) . ..A(4) = 2.0000 -12.aooo 22,0000 -~12.0000
N = 4 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-1 IPRINT = 0
A(l)...A(S) = 1.0000 -10.0000 35.0000 -50.0000 24.0000
N 3 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-1 IPRINT = 0
A(lI,..A(4) = 0.5000 4.0000 10.5000 9.0000
n = 3 ITMAX = 25 TOP = l,a~30
El's = I.0E-1 $PRINT = 0
A(l)...A(4) = 1.0000 -19.0000 55.0000 75.0000
N = 3 ITMAX = 25 TOP = I.OE30
EPS = 1.OE-1 IPRINT = 1
A ( 1 1 . ..A(4) = 0.2500 -2.2500 2.0000 -1.0008
Example 3.1 Graeffe's Root Squaring Method-Mechanical Vibration Frequencies
A(l)...A(5)
4
1.OE-1
=
ITMAX = 25
IPRINT = 0
1.0000. -35.0000
TOP = 1.OE3O
146.0000 -100.0000
N = 4 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-L IPRINT = 0
A(l)...A(5) = 1.0000 -16.0000 78.0000 -412.0000
N = 3 ITMAX = 25 TOP = 1.0~30
EPS = 1.OE-1 IPRINT = 0
A(l)...A(4) = 1.0000 0.0000 -3.0000 1.0000
N = 4 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-1 IPRINT = 0
A(l)...A(5) = 1.0000 -24.0000 150.0000 -200.0000
N = 4 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-I lPRlNT= 0
A(l)...A(S) = 1.0000 -1.0000 0.7500 0.2500
N = 4 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-11 1PR1NT = 0
A(l)...A(5) = 1.0000 -2.0000 1.2500 -0.2500 -0.7500
N = 8 ITMAX = 25 TOP = 1.OE30
EPS = 1.OE-11 IPRINT = 0
A(l>...A(5) = 1.0000 -16.0000 105.0000 -364.0000 715.0000
A(6)...A(9) = -792.0000 462.0000 -120.0000 9.0000
N = 8 ITMAX = 25 TOP = 1.OE30
EPS 1.OE-1. IPRINT = 0
A(l)...A(5) = 1.0000 -20.0000 157.0625 -623.4374 1341.4450
A(6)...A(9) = -1557.6560 912.2167 -227.9003 15.6643
Computer Output
Results for the 1st Data Set
N
ITMAX
TOP
I
=
- 2
25
1.OE 3 0
EPS 1.OE-01
IPRINT = 1
ITER = 1
ITER = 2
ITER 3
ITER = 4
So Iution of Equations
B(l),..B( 3)
1,000000E 00 -4.294967E 09 4.294967E 09
ITER 6
B(l)...B( 3)
1.000000E 00 -1.844674E 19 1.844674E 19
ITER = 7
B(l)...B( 3)
PROBABLY A ROOT
PROBABLY A ROOT
ITER = 1
ITER * 2
Example 3.1 Craeffe's Root-Squaring Method-Mechanical Vibration Frequencies
B(lI...B( 4)
ITER = 4
B(l)...B( 4)
ITER = 5
B(l)...B( 4)
1.000000E 00 -8.589935E 09 1.844674E 19 -1.84467hE 19
lTER = 6
PROBABLY N O T A ROOT
PROBABLY NOT A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
N - 8
ITMAX = 25
TOP = 1.OE 3 0
EPS = 1.OE-01
IPRINT = 0
PROBABLY N O T A ROOT
PROBABLY N O T A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
PROBABLY A ROOT
Example 3.1 Graeffe's Root-Squaring Method-Mechanical Vibration Frequencies 153
Discussion of Results Here the roots are well separated, and good accuracy is
Single-precision arithmetic was used for all calcula- attained in just four
tions. Results are shown for data sets 1,2, 7,9, 14, and Calculated
15. In most cases, the printing of intermediate coefficients Data Set 7 (results shown) Roots True Roots
was not requested. Final results for each data set are
listed below, along with the polynomial pn(x) and the pn(x) = 0.25x3 - 1.25x2 2.021778 2.000000
known roots. +2x-1 1.978456 2.000000
ITER = 6 1. ~ 0 0 0 1.000000
Calculated
Data Set 1 (results shown) Roots True Roots Again, as in data set 5, there are multiple real roots. If
a multiple root were known to exist, then (3.8) could be
pn(x) = xZ - 3x + 2 2.000000 '2~~00000 applied to find better root values from the solution of the
Number of iterations, 1 .oooooo 1 . ~ ~ 0 0 0 0 quadratic equation
ITER = 7
Calculated
Data Set 2 (results shown,) Roots T~~~R~~~~ The predicted roots are:
2.000000 a f 6= a f 4= 1.8446745 x 1019
1.000000 ag4 h 1.8446745 x 1019
In this case, the maximum number of iterations permitted which to seven significant figures yields a, & a 2
was 3. Hence the roots of the squared polynomial have 2.000000.
not been separated far enough to attain the accuracy
shown for the same polynomial in data set 1. Calculated
Data Set 8 Roots
Calculated
Data Set 3 Roots True Roots pn(x) = x4 - 35x3 + 146~' - lOOx + 1 30.288681
ITER = 4 3.858056
pn(x) = 2x3 - 12x2 + 22x - 12 2.999999 3.000000 .843 107
ITER = 6 2.000000 2.000000 .010150
1 .oooooo 1.000000
This polynomial is the characteristic function found by
Calculated the method of Danilevski (see Chapter 4) for the sym-
Data Set 4 (Roots True Roots metric matrix
+
p,(x) = x4 - lox3 3 5 ~ ~ 4.00001 1 4.000000 1 0 9 7 5
- 50x+ 24 2.999990 3.000000
ITER = 5 1.999999 2.000000
1 .oooooo 1 .oooooo
Calculated Calculation of the roots of pn(x) (the eigenvalues of the
Data Set 5 R~~~~ T~~~R~~~~ matrix) using the Power, Rutishauser, and Jacobi
methods (see Examples 4.2, 4.3, and 4.4, respectively)
+
pn(x) = 0 . 5 ~ 4x2
~ + 1 0 . 5 ~ -3.065690 - 3.000000 yielded the following results:
+ 9 -2.935715 -3.000000
ITER = 5 - 1.999999 -2.000000 Power Method Rutishauser M e t h o d Jacobi Method
In this case the dominant root has multiplicity 2. The 30.288685 30.288685 30.288685
program indicated that -- 3.065690 and -2.935715 were 3.858057 3.858057 3.858057
probably roots, since the polynomial values were 0.843107 0.843107 0.843107
-0.00593 and -0.00386, respectively, smaller than the 0.010150 0.010150 0.010150
data value read for E (0.1). Typically, Graeffe's method Calculated
estimates of multiple real roots will span the true value, Data Set 9 (results shown) Roots True Roots
that is, (-3.066 - 2.936),12 A -3.0.
pn(x) = x4 - 16x3 + 78x2 11.999994 12.000000
Calculated - 4I2x + 624 5.324727 ( N R ) 1.0 + 5i
Data Set 6 Roots True Roots ITER = 4 4.882880 (NR) 1.0 - 52'
pn(x) = x3 - 19x2 + 55x -f 75 14.999993 15.000000 2.000000 2.000000
ITER = 4 4.999995 5.000000 The program indicated correctly that 5.32 and 4.88 were
- 1.000000 - 1.000000 probably not roots (NR). The two real roots were found,
154 Solution of Equations
but not the pair of complex conjugate roots. The starting This polynomial is used in the numerical example of Sec-
polynomial in this case is the characteristic function of tion 3.2. The two real and distinct roots were found. The
the matrix pair of complex conjugate roots was not found, as
before. Equation 3.8 could be used to find them, however.
Calculated
Data Set 14 (results shown) Roots
Calculated +
pn(x) = x8 - 16x7 1 0 5 -
~ 364x5
~ 3.931828 (NR)
Data Set 10 Roots True Roots + +
715x4 - 792x3 46%' 3.504101 (NR)
pn(x) = x 3 - 3~ +1 - 1.879385 - 1.879385 - 120~ 9+ 2.987610
lTER = 4 2.344709
ITER = 7 1.532089 1.532089
1.652354
0.347296 0.347296
0.999980
The computed roots agree exactly with the roots calcu- 0.46791 1
lated for pn(x) by the method of successive substitutions 0.120615
(see Table 3.5).
Calculated This polynomial is the characteristic function for the
Data Set 11 Roots True Roots eighth-order striped symmetric matrix (3.1.10) for Case A.
pa(%)= x4 - 24x3 14.999993 15.000000
It is also used as an example data,set for calculation of -
the roots (eigenvalues) by the Power, Rutishauser, and
+ 150x2 - 2 0 0 ~ 5.221369 (NR) 5.000000
Jacobi methods (see Examples 4.2,4.3,4.4).
-375 4.788013 (NR) 5.000000
ITER = 4 - 1.00oooo - 1. 0 0 m
Power Method Rutishauser Method Jacobi Method
This is the characteristic function of the matrix
3.879385 3.879385
3.532089 3.532089
3.000000 3.000000
2.347296 2.347296
1.652704 1.652704
Calculated 1.000000 1.000000
Data Set 12 Roots True Roots 0.4679 11 0.46791 1
0.120615 0.120615
+
pn(x) = x4 - x 3 0.75x2 1.000000 (NR)
0.5 JJi
+ 0 . 2 5 ~- 0.25
+_
2
The vibrational frequencies predicted by Graeffe's method
ITER = 6 I .OOOOOO (NR) 0.5 -- for the mechanical system of Fig. 3.1.1 with the parameter
- 2 values for Case A are:
0.505445 0.500000
-0.494614 -0.500000
In this case there are two pairs of roots, one complex
conjugate, the other real. As before, the routine fails to
find accurately any root from a root pair.
Calculated
Data Set 13 Roots True Roots
+
pn(x) = x4 - 2x3 1.25x2 1.500000 1.500000
- 0 . 2 5 ~- 0.75 The two or three highest frequencies computed using
ITER = 8
1.000000 (NR)
0.5 i + J5 Graeffe's method may not be of adequate accuracy.
2 However, the method has produced good approximations
1.000000 (NR)
0.5 -
J3 to these roots. These may be used as first estimates in
one of the iterative root-finding procedures to be dis-
cussed later in this chapter.
Example 3.1 Graefle's Root Squaring Method-Mechanical Vibration Frequencies 155
Calculated adequate accuracy, but can serve as very good starting
-
Data Set 15 (results shourn) Roots True Roots values for some other root-finding method. Based on the
Graeffe's method results, the natural frequencies for the
P,(x) = x8 - 20x7 6.595325 (NR)
+ 157.0625x6 4.708691 (NR) mechanical system of Fig. 3.1.1 with the parameter
values of Case B are:
- 623.4374~~ 3.365894
+ 1341.4450x4 2.342498
- 1557.6560x3 1.544105
-I-912.2167x2 0.912852
-227.9003~ 0.425053
$ 15.6643 0.106776
ITER = 4
3.4 Iterative Factorization of Polynomials and let the Jacobian involved in the Newton-Raphson
The techniques discussed thus far are usually useful in technique be different from zero at the point p =
finding approximate values of one or more roots off (x). (p,,p,,. .., p,). Let P") = (py', py, . ..,p:)) and let the
Should a root be located which is not multiple-valued, a point P(') be "near enough" to p. Then the sequence of
procedure such as Newton's method (p.171) can be em- points {P'j)), defined below, converges to p, and
ployed to determine the root more accurately. In such
event, a polynomial of reduced degree can be formed for
further investigation by ordinary synthetic division (p.7).
Proceeding in this manner, if no multiple roots are present, Po = 1 and p = (PI, /I2,..., Po) is given by
the solution can be completed. However, this procedure
can be expected to make approximations to successive /I = lim (by), bij), ..., b:!,).
j-m
roots more and more inaccurate, and the presence of
multiple roots causes difficulty. In this section (see also Here the numbers by) are related to the numbers pl') [see
Luther [6]), a method is presented for improvingtheaccu- (3.1511 by
racy for single roots, and for maintaining a balance of m
accuracy among the various roots as solution progresses. 1pii'b$-?i
i=O
= at, bj" = 0 for s < 0. (3.18)
Bairstow's method [4] is an algorithm for finding
quadratic factors iteratively for the polynomial of (3.2). To find the numbers pj"" from the numbers p?,
The iterative technique which follows produces factors of (1 < i < m), first solve, for the numbers cp), the equations
arbitrary degree m for this same polynomial. Program- (O<k<n):
ming in terms of m as a parameter is simple: when m is
unity, the method is Newton's method; for m equal to
...
p!"c$ci = - bij), c:" = 0 for s < 0. (3.19)
two, the method is closely related to Bairstow's method, i=O
but is somewhat simpler.
Consider first the problem, useful in its own right, of Then, having thus determined the cy (0 < s < n), solve,
dividing for the pji+'), the simultaneous linear equations:
~4 = -b4 - ~ z p z
- C3P1,
removed from f(x). This process also delivers the equa-
tion of reduced degree, which can then be studied. CZP; + C I P ; = -2b3 - cs,
Successive factors can be combined so as to maintain a csp; + C ~ P = ; -264 -~ 4 .
better accuracy balance for successive zeros. Table 3.3 illustrates the resulting sequences. Thus, in terms
Example. Consider the polynomial of the previous section, of quadratic factors, the polynomial is
namely, f ( x ) = (x" - x + 1)(x2- 0.25).
f ( x ) = x4 - x3 + 0.75x2 + 0 . 2 5 ~- 0.25, For the same polynomial, the sequence using a starting
factor ( x 2+ OX + 0 ) is shown in Table 3.4. Thus, the same
and use as an approximate factor the result of the tenth step factors,
of the 33ernoulli process, or x Z - 1.001Ox + 0.9961. Using
+
primed letters for the (k 1)th step and unprimed letters for f ( x ) = (x" 0.25)(x2 - x l), +
the kth step, the appropriate formulas are: have been found, but this time in reverse order.
X +c n m j i n - m - j + i > 0,
Xi,j 0,+ n - r n - j + i < ~ , ] j = 1 , 2 ,..., rn, i = 1 , 2 ,..., m. (3.2.8)
Xi,m+l + -(2bn-m+i + cn-rn+i),
The function SIMUL is called to solve the equations for
bo = a. = 1
\ the pi, which are then overstored in the p vector,
bi = a, -
bi = a, -
i
j= 1
m
j= I
pjbi-j,
pjbiej,
i < m,
i > m,
IJ (3'2'4)
'picpi, i = 1,2, ..., m. (3.2.9)
The iterative factorization process is continued until the
convergence test is passed, or until the maximum number
of factorization cycles has been completed.
Example 3.2 Iterative Factorization of PoIynomials
Flow Diagram
"Bad
I
I
I
I
I
I
I
I
L---------------
I
iter 1 I
I
Po, . . ., Pm, I
bo, . . ., b, Solve system of I
linear equations &4Xi,m+l + -(2bn-rn+:+ cn-m+iI 1I
with augmented I
coefficient matrix X F---------- -- 7 I
for unknown \ I
p i , i = 1,2,..., m Pi + P I
(Function SIMUL).
O-q-J-J Convergencew
160 Solution of Equations
FORTRAN Implementation
List of Principal Variables
Program Symbol DeJinition
At Vector of coefficients, a i , of the starting polynomial, 4,(x).
B. C t Vector of coefficients, bi (see (3.2.4)) and ci (see (3.2.5)), respectively.
CHEK el, small positive number used in the termination test (3.2.6).
EPS Minimum pivot magnitude allowed during Gauss-Jordan solution of linear equations (see
SIMUL).
I, IMJ, J, K i, i -j, j, and k, respectively.
ITER Iteration counter for the factorization algorithm, iter.
ITMAX Maximum number of iterative cycles permitted, itmax.
M m, degree of the desired factor, g(x) (see (3.2.1)).
MPI, MPI MI m + 1 and m -I-1 - i, respectively.
N n, degree of starting polynomial, &(x).
NMII, NMJI, NPI -
n - m + i + 1, n - m j + i, and n + 1 , respectively.
P t Vector of coefficients, p i , of the polynomial factor, g(x) (see (3.2.1)).
SIMUL SIMUL implements the Gauss-Jordan reduction scheme with the maximum pivot strategy
to solve systems of linegr equations (see Example 5.2). For argument list (m, X, p, E), SIMUL
calculates the solutionsp,,p, .. .,p, ,for the m simultaneous linear equations whose augmented
coefficientmatrix is in them x (m i- 1) matrix X.E is the minimum pivot magnitude which will
be used by function SIMUL.
SUM The repeated sum in convergence test (3.2.6).
X X,the m x (m + 1) augmented coefficient matrix for the linear equations of (3.2.7) (see (3.2.8)).
t Because of FORTRAN limitations (subscripts smaller than one
are not allowed), all subscripts on the vectors of coefficients a, b, c,
and p that appear in the text and flow diagram are advanced by one
when they appear in the program; for example, a, becomes A(l),
+
p , becomes P(M l), etc. Limitations on the:form of subscript
expressions and the absence of a zero subscript in most FORTRAN
implementations, result in the introduction of a number of variables
that do not appear in the flow diagram.
Example 3.2 Iterative Factorization of Polynomials
Program Listing
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 3.2
C I T E R A T I V E FACTORIZATION OF POLYNOMIALS
C
C T H I S PROGRAM USES AN I T E R A T I V E PROCEDURE TO FACTOR A POLYNOMIAL
C OF DEGREE M W I T H COEFFICIENTS P ( I ) . . . P ( M + l ) FROM A POLYNOMIAL
C OF DEGREE N WITH COEFFICIENTS A ( l ) . . . A ( N + l ) . SUBSCRIPTS
C l NCREASE WITH DECREASING POWERS OF THE VARIABLE. COEFFI C l ENTS
C OF THE N TH DEGREE POLYNOMIAL ARE F I R S T NORMALIZED BY
C
C
C
P(2). ..
D I V I D I N G EACH BY A ( 1 ) . I N I T I A L ESTIMATES FOR THE COEFFICIENTS
P ( M + l ) ARE READ AS DATA. THE COEFFICIENTS OF THE
RESIDUAL POLYNOMIAL ARE SAVED I N B ( l ) . . . B ( N + l ) . THE PROCEDURE
C INVOLVES I T E R A T I O N TO IMPROVE CURRENT VALUES OF THE COEFFI-
C CIENTS P ( 2 ) . . . P ( M + l ) I N SUCH A WAY THAT THE COEFFICIENTS OF THE
C RESIDUAL POLYNOMIAL B(N-M+2)...B(N+l) VANISH. THE COEFFICIENTS
C C(l)...C(N+l) (SEE TEXT) ARE SAVED I N THE C VECTOR. CONVERGENCE
C I S ESTABLISHED WHEN THE ACCUMULATED MAGNITUDE (SUM) OF
C R(N-M+2)...B(N+l) I S LESS THAN CHEK. WHEN THE CONVERGENCE TEST
C FAILS, THE FUNCTION S I M U L (SEE PROBLEM 5.2) I S CALLED TO
C SOLVE THE SET OF LINEAR EQUATIONS FOR THE UPDATED P VALUES,
C WITH THE AUGMENTED C O E F F I C I E N T MATRIX I N THE ARRAY X.
C EPS I S THE MINIMUM P I V O T MAGNITUDE ALLOWED BY SIMUL.
C I T E R A T I O N PROCEEDS U N T I L THE CONVERGENCE TEST I S PASSED OR
C U N T I L ITER, THE NUMBER OF ITERATIONS, EXCEEDS ITMAX.
C
I M P L I C l T REAL*B(A-H, 0-2)
DIMENSION A ( 2 0 1 , B ( 2 0 1 , C ( 2 0 ) , P(20), X(21,21)
C
C ..... READ DATA, NORMALIZE A'S,
1 READ (5,100) N,M, ITMAX,CHEK,EPS,(A(I
PRINT .....
), I = l , N ) , A ( N + l )
N P 1 = N + :I
MP1 n M + 1
READ ( 5 , 1 0 1 ) ( P ( I ) ,I =2,MP1)
DO2 1 = 2 , NP1
2 A(!) = A(I)/A(l)
A ( 1 ) = 1.
B ( 1 ) = 1.
C ( 1 ) = -1.
P ( 1 ) = 1.
WRITE (6,200) N,M, ITMAX,CHEK,EPS,NPl,(A(l ),l=l,NPl)
WRITE (6,201) MP1, ( P ( 1 ), I = l , M P l )
C
C .....
IF
CHECK
M.GT.0
(
FOR ARGUMENT CONSISTENCY
.AND. t4.LT.N GO TO 4
.....
WRITE (6,202)
GO TO 1
C
C
S
.....
DO 1 9
BEG1 N l TERATI VE FACTORIZATION
I T E R = 1, ITMAX
.....
C
C .....
SUM = 0.
COMPUTE COEFFICIENTS I N B AND C ARRAYS AND SUM .....
K = 1
DO 11 I 2, N P 1
B(I) = A({)
I F (K.LT.MP1) K = K + 1
6 DO7
IMJ = I
7 B(I) = B(l 1
- -
J = 2 , K
J
P(J)*B(IMJ+l)
I F ( I.GT.FIP1-M ) SUM = S U M + D A B S ( B ( I ) )
C(I) = -B(I)
DO 11 J a: 2, K
IMJ = I - -
Jl
11 C ( 1 ) = C ( I ) P(J)+C(IMJ+l)
C
C ..... CHECK FOR CONVERGENCE
I F ( SUM.Gl'.CHEK ) GO TO 1 3
.....
WRITE ( 6 , 2 0 3 ) ITER,MPl,(P( I), I = l , M P l )
WRITE (6!,204) NPl,(B(I),I=l,NPl)
GO TO 1
162 Solution of Equations
18
DO 1 8 --
SOLVE LINEAR EQUATIONS FOR NEW P'S
CALL SIMULC M, X, P, EPS, 1, 2 1
M P l M l = MP1
1 1, M
I
P ( M P l M I + l ) = P(MP1MI
SUBSCRI PTS
19 P ( 1 ) = 1.
WRITE (6,205)
GO TO 1
END
Data
N = 4 = 2 ITMAX = 30
CHEK = 1.0E-2 = 1.OE-20
A(l)...A(5) =
P(2)...P(3) =
N = 4
CHEK 1.OE-4
A(l)...A(5) =
P(2)...P(3) = 10.000 10.000
N = 4 = 2 ITMAX = 30
CHEK = 1.OE-4 1.OE-20
A(l)...A(5) = 1.000 -10.000 35.000 -50.000
P(2)...P(3) = 0.000 0.000
N = 4 = 3 ITMAX = 30
CHEK = 1.OE-4 = 1.OE-20
A(l)...A(S) = 1.000 -10.000 35.000 -50.000
P(2)...P(4) = 10.000 10.000 10.000
N = 4 = 3 ITMAX = 3 0
CHEK = 1.OE-4 = 1.OE-20
A(l)...A(5) = 1.000 -10.000 35.000 -50.000
P(2)...P(4) = 0.000 0 .DO0 0.000
N = 4 = 1 ITMAX = 30
CHEK = 1.OE-4 = 1.OE-20
A(l)...A(5) = 1.000 -10.000 35.000 -50.000
P( 2 = 10.000
N = 4 = 1 ITMAX = 3 0
CHEK = 1.OE-4 = 1.OE-20
A(l)...A(5) = 1.000 -10.000 35.000 -50.000
P(2) P 0.000
N = 4 M = 4 ITMAX = 3 0
CHEK = 1.OE-4 EPS 1.OE-20
A(l)...A(5) = 1.000 -10.000 35.000 -50.000
P(2)...P(5) = 10.000 10.000 10.000 10.000
Example 3.2 Iterative Factorization of Polynomials
Computer Output
Results for the 1st Data Set
N e 4
M I 2
=
-
ITMAX :I 0
CHEK = 0.01000
EPS 0.1D-19
ITER = 12
P(l)...P( 5)
1.000000 10.000000 10.000000 10.000000 10.000000
BAD DATA ENCOUNTERED AND IGNORED
ITER = 6
000000'0 000000'0 000000'1 000000'1- 000000'1
(5 )8""(1)8
000052'0- 000000'0- 000000'1
(£ )d""(I)d
S = 11311
3.5 Method of Successive Substitutions previously mentioned. If we set xj+,= cos(xj), then
F'(x) = -sin x. The reader should establish graphically
The following discussion is not confined to polynomial
that IF'(a)l < 1 for the unique solution a.
equations. We rewrite (3.1) in the form
Note that the equation x = F(x) can be formed from
x = F(x), (3.21) the original equation, f ( x ) = 0, in an unlimited number
such that iff (a) = 0, then a = F(a). If an initial approxi- of ways. While the choice of F will depend on the par-
mation x , to a root a is provided, a sequence x,, x,, .. . ticular situation, one suggestion is offered. If a = F(a),
may be defined by the recursion relation +
then also a = (1 - k)a kF(a); therefore, instead of
(3.22), we can consider
xj+ I = F ( x j ) , (3.22)
with the hope that the sequence will converge to a. The
successive iterations are interpreted graphically in to see whether a suitable choice of k will affect conver-
Fig. 3.la. gence favorably.
(a) (b)
Figure 3.1 Graphical interpretation of method of successive substitutions.
Convergence will certainly occur if, for some constant Further discussion of this and other iterative methods
p where 0 < p < 1, the inequality can be found in Traub [14].
IF(x) - F(a)l < A x - 4 (3.23) Example. Consider the equation
holds true whenever Ix - a1 < Ix, - a / . For, if (3.23)
holds, we find that
1x2 - 4 = IF(x1) - al = IF(x1) - F(a)I <PIX, -4 ,
sincc a = F(a). Proceeding,
- a1 = IF(x,) - F(a)l < plx, - a1 < p21x, - BI.
Con Linuing in this manner, we conclude that Ixj - a 1 <
Ix, - a [ , and thus that lirn x j = a.
j-+ -D
Starting Value,
XI: 0.5 1.5 -1.5
3.6 Ward's Method where K and the c 4 ] are positive, cannot be solved by the
Let the polynomial f(z) be a function of the complex process just described if z = 0 is the point of departure.
variable z = x + iy, so that One can, of course, introduce variations of the search
process described above.
To show that if w(x,y) # 0, there does exist in every
neighborhood of (x,y) a point (x',yl) such that w(x',yf) <
Clearly, f(z) has a zero cr = /3 + iy if and only if u(0,y) =
w(x,y), proceed as follows, writing z = x + iy and
v(P,y) = 0.This pair of simultaneous equations in u(x,y)
z' = x' + iy'. We have
and u(x,y) may be used in various ways. One may, for
example, seek to minimize u2(x,y) f- v2(x,y). Ward's 1
method [3] seeks to minimize f (z') =f (z) + (2' - z,"[,f'"'(z)
m. + ~(ZI)],
where f("jjz)/m! is the second non-zero coefficient in
Since no derivatives are employed, the method seems well Taylor's expansion of f(z@) in powers of z' - z. Also,
suited for finding multiple roots. The technique is based S(Z)= 0, for s(zl) = (z' - z)[f (m'')(~)+ r(zl)]/(m + 1>!
on the knowledge (subsequently verified) that in every Let f("'(z)/m! = aeih and let z' - z = reir. Choose r, so
170 Solution of Equations
small that Is(z')l = k < a13 for r < r,. Then if f ( z ) = lu + rmacos 4 + rmkcos $1 = iul - P ( a + k cos $)
Let $ = b + m , # = c + m ~ . T h e n Also,
w(x',yf) = (u + P a cos 4 + rmkcos #(
+ lv + rmasin 4 + rmksin $1.
Iv + rmasin 4 + rmksin $1 c Ivj + -a3 rm.
Then, in this case as well, w(xfy') c w(x,y).
Jf # O* r2 that r2 rl and +1' < IuI. Finally, if u = 0, and, of course, f 0, choose r, so
If u v 0, choose $ = n and r c r2. Then that r,- c r,- and r?(a + k ) < 101. If v > 0, choose 4 =
lu + ma cos 4 + rmkcos =u - rma+ rmkcos $ -n/2; if v < 0, choose 4 = n/2.Then for r < r, we have,
as before, w(xl,y') < w(x,y).
< u - rma+ rmk
+
Example. Starting with z = 1 i, and with an initial step
a h = 0.1, find a zero of the following function:
<u-rma+fz
3 f ( z )= z4 - 22' + 1 .25z2 - 0.252 - 0.75
2
c u - - arm.
+
= ( Z - l . 5 ) ( ~ 0.5)(z2- z + 1)
3 = (Z- I.S)(Z + + ) x-z0.5(1 - iJj)).
O . ~ ) ( Z- 0.5{1 iJ ~
Also, Since z = x+ iy, f ( z )= u + iv, where
u = x4 - 6x2ya+ y4 - 2x3 + 6xy2 + 1.25~' - 1.25~'
+
Ju J"a sin 9 + r"'k sin *I < Jvl + rm3 ' - 0.25~- 0.75,
v = 4x3y - 4xy3 - 6x2y + 2y3 + 2 . 5 ~ 0.25~.
~ -
Therefore, w(x',yf) < lul + Ivl - 3arm< w(x,y). Table 3.6 lists the successive values of x, y, lul, Ivl, and
Suppose next that u < 0. Choose 9 = 0, Then, for w(.= lul +1 ~ 1 ) . Unnecessary calculations are, of course,
r < r2, omitted. The required root is approximately 0.500 +0.860i.
3.7 Newton's Method It can be shown that if ci is a simple zero of f(x) and
Newton's method for finding the zeros of f(x) is the if lirn,,, xk = a, then
most widely known, and it is not limited to polynomial
functions. It will be presented here for the complex case.
Consider, then, z = x + iy and f(z) =: u(x,y) iu(x,y). +
For an iterative process, the complex expression This means that once xk is near a, the error in the next
step is proportional to the square of the error in xk; the
resulting quadratic convergence is then rapid in com-
parison with the linear convergence of several other
is equivalent to the two expressions methods.
To understand (3.31), recall, by Taylor's theorem. that
lim x-k+l-a -- 1
[/"(a)
1
- if "(a)] =
f "(a)
-
(x, - aI2 f '(a)
k-. a 2f ' ( 4
'
Then the asymptotic convergence factor for a zero, a, of Example. Starting at the point ( l , i ) , use Newton's method
f (x) becomes, for x real, to find a zero of the following function, in which z = x + iy:
f (z) = z4 - 22" 1.25z2 - 0.252 - 0.75
= (Z - 1.5)(z + 0.5)(z2 z i1)
-
This means that convergence is guaranteed (for f '(a) # 0) = (z - I.S)(Z + 0.5)(z - O.S{I + i J i ) ) ( z I i J3)).
- o . ~ {-
if the initial value x, is near enough to a.
For this function,
If f(x) is the polynomial (3.2), observe that f(r) may
be written in the form +
u(x,y) = x4 - 6x2y2 y4 - 2x3 + 6xy2 i -1.25x2
(-. .(((I))- + a'))- + az)r. - -)r + a,. -~0 . 2 5 ~- 0.75,
-1 . 2 5 ~
u(x,y) = 4x3y - 4xy3 - 6x2y + 2y3 + 2.5xy - 0.25y,
This is really synthetic division. It may be phrased u,(x,Y) = 4x3 - 12xy2 - 6x2 + 6y2 + 2 . 5 -~ 0.25,
iteratively as f (x) = (x - r) C;:,' bixn- '- + b,, with
,
b , + , = b,r + a,+ [see equation (3.15), using m = 1 and u , ( x , ~ )= -12x2y + 4y3 + 12xy - 2 . 5 ~ .
p , = r]. Observe that f '(r) = XE,' birn-' - '; therefore, Table 3.7 lists x' and y' as the iterative successors of -
f (r) and f'(r) can be calculated simultaneously. x and y.
172 So lutio* qf Equations
Flow Diagram
+ Aoa-- RcB,
O-(O-(k
Begin
a, A,, b,&, c,
R, E , itmax, T, P
y t -RTBob
g , .beTo 2
T~ - 7
I
I
I
I
v, RT
-
4-
P V
I
I
I
FORTRAN Implementation
List of Principal Variables
w Convergence"
Program Listing
C APPL l ED NUMER l CAL METHODS, EXAMPLE 3.3
C SOLUTION OF AN EQUATION OF STATE U S I N G NEWTON'S METHOD
C
C G I V E N A TEMPERATURE T AND PRESSURE P, T H I S PROGRAM USES
C NEWTON'S METHOD TO COMPUTE THE MOLAR VOLUME V OF A GAS WHOSE
C PRESSURE:-VOLUME-TEMPERATURE BEHAVIOR I S DESCRI BED BY THE
C BEATTIE-BRIDGEMAN EQUATION OF STATE. R I S THE UNIVERSAL GAS
C CONSTANT. A, AZERO, B, BZERO AND C ARE E M P I R I C A L CONSTANTS,
C D I F F E R E N T FOR EACH GAS. BETA, GAMMA, AND DELTA ARE TEMPERATURE-
C DEPENDENT PARAMETERS DESCRIBED I N THE PROBLEM STATEMENT.
C I T E R I S THE I T E R A T I O N COUNTER AND DELTAV THE CHANGE I N V
C PRODUCED BY ONE A P P L I C A T I O N OF NEWTON'S ALGORITHM. FOR
C CONVERGENCE, THE MAGNITUDE OF DELTAV/V I S REQUIRED TO BE
C SMALLER THAN SOME SMALL P O S I T I V E NUMBER EPS. AT MOST ITMAX
C I T E R A T I O N S ARE ALLOWED. I F THE CONVERGENCE TEST I S PASSED,
C THE COMPRESS l B l L l TY FACTOR Z I S ALSO COMPUTED. THE l DEAL
C GAS LAW I S USED TO GET A F I R S T ESTIMATE OF V. I T I S ASSUMED
C THAT TC, THE TEMPERATURE READ I N AS DATA, HAS U N I T S OF
C DEGREES CENTIGRADE. T HAS U N I T S OF DEGREES K E L V I N . UNITS
C FOR A L L OTHER PARAMETERS MUST BE DIMENSIONALLY CONSISTENT.
C
1 READ ( 5 , 1 0 0 ) A,AZERO,B,BZERO,C,R,EPS, ITMAX
WRITE (6,200) A,AZERO,B,BZERO,C,R,EPS, ITMAX
C
2 READ ( 5 , 1 0 1 ) TC,P
C
C ... ..COMPUTE TEMPERATURE-DEPENDENT PARAMETERS FOR GAS
T = TC + 2 7 3 . 1 5
.....
BETA = R * T t B Z E R O
GAMMA = -R*T*BZERO*B + AZERO*A
-
AZERO -
R*C/(T*T)
-
R*C*BZERO/(T*T)
DELTA = R * R Z E R O * B * C / ( T * T )
C
C ...
..USE
V = R*T/P
I D E A L GAS LAW FOR F l RST VOLUME ESTIMATE .....
C .....
DO 4
B E G I N NEWTON METHOD I T E R A T I O N
I T E R = 1, ITMAX
.....
DELTAV = ( ( ( ( ( - P * V + R * T ) * V + B E T A ) t V + G A M M A ) * V + D E L T A ) * V ) / -.
1 (((R*T*V+2.*BETA)*V+3.*GAMMA)*V+4.*DELTA)
V = V + DELTAV
WRITE ( 6 , 2 0 2 )
GO TO 2
Data
A = 0.01855 AZERO = 2.27690 B = -0.01587 ,
BZERO = 0.05587 C = 128300. R = 0.08205
EPS = 1.OE-6 ITMAX = 20
TC = 0.00 P = 1.00
176 Solution of &uations
-
TC = 200.00
TC = 200.00
TC 200.00
TC 200.00
TC a 200.00
TC = 200.00
TC = 200.00
Computer Output
A x 0.01855
AZERO = 2.27690
B t -0.01587
BZERO = 0.05587
C = 128300.00000
R c 0.08205
EPS = 1.OE-06
ITMAX = 20
l TER
3
3
3
3
4
4
4
5
5
5
5
6
6
7
2
2
2
2
3
3
3
2
3
Example 3.3 Solution of an Equation of State Using Newton's Method 177
Discussion of Results
The calculated results shown in the computer output
are plotted in Fig. 3.3.1 along with experimental values
reported by Brown, Katz, Oberfell, and Alden [16] (the
solid lines). In the pressure range 0-200 atm, agreement is
quite good at 200°C (maximum deviation is approxima-
tely 0.3 percent). Predicted values for 0°C are quite good
at pressures below 100 atm, but at higher pressures are
in considerable error; the Beattie-Bridgeman equation
would have to be used with some caution at higher pres-
sures.
Pressure (atrn)
Plgrrre 3.3.1 Compressibility factor for methane (CHS.
-Experimental values.
Valnespredicted by Beattie-Bridgeman equation of
state with the given set of co~~~tants.
178 Solution of Equations
3.8 Regula Falsi and Related Methods (c, f(c)) be a fixed point on y =f(x). Draw a chord
For the real case of Newton's the expression through this point and the point ( ~ k , f ( ~ k ) ) that it
[see (3.29)] : intersects the x-axis in a point (x~+~,O).
Thus,
has the interpretation illustrated in Fig. 3.3. We draw a T'his new point may well yield a better approximation
tangent to the curve y =f(x) at the point (xk,f(xk)).This than xk to a.
The procedure may be justified by the method of
I, successive substitutions. Let
reduces by half the lenglh of the interval in x known to the points chosen, this is also anexample of themethod of false
contain a, this procedure is called the half-interval position; note that X R L remains unchanged throughout the
method. Note that since the interval of uncertainty is course of the iteration and this is equivalent to c in equation
always known, we can specify, a priori, the number of (3.32). Hence, the required root is approximately 1.532; it
iterations required to locate the root within a prescribed is computed more accurately to be 1.532089.
tolerance. If A, is the length of the starting interval, then
the number n of interval-halving operations required to
reduce the interval of uncertainty to A, is given by
Problem Statement When the first root zo has been found, we again step to
the right in increments of 0.05, until P,+,(z) again
Write a program that computes the base-point values
changes sign. The procedure is repeated until all n + 1
and weight factors for use in the (n f 1)-point (n 6 9)
roots zo, z,, . .., zn have been located within the required
Gauss-Legendre quadrature (see Section 2.10 and Exam-
degree of accuracy.
ple 2.3):
The corresponding weight factors wo, w,, . . ., w, are
given from equation (2.85) :
Flow Diagram
Mail7 Prograin
~ O . O. .y ~a10.10
. . ., 10 aiSoc - -ai-2.0
to zero
. . ., 10
Y
Use half-interval method to
2i- 1
find roots zo, . . ., z, of P,,,
,(z) a i j t- . a i - l , j - l- -
(Subroutine ROOTS) I i
I (rounded up) I
FORTRAN Zmplemenration
List of Principal Variables
Program Symbol Definition
(Main)
At Matrix whose rows contain coefficients of the successive Legendre polynomials.
EXACT1, EXACTP, Exact values of the four integrals, I,, I,, I,, and I,.
EXACT3, EXACT4
FI1, F12, Approximations to the integrals I, I, I3and I,.
F13, F14
N n.
ROOTS Subroutine for determining the roots of P,+,(z).
wt Vector of weight factors wi . .
WEIGHT Subroutine for finding the weight factors wi.
zt Vector of roots zi .
(Subroutine
ROOTS)
FZL, FZHALF Va.lues of P,+,(z) at the left end and midpoint of the current interval,f, andf,,, , respectively.
ITER Number of half-interval iterations, k.
POLY Function for evaluating P,+,(z).
ZL, zR, ZHALF Va.lues of z at the left end, right end, and midpoint of the current interval, z,, z,, and z,,, ,
respectively.
(Subroutine
WEIGHT)
ct Vector of coefficients c in (3.4.3).
Program Listing
Main Program
APPLIED NUMERICAL METHODS, EXAMPLE 3.4
GAUSS-LEGENDRE BASE POINTS AND WEIGHTS BY HALF-INTERVAL METHOD.
.
SUBROUTINE ROOTS, WHICH EMPLOYS THE HALF-INTERVAL METHOD.
THE CORRESPONDI NG WEIGHT FACTORS W ( 1). .W(N) ARE COMPUTED
BY THE SUBROUTINE WEIGHT. FINALLY, THE INTEGRALS OF FOUR
COMMON FUNCTIONS ARE ESTIMATED BY AN ( N + l ) - P O I N T GAUSS-
LEGENORE QUADRATURE AND ARE COMPARED WITH T H E I R ANALYTICAL
VALUES .
DIMENSION W(101, Z(101, A(11,ll)
P I = 3.1415926
..... ESTABLISH
POLYNOMIALS UP TO ORDER N = 1 0 .....
COEFFl C l ENTS OF LEGENDRE
DO 1 I = 1, 11
DO 1 J = 1. 11
A(I,J) = 0.0
A(1,l) = 1.0
A(2,2) = 1.0
DO 2 1 = 2, 1 0
FI = I
C 1 = (2.0+FI
C2 = ( F I
A(I+1,1) =
--- l.O)/FI
l.O)/FI
C2*A(I-1,l)
IP1 = I + 1
A(lP1,IPl) = A(l,l)*Cl
DO 2 J P l = 2. 1
WRITE-(~,~OO) -
DO 3 1 = 1, 11
WRITE ( 6 , 2 0 1 ) (A(I,J), J = 1, I )
C
100
..... FORMATS FOR INPUT AND OUTPUT STATEMENTS
F ~ R M A T (6X, 1 4 )
.....
200 FORMAT ( 8 1 H 1 THE COEFFICIENTS FOR THE LEGENDRE POLYNOMIALS OF
lORDER ZERO THRO&H TEN ARE)
201 -FORMAT-TIHO, F7.5, 10F10.5)
202 FORMAT ( 3 7 H 1 GAUSS-LEGENDRE QUADRATURE, WITH/
1 1H0, 9X, 8HN , = 16)
203 FORMAT (51HO THE ROOTS OF THE ( N + l ) T H ORDER POLYNOMIAL ARE/
1(1H0, 5X, 1 0 F 1 0 . 6 ) )
204 FORMAT (42HO THE CORRESPOND l NG WE1 GHT FACTORS ARE/
l ( l H 0 , SX, 1 0 F 1 0 . 6 ) )
205 FORMAT (39HO ESTIMATED VALUES OF INTEGRALS ARE/
1 1H0, 5X, 1 4 H FI1 = , F10.6, 1 4 H F12 = , F10.6,
214H F13 , = F10.6, 14H F14 ,
= F10.6/
3 35H0 EXACT VALUES OF INTEGRALS ARE/
4 1H0, SX, 1 4 H EXACT1 =, F10.6, 14H EXACT2 = , F10.6,
5 14H EXACT3 = F10.6, 14H ,
EXACT4 = F10.6)
C
END
Subroutine ROOTS
c SUBROUTINE TO F I N D ROOTS Z ( l I . . . Z ( N + l ) OF THE ( N + l ) T H OKDEK
C LEGENDRE POLYNOMIAL, US l NG THE HALF- INTERVAL METHOD.
C
SUBROUTINE ROOTS (N, A, Z )
DIMENSION A(11,11), Z(l1)
NP1 = N + 1
lTER = ALOG(O.OS/l.OE-6)/ALOG(2.0) + 1.0
WRITE (6,200) ITER
C
C ..,.,-
2R =
E S T A B L I S H INTERVAL W I T H I N WHICH ROOT L I E S
1.0
.....
0 0 7 1 a 1, N P 1
Z L = ZR
1 I F (POLYCZL, A, N)*POLY(ZL+6.05, A, N) .LT. 0.0) GO TO 3
Z L = Z L + 0.05
GO TO 1
3 ZR = Z L + 0.05
F Z L = POLY (ZL, A, N)
C
C ..... B E G I N HALF-INTERVAL I T E R A T I O N
DO 6 J a 1, I T E R
.....
ZHALF = ( Z L + Z R ) / 2 . 0
FZHALF = POLY (ZHALF, A, N)
C
C ..... CHOOSE THE SUB-INTERVAL CONTAINING THE ROOT
I F ( F Z H A L F * F Z L .LE. 0 . 0 ) GO TO 5
.....
Z L = ZHALF
F Z L = FZHALF
GO TO 6
5 ZR = ZHALF
6 CONTINUE -
7 Z ( I ) = ( Z L + ZR)/2.0
RETURN
C
C
200
..... FOR,MAT FOR OUTPUT STATEMENT
FORMAT (IHO, 9X, 8 H l T E R 16) ,
.....
C
END
186
Program Listing (Continued)
Subroutine WElG HT
C SUBROUTINE TO ESTABLISH WEIGHT FACTORS W(l)...W(N+l) FOR
C ( N + l ) - P O I N T GAUSS-LEGENDRE QUADRATURE.
C
SUBROUTINE WEIGHT (N, 2, W)
DIMENSION C(10), Z ( l l ) , W ( 1 1 )
NP1 = N + 1
-
C
C ..... F I N D COEFFICIENTS OF POWERS OF Z I N INTEGRAND .....
K -
DO 8 1 = 1, N P 1
C ( 1 ) = 1.0
1
DO 5 J = 1, N P 1
I F ( J .EQ. I ) GO TO 5
K = K + l
DENOM = Z ( I )-
C(K) = C(K-l)/DENOM
Z(J)
L E K - 1
2 I F ( L .LT. 2 ) GO TO 4
C(L) = (C(L-1)
L = L - 1
- Z(J)*C(L))/DENOM
4
5 CONTINUE
-
GO TO 2
C(11 = Z(Jl*C(l)/DENOM
C
C .....
W ( I ) 5 C(1)
EVALUATE W ( I ) AS THE INTEGRAL .....
I F ( N P 1 .LT. 3 ) GO TO 8
DO 7 J * 3, NP1, 2
FJ = J
7 W ( I ) = W ( I ) + C(J)/FJ
8 W ( I ) = 2.O*W(I)
RETURN
C
END
Function POLY
C FUNCTION FOR EVALUATING ( N + l ) T H ORDER LEGENDRE POLYNOMIAL.
Data
Computer Output
THE COEFFICIENTS FOR THE LEGENDRE POLYNOMIALS OF ORDER ZERO THROUGH TEN ARE
1.00000
0.0 1.00000
0.0 2.46093 -0.0 -36.09369 -0.0 140.76532 -0.0 -201.09326 -0.0 94.96072
-0.24609 -0.0 13.53513 -0.0 -117.30446 -0.0 351.91284 -0.0 -427.32275 -0.0 180.42534
N I 2
ITER = 16
N - 4
ITER = 16
N I 9
ITER = 16
-0.973907 -0.865058 -0.679113 -0.433394 -0.148875 0.148874 0.433394 0.679413 0.865058 0.973909
0,066670 0.149284 0.219296 0.269215 0.295650 0.295694 0.269552 0.219099 0.149464 0.066672
E
T ,,"Possibly
no root"
-
p-nA T
I
I
I I
# Convergencew
Solution of Equtitlpns
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
CAMF Function that computes the value off@), in, (see equation 3.5.3).
D t ? m follower displacement, D, in.
EPS Tolerance for convergence criterion, 8 , in,
FX2, FXL, FXR f @ k + 11, f(x~,k),and ~ ( X,k),R in.
ITER Iteration counter, k.
ITMAX Maximum number of iterations permitted, itmax.
x2, XL, XR xk+I, X L , ~ and
, X R , ~ ,radians.
Example 3.5 Displacement of a Cam Follower Using the Regula Falsi Method
P q r a a Listing
C APPLIED NUMERICAL METHODS, EXAMPLE 3.5
c DISPLACEMENT OF A CAM FOLLOWER USING A METHOD OF FALSE POSITION
C
C T H I S PROGRAM FINDS X2, THE ANGULAR DISPLACEMENT ( I N RADIANS)
C OF A CAM ON THE ANGULAR INTERVAL (XL,XR) WHICH CORRESPONDS
C TO A GIVEN FOLLOWER DISPLACEMENT D, USING THE REGULA F A L S I
C ALGORITHM. THE CAM DISPLACEMENT EQUATION I S DEFINED B Y THE
C STATEMENT FUNCTION CAMF. FXL, FXR, AND FX2 ARE THE VALUES
C OF CAMF AT XL, XR, AND X2 RESPECTIVELY. ITERATION CONTINUES
C U N T I L THE ITERATION COUNTER ITER EXCEEDS ITMAX OR U N T I L THE
C MAGNIT(JDE OF FX2 I S LESS THAN OR EQUAL TO EPS.
C
C ...., DEFINE CAM FUNCTION .....
CAMF(X) = 0.5 + 0 . 5 * ( E X P ( - X / 6 . 2 8 3 1 8 5 ) + S I N ( X ) ) -D
C
..... READ AND D,PRINT
READ (5,100)
DATA .....
XL, XR, EPS, ITMAX
WRITE (6,200) D, XL, XR, EPS, ITMAX
....,
IF
CHECK
FXLtFXR
(
FOR PRESENCE OF A ROOT
) 5, 3, 2
...,.
WRITE [6,201)
GO TO 11
ITER = 1
D
EPS =
D =
EPS =
0.700000
0.000001
1.000000
0.000100
XL =
ITMAX
XL =
ITMAX
=
=
3.140000
100
0.000000
100
XR =
XR - 5.000000
3.140000
Computer Output
D
XL
XR
-
=
=
0.500000
0.700000
3.700000
EPS = 0.000010
ITMAX = 50
ITER = 5
X2 = 3.141594
FX2 = -0.000000
D = 0.750000
XL = 0.250000
XR = 1.500000
EPS = 0.000050
ITMAX = 50
ITER = 5
X2 = 0.580566
FX2 = 0.000043
D = 0.700000
XL = 3.139999
XR = 5.000000
EPS = 0.000001
ITMAX = 100
POSSIBLY NO ROOT ON THE STARTING INTERVAL
D = 1.000000
XL = 0.0
XR = 3.139999
EPS = 0.000100
ITMAX = 100
POSSIBLY NO ROOT ON THE STARTING INTERVAL
l?xample 3.5 Displacement of a Cam FoIIower t4~iwthe Rcguia Falsi Method 195
D W o n of Results used to find the angular displacement corresponding to a
The computer output shows results for two data sets @ve" f ~ l l displacement
~ ~ r for any cam; the func-
that yield solutions and two that do not. (The exact solu- CAMF need be modified to include the appropriate
tion for the first data set is x = n.) The program can be radius functions r(x).
196 Solution of Equations
I Uk+rn-~
'k+2
:
Uk+m
...
...
Ulr+m- I
"k+m
.
uk+zrn-21
, (3.40)
Thus if the zeros cri are distinct, we have, by (3.12), for all
values of k,
n
uk = C tiff'. (3.43) Thus, if a row of q's and the succeeding row of e's are
,= 1 known, we may build the next row of q's and then the
If the values of u, are given as described in (3.42), it next row of e's. TOdo this, we need proper starting values.
develops that the relation (3.43) is valid for all choices of For the case presented in (3.46), these are given by
cri. ~ e t j h distinct
e zeros of x;=,
aix"-' be P I , p,, . . .,P,,
and let their respective multiplicities be t,, t,, . . ., t,. This
qbl)=-al, (m)
qt-,=O, m = 2 , 3 ,..., n,
(3.48a)
means that if
Another starting procedure is essentially that employed It is known ([I], p. 171) that if the numbers generated by
in Section 3.3 for Bernoulli's method. Let u0 = 1 and, for (3.47), (3.48), and (3.49) exist, then they are the same as
l<k<n-1, those generated by (3.37) and (3.46), together with
k
ek0) = 0 for all k. Table 3.10 shows the beginning rows
U, = -- 1ajuk- j. (3'46) for n = 4 (compare with Table 3.9).
j= 1
q n - I(X)= f:Clxi-2,
1=1
where
Find the asymptotic convergewe factor for this iterative
scheme, and determine a necessary condition for Convergence
to a root.
3.g Since complex roots of a polynomial with real coeffi-
cients occur in conjugate pairs (ifat all), isolation of quadra-
tic factors from polynomials of degrce greater than two is an
important approach to the solutian of polynomial equations.
Show that introduction of these relationships inte Newton's
Once a quadratig factor has been found, then two real or
algorithm of (3.29) leads to complex roots may be found directly with the quadratic
formula;no further iteration is required. One suitable approach
is to use the method of iterative factorization of Section 3.4.
A simpler, though less ~fficient,iterative prwdure for findisk
an iterative method for finding a root, a = lim x,, of p,(x). quadratic factorscan k dovelo@, based on synthetic division
k-m
n i s COQ~-finding PrQCedure is know11 as iterutud syrctiietic by a quadratic War,
diuision, 8tarting with the polynomial
Y the p~lynon)ialp,(x) has a root near zero, what would be
a good guess for x, ? Generalize the algorithm, sa that up to 4
nwl roots olp.(z) may bs extracted, ane at a tim.
3.3 Write a functian, named PRQBT, that implements the
iterated synthetic division algorithm described in Problem 3.2.
bt the argument list be
Problems
where the b, are those of Problem 3.5, and show that the i-0
2aLhi= 0. Write a program that will read values for n, no, a,,
equations developed above can be rewritten in the form .. ., am.and E (a tolerance), and proceed to compute (possibly
with the aid of one of the functions already developed) and
.
print values for the eigenvalues A,, Az, . .,A,, known to bc
real, each within k g . Test your program with the following
This iterative algorithm for finding ever-improving estimates characteristic equations, mentioned on pages 220, 224, and
of B and 4 is known as Bairstow's method. 225.
Find quadratic factors for the polynomial given in Prob- + - +
(a) h4 20h3- 700h2 8000h 120000 = 0,
lem 3.5, starting with p = 0,q = 0, and compare the results
with those found using Lin's method. (b) -ha +4th'- 539h f 2058 = 0,
3.7 Write a program that implements Bernoulli's method - -
(c) -Ah - 16h3- 93h2 232h 209 = 0.
of Section 3.3 for finding the dominant root or two roots of 3.9 Ah a continuation of Problem 3.8, write a program
largest moduli, of the nth-degree polynomial that will handle the possibility of complex eigenvalues. Test
your program with the following characteristic cquati~n.
h4 - 16h3f 78Xa - 412h + 624 = 0,
where the a , are real and a. # 0.The program should compute
-
the sequences {uk},{vk},ancl {t,) of (3.9) and (3.10). Satis-
factory values for the starting sequence are ui 0, for
-
which corresponds to one of the matrices in Examplo 43, and
has roots h 12, 1 &- Si, and 2,
3.10 When using the technique of Laplace transformation
OC k < n - 1,and u r n - , = 1. Theelements u , , u , + ~ ,and U.,Z for solving problems, we are frequently cenfronted with the
should be computed first, followed by the computation of task of splitting the ratio of two polynomials,
. +
ur, k = 1,2, . ., n +
1, and tk,k ='2, 3, , . ., n 1. The ratio
tests of (3.1 1) and (3.13) should be applied to establish con-
vergence to a root@). Suggested versions of these tests are:
200 Solution of Equations
into partial fractions. The degree n of the polynomial in the where
denominator exceeds the degree m in the numerator. F(s) is the
Laplace trqnsform of the function, f ( t ) for example, that is
being sought. A key step is to find the zeros a,, a,, ..., a.
(possibly complex) of q,(s). If there are no repeated zeros, let
Express I(s) as the ratio of two polynomials, p,(s)/q.(s) (see
Problem 3.10). Write a program that will find the zeros of
q.(s). Then invert I(s) with the aid of tables ([21], for example)
to give the actual current as a function of time.
By multiplying through by s - a,, letting s approach a,, and
using Taylor's expansion, we obtain Suggested Test Data
V. = 10 volts, R = 100 ohms, C, = 0.25 x C1=
1x farads, L1 = 0.005, L, = 0.001 henrys, with w = lo*,
3 x lo4, and 105 sec-I.
3.12 At time t = 0, the switch in the circuit of Fig. P3.12
If there is a repeated root, for example, a, = a, = . . . = ax= p,
let L1
3.16 Based upon the notions of inverse interpolation (see Also write a function named CYLPLN that will compute F12
Problems 1.14 and 1.15) and of iterated linear interpolation for the infinitely long cylinder and plane shown in Fig. P3.17~.
(see Problems 1.11, 1.12, and 1.13), develop a root-finding Anticipate that a typical reference will be
method for a function f(x), single valued on an interval F12 = CYLPLN (D,H, L, W)
[xo,x.] known to contain a zero. Use your method to find the
root of the function where the arguments have obvious counterparts in Fig. P3.17~.
Figure P3.17~
Now, solve for the two roots of pz(x) using the quadratic
normal to the plane of the paper. Suppose we wish to evaluate formula. Let the two roots be r1 and rz, and evaluate the
Fix,the fraction of thermal radiation emitted by surface 1 that corresponding functional values, f (r,) and f (r2). Let x3 be r ,
is directly intercepted by surface 2. In the string method (see or r2, depending on which of I f(rl)l or If(rz)l is smaller. Next,
Hottel and Sarofim [23], for example), four threads are
fit the points (x,, f(xl)), (x2,f(xZ)),and (x3,f(x3)) with a second-
stretched tightly between AID, BC, AC, and BD. The geometric
degree interpolating polynomial, solve for the roots, choose
view factor F,2 (see Problen~2.41) is then given in terms of the x4 to be that root which yields the smaller magnitude for the
lengths of the threads by
functional value, etc. Continue this process of fitting successive
second-degree polynomials until, if convergence occurs, the
functional value assumes some arbitrarily small value. Note
that this procedure, known as Muller's method [26], allows
where L1 is the distance between A and B along the surface AB. the isolation of complex as well as real roots of f(x).
TWOinfinitely long parallel cylinders of diameter d have Implement Muller's method as a function, named MULLER,
their axes a distance w apart, as shown in Fig. P3.176. Show with argument list
by the string method that
(X, F, EPS, ITMAX, ITER)
How would you modify the function so that it could isolate volumetric flow rate v of a solution containing equal inlet
complex conjugate roots of a polynomial with real coefficients? concentrations a. each of A and B is fed to two CSTRs (con-
3.20 The 655 triode shown in Fig. P3.20 is used for ampli- tinuous stirred tank reactors) in series, each of volume V.
fying an a-c input signal of small amplitude. The amplifier gain Denoting the exit concentrations of A from the first and
second CSTRs by a t and a', respectively, rate balances give:
High-tension
6J5 supply, us
A=---
gmrrR
+
r , R'
where r, is the dynamic plate resistancb and g, is the trans- where is in (xk,a) and 5 2 is in ( ~ k + ~ , a ) .
conductance (see Problem 2.48). If the high-tension supply If 6, = t 2 , show that the solution a is given by
voltage is constant at v,, we have the following additional
relation involving the anode voltage v. and the anode current
i. as unknowns:
Ri, = v, - v.. whereAxk+, = x k +- ~~ ~ + ~ a n d A ~ x t = x ~ ++xk. ~
If v,, v,, and R are specified, devise a procedure for cornpu- 3.24 In general, and f 2 of Problem 3.23 will not be
ting v. and the amplifier gain A. Write a program to implement equal. However, if xb xk and x k +2 are near a, then f 1 = f 2 ,
the method, making use of the functions already developed in so that the next iterate may be taken as
Problems 1.42 and 2.48 for the 6J5 triode. Suggested test data
(usandugin V, Rinkn):v,= 300, v,= -6.5, R = 10;vS=300,
0, = - 16.2, R = 22; us = 300, U, = -2.3, R = 22.
3.21 The first-order irreversible chemical reaction A -+B ,
If x j t = F(x,) is a first-order process (see Problem 3.14). this
has a reaction rate constant k hr-' at a temperature T. A extrapolation technique usually accelerates convergence to a,
stirred batch reactor is charged with Vcu ft of reactant solution ,
that is, If,, - a1 < Ixk.3 - a \ , where xk.3 = F(xk+').
of initial concentration a. lb moles/cu ft and is operated The iterative process that employs the sequence of calcula-
isothermally at a temperature T for t o hours. The reaction tions
produas are then removed for product separation, and the X Z = F(xI),
reactor vessel is cleaned for subsequent reloading with fresh
~3 = F(xz),
reactar,f.
The reactor is operated cyclicly; that is, the process of 24 = x3 - ( A X ~ ) ~ / A ~ X I ,
loading fresh reactant, allowing the reaction to proceed, xs = F(23,
dump:ng the product, and cleaning the reactor is repeated
X6 = F(x5).
indefijiitely. If the down time between reaction cycles is t,
hours, show that the reaction time t o required to maximize the 2 7 = ~6 - (AX~)~/A'Z~,
overall yield of product B per hour is given by the solution of xs = F(37),
the equation etc.,
is known as Aitken's A' process.
Solvt this equation for the following test data: Use Aitken's A' process to find the three roots of f(x) =
v (CUft) 10 10 10 10 x3-3x+l=Owith
a. (Ib moles/cu ft) 0.1 0.1 0.1 0.1
k (hr-I) 2.5, 2.5 1.0 1.0
t, ; (hr) 0.5 1.0 1.0 2.0
. -.
g22 The isothermal irreversible second-order constant In each case, compare the sequence of iterates with the results
+ +
volume reaction A B 4 C D has a velocity constant k. A of Table 3.5.
Proble
Figure P3.39
The pump raises the pressure of the liquid from p1 (atmos-
pheric pressure) to pr, but this pressure is gradually lost If all other values are given, devise a scheme for finding the
because of friction inside the long pipe and, at the exit, p3 is time t taken for the temperature at a distance x to reach a
back down to atmospheric pressure. preassigned value T*. Implement your method on the com-
The pressure rise in psig across. the pump is given approxi- puter.
mately by the empirical rela tion
Suggested Test Dara
To = 70°F,q = 300 BTU/hr sq ft, k = 1.0 BTU/hr ft OF,
where o and b are constants that depend on the particular a = 0.04 sq ft/hr, x = 1.0 ft, and T* = 120°F.
206 Solution of Equations
3.42 A bare vertical wall of a combustion chamber con- x corresponding to ERFX, and a composite Gauss-Legendre
taining hot gases is exposed to the surrounding air. Heat is quadrature (see Problem 2.21) should be used to evaluate the
lost at a rate q BTU/hr sq ft by conduction through the wall error function when needed. Since, to ten significant figures,
and by subsequent radiation and convection to the surround- erf x = 1.000000000 for x > lo., XLI = 0 and X R = ~ 10. are
ings, assumed to behave as a black-body radiator. Let T,, T,, satisfactory starting values for (3.34).
and T. denote the temperatures of the gases, the exposed Write a short main program to test \N\JERF. Suggested.
surface of the wall, and the air, respectively. If a isthe Stefan- values for ERFX and the corresponding tabulated values for x
Boltzmann constant, 0.1 1 1 x BTU/hr sq ft O R 4 , and E , t, are :
and k denote the emissivity, thickness, and thermal conducti-
ERFX x
vity, respectively, of the wall, we have
0.0000000000 0.00
0.1 124629161 0.10
0.71 11556337 0.75
The extra subscript R emphasizes that the absolute or Rankine 0.8427007929 1.00
temperature must be used in the radiation term ("R="F+460). 0.9661051465 1 .SO
The convection heat transfer coefficient h, BTU/hr sq ft O F , is 0.9953222650 2.00
given by the correlation h = 0.21 (T, - T.)'I3, suggested by 1.0000000000 10.00
Rohsenow and Choi [24].
Assuming that T,, T,, F , k , and tare specified, rearrange the 3-45 Repeat Problem 2.15, with the following variation.
above relations to give a single equation in the outside wall ~ ~ the exchanger length L is a known quantity, to be
A S S I I that
temperature T,. Compute T, for the following test data: included in the data, and that the resulting exit temperature
T, = 1 0 o 0 ~t ,= 0.0625 ft, with (a) T, = 2100°F, k = 1.8 (fused TZis to be computed by the program. The problem is now to
alumina) BTU/hr ft OF, e = 0.39, (b) T, = 1100, k = 25.9 find the root of
(steel), E = 0.14 (freshly polished) and e = 0.79 (oxidized). In
each case, also compute q anc! the relative importance of radia-
tion and convection as mechanisms for transferring heat from
the hot wall to the air. for which the regula falsi, half-interval. or false-position
3.43 The rate qdh at which radiant energy leaves unit method could be used.
area of the surface of a black body within the wavelength An alternative method for finding Ta is discussed in Prob-
+
range h to h dh, is given by Planck's law: lem 6.19.
3.46 A vertical mast of length L has Young's modulus E
2nhc V h ergs and a weight w per unit length; its second moment of area is I.
qdA =
Xs(ehcJki- 1) ' cmZsec Timoshenko [25] shows that the mast will just begin to buckle
where c = speed of light, 2,997925 x 101° cm/sec, under its own weight when /3 = 4n*L3,9EI is the smallest root
of
h = Planck's constant, 6.6256 x lo-'' erg sect
k = Boltzmann's constant, 1.38054 x 10-l6 ergIoK,
T = absolute temperature, OK,
A = wavelength, cm. The first coefficientis c, = -318, and the subsequent ones are
given by the recursion relation
For a given surface temperature T, devise a scheme for
determining the wavelength A,., for which the radiant energy
is the most intense, that in, h corresponding to dq/dA = 0.
Write a program that imple~nentsthe scheme. The input data
should consist of values for 'I;such as 1000,2000,3000, 4000°K; Determine the appropriate value of 13.
the output should consist of printed values for A,,. and the 3.47 The stream function
corresponding value of q. Verify that Wien's displacement
law, h,,,T= constant, is obeyed.
3.44 Write a function, named INVERF, that computes the
inverse error fu)7ction,x, where the error function is given by represents inviscid fluid flow past a circular cylinder of radius a
with two effects superimposed [22]: (a) a stream whose
velocity is uniformly U in the negative x direction far away
from the cylinder, and (b) an anticlockwise circulation of
The function should have arguments (ERFX,TOL) where strength K round the cylinder. Here, r = ( x z - J ~ ) ' is' ~the
ERFX is thespecified value of the error function (0 G ERFX<l) radial distance from the center of the cylinder, whose cross
for which the inverse error function, x , is desired, and TOL is section is shown in Fig. P3.47. Note that the streamlineb,z = 0
the maximum error allowed in the calculated estimate of x. includes the surface of the cylinder.
The final estimated value of the inverse error function should Write a program that will produce graphical output (in the
be returned as the value of INVERF (real). style of Examples 6.3,6.5,7.1 and 8.5) showing points lying on
The regula falsi method of (3.34) should be used to find the selected streamlines within the dimensionless interval
Problems 207
computed as a function of temperature from the general
relation
CP, = a, + bt Tk + c,Tz + dl/Ti cal/g mole OK,
where i= 1,2,3,4, and 5 for CH4, 0 2 , N2, HzO (vapor), and
C02, respectively, and Tkis in OK. Table P3.49 [I91 also shows
the standard heat of formation at 29S°K, AH{zss cal/g mole,
for each component.
then
By the conjugate transpose A* of matrix A, we mean Example. If, for the matrix A, we take
(X)'.Clearly, (K)' = (A') and (AB)* = B*A*. A matrix A
is Hermitian if and only if A* = A (this requires of course
that m = n). A matrix A is symmetric if and only if
A = A'. A real matrix is Hermitian if and only if it is
symmetric.
Example. Choose
If A is an n x n square matrix, there is an associated adjoint of A and is denoted adj(A). Because of the proper-
number called the determinant of A and denoted det(A), ties described above, it is seen that
det A, or IAI. It is defined as
Because of the properties of transposes, if s # I, have the uniquc solution x , - 1, x , = 2, x , = 3; also, it wilt
be found that the determinant of the matrix of coefficients
has the value
where, on the right, matrix multiplication is intended. are orthonormal, hence also linearly independent.
+
Thus if n = 3, u = [2 -I-3i, 3 - i, 4 i]' and v = [l i, + A vector space is of dimension q if and only if q linearly
+ + +
1 - i, 2]', then (u, v) is (2 -- 3i)(l i) (3 i)(l i ) + - independent vectors belong to the space and any set of
-
(4 i)2 or 17 - 5 i. Since the fundamental postulates +
q 1 (or more) vectors from the space is linearly de-
satisfied (designed for a more general treatment) will be pendent. Should such a set of linearly independent
an expediting feature, they are listed and should be vectors exist, every vector of the space can be expressed
214 Matrices and Related Topics
as a linear combination of these vectors. For this reason, any n x m matrix U, the maximum number of linearly
such a set is called a basis for the space. In the case of the independent columns is called the column rank; the
vector space V, of all n x 1 matrices, let el = [I, 0,0, . . ., maximum number of linearly independent rows is called
0]', c2 = [O, 1,0, . . ., 01' and in general zi be the column the row rank. It can be shown that these numbers are the
matrix whose first i - 1 rows and whose last n - i rows same, and are the same number as the (determinant)
all are zero, while the element in the ith row is one. This rank of U previously defined. If we know that row rank
set is clearly linearly independent. If u = [u,, u2, . . . u,]' is determinant rank, a knowledge of transposed matrices
is any vector of V,, then and determinants convinces us that column rank is the
same number. No attempt is made here to show that row
rank is determinant rank. It is worth observing that U,
U*, and U' all have the same rank. If U-' exists, it has the
Now consider a set ul, u2, . . ., u , + ~ of
, vectors from V,. same rank as U and, in such event, the rank is the order.
Let uj 5 xy=l
all zero, exist such that
,,
ujiei. Then constants c,, c,, . . ., c,+ not A feature of value, concerning matrices of order n
whose rank r is less than n, is that they can always be
written as the product of an n x r matrix and an r x n
matrix, each of rank r. Formal proof is not difficult;
however, we merely indicate the proof for a matrix of
for any n linear homogeneous equations (in this instance order 4 and rank 2. Let the first two columns be linearly
C"j2: cjuji= 0,i = 1, 2,.. ., n) in more than n unknowns independent; then the matrix may be written (and
(here c,, c2, . . ., cn+,) always have a nontrivial solution. rephrased) as
Thus the dimension of V, is n. The vectors zi, 1 < i < n,
constitute a particular (orthogonal) basis, often called the
initial basis.
Indeed, any n nonzero orthogonal vectors of V, form a
basis for V,. Let v,, v,, . . ., vn be such a set. If we assume
the existence of scalars el, c,, . . ., c,, such that
it follows that
Conversely, if two such matrices, each of rank 2, are
multiplied together, we can always find, in the product
matrix, a minor that is the product of two nonvanishing
determinants, one from each factor. This is readily seen
by partitioning, so that the submatrices of rank two (one
from each factor) can be seen to yield a submatrix in the
whence cj = 0 and the set is linearly independent. In product, also of rank two. Moreover, three or more
similar fashion, if u is any vector of V,, then columns must be linearly dependent.
Another factorization theorem applies to nonsingular
matrices. The leading submatrices of a square matrix
A = (aij) are the matrices
Example. The orthogonal vectors
where 6 , = a, - s'w.
The requirement that Ai # 0, 1 C i < n, seems very
EXAMPLE 4.1
MATRIX OPERATIONS
Write subroutines that will use double-precision Typical Call Operation Formula Used
arithmetic to perform the commonly used matrix and
vector operations, such as addition, multiplication, etc.
CALL MATMLT (A, U, T, M, N, P) T t AU
table also serves in place of a flow diagram. The following CALL SCAVEC (S, X, Y, N) ytsx yi = sxi
x, =ks,zkak,
Column Vectors: x, y (both n x 1); z (m x 1).
Scalar: s. CALL MATEQ (A, B, M, N) B+A bi, = a,,
FORTRAN Implementation
The subroutine calls are listed in able 4.1.1; the
argument names are self-explanatory.
Example 4.1 Matrix Operations
Program Listing
C A P P L I ED NUMERICAL METHODS, EXAMPLE 4 . 1
C SUBROUTINES FOR MAN1 P U L A T I O N S OF M A T R I CES AND VECTORS.
C
C ..... T(M,P) = A(M,N) * U(N,P)
SUBROUTINE MATMLT (A, U, T, M, N, P I
.....
R E A L r 8 A, 8, C, T, U, V, X , Y, Z, S, SUMSQX
INTEGER P
DIMENSION A(10,10), B(10,10), C(10,10), T(10,10), U(10,10),
1 V(lO,lO), X(lO), Y(l01, Z(10)
D O 1 I = i , M
D O 1 J = l , P
1 T(I,J) = 0.
DO2 1 = i , M
D O 2 J.1, P
DO2 K = l , N
2 T(I,J) = P,(I,K)*u(K,J) + T(I,J)
RETURN
C
C ..... C(M,N) = A(M,N) + B(M,N)
ENTRY MATADD (A, B, C, M, N )
.....
DO3 l = l , M
DO3 J = l , N
3 C(I,J) = A,(I,J) + B ( I , J )
RETURN
C
C ..... C(M,N) = A(M,N) -
8(M,N)
ENTRY MATSUB (A, B, C, M, N )
.....
DO4 I = l , M
4
DO4 J r l , N
G(I,J)
RETURN
= A(I,J) -
B(I,J)
C
C ..... .?(MI = A(M,N) * X(N)
ENTRY MATVEC (A, X, Z, M, N )
.....
DO5 1 a 1 , M
5 t ( l ) = 0.
DO6 1 = l , M
DO6 J = l , N
6 Z ( I ) = A(I,J)*X(J) + 2(I)
RETURN
.. B(M,N) = S*A(M,N)
'RY SCAMAT (S, A, B, M,
.....
N)
8 1 = 1 , M
DO8 J = l , N
B(I,J) = S*A(I,J)
RETURN
12
-
DO 1 2 1
SUMSQX
S
1, N
SUMSQX + X ( I ) * X ( I )
DSQRT(SUMSQX)
RETURN
-
13 Y(I)
RETURN
-
ENTRY VECEQ (XI Y,
DO 1 3 1
X(I)
1 0 N
N)
C
C ..... V(N,M) = A(M,N) TRANSPOSED
ENTRY TRNSPL (A, V, M, N)
.....
14
DO 1 4 J
V(J,I)
RETURN
END
-
00 1 4 I m 1, M
1, N
A(I,J)
4.3 Linear Transfor.marions and Subspaces 2 19
4.3 Linear Transformations and Subspaces rank of A plus the nullity of A is the dimension of Vn.
A set of vectors W from a vector space V may be said (The trivial space consisting of the null-vector only has
to form a (vector) subspace of V if and only if, for every rank zero.)
scalar c and every pair of vectors u and v in W, it is true .
To demonstrate the proposition above, let el, e,, . ., em
that both u + v and cu alre vectors of W. Let A be any be a basis for the null-space of A. Let em+,,...,en be
additional vectors such that el, e,, . . ., en in toto consti-
(fixed) I? x n matrix. Then the set of all vectors of the
form Au, where u is any (variable) vector of Vn,consti- tute a basis for Vn. Since every vector u =
transforms as x;=,+, x:= uiei
uiAei, it follows that every vector
tutes a subspace of Vn.For Au is an n x 1 matrix; there-
fore, it is an element of Vn.Moreover, it is readily verified of the space W of all transforms is a linear combination
that of the vectors Ae,, m + 1 < i < n . But these are linearly
independent, for if it were not so, some nontrivial linear
u + v = Au, + Av, = A(ul + vl), combination ~ I = , + b,Aei , would be 0, whence
cu = cAul = Acu,. (4.6) A x:=,+, biei would be zero. In that event ~ ~ = , +biei
0, which contradicts the assumption that the vectors
, =
That the set of all vectors Au is a subspace of Vn means, el, e,, . . ., en are a basis for V,.
in part, that a set of linearly independent vectors of the An important theorem involving nullity is Sylvester's
form Au will serve as a basis for the space of all vectors law of nullity, which states that the nullity of the product
of that form. Note that A E ~is the first column of A, of two matrices equals or exceeds the nullity of either
Ac2 is the second column of A, and so on. Since u =
x;=, ujsj, by an obvious extension of equation (4.6), it is
seen that
factor, and that the nullity of the product cannot exceed
the sum of the nullities of the factors.
It is intuitively obvious that the set of all vectors of
Vnsuch that the nth row is zero constitutes a subspace of
V,. It can be phrased formally if for the matrix A the
Then for a basis of the space, we may choose any maxi- diagonal matrix [ l , 1, . . ., 1,0] is used, where every
mum number of linearly independent columns of A. It is diagonal entry but the last is unity.
seen that the dimension of the subspace W of vectors In future consideration of the transformation of vectors
Au is the rank of A. by square matrices A, an extremely useful relation is the
A transformation of a space V into a subspace W of V transfer rule:
may be viewed as a device for associating with each (u, Av) = (A*u, v). (4.7)
element of V a uniquely defined image in W (more
Proof is straightforward: u*(Av) = (A*u)*v since
precisely, such a transformation is a many-one corres-
(A*u)* = u*A.
pondence from V to a subset of V). Expressed in operator
form, Tu = v, meaning that the transform or image of Example. As an example of a null-space, consider
u is V. The transformation is linear if and only if for all
u and v in V and any scalar c,
T(u + v) = Tu + Tv;
and
T(CUI)
= cTu.
and let x' = [ X I x 2 x 3 x4 x51. The simultaneous equations
Observe immediately, reading equation (4.6) in reverse, Ax = 0 have the solution x = rv, + svz, where r and s are
that square matrices A of order n may be viewed as arbitrary and vi = [-5, 2, 5, 7,0],v i = [-13,1, 6,0,7].Thus
linear operators for Vn. the nullity of A is at least two. Since the third-order determinant
Let A be an n x 12 matrix and u a vector of Vn such in the upper-left cdrner has the value -35, the rank of A is
at least three. Hence the nullity is two and the rank is three.
that Au = 0. If A is nonsingular, its determinant is not
zero, and the set of simultaneous linear equations, repre- Associated with every square matrix A is a special set of
sented by Au = 0, has only the trivial solution u = 0. If, vectors, called eigenvectors, and a related set of scalars,
however, A is singular [that is, det(A) = 01, then u exists called eigenvalues. Formally, the vector u is an eigenvector
such that u # 0 and Au = 0, for in such cases, the simul- of A if and only if u is a nonzero vector and A is a scalar
taileuub equalior~sinvolved have a nontrivial solution. (which may be zero), such that
The set of all vectors, whose image (using a fixed matrix
A) is the null-vector, is a subspace of VH.This is readily
verified in the manner by which equation (4.6) was The scalar /I is an eigenvalue of A if and only if there exists
established. This set is called the null-space of A. Its rank a nonzero vector u such that (4.8) holds. It is seen that the
is called the nullity of A, and it will be shown that the eigenvectors pertaining to A are those nonzero vectors
220 Matrices and Related Topics
Equation (4.10) is the clzaracteristiceq,uation for matrix A. where the ai (in addition to being the elementary sym-
If A = (aij), then metric functions of the roots A,, A,, ..., An) are certain
combinations of the minors of A. One can show that the
sum of the diagonal entries of A is the sum of the eigen-
values of A. This sum is called the spur or trace of A.
Thus,
is interesting to observe that, under these circumstances, then A is nonsingular. Proof is sketched for the second
adj(A - AiI) = uv' where u is an eigenvector for A cor- version. Suppose A is singular. Then so is A', and there
responding to Ai and v is an eigenvector for A', also cor- exists a nonzero vector u such that Atu = 0. Let urnbe the
responding to Ai. For by Sylvester's law of nullity, if r component of u of maximum absolute value. Then
be the rank of the adjoint, n - 0 < n - (n - 1) + n - C;= aj,,,uj = 0 and
r o r r < 1. Since r # O , r = 1. Then adj(A-LiI)=uvt,
as explained on page 214.
Example. An example of some of the foregoing concepts
can be found by using the matrix
It follows that
17 - 1 -27 -6
6 -14 -54 -24 IammI< x
n
j= 1
j+m
IajmI < IammI.
When A - 11 is used in the role of matrix A in the a # c. There are certain unifying principles, and we pro-
relations of (4.14) or (4.19, an immediate consequence is ceed with a partial description.
that every eigenvalue of' a square matrix A lies (in the If P is a nonsingular square matrix of order n, then for
complex plane) in at least one of the circles arbitrary vectors u, the relation
I1
u =Pv (4.18)
A -a <~ a i l 1 < i < n, (4.16)
= l
j+i can be construed as a change in coordinates. Under these
as well as in at least one of the circles circumstances, given v, we can find u, or, given u, we can
find v as P-'u. Consider now the eigenvector-eigenvalue
n
11 - a < a 1<i < n. (4.17) relation Aui = Aiui under such a change of variable.
J= I Letting B = P-'AP, from Bvi = P-'APv, = Aivi, and
j t i
A=E 01
eigenvectors for rhe matirix
0 0 0
0
O l c
oc 0 '
together with A, = 10, A, = 20, X3 = -30, A4 = -20. It is It is not difficult to see that, if we denote diag (A,, A,, ...,
readily verified that 1,) by A, then A2 = diag (A:, A,: . . ., A:) and, in general,
1 0 2 Ak = diag ( i t , A:, . . ., A:). Also, for arbitrary scalars, c,
U-l-[i :
0 1 - 6
y i].
0
and c2, and diagonal matrices D, = diag (e,, e2, . . ., en)
and D2 = diag (fl,f,,. . .,fn),
c1D1 + c2D2
and that AU = U diag (LC,20, -30, -20) and that each is,
in fact. = diag (clel + c2f1, c1e2 + c2f2,. . ., clen + c2f,).
Applying these concepts to the above, the net result is
that
P-'g(A)P = diag [g(A,), g(A2), . . ., g(ln)l,
or
It can be shown that every matrix is similar to a matrix
of specifiable structure called the Jordan canonical foum. dm' = P diag [ d l , ) , d l , ) , . . ., g(1,)l. (4.22)
~ a t r i c e sof the type, For distinct eigenvectors, then, it is clear that the eigen-
, [ I, 1 A ]
A 0 0
O I A
[
A 0 0 0
O O l i
, .. .
values of g(A) are g(ii) and, in addition, that the eigen-
) the same as those of A.
vectors o f g r ~ are
Exanzple. As a case in point, consider g(x) = x 2 - 4 and
Let the eigenvalue I , lie in the circle with center at a,, and
(4.26) matrix. To understand this, note that for positive integral
values of k, A k - I k I = ( A - I I ) ( A k - 1 + A A k - 2 + . . . +
Ak-lI). This means that
with radius equal to
4(A)- = ( A - II)\(r,
where \Ir is a polynomial in I and A.
Since adj(A - A) is composed from the cofactors of
A - 21, it also is a polynomial in I with matric coefficients.
Then, since Ilk/- lammld IAk - amml,it is seen that IIkI < Moreover, 4 ( l ) I = ( A - 21) adj(A - II). Adding this to
I$=,
lamil. From this, (4.25) follows. Proof of (4.26) is the above, we obtain
similar.
The matrix A of page 222 will serve to illustrate the $(A) = ( A - W C ,
above. By (4.25), 13.,1 < 49. This is verified, since I, = 7, where C is a polynomial in I with matric coefficients.
A2 = 14, A3 = 2 1. By (4.26), lIkl < 48, a slightly sharper Since the right side will involve I nontrivially if C is not
result. zero, and since 4 ( A ) is independent of I , it follows that
The ideas of the paragraph above will find application, $(A) is zero.
for example, in the following chapter in conjunction with Example. As an illustration, consider again the matrix A
the iterative solution of simultaneous linear equations. A of page 222. A2 and A3 are found to be
related concept involves the inequality
The characteristic function is - A 3 + 42A2 - 539A -k 2058, It is next indicated that if A is any Hermitian matrix,
+
and it is found that -A3+ 42A2 - 539A 20581 = 0. then there exists a unitary matrix P such that
4.5 Symmetric and Hermitian Matrices
Recall that a matrix A is Hermitian if and only if where A = [A, I., .
;I,] and A,, A2, . ., 1, are :he (real)
A = A* = At. A is symmetric if and only if A = A'. eigenvalues of A. Should the eigenvalues be distinct,
Thus A is symmetri~~ n dHermitian if and only if A is there are n orthogonal eigenvectors, thus n linearly
real and self-transpose. independent eigenvectors. Then it follows, as in estab-
An Hermitian,form is an expression of the type lishing (4.20), that (4.31) is true, To guarantee that
P* = P-', we need only require that each eigenvector be
normalized in forming P. We then see by direci multi-
where the ui are construed as complex variables and the plication that P*P = I, hence P* = P-'. No proof is
a i j as constants. It is apparent thatsuchaform mayalways attempted here for the case of multiple eigenvalues,
be written though the theorem remains true (see Jacobi's method,
(u, Au), where A = A*. (4.29) page 250).
An Hermitian matrix A is positive definite if and only if,
A quadratic form is an expression of the type for all u # 0, (u, Au) > 0. Such a matrix is positioe semi-
dejinite if and only if, for u # 0, (u, Au) > 0. Correspond-
ing statements define negative definite and negative semi-
where the a i j are construed as constants and the ui as defnite Hermitian matrices. Hermitian matrices thus far
variables. We are here concerned only with real quadratic not characterized are called indefinite.
forms. In that event the quadratic form may be written as It is a simple matter to verify that for the real Hermitian
matrix
(u, Au), where A = A = A', and u is real. (4.30) - 4 . * 1 0
If u and A satisfy either (4.29) or (4.30), then:
(a) For all u, (u, Au) is real.
(b) Every eigenvalue of A is real.
(c) Eigenvectors corresponding to distinct eigenvalues we may u s e h = 1-4 - J2, -4, -4 + JZ] and
are orthogonal.
To prove (a), note that (u, Au) = (A*u, u) = (Au, u) =
(u, Au) (see equations (4.2) and (4.7)). To show (b),
(u, Au) = (u, Iu) = A(u, u); since (u, Au) and (u, u) are
real, so is 1,. In case (c), (u,, Au,) = A2(u1,u,) and Recall that the leading submatrices of a square matrix
(u1,Au2)= (Au1,u2)= X1(u1,u2)= ;I1(u1,u2).Then 1, # I, A are those square matrices of order m, 1 m < n, <
and I,(u,, u,) = E.,(u,, u,) imply (u,, u,) = 0. formed from the first m rows and columns of A, and that
An example of a quadratic form is given by 4x: - the corresponding determinants have been denoted
2x,x2 + 4x: - 2x2x3 + 4 4 - 2x3x4 + 4x2. Since this A1, A2, . . ., A,, . . ., A,. Let the submatrices be denoted
+
may be written as 3x1 + (x, - x,), + 2x22 (x, - x3), + A('), A(,), . . ., A'"), . . ., A'"). A theorem of consequence
2x2, +(x3 - xJ2 + 3x;, it is clear that the form is also concerning Hermitian matrices states that between two
positive definite (see below). distinct eigenvalues of A ( ~ + ' there
) lies at least one eigen-
A matrix A is unitary if and only if A* = A-'. A real value of A(&)which may coincide with either of these two
matrix A is orthogonal if and only if A' = A-'. A matrix eigenvalues. Moreover, if 1 is a multiple eigenvalue of
A is isometric if and only if, for all n-dimensional vectors order p for A(~+", then it is an eigenvalue of order at
u, v, it is true that (u, v) = (Au, Av). If w = Au be inter- least p - 1 for A ( ~ )For. brevity in presentation, let
preted as a change of variable, it is seen that for an iso-
metric transformation, (u, u) = (Au, Au) = (w, w); there-
fore, length is preserved. Clearly a real unitary matrix is
an orthogonal matrix. It develops that a matrix A is where U is unitary and A is the matrix diag (I, I, Ik). -
isometric if and only if it is unitary. For suppose A is Let I be an eigenvalue of C and [vfa]'the corresponding
unitary; then (Au, Av) = (A*Au, v) = (u, v). Next con- eigenvector, v being a k x 1 matrix. Thus
sider (Au, Av) = (u, v) for all u and v. It is true, in par-
ticular, if v = (A*A - 1)u. Then (Au, A(A*A - 1)u) =
(u, (A*A - 1)u) implies (A*Au, (A*A - 1)u) = (u, (A*A -
1)u) or ((A*A - I)u, (A*A - 1)u) = 0 for all u. This means whence
A*A-1=OorA*=A-'. Bv + aw = Iv, w*v + afi =la. (4.32)
4.5 Symmetric and Hermitian Matrices 225
Let v = Ux. Then the first of these equations (4.32) matrix itself has the characteristic function 209 +232A
yields UAx + ctw = 3.Ux; then Ax ctU*w = Lx and + +
+93A2 16A3+ A4 and the eigenvalues (-9- J5)/2,
(A1 - A)x = ctU*w. When the latter is substituted in the (-7 - J5)/2, (-9 + J5)/2, and (-7 + JS)/2.
second equation of (4.32), there results
If the matrix A is Hermitian, each of the following
w*U(2I - A)-'otU*w +
crp = Aa. statements give a necessary and sufficient condition for
This is, of course, valid only if ;l is not an eigenvalue A to be positive definite:
of B. (a) All the eigenvalues of A are positive.
The factor a may be removed, since we may view the (b) The coefficients of the characteristic equation for
components of the matrix. A as variables. Since 11- A is A alternate in sign.
diagonal, its inverse is diag (p, p2 - - . p,) where pi = (c) Each leading submatrix of A is positive definite.
1/(A - Ai). Using this leads to the equation (d) A, > 0, 1 < rn < n.
First consider (a). If A is positive definite, then (u, Au)
> 0, (u, u) > 0 and Au = Au imply 1> 0, because
(u, Au) = A(u, u). Now suppose A,, A,, . . ., 2, positive.
where U = [u,, u,, . . ., ukl. Should (w, uj) = 0, it is easy
to verify that [:] = [z] is an eigenvector and 2, an
Since A is Hermitian, it has n corresponding eigenvectors
x,, x2, . . ., x, that are orthonormal. Then for any u,
eigenvalue for A',+ ''. Should ilj be a multiple root such
that for 1 different indices>/,,j,, . . .,j,, A, is the eigenvalue whence
for uj, and (w, uj,) # 0, then ibj is an eigenvalue of multi-
plicity at least I - 1 for A(kf". This is illustrated for U = (x,, u)xl f (x,, U)X, + .. + (xn,U>X,.
'
1 = 2, and for convenience we suppose (w, u,) and (w, u,) Moreover,
are not zero, while both u, and u, have the eigenvalue
= A,(x,, u)x, + A,(x,, u)x, + . . . + ;l,(xn, u)x,,
A,. Then investigation shows that the vector
so that
with proper choice of y and 6, will serve as an eigen-
vector of A(k+I ) corresponding to the eigenvalue A,. We
+
need only require that ywhu, 6w*u2 = 0, with y and 6 To establish (b), observe that if the coefficients of the
not both zero. Thus under all circumstances (4.33)
. . leads characteristic equation alternate in sign, there can be no
to a polynomial equation of requisite degree for deter- negative root. Since the matrix is Hermitian, all roots are
mining the eigenvalues of C distinct from those of B. real, hence all are positive. Then, by (a), A is positive
(If all the eigenvalues of B are eigenvalues of C, and definite. Conversely, if A is positive definite, then all
(w, uj) = 0 for all values ofj, then A = p is the new eigen- eigenvalues are positive and the coefficients of the char-
value and may equal a previous eigenvalue.) The remain- acteristic equation alternate in sign.
ing details are omitted, with the remark that a sketch of Consider next (c) and suppose A is positive definite. Let
a simple situation involvic~greal values of li is informa- u = [u,, u2, . . ., urn,0, . . ., 01' be nonzero, yet such that the
tive. This sketch may take the form of plotting z = 2 - P last n - rn entries are zeros. The inner product (u, Au) > 0;
and it is also the inner product for an arbitrary vector in
Iw, u,l2 m-dimensional space, one which uses as its matrix the
z= C-
j=lA-A leading submatrix of order m. Hence this submatrix is
J'
positive definite. The condition of part (c) is obviously
on the same coordinate plane. sufficient, since A itself is then positive definite.
Exaniplc. An example is furnished by the matrix Turning to part (d), suppose A is positive definite.
Since the determinant of a matrix is the product of its
eigenvalues, from part (c) it follows that each A, > 0. To
see that the condition of (d) is sufficient, proceed by in-
duction. The proposition is obviously true for n = 1.
Wow assume the proposition to be true for all Hermitian
The leading submatrix [-41 has the characteristic function matrices of order k and consider one, say of order
-4 --A and the eigenvalue -4. The leading submatrix I' + 1. Let A be (if possible) a negative eigenvalue for
,
Then since A,,, > 0, and A,+ is the product of
[-:
- -
has the characteristic function 15 +8A + A 2 and
the eigenvalues and
-3 The leading submatrix of order
-5.
all eigenvalues for ACkf", A'~'') has a second negative
eigenvalue. By the theorem just presented, A(k)has an
three has the characteristic function -56 -46A -12AZ - A 3 eigenvalue which is negative. This cannot be; thus the
and the eigenvalues 4 - 4 2 , -4, and -4 + 42. The eigenvalues of A are positive and A is positive definite.
226 Matrices and Related Topics
Example. An example of a positive definite quadratic form and corresponding eigenvectors be A,, A,, . . ., A, and
+ + + +
is 13y: 9y: 57y3 8y1y2 8y1y3 - 6y2y3. That this is u,, u,, . . ., u, (ordering by magnitude is not demanded).
positive definite may be seen by writing it as 5y: + (2yl 2 ~+ ~The) eigenvectors
~ must be orthogonal and we may, in
+ + + +
4y; ( 2 y 1 f 2y3)' 44y: ( y , - 3 ~ ~When ) ~ written
. in addition, require that they be of unit length. Let A, = A,
the form (Y, AY) where Y* = [YI y2 y31, and define recursively
Flow Diagram
,
Begin =- B + I i = l,2, -1
. . ., I 1 I
I I
230 Matrices and Related Topics
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
A Matrix A, whose eigenvalues are required.
B -
Repeated product matrix, B = (A L,I)(A 411 ..- .
C, D Matrices used for intermediate storage.
EPS Tolerance, 8, used in convergence test.
IDENT Identity matrix, I.
L Length, I, of v .
LZERO I,, used for temporary storage of I.
LAMBDA Vector containing eigenvalues, hi.
M Iteration counter, m.
N Number of rows, n, of matrix A.
MFREQ Number of iterations, rn,,,,, between periodic rcorthogonalization of v.
M MAX Maximum number of iterations permitted, m,,.
u Matrix U whose columns contain the eigenvectors of A.
v Current approximatian, v , to eigenvector.
VZERO Starting guess, v, , for eigenvector.
Y Vector for temporary storage, y.
Example 4.2 The Power Merhod
Program Listing
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 4.2
C POWER METHOD FOR DETERMINING EIGENVALUES AND EIGENVECTORS.
C
C THE FOLLOW 1 NG PROGRAM MAKES EXTENSIVE USE OF THE MATRl X
C OPERATIONS DEFINED I N THE SUBROUTINES OF EXAMPLE 4.1
C
I M P L I C I T REAL*8(A-H, 0-2)
REAL+8 L, LZERO, LAMBDA, IDENT
DIMENSION A(10,10), B(10,10), C(10,10), D(10,10), IDENT(10,10),
1 U(10,10), LAMBDAflO), V ( 1 0 ) , VZER0(10), Y ( 1 0 )
C
..... READ AND CHECK I N P U T DATA .....
READ ( 5 , 1 0 0 ) N, MMAX, MFREQ, EPS, (VZERO(I 1, I = 1, N )
WRITE (6,200) N, MMAX, MFREQ, EPS
WRITE (6,207) (VZERO( I), I = 1, N)
READ ( S 8 1 0 1 ) ((A(I,J), J 1, N), 1 a 1, N )
WRITE (6,201)
DO 1 5 1 = 1, N
WRITE ( 6 , 2 0 7 ) (A(I,J), J = 1, r )
.....
DO 11
PERFORM POWER METHOD FOR A L L N EIGENVALUES
1 = 1, N
.....
..... MOOIF'Y
~.
GONAL TO A L L PREVIOUSLY COMPUTED EIGENVECTORS ..,..
~
STARTING VECTOR SO THAT I T I S ORTHO-
.....
DO 5
PERFORM SUCCESSIVE POWER METHOD ITERATIONS
M = 1, MMAX
.....
..... P E R I O D I C A L L Y RE-ORTHOGONALIZE THE VECTOR V
I F ((M/MFREQ)*MFREQ .NE. M) GO TO 4
.....
CALL MATVEC (0, V, Y, N, N)
CALL VECL-EN (Y, L, N )
CALL SCAVEC ( l . O / L , Y, V, N)
.....= -
IM1
SALVAGE P A R T I A L RESULTS I F METHOD D I D NOT CONVERGE
I 1
....
WRITE (6,202) 1, M, (LAMBDA(K1, K = 1, I M 1 )
WRITE (6.203)
DO6 K S 1 , N
WRITE (6,207) (U(K,J), J = 1, I M 1 )
GO TO 1
DO8 K = l , N
I F (DABS(V(K)) .LT. 1.OD-3) GO TO 8
I F (V(K)*Y(K)
GO TO 9
.LT. 0.0) L =- L
CONTINUE
232 Matrices and Related Topics
END
Data
= 3, MMAX = 100, MFREQ = 15, EPS = 1.OE-9
= 1. 1. 1.
-11. 6. -2.
13.
N = 4, MMAX = 50, MFREQ = 1, EPS = 1.OE-9
VZERO = 1. 0. 0. 0.
A = 10. 9. 7. 5. 9. 10. 8. 6.
7. 8. 10. 7. 5. 6. 7. 5.
N = 8, MMAX = 300, MFREQ = 10, EPS = 1.OE-9
VZERO = 1. 0. 0. 0. 0. 0. 0. 0.
A = 2. -1. 0. 0. 0. 0. 0. 0.
-1. 2. -1. 0. 0. 0. 0. 0.
0. -1. 2. -1. 0. 0. 0. 0.
0. 0. -1. 2. -1. 0. 0. 0.
0. 0. 0. -1. 2. -1. 0. 0.
0. 0. 0. 0. -1. 2. -1. 0.
0. 0. 0. 0. 0. -1. 2. -1.
0. 0. 0. 0. 0. 0. -1. 2.
Example 4.2 The Power Method
Computer Output
Results for the Ist Data Set
POWER METHOD FOR DETERMINING EIGENVALUES, WITH
N = 3
MMAX = 100
MFREQ = 15
EPS = 0.100D-08
STARTING VECTOR VtERO(l)...VZERO(N) IS
1.000000 1.000000 1.000000
THE STARTING MATRIX A(1,l). ..A(N,Nl IS
11.000000 6.000000 -2.000000
EIGENVALUES LAMBDA(1).
21.000000 14.000000
..
LAMBDA(N1 ARE
7,000000
EIGENVECTORS ARE SUCCESSIVE COLUMNS OF
0.000000 0.894427 -0.447214
0.316228 0.447214 0.000000
0.948683 -0.000000 -0.894427
=
50
1
0.100D-08
STARTING VECTOR VZERO(l)...VZERO(N) IS
1.000000 0.0 0.0 0.0
THE STARTING MATRIX A(l,l)...A(N,N) IS
10,000000 9.000000 7.000000 5,000000
9.000000 10.000000 8.000000 6.000000
7.000000 8.000000 10.000000 7.000000
5.000000 6.000000 7.000000 5.000000
3.858057
..
EIGENVALUES LAMBDA( 1). LAMBOA(N1 ARE
30.288685 0.843107 0.010150
EIGENVECTORS A R E S U C C E S S I V E COLUMNS OF
0.520925 -0.625397 0.567641 -0.123697
Matrices and Related Topics
N = 8
MMAX = 300
MFREQ = 10
EPS = 0.100D-08
I = 1 M = 97 L = 3.879385
1 - 2 M = 137 L = 3.532089
1 = 3 M = 95 L = 3.000000
1 = 4 M = 56 L = 2.347296
1 x 5 M = 34 L = 1.652704
1 = 6 M = 19 L = 1.000000
1 = 7 M = 11 L = 0.467911
4.7 Method of Rutishauser [4] for r,,. Solve the system Rv = r,,v, where v' = [a, h, 1, 01,
Throughout this section, for i 2 1, L', L,, L; will be to obtain the eigenvector for r,,, etc. The technique for
used to denote lower triangular matrices whose diagonal individual eigenvectors is that of back substitution in
elements are all ones, while R, R', Ri, Rf will be used to Gaussian elimination (see page 270).
denote upper triangular matrices (here R', for instance, In application, we can adopt the philosophy of using
is not the transpose of R-for this we consistently use the the results if convergence occurs. We emphasize that
notation R'). convergence does take place for positive definite matrices.
Let A = A, be a real square matrix such that A, = LIRl A technique is still needed for writing a suitable matrix
(this can always be accomplished if, as previously shown, B as CD where C is lower triangular (with ones on the
A is positive definite). Define A, as RILl. It may be that and is upper Let =
A, = L,R,. If so, define A, as R,L, In general, assume = ('ii). = (dii)7 it being that
that cij=O for i < j < n , cii=l;
A, = LkRk, Ak+1 = RkLk. (4.39) d 1J. . = O for i > j .
Note that in such event
Since bij = xi= cikdkj, by the above.
Then
Ak =
u11 u12
u2.
"'
-
Ul, ulll: v,,A: ...
.. _]
unll:
As k increases, because the li are in order of decreasing magnitude, the value of det(Dji) approaches that of
det(Dji) where
That is,
To aid in seeing this, observe that Dji is the sum of similar terms, all other terms having a middle factor,
diag (l:,Ak . . . A:), which for k large is small compared to the one shown. Use partitioning to see that Dii contains
all terms of the type described. Thus for k large, cij is approximated by
where
Here, U = L,R, expresses U as the product of a lower triangular matrix (with ones on the diagonal) by an
.
upper triangular matrix. Therefore also, R = R, diag (1,1, . . 1,)R;'.
There is a modification which can be used in conjunction with real matrices A whose eigenvalues may be complex.
EXAMPLE 4.3
RUTISHAUSER'S METHOD
Further transformations column to the next) will also reduce the subdiagonal
elements of the remaining columns substantially.
A,+z = L,:lAm+lLm+l, In the subroutine, the elements vi, which are stored in
Am+3= Lm:zAm+zLm+z,etC.9 the vector V, are determined for a particular column j
from the relation
where
n
I,
+ k = i + 1aikVk
I
1 aij
1 0 t). =
ajj - aii
, j=1,2, ..., n - 1 .
v3 1 i=n,n-1, ...,j + l ,
Lm+1= U4 1
This process of "sweeping" through the columns may
be repeated with ever-increasing effect. Finally, note that
Vn 1 if the sweeping procedure is applied to a tridiagonal
matrix, it will introduce small nonzero values into
elements that were previously zero. The technique of
(Id) above is then no longer advantageous, but this is of
little consequence, since the very introduction of the
Lm+%
= 1 ]etc., sweeping procedure means that the required degree of
convergence will soon occur.
We have not attempted to write a concise flow diagram
On for this example. Instead, the overall approach can be
understood best by reading the program comment cards
(and the v's are chosen properly, but will vary from one in conjunction with the above algorithms.
Example 4.3 Rutishauser's Method
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 4.3
,.
c
l,
EIGENVALUES BY RUTISHAUSER'S LEFT-RIGHT TRANSFORMATION.
7
GO TO 1 -
WRITE ( 6 . 2 1 1 )
DO8 1 = 1 , N
8 WRITE ( 6 , 2 0 5 ) (U(I,J), J = 1, N)
GO TO 1
C
C
100
..... FORMATS FOR I N P U T AND OUTPUT STATEMENTS
FORMAT (6X, E7.1,
.....
l o x , E7.1, l o x , E7.1, lox, F 4 . 1 /
1 6X, 13, 11X, L 2 )
101 FORMAT (3X. 13, 11X. I h . 2(12X. L 2 ) )
102 FORMAT ( l o x , 1 4 ~ 5 . l j
200 FORMAT ( 6 2 H 1 DETERMINATION OF EIGENVALUES OF A MATRIX BY R U T I S H
lAUSERIS/ 4 7 H LEFT-RIGHT TRANSFORMATION. WITH PARAMETERS/lH
= , E12.3/ 7X, 1 0 H E P S ~ = , E12.3/
201
1
2
FORMAT i 7 ~ , 1 0 H E P S l
7X, 1 0 H EPS3
7X, 1 0 H FREQ
FORMAT (7X, 1 0 H N
= , E 1 2 . 3 / 7X, ZOH EPSS
= 14
FORMAT (1~1,4x, ~ H E X A M P L ~ ,I3, I~H, WITH PARAMETERSIIH
= , 14
-
/ 7 ~ , 1 0 H SWEEP
= , F6.1 /
/ 7X, 1 0 H ITMAX = , 1 4
, L4 )
)
/
1 7X, 1 0 H EIGVEC = L4 ,
/ 7X, 1 0 H S T R I P D = L4 1
FORMAT ( 2 9 H O THE S T A R T ~ N GMATRIX A I S )
FORMAT ( 7 X 8 10F10.6)
FORMAT (1H0, 6X, 1 0 H I T E R , 5 I 4/ 7X, 1 0 H T A G l = , L4/
1 7X, 1 0 H TAG2 = L4)
FORMAT ( 3 5 ~ 0 THE TRANS FOR ME^ MATRIX ANEW I S )
FORMAT (3OlHO E l GENVECTORS NOT REQUIRED)
FORMAT (45HO EIGENVECTORS NOT COMPUTED BECAUSE ONE OR/
1 41H MIORE SUB-DIAGONAL ELEMENTS TOO LARGE)
242 Matrices and Related Topics
Subroutine RUTIS
DO4 J = l , N
BEGIN(J) = 1
FlNISH(J) = N
CONTINUE
DO6 1 = l , N
JLOW = B E G I N ( I
JHlGH = F I N I S H ( I )
DO 6 J = JLOW, J H l G H
B(I,J) = A(I,J)
Example 4.3 Rutishauser's Method
DO 5 1 I T E R = 1, I T M A X
C
C
C
..... UPPER AND LOWER TRIANGULAR FACTORS .....
THE M A T R I X B I S DECOMPOSED I N T O
DO 1 0 J = 1, N
ILOW = B E G I N ( J 1
DO 8 1 = I LOW, J
SUM = 0.
IMl = I - .L
0
KLOW = B E G I N ( I 1
I F (KLOW .GT. I M 1 ) GO TO 8
DO 7 K = KLOW, I H 1
7 SUM = SUM + B ( I , K ) * B ( K , J )
8 B(I,J)
JP1 = J + 1
= B(I,J) -
SUM
IHIGH = FlNISH(J)
I F ( J P 1 .GT. I H I G H ) GO TO 1 5
DO 1 0 I = JP1, I H l G H
SUM = 0.
KLOW = B E G I N ( 1 )
JM1 = J - I!
I F (KLOW .GT. J M 1 ) GO TO 1 0
DO 9 K = KLOW, J M 1
9 SUM = SUM + B ( I , K ) * B ( K , J )
10 B(I,J) = (O(I,J) -
SUM)/B(J,J)
C
C
C
..... THE ACCUMULATED PRODUCT OF THE SUCCESSIVE LOWER
TRIANGULAR DECOMPOSITION MATRICES I S COMPUTED .....
15 I F (.NOT. E I G V E C ) GO TO 1 8
DO 1 7 1 2, N
IM1 = I
DO 1 7 J
-
1
1, IM1
X(I,J) B(I,J) + X(I,J)
-
KLOW J + 1
I F (KLOW .GT. I M 1 ) GO TO 1 7
00 1 6 K KLOW, I M 1
16 X(I,J) = X(I,J) + X(I,K)*B(K,J)
17 CON~INUE
C
C
18
..... AND THE FACTORS ARE COMBINED I N REVERSE ORDER
DO 2b I = 1, N
.....
JLOW = B E G I N ( I )
IM1 = I - 1
I F (JLOW .ET.
DO 2 0 J
B(I,J)
-
I M 1 ) GO r0 2 1
JLOW, I M 1
= B(l,l)*B(I,J)
IP1 = l + 1
KHIGH = F I N I S H ( I 1
I F ( I P 1 .GT. K H I G H ) GO TO 2 0
DO 1 9 K = IPl, K H I G H
19 B(I,J) = B(1,J) + B(I,K)*B(K,J)
20 CONTl NUE
21
DO 23 J
JPl = J + 1
-
JHlGH * F I N I S H ( I )
I, J H l G H
KHIGH FINISH(J)
I F ( J P l .CT. K H I G H ) GO TO 2 3
DO 2 2 K = JP1, K H I G H
22 B(I,J) = B ( I , J ) + B(I,K)*B(K,J)
23 CONTINUE
2S CONTINUE
DO 2 5 1 = 1, N
JHlGH
DO 2 5 J
- -
JLOW = B E G I N ( I )
FiNISH(I)
JLOW, J H l G H
25 I F (DABS(B(1,J)) .LT. 1.OD-10) B(I,J) = 0.
L = L + l
244 Matrices and Related Topics
..... .....
A
DO 3 2 I T = J P l , N
1 = N + JP1
V ( I ) = B(I,J)
- IT
IP1 = I + 1
I F ( 1 .EQ. N) GO TO 3 2
DO 3 1 K = I P 1 , N
V ( I ) = V ( I ) + B(I,K)*V(K)
V ( I ) = V(I)/(B(J,J) -B(l,l))
.....
DO 3 5
POSTMULTIPLY B W I T H SWEEPING MATRIX
1 = 1, N
.....
CONTINUE
I F (.NOT. S T R I P D ) GO TO 4 1
DO 4 0 J = 1, N
BEGIN(J) = 1
FINISH(J1 N
CONTl NUE
CONTl NUE
L
C ..... CHECK FOR CONVERGENCE .....
I F (.NOT.(L.EQ.FREQ .OR. ITER.EQ.ITMAX .OR. SUBSUM.LT.EPS1))
1 GO TO 5 0
L a o
50 CONTINUE
51 I F (SUBSUM .LT. EPS1) GO TO 5 2
5 2 DO 5 3 1 = 1, N
53 X(I,I) = 0.
C
C
C
..... ANY TWO EIGENVALUES ARE CLOSER TOGETHER THAN EPS2 .....
CHECK TO SEE I F EIGENVECTORS ARE REQUIRED OR I F
I F (.NOT. EIGVEC) GO TO 72
I F (SUBSUM .LE. EPS3) GO TO 5 6
TAG1 = .TRUE.
GO TO 7 2
54
IP1 -
DO 5 5 1 = 1, NM1
1 t 1
DO 5 5 J = I P 1 , N
I F (DABS(B(1,I)
TAG2 = .TRUE.
B(J,J))- .GE. EPS2) GO TO 5 5
GO TO 7 2
55 CONTINUE
Example 4.3 Rutishauser's Method
C
C ..... COMPUTE EIGENVECTORS OF O R I G I N A L M A T R I X
DO 6 7 1 = 1, N
.....
IMl = I -
1
I F ( I .EQ. 1) GO TO 6 5
DO 6 4 J = 1, I M 1
U(I,J) = X(I,J)
JM1 = J
.-
1
-
-.
- > - .
DO 6 3 K = 1, J M I
63 U(I,J) = U(I,J) + X(I,K)*X(K,J)
64 CONTl NUE
DO 6 7 J = 1, N
U(I,J) X(I,J)
IM1 = I
5
-1
I F ( 1 .EQ. 1) GO TO 6 7
DO 6 6 K = 1, 1 M 1
U(I,J) = U(l,J) + X(I,K)*X(K,J)
CONTl NUE
CONTl NUE
RETURN
END
Data
E P S l = 1.OE-7 EPSZ = 1 . O E - 5 EPS3 = 1.OE-4 EPSS 0.1
FREQ = 5 SWEEP = T
N = 4 ITMAX = 25 EIGVEC = T STRIPD = F
A(1,l) = 10. 9. 7. 5.
9.
7.
5.
l TMAX
= 6.
4.
4.
1. 6.
l TMAX EIGVEC = F STRIPD = F
= 4. 3.
0.
5.
3.
Matrices and Related Topics
0. 0. 0, 0. 0.
-1. 0. 0. 0. 0,
2. -1. 0. 0, 0.
-1. 2. -1. 0. 0.
0. -1. 2. -1. 0.
-
0. 0. -3. 2. -1.
0. 0. 0. -1. 2.
EIGVEC = T STRl PD T
0. 0, 0. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
-1. 0. 0. 0.
2. -1. 0. 0.
-1. 2. -1. 0.
0. -1. 2. -1.
0. 0. -2. 2.5
Computer Output
DETERMINATION OF EIGENVALUES OF A MATRIX BY RUTISHAUSER'S
LEFT-RI GHT TRANSFORMATI ON, W l TH PARAMETERS
EPSl = 0.1000-06
EPS2 = 0,1000-02
EPS3 1 O.1OOD-03
EPS4 0.1
FREQ = 5
SWEEP = T
ITER = 11
TAG1 = F
TAG2 = F
THE TRANSFORMED MATRIX ANEW I S
30.288685 42.270007 10.019862 5.000000
0.0 3.858057 1.007116 0.702164
0.0 0.0 0.843107 -0.316835
0.0 0.0 0.0 0.010150
THE FOLLOWING MATRIX CONTAINS THE NORMALIZED EIGENVECTORS
0.520925 -0.625396 0.567651 0.123697
0.551955 - 0 . 2 7 1 6 0 1 -0,760318 -0.208554
,0.528568 0.614861 0.301652 -0.501565
0.380262 0.396306 -0.093305 0.830444
Example 4.3 Rutishauser's Method
N = 4 N = 4
ITMAX = 25 lTMAX = 25
EIGVEC = T EIGVEC = F
STRlPD= F STRlPD= F
ITER = 12 ITER = 25
TAGl = F TAGl = F
TAG2 = T TAG2 = F
EXAMPLE 4, W I T V PARAMETERS
N = 8
ITMAX = 100
EIGVEC = T
STRlPD= T
THE S T A R T I N G M A T R I X A I S
2.000000 -1.000000 0.0 0.0
-1.000000 2.000000 -1.000000 0.0
0.0 -1.000000 2.000000 -1.000000
0.0 0.0 -1.000000 2.000000
0.0 0.0 0.0 -1.000000
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
ITER = 41
TAGl = F
TAG2 = IF
THE S T A R T I N G M A T R l X A I S
2.500000 -2.000000 0.0
-1.000000 2.000000 -1.000000
0.0 -1.000000 2.000000
0.0 0.0 -1.000000
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
4.8 Jacobi's Method for Symmetric Matrices concern ourselves only with a!;"), a$+') and a$+').
We consider here an iterative method, credited to
,
When A, is premultiplied by U,, ,the new entry in the ii
Jacobi, for transforming a real symmetric matrix A into
+
position is a$) cos a a? sin a, that in the ij position is
a$) cos ci + a$) sin a, that in the jj position is a!:) sin a -
diagonal form. This method consists of applying to A
a$) cos a, and that in the ji position is - a $ ) cos a +
a succession of plane rotations designed to reduce the
aii sin a. When the result this far is postmultiplied by
off-diagonal elements to zero. Let A, = A and let Ui, i 2 1,
be orthogonal matrices. Define A, = U;'AoU1, A, =
,
U, + , we have
U;'AlU2, and, in general, al:+') = a[:) cos2 a+ a$) sin2 a + 2a$) sin u cos a;
a$+') = af)sin2 a + a$)cos2 a - 2a$)sin a cos a;
Then if U; = UlU2 . . . U,, aik+')
v = (a::) - a;;)) sin a cos u - a!;) (cos2 a - sin2a).
Now choose u so that ai?") = 0. Then
and A,+, has the same eigenvalues as A. Moreover, for 1 + cos 2a 1 - cos 2a
all indices k, A, is real and symmetric.
=
a 'iik' + a$) + a$) sin 2u;
Recall that Sp (A*A) = XI=, x;=,
aijZij, or, for A real
2 2
and symmetric, Sp (A2) = C:= ,Xy=afj. If T is any non-
singular transformation, T-lA2T has the same eigen-
a$+,) = aii(k) 1 - cos 2a
2
+ a$' 1 + cos
2
2a
- a$) sin 2a;
values as A2, and thus Sp (T-'A2T) =Sp (A2), since it is
the sum of the eigenvalues. Thus, if A, = (a$)), we have, and, unless a$)' = a$),
for (4.48) tan 2a = 2a!f)/(aj:) - a):?), (4.52)
where
the sequence
Flow Diagram
@+ ,-Gq
vergence"
254 Matrices and Related Topics
FORTRAN Implementation
List of Principal Variables
Program Symbo I Dejinit ion
A Upper triangular matrix, A.
AIK Vector used for temporary storage.
CSA, SNA cos a and sin a (see equations (4.56) and (4.57)).
ElGEN Vector of the eigenvalues 4 , A,, .. ., 1,.
EPSl Tolerance, E, ; for q < E,, ci = n/4.
EPS2 Tolerance, E,; aij is bypassed if lai,/ < c 2 .
EPS3 Tolerance, E,, used in termination criterion.
ITER Counter, k, for the number of complete Jacobi iterations.
ITMAX Maximum number of iterations permitted, k,,, .
N Dimension, n, of the matrix A.
OFFDSQ Sum of squares of off-diagonal elements of A.
P, Q p and q (see equation (4.56)).
S Sum of squares of all elements in the full starting matrix.
SIGMA1, SIGMA2 Sums, a, and o,, of the squares of the diagonal elements of A before and after an iteration,
respectively.
SPQ (pz -I-q2)1/2.
T Product of rotation matrices; ultimately contains eigenvectors.
Example 4.4 Jaeobi's Method
Program Listing
C APPLI ED NUMERI CAL METHODS, EXAMPLE 4.4
C EIGENVALUES AND EIGENVECTORS BY THE JACOB1 METHOD.
ONLY THE UPPER TRIANGULAR PART OF THE REAL SYMMETRIC STARTING
MATRIX A I S READ. T I S AN N BY N ORTHOGONAL MATRIX, BEING THE
PRODUCT OF THE SEQUENCE OF TRANSFORMATION MATRICES USED TO ANN-
I H I L A T E SUCCESSIVELY THE OFF-DIAGONAL ELEMENTS OF A, AND CON-
SEQUENTLY TO REDUCE A ITERATIVELY TO NEAR-DIAGONAL FORM.
S l G M A l AND SIGMA2 ARE THE VALUES OF SIGMA A ( l , l ) * * 2 BEFORE AND
AFTER ONE COMPLETE ITERATION. SINCE ANNIHILATION OF AN ELEMENT
MAY CAUSE ANOTHER ALREADY-ANNIHILATED ELEMENT TO ASSUME A
-
NON-ZERO VALUE, THE ITERATIVE PROCESS I S REPEATED UNTl L
THE CONVERGENCE TEST I S PASSED (1 SIGMAl/SIGMA2 LESS THAN
EPS3) OR ITMAX COMPLETE ITERATIONS HAVE FAILED TO PRODUCE CON-
VERGENCE. AN OFF-DIAGONAL ELEMENT SMALLER I N MAGNITUDE THAN
COMPARED WITH (A(1,I) -
EPS2 I S IGNORED I N THE ANNIHILATION PROCESS.
A(J,J)) TO DETERMINE THE
METHOD OF COMPUTING CSA AND SNA, THE COSINE AND S l N E OF
EPSl I S
1
T(l,J)
A(I,J)
NM1 = N
= 0.0
= 0.0
READ (5,101) N, ITMAX, EPS1, EPS2, EPS3, ((A(1,J).
-1
J I, N),
I = 1. N)
-
WRITE (6,200) N, ITMAX, EPS1, EPS2, EPS3
DO3 1 =1,N
WRITE (6,201) (A(I,J), J = 1, N)
..... SET UP I N I T I A L MATRIX T,
S l G M A l = 0.0
COMPUTE S l G M A l AND S .....
OFFDSQ = 0.0
DO5 I m1.N
S l G M A l = SIGMAI + A ( I , I ) * * 2
T(l,l) = 1.0
1p1-¤ 1 + 1
I F ( I .GE. N) GO TO 6
DO 5 J IP1, N
OFFDSQ = OFFDSQ + A(I,J)**2
S = P.O*OFFDSQ + S l G M A l
..... COMPUTE
DO16
NEW ELEMENTS
K = I, N
OF A I N ROWS I AND J .....
IF i~.NE. J) GO TO 1 4
A(J,K)
GO TO 1 6
= SNA*AIK(K) -
CSA*A(J,K)
HOLDIK = A(I,K)
A ( I ,K) = C S A * H O L D I K + SNA*A(J,K)
A(J,K)
CONT l NU E
= SNA*HOLDIK -
CSA*A(J,K)
.....
AIK(J)
COMPUTE NEW ELEMENTS OF A I N COLUMNS I AND J
= SNA*AIK(I) -
CSA*AIK(J)
.....
..... WHEN K I S LARGER THAN I
DO 1 9 K = 1, J
.....
I F ( K .LE. I ) GO TO 1 8
A(K,J)
GO TO 1 9
= SNA*AIK(K) -
CSA*A(K,J)
HOLDKI = A ( K , I )
A(K, I ) = CSAeHOLDKl + SNA*A(K,J)
A(K;J) -
= S N A ~ H O L D K I CSA*A(K,J)
CONTl NUE
A(I,J) = 0.0
Data
N = 4, ITMAX = 50,
E P S l = 1.00E-10, EPSZ x
A(1,l) = 10.0 9,O
6.0 10.0
N = 4, ITMAX 50,
E P S l = 1.00E-10, EPS2
A(1,l) = 6.0 4.0
4.0 6.0
N = 8, ITMAX = 50,
E P S l = 1.00E-10, EPSZ =
A(1,l) = 2.0
01 0
01 o
.. -1.0
0.0
0.0
030
CI 0
290
. 0.0
0,o
-1.0
Computer Output
Resultsfor the 1st Data Set
DETERMINATION OF EIGENVALUES B Y JACOBI'S METHOD, WlTH
N = 4
ITMAX = 50
EPSl = 0.1000-09
EPS2 = 0.1000-09
EPS3 = 0.100D-0l1
N = (I
ITMAX = 50
EPSl = 0.100D-09
EPS2 = 0.1000-09
EPS3 = 0.100D-04
Discussion of Results Since the sums of the squares of all the elements in the
The eigenvalues and eigenvectors have been computed starting matrices were 933, 276, and 46, respectively, all
for three test matrices. The results are virtually identical off-diagonal d ~ m e n t have
s been reduced to *he vanishing
with those produced by Rutishauser's method in Example point. Convergence is rapid in all cases; even the 8 x 8
4.3. The sums of the squares of the diagonal elements O ~ A matrix in the third data set requires only four ~ a c o b i
after each iteration are as follows: sweeps to'meet the convergence criterion.
4.9 Method of Danilevski where B,, = b,, = a,, and 0 denotes the 1 x (n - 1) null
matrix.
Let A = (aij) be a square matrix of order n and suppose
be a matrix such that Finally, the process may be continued for a time,
that a,2 + 0. ~~t ~ ( 1 =)
mi,!) = a,, (the Kronecker delta, that is, aij = 0 for stopping when all choices for the pivot element lead to a
. , where now
zero. In such event B has the form of (4.58).
0 1 0 0 .-. 0 0
0 0 1 0 ... 0 0
.................................................. (4.59)
0 0 0 0 ... 0 1 0
0 0 0 0 ... 0 0 1
bml bM2 bm3 bm4 ... bm,m-2 bm,m-1 bmm
- while 0 denotes the m x (n - m ) null matrix, and B2, ,B2 2
i # J and a,, = 1 for i =j) unless i = 2. Let m'z:'= lla12 have no special character.
and let mi:' = -alI/al2 if j # 2. Let the inverse The procedure is continued, treating B2, as A itself
M") be P'". Then if P"' = (p!,!'), it is easy to verify that was treated (except that it is not considered as detached
pj;) = a,, if i # 2, while &,' = all. It is also seen that if from B). The final result may be written C = M-'AM,
is used as a po~tmultiplierfor A, and p"' as a Pre- where a typical form for C might be
multiplier, the result is a matrix A ( ~ =(a!:))
' such that
a%)= 1 while a!:) = 0 if.) # 2. Cll 0 0 0
If a,, is zero, or if it be desired to base the effect on
some other nonzero element of the first row, any element
of that row, other than the first, can be brought to this C41 C42 C43 C44
location by an interchange of two columns. If this is
Here the "diagonal" matrices Cl1, C22rC33, and C4,
followed by an interchange of the corresponding rows,
have the form (4.59), or are 1 x 1 matrices, zero or other-
the resulting matrix will always be similar to A.
wise.
Now let M(2)= (m:?)) be a matrix such that mlf) = dij
The result of first importance is that from the matrices
unless i = 3. Assuming ni2,) $0, let = l/a$<) and
mi:) = -ai:)/a$:) if j # 5. Let the inverse of M ( ~ be ) CI1,C22,C33,and C4, we may quickly find a factored
P(2)= (pi:)). Then p!:) = a,, if i # 3, while pi:) = a$:). form for the characteristic function of A. This is because
It is also seen that if M(2)be used as a postmultiplier for the characteristic function for A is that for C, and the
A(2) and P(2) as a premultiplier, the result is a matrix characteristic function for C is the product of those for
A(3)= (a!;))such that a\? = 1, a(,:) = 0 if j # 2, a$:) = 1, CII,C22, C33, and C44.
a$;) = 0 i f j # 3. When the characteristic function is known, it may be
If ay? is zero, or if it be desired to base the effect on that its zeros can be found. With this information, the
some other nonzero element of the second row, any matrix C and the matrix M may be used to find the eigen-
element of this row, other than the first two, can be vectors of A, for the eigenvectors of A are M times the
brought to the proper location by an interchange of two eigenvectors of C.
columns. If this is followed by an interchange of the The formation of the characteristic vectors of C will be
corresponding rows, the resulting matrix is similar to illustrated only for the case where C has the form
A(2)and the first row is unaltered. C,, 0 0 0
Continuing in this manner we arrive at a matrix B,
0 c22 0
similar to A and having one of three possible forms. If
the process can continue unhindered, then we find
0 c44
0 1 0 0 a3.0 0
and each C,,has the form of (4.59). Suppose c,, IS
0 0 1 0 . . - 0 0
...................#...............,........ P x p, c22 i~ q X grC J 3is r x r, and C,, is s x s. Let the
0 0 0 1 last row of C11 be [el e2 . . . e,], those for CZz,C,,, and
C44 being [flf 2 . ..f,], [gl g, . . . g,], and [h, h, . . . h,],
. . S O
0 0 0 0 ... 0 0 1
respectively. Just as with the companion matrix (4.32), the
bnl bn2 bn3 bn4 bn,,-z b,,,-, bnn
It may be that all elements of the first row, other than
characteristic function of C, is ,
perhaps a, , , are zero. In such event B may be represented
in partitioned form as
and similarly for C,,, C,,, and C4,.
(4'58) Let a be an eigenvalue of C and let x, y, I, r be arbitrary
262 Matrices and Relaled Topics
for the moment. Then from the nature of C,,, etc., we tion of C1, only, then x is arbitrary and y = z = t = 0.
see that an eigenvector u corresponding to a must be Moreover, even if a is a multiple eigenvalue, there is
.
such that u' = [x, ax, ...aP-'x, y, ay, . .aq-'y, z,az, ... still only (essentially) one eigenvector. If, say, a is an
ar-Iz, t, at,. ..a'-'t]. In addition, we must have eigenvalue for both Cl1 and C3, but not C2, and C44,
then x and z are arbitrary, while y and t are zero. In such
P
x C eiai- = apx,
i=l
y x fi
9
i- 1
'
ai- = aqy, z
r
i= 1
@pi-= arz, event, there are two linearly independent eigenvectors
for a. In general, all eigenveciors can be found from the
and eigenvectors for the component matrices by using zeros
in the rows corresponding to other component matrices.
t xs
i= 1
'
hiai- = a?. For the case examined last, the eigenvectors would be
u \ = [ l , a ,... aP",O.O ,... 0,0,0,...0,0,0 ,... 01 and
Thus we see that if a is a zero for the characteristic func- u$ = [O, 0, ...O, 0,0, ...O, 1, a, ... aq-', O,0, .. .0].
Problems
;: :-,I.
4.10 Find one eigenvalue and a corresponding eigenvector
for the general circulant
[XI Xz. .. xo
Since this method involves also the computation of B t , B2,
.
. .,B,- where
B(A) = adj (XI - A)
264 Matrices and Related Topics
the program can be written so that we also find: time-level n, and the boundary values g,(t,) and g,(t.) are
zero, show that
(a) adj (A) = (- I)"-' adj (-A) = B.-I,
V n + l =Avn,
(b) A- = a; adj A = a; 'B,-, , provided that A is non-
singular, in which A = I + r T M - , ,where r = A~/(AX)~
and Tw-I is the
(c) for any known eigenvalue hi, a corresponding eigen- matrix of Problem 4.19 (now with M - 1 rows and columns).
vector, p,, by taking any nonzero column (see page 220) of The eigenvalue approach for discussing stability of the
B(X1). method involves proving whether the eigenvalues of A are less
than one in magnitude (see page 222). Show that these eigen-
The process, which follows, is established in Gantmacher
values are
[Ill:
A1 =A, UI = Sp(AI), B1= 011 - AL,
1 and that stability occurs if r < 9.
A2 = ABI, (12 =- Sp(Az), Bz = azI - Az,
2 4.21 In the Crank-Nicolson scheme for the numerical
solution of u, = u,, (page 451,also [9], p. 64), the eigenvalue
approach for discussing stability involves proving that the
+
eigenvalues of A = (21 - rTM-,)- '(21 rTM-,) are less than
one in magnitude. Use Problem 4.19 to show that the eigen-
values are
!I,
solution of partial differential equations is the n x n tri-
diagonal matrix [9]:
= [ : : -1
-2
1 -2
1 0
1
o...o
o...o
1 . .
o... 1 -2
0
Figure P4.23
and x2 are measured relative to the position of static equili-
brium. The spring stiffnesses k , , k,, and ka are the forces re-
quired to extend or compress each spring by unit length.
wherein all entries are zero except the diagonal entries, always (a) Show that the equations of motion are
-2, and the infra- and super-diagonal entries, always 1. Show
that the eigenvalues and corresponding eigenvectors are
given by
(b) If the deflection vector is x = [x, x2]', rewrite the equa-
tions of motion in the form x = Ax.
(c) Show that the substitution x = beJ"', where j = d\/--1,
in 2in ni?s
sin -
n+l ' I ' leads to the eigenvalue problem
Ab = Xb,
where i = 1 , 2, . . ., n. where X = -wZ. The possible values that w may assume are
4.20 The explicit method for the numerical solution of the natural circular frequencies of vibration of the system.
u, = u,, is discussed in Section 7.5 (see also p. 61 of Smith (d) If k l = kz = k , = I lb,/sec2, and m, = m2= 1 lb,, find
[g]). If v. = [vl,. VZ,,, . . . Z ~ M - ~is, ,the
, ] ~vector of solutions at the eigenvalues and eigenvectors of A.
(e) If the initial conditions at t = 0 are xl = 1, x2 =XI = where x is the axial distance along the beam, M is the local
x2 = 0, show that bending moment (considered positive if it tends to make the
beam convex in the direction y, as shown), E is Young's
modulus, and I is the appropriate cross-sectional moment of
inertia.
I,,Iz, and ISare the moments of inertia (Ib, in. sec2) of the
rotating masses. The shaft st.iffnesses k l and kz are the torques
(lb, in.) required to twist each section through unit angle. and that the solution is then y = A sin(n~x/L),where A is
Let f l , , 82, and 0, be the angular displacements of the rotating an arbitrary constant. Note that for n = 1, we have P =
masses. a2EIiL2(known as the Eulev load), under which the column
(a) By equating torque to the product of moment of will just begin to buckle.
inertia and angular acceleration, show that What will happen if P does not equal one of these charac-
teristic values ?
4.28 Approximate the solution to Problem 4.27 by the
following finite-difference method. Divide the beam into
+ +
n 1 segments, each of length Ax = Li(n I), by introducing
(b) Following the general pattern of Problem 4.23, com-
+
points labelled 0, 1, 2, . . ., i, . .., n, n 1, as shown in Fig.
P4.28.
pute the natural frequencies and the associated vectors of
relative displacements for each mode of torsional oscillations
if I, = Iz= 4, 1, = 20 lb, in. sec2, k , = 8 x lo6, and k2 = lo7
lb, in./radian.
4.26 Write a program that will generalize the situation in
Problem 4.25 to that of n rotating masses on a shaft. Figure P4.28
Test the program with th~edata of Problem 4.25, and also
From equation (7.7), the approximation to the differential
for the following four-cylinder engine and flywheel: 1, =Iz=
equation at the ith point is
I , = I.+= 4, Is = 20 lbf in. sec2, kl = k2 = k3 = 8 x lo6,
k4 =: lo7 lb, in./radian. Also investigate the effect of adding
a generator (I6 = 8) connected by a shaft (ks = 2), (a) next
to the flywheel, and (b) next to the first cylinder.
4.27 The transverse deflection y of a beam obeys the (a) By considcring points i -- 1, 2, .. ., n in turn, show that
differential equation the vector of deflections, Y = [ylyz . . . y.]', obeys
d2y M
--- - -
dx2 EI'
266 Matrices and Related Topics
Systems of Equations
5.1 Introduction I and replacing the ith diagonal element with a nonzero
This chapter is concerned with methods for solving the constant q. For example, with n = 4 and i = 3,
following system of n simultaneous equations in the n
unknowns x,, x,, . . ., x,:
!1(~1,~2,...r xn) = 0,
f2(~1,~27..xn) = 0,
.1
(5.1) Note that det Q = q, and that the inverse matrix Q-' =
diag (1, 1, I/q, 1) is again like I, this time with l/q in the
jn(xl,x:zl .., x,) = 0. ith diagonal position.
2. An elementary matrix of the second kind is an n x n
The general case, in which the functions fi,f2, . . .,A do matrix R, formed by interchanging any two rows i and
not admit of any particular simplification, is treated in j of I. For example, with n = 4, i = 1, and j = 3,
Sections 5.8 and 5.9. However, if these functions are
linear in the x's, (5.1) can be rewritten as:
Also define three elementary matrices of the third kind Note that by augmenting the coefficient matrix with
several right-hand side vectors, we can solve several sets
of simultaneous equations, each having the same coef-
ficient matrix, at little extra computational cost.
Example. Consider the system of equations
2 x 1 - 7x2 f4x3 = 9 ,
XI + 9x2 - 6x3 = 1 ,
+
- 3 ~ 1 + 8x2 5x3 = 6 ,
for which the solution is x l = 4, x2 = 1, and x 3 = 2. The
augmented matrix [B 1 u I] will be formed, and the Gaussian
elimination procedure just described will be carried out,
except that the normalization steps will be introduced in a
The operations producing (5.6) from (5.4) can then be somewhat different order. Starting with the matrix,
expressed as
2 - 7 4 9 1 0
s3s2s1c = [:
bll b12
Z :
b13 U1
-
9
3 8 5
0
6 0 0
1
1
",
we multiply the top row by 112, add - 1 times the new first
The back-substitution is expressed in terms of premulti- row to the second row, and 3 times the new first row to the
plication by elementary matrices of the first and third third row. The result is
kinds. Let Q,, Q2, and Q 3 denote the three matrices of
the first kind which are needed. For example,
Then, with three more matrices of the third kind, which This is equivalent to having formed the equations
we call S,, S,, and S,, the complete sequence of opera-
tions results in
Q ~ S ~ S S Q ~ S , Q , S ~ S=
~S,C
Returning to (5.7), multiply the second row by 2/25, and Inspection shows that the relevant diagonal elements are
then add 512 times the new second row to the third row. The simply the multiplying factors used in the normalization steps,
result is : so that
det B = X [! -2
2 25 43
X -1
5 -'
= 235.
Finally, multiply the second row by 712 and add to the first.
The result is
The determinant of the coefficient matrix B equals the Finally, normalize the last row by dividing by the pivot
produ~.of the reciprocals of the diagonal elements appearing element 4715 ; then reduce the remaining elements of the
in the Q-type matrices involved in the above transformation. third column to zero by subtracting -(6125) and -(16125)
5.4 Gauss-Jordan Elimination 273
times the new third row from the first and second rows, its highest value (n 3. m ) until the pivot column is reached.
respectively. The resulting matrix is [I 1 x B-'1, where x Thus far, elementary matrices of the second kind have
is the solution vector, and'B- '
is the inverse of the original not been used; neither has mention been made of the
matrix of coefficients: fact that at some stage, say the first, a potential divisor
or pivot, such as b,,, may be zero. In this event, we can
think of interchanging rows, which is expressible, of
course, in terms of elementary row operations of the
second kind. A related problem is that of maintaining
sufficient ac.curacy during intermediate calculations in
order to achieve specified accuracy in the final results.
This might be expected for a nearly singular system; it
can also happen when the magnitude of one of the pivot
elements is relatively small. Consider, for instance, the
The determinant of the original coefficient matrix is system
again the product of the pivot elements and thus equals 0.0003 XI +
3.0000 x2 = 2.0001,
2 x 2512 x 4715 or 235. +
1.0000 x, 1.0000 x, = 1.0000,
We conclude this section by developing an algorithm
which has the exact solution x, = 113, x, = 213. If the
for the above procedure, which is called Gauss-Jordan
equations are solved using pivots on the matrix diagonal,
elimination. Let the starting array be the n x (n m) + as indicated in the previous examples, there results
augmented matrix A, con~sistingof an n x n coefficient
matrix with m appended columns: 1.OOOO x1 + 10000 x2 = 6667,
x2 = 6666/9999.
If x, from the second equation is taken to be 0.6667, then
from the first equation x, = 0.0000; for .u2 = 0.66667,
x1 = 0.30000; for x2 = 0.666667, x, = 0.330000, etc.
The solution depends highly on the number of figures
retained. If the equations are solved in reverse order,
Let k = 1, 2, . . ., n be the pivot counter, so that a,, is the that is, by interchanging the two rows and proceeding as
pivot element for the kt11 pass of the reduction. It is before, then x, is found to be 1.9998/2.9997 = 0.66667
understood that the values of the elements of A will be while xi = 0.33333. This example indicates the advisa-
modified during computation. The algorithm is
Normalization
Reduction
Problem Statement with each cycle of the algorithm, to yield the, deter-
minant of B upon completion of the nth cycle. The
Write a program that implements the Gauss-Jordan
complete algorithm is
elimination algorithm outlined in (5.8) to solve n simulta-
neous linear equations. The program should allow con-
current solution for m solution vectors. Initialization
As one of the data sets for the program, use the d c1
linear equations whose solutions are the potentials at
nodes (junctions) 1 through 6 in the electrical network of Updating the determinant
Fig. 5.1.1. The values of the resistances are shown in dcdakk
ohms, and the potential applied between A and B is
100 volts. Normalization I
Reduction
I
Figure 5.1.1 Electrical network Should aik already be equal to zero, the reduction step
for the ith row may be ignored.
Method of Solution A zero or very small pivot element may be encountered
The reduction algorithm: The starting matrix A = (aij) in the elimination process (this may or may not indicate
is assumed to be the n x (n + m) augmented matrix of that the coefficient matrix in the first n columns of A
coefficients of page 273, where the column vectors is singular or nearly singular). A test for pivot magnitude,
a j = [a, j,azj, . . .,anjIt, for j = 1, 2, . . ., n, correspond to
the matrix B of (5.3). The vectors aj, for j = n 1, +
n + 2, . . ., n + m, are rn right-hand side vectors for which
solutions are desired. is made before the norm'alization step for the kth cycle,
The diagonal pivot strategy of (5.8), that uses, as the n k = 1, 2, . . ., n, to insure against extremely small divisors
pivot elements, the elements along the main diagonal in normalization. If test (5.1.2) is failed, computation is
of the matrix of coefficients (the first n columns of A) stopped for the offending set of equations.
leads to the transformation Electrical network equations: From Ohm's Law, I,,,
the current flowing from node p to node q in leg pq of
the network, is given by
Flow Diagram
FORTRAN Implementation
List of Principal Variables
Program Symbol Dejinition
A Augmented matrix of coefficients, A = (aU).
DETER d, determinant of the original coefficient matrix (the first n columns of A).
E PS Minimum allowable magnitude, E , for a pivot element.
I. J Row and column subscripts, i and j.
K Cycle counter and pivot element subscript, k.
KPl k 1- 1.
M Number of solution vectors, m.
N Number of equations, n.
NPCUSM n +- m,
276 Systems of Equations
Program Listing
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 5.1
C GAUSS-JORDAN REDUCTION
TH lS PROGRAM F l NDS M SOLUTION VECTORS CORRESPOND l NG
TO A S E T OF N SIMULTANEOUS LINEAR EQUATIONS U S I N G THE GAUSS-
JORDAN REDUCTION ALGORITHM W I T H THE DIAGONAL P l V O T STRATEGY.
THE N BY N MATRIX OF COEFFICIENTS APPEARS I N THE F I R S T N
COLUMNS OF THE MATRIX A. M RIGHT-HAND S l D E VECTORS ARE
APPENDED AS THE ( N + l ) T H TO (N+M)TH COLUMNS OF A. ON THE
K ( T H ) PASS OF THE E L I M I N A T I O N SCHEME, K ( T H ) ROW ELEMENTS ARE
NORMALIZED BY D I V I D I N G BY THE P l V O T ELEMENT A(K,K). DETER,
THE DETERMINANT OF THE C O E F F I C I E N T MATRIX, I S UPDATED PRIOR
TO E L I M I N A T I O N OF A L L NONZERO ELEMENTS (EXCEPT FOR THE P l V O T
ELEMENT) I N THE K ( T H ) COLUMN. SHOULD A P l V O T ELEMENT BE
ENCOUNTERED WHICH I S SMALLER I N MAGNITUDE THAN EPS, COMPUTATION
I S DISCONTINUED AND AN APPROPRIATE COMMENT I S PRINTED.
THE SOLUTION VECTORS CORRESPONDING TO THE OR1 G I NAL R I G H T -
HAND S l D E VECTORS ARE STORED I N COLUMNS N + l TO N+M OF A.
I M P L I C I T REAL*8(A-H, 0-2)
DIMENSION A ( 5 0 , 5 1 )
9 CONTl NUE
C
WRlTE (6,203) OETER,N,NPLUSM
DO
-. 1
- 0- l = 1. N
10 WRITE ( 6 , 2 0 i ) . ' ( ~ ( l ,J),J*~,NPLUSM)
GO TO 1
C
100
..... FORMATS FOR I N P U T AND OUTPUT STATEMENTS
FORMAT ( 2(10X, 12, 8x1, lox, E 7 . 1 )
.....
101 FORMAT ( 20X, 5F10.5 )
200 FORMAT ( l O H l N = , 18 / 1 0 H M = , I 8 / 1 0 H EPS = ,
1 lPElb.l/22HO A(l,l)...A(* t 2 * lH,, 12, 1 H ) / 1 H
2 0 1 FORMAT ( 1 H 7F13.7
2 0 2 FORMAT ( 37HOSMALL P l V O T -
MATRIX MAY BE SINGULAR
2 0 3 FORMAT ( ~ O H O D E T E R = , E14.6/ 22H0 A(lOl)...A(O 12, l H O ,
1 12, 1 H ) 1 1 H
C
END
Example 5.1 Gauss-Jordan Reduction
Computer Output
Results for the 1st Dafa Set
N - 3
M - 4
EPS = 1.OD-10
278 Systems of Equations
DETER = 0.235000D 03
DETER = -0.235000D 03
SMALL P I V O T - M A T R I X MAY B E S I N G U L A R
SMALL P I V O T - M A T R I X MAY B E S I N G U L A R
Example 5.1 Gauss-Jordan Reduction
Computer Output (Continued)
Results for the 5th Data Set
N 3
M -
P
4
EPS = 1.OD-20
DETER = -0.490000D 02
DETER = 0.150~000D 0 7
DETER = 0.2999970 01
280 Systems of Equations
DETER = -0.299997D 01
DETER = 0.299997E 01
DETER = -0.299997E 01
Example 5.1 Gauss.
Discussion of Results Results for the seventh data set are shown for calcu-
Except for the last ~ M I Osets of results shown in the lations done in both double- and single-precision
computer output, all ,calculations were done using arithmetic. For the IBM 360167, single- and double-
double-precision arithmetic. The first data set consists precision word sizes are the equivalent of 6-7 and 15-16
of the three equations used as the illustrative example in decimal digits, respectively. The equations are
Section 5.4. The starting matrix A consists of the co-
efficient matrix B and four right-hand side vectors,
including the three unit vectors in order, that is,
The solutions are
Problem Statement computer program form in Example 5.1, the pivot for
the kth cycle is chosen to be the element in the a,,
Write a function named SlMUL that solves a set of n
position, that is, an element on the diagonal. As dis-
simultaneous linear equations,
cussed in Example 5.1, this strategy can lead to compu-
tational difficulty for some systems of equations. Should
akkbe equal to zero, then the normalization steps of the
algorithm must not be carried out. When a,, is of
relatively small magnitude when compared with other
elements in the first n columns of A, the normalization
and reduction operations can often be carried out; but
using Gauss-Jordan reduction with the maximum pivot computed results may be inaccurate because of round-off
strategy, described in the next section. The subroutine error (see results for the eighth data set in Example 5.1).
should have three alternative modes of operation, con- In such cases, provided that the matrix of coefficients is
trolled by one of its arguments: not near-singular, it is usually possible to overcome the
Mode 1. The equations of (5.2.1) should be solved problem by rearranging the rows or columns of the
and the solutions saved, in order, in a vector coefficient matrix; this is equivalent to reordering the
A. equations or renumbering the variables, respectively. An
Mode 2. The equations should be solved as in mode 1. alternative possibility is to choose any element of
In addition, the inverse of the matrix of significant magnitude that is still available for pivoting
coefficients should be calculated "in place," (not in a row or column already containing a pivot) as
that is, the inverse should be overstored in the the pivot for the kth pass. Usually the largest such element
first n columns of the matrix A, without use is preferred, as its use is likely to introduce the least
of any auxiliary matrices (see next section). round-off error in the reduction pass; the technique is
Mode 3. In this case, the matrix A contains only n termed the Gauss-Jordan reduction with the maximum
columns. The inverse should be computed pivot strategy. It is only necessary to keep lists of the
"in place" as in mode 2. row and column subscripts of successive pivot elements.
Let rk and ck be, respectively, the row and column sub-
In each case, the value of S ~ M U Lshould be the deter- script of the kth pivot element, pk.
minant of the matrix of coefficients. The algorithm, closely related to that of Example
Write a main program to test SIMUL. As one of the 5.1, is
data sets for the program, use the linear equations
whose solutions are the member forces in the statically Initialization \
determinate, simply supported, eleven-member plane
truss shown in Fig. 5.2.1. d t l
Choosing the pivot
$ IOT
Updating the determinant
d ~ k
Normalization
I
1
k = 1,2,..., n.
The elements rk and ck must be assigned the appropriate The reduction steps lead to
values, once the kth pivot, pk, has been selected. Here, as
before, d is the determinant (possibly with incorrect sign)
of the matrix of coefficients. After reduction is completed,
the first n rows of A will contain a (possibly) permuted
identity matrix. The (n + 1)th column will contain the
solution vector x = [x,,x2,. . .,x,]', although the elements For the second cycle, only a,,, a,,, a,,, and a,, are
will usually be out of order. The solutions can be un- available as potential pivots. Since a,, has the greatest
scrambled by using the information saved in the vectors magnitude of the four candidates, p, = 3113, r, = 1,
r and c, as follows: c, = 3. The determinant value is updated to 9 x 3113 =
93. After the normalization and reduction steps, the
matrix becomes
The resulting transformed coefficient matrix has a
determinant equal to f 1 (it is either an elementary
matrix of the second kind or is the identity matrix itself).
Therefore the value computed for the determinant, d,
may be of incorrect sign. It is necessary to establish For the third and last cycle, only a,, is available for
whether an even or odd number of row interchanges is pivoting. Then p3 = 235193, r3 = 2, c3 = 1. The deter-
required to reorder the fi~nalpermuted matrix as the minant value is updated to 93 x 235193 = 235, and after
identity matrix. The problem can be solved by forming normalization and reduction, the matrix is
an auxiliary vector, j, such that
x3 = a , , = 2.
The augmented coefficient inatrix for this system is
The auxiliary vector j, formed according to (5.2.3), is
j, = 3
j, = 1
j, = 2.
Then, for k = 1, that is for the first pass, element a,, Since two pairwise interchanges are required to put j into
has the greatest magnitude of the nine possible coeffi- ascending sequence, the sign of d is correct, and the
cients and p, = 9, r, = 3, c , = 2. The determinant value, determinant of the original matrix of coefficients is 235.
d, is updated from its initial value of 1 to 9. After the
The Inverse Matrix
normalization steps for the first cycle, the transformed
matrix is The inverse matrix could be developed by appending
an n x n identity matrix to the augmented matrix of
coefficients, and carrying out the maximum pivot
strategy as describe.d in the preceding paragraphs. In
that case, the normalization and reduction steps would
284 Systems of Equations
be applied to all 2n + 1 columns of the matrix, rather For the numerical example, the introduction of (5.2.4)
than just the first n + 1 columns. The initial matrix for and (5.2.5) into the maximum pivot strategy leads to
the preceding numerical example would be the following three matrices after the first, second, and
third cycles of the algorithm, respectively.
Cycle 2. -35193 0 1
235193 0 0
-13193 1 0
Cycle 3. 0 1
[ 8 0
1
0
0
Note that after the first cycle only the last column of
the original identity matrix has been changed. Since the
contents of the column containing the pivot element
(column 2 in this case) are known to be a one in the pivot
position and zeros elsewhere, there is no need to retain
them. The elements of the developing inverse (in this
case in column 7) can be overstored in place in the pivot
column. Similar behavior can be observed for the results The solution vector is unscrambled as before, and the
of the second and third cycle reduction calculations. determination of the appropriate sign for the deter-
The maximum pivot strategy already developed may minant is unchanged. The elements of the inverse matrix
be modified slightly to implement the inverse calculation are, of course, not in natural order unless all pivot
without the necessity of appending n additional columns elements are on the main diagonal of the coefficient
to the coefficient matrix or of using other auxiliary matrix. The unscrambling process involves both row and
matrices. The procedures for calculating the determinant column interchanges. Let y be an n element vector. Then
and selecting the pivot element are unchanged. All the inverse can be properly ordered using the following
elements of the row containing the pivot element, row scheme in sequence:
rk, are normalized as before, except the pivot element
itself, which is replaced by its reciprocal. Thus the Yci arij, i = 1 , 2 ,..., n,
+
j = 1 , 2,..., n,
normalization step is given by aij Yi, i = 1 , 2 ,..., n, (5.2.6)
Flow Diagram
Main Program
Evaluate
determinant, d,
(Function SIMUL)
Example 5.2 Inverse Matrix Using the Maximum Pivot Strategy
m+iz+ 1
Y
Enter d c1 --
I
F m+n A I
I
Sy$lt?msof Equations
0 Return
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
(Main)
A Augmented matrix of coefficients, A = (aij).
DETER d, determinant of the original coefficient matrix (the first n columns of A).
EPS Minimum allowable magnitude, e, for a pivot element.
I. J Row and column subscripts, i and j.
INDlC Computational switch, s.
MAX Number of columns in A, either n or n + 1.
N Number of rows in A, n.
X Vector of solutions, xi.
(Function
SIMUL)
AlJCK
l NTCH c*, number of pairwise interchanges required to order elements of vector j.
IP1, KM1, NMI i+1,k-l,andn-1,respectively. .
IROW Vector of pivot element row subscripts, r,.
JCOL Vector of pivot element column subscripts, c,.
IROWI, IROWJ, ri, rj, r,., c i , cj, and c,, respectively.
IROWK, JCOLI,
JCOLJ, JCOLK
ISCAN, JSCAN Indices q and t , used in scan of vectors c and r during pivot element search.
JORD The vector j.
JTEMP Temporary variable used in ordering the j vector.
K Cycle counter and pivot element subscript, k.
NRC N,,row and column dimensions of storage for the matrix A (assumed t o be square).
PIVOT Pivot element, p,.
Y Vector y, used in unscrambling the inverse matrix.
Exampie 5.2 Inverse Matrix Using the Maximum PivolStrategy
Program Listing
Main Program
C A P P L I E D NUMERICAL METHODS, EXAMPLE 5.2
C CALCULA'TION OF THE INVERSE MATRIX I N PLACE
C
C T H I S PROGRAM READS VALUES OF N, I N D I C, AND EPS. I F INDl C IS
C NEGATIVE, ELEMENTS OF AN N B Y N MATRIX A ARE READ, AND THEN THE
C FUNCTION S I M U L I S CALLED TO COMPUTE THE INVERSE OF A I N PLACE.
C I F I N D l C I S ZERO, ELEMENTS OF AN N BY N + l M A T R I X A ARE READ,
C AND THEW THE FUNCTION S l M U L I S CALLED TO SOLVE THE SYSTEM OF
C L I N E A R EQUATIONS WHOSE C O E F F l C I E N T MATRIX 1 s I N THE F I R S T N
C COLUMNS OF A AND VECTOR OF R I G H T HAND S I D E S I S APPENDED I N
C COLUMN N + l . THE N SOLUTIONS APPEAR I N X ( l ) . . . X ( N ) AND THE
C INVERSE OF THE C O E F F l C l E N T MATRIX APPEARS I N THE F I R S T N
C COLUMNS OF A. I F I N D l C I S P O S I T I V E , THE LATTER PROCEDURE I S
C FOLLOWED, EXCEPT THAT THE INVERSE I S NOT COMPUTED I N PLACE.
C S I M U L RETURNS AS I T S VALUE THE DETERMINANT OF THE F l RST N
C COLUMNS OF A, EPS I S THE MINIMUM P I V O T MAGNITUDE PERMITTED B Y
C SIMUL. SHOULD NO ACCEPTABLE P I V O T B E FOUND, S l M U L RETURNS A
C TRUE ZERO AS 1TS VALUE, DETER, THE DETERMINANT OF THE M A T R I X
C OF C O E F F l C l E N T S I S RETURNER AS THE VALUE OF S I M U L .
C
I M P L I C I T REAL*8(A-H, 0-Z)
D I M E N S I O N X ( 5 0 1 , A(S1,51)
C
C ....,
READ AND P R I N T M A T R I X A
1 READ ( 5 , 1 0 0 1 N,INDIC,EPS
,,.,.
WRITE ( 6 , 2 0 0 ) N, INDIC,EPS
MAX = N
I F ( INDIC.GE.0 1 MAX s N 1 *
DO4 I = l , N
READ ( 5 , 1 0 1 ) ( A ( I ,J),J=I,MAX)
4 WHITE (6,201) ( A ( I ,J),J=O,MAX)
C
C ,....CALL f l M U L
DETER = S l M U L ( N,
....,X, EPS,
A, lNDlC, 51
C
C ..... P R I N T SOLUTIONS
I F ( INDIG,GE,O BO
..,.,8
TO
WRITE ( 6 , 2 0 2 ) DETER
DO7 I p 1 , N
7 WRITE (6,201) (A(18J),J=1,N)
GO TO 1
8 WRITE 6 6 , 2 8 3 ) DETER,N,(X(I 1, I = l , N )
I F ( INOIC.NE.0 1 GO TO 1
9 WRITE (6,204)
DO 1 0 1 = It N
19 WRITE ( 6 , 2 0 1 ) [A(!,JI,J=l,N)
GO TO 1
C
C
100
.. .
, , FORMPiTS FOR I N P U T AND OUTPUT STATEMENTS
FORMAT ( 10X, 12, 18X, 12, 18X, E 7 . 1 )
.....
101 FORMAT ( 20X, 5F10,5
200 FORMAT ( 10IHlN ,
I C / 10H I N D l C 1 4 / 1 0 H EPS = ,
1 E 1 0 . 1 / 23HOTHE STARTING MATRIX I S / 1 H j
201 FORMAT ( 1 H , 7 F 1 3 . 6 )
202 FORMAT ( 1OHODETER = , F 1 2 , 6 / 22HOTHE INVERSE M A T R I X I S / 1 H )
203 FORMAT ( lOHODETER = , F 1 2 . 6 / 24HOTHE SOLUTIONS X(l)...X(, 12,
1 5H) ARE / 1 H / ( 1 H 7F13.6) ]
204 FORMAT ( 22HOTHE I N V E R ~ E MATRIX I S / 1 H )
C
Systems of Equations
..... B E G I N E L I M I N A T I O N PROCEDURE
DETER = 1.
.....
DO 1 8 K = 1, N
KM1 = K - 1
.....
DO 11 J = 1, N
SCAN IROW AND J C O L ARRAYS FOR I N V A L I D P l V O T S U B S C R I P T S
I F ( K.EQ.l ) GO TO 9
.....
DO 8 I S C A N = 1, K M 1
DO 8 JSCAN = 1, K M 1
I F ( I.EQ.IROW(ISCAN) ) GO TO 11
I F ( J.EQ.JCOL(JSCAN) GO TO 11
CONT l NU E
9 I F (DABS(A(I,J)).LE.DABS(PIVOT) ) GO TO 11
PlVOT = A(I,J)
JCOL(K) = J
11 CONTINUE
C
C .....
IF
I N S U R E T H A T SELECTED
DABS(PIVOT).GT.EPS
( )
P I V O T I S LARGER THAN EPS
GO TO 1 3
.....
S l M U L = 0.
RETURN
17
18
DO17 Ja1,MAX
I F ( J.NE.JCOLK
CONTINUE
A(I,J) = A(I,J) -
AIJCK*A(IROWK,J)
C
C .....
DO 2 0
ORDER S O L U T I O N VALUES ( I F ANY) AND CREATE JDRD ARRAY
1 = 1, N
.....
!ROW1 = I R O W ( I 1
JCOLl = JCOL(I)
JORD( IROWI = JCOLl
20 I F ( INDIC.GE.0 ) X ( J C 0 L I ) = A(IROW1,MAX)
INTCH -
JORD( I ) = JTEMP
INTCH + 1
22 CONTINUE
I F ( INTClH/2*2.NE.INTCH ) DETER = - DETER
C
C ..... I F I N D l C I S P O S I T I V E RETURN W I T H RESULTS
I F ( INOIC.LE.0 ) GO TO 2 6
.....
S l M U L = DIETER
RETURN
I]
C
C
..... FI FI R SI NT DBYl C ROWS
I S N E G A T I V E OR
,.... ZERO, UNSCRAMBLE THE I N V E R S E
26 DO 2 8 J 1, N
DO27 1 = I , N
IROWl = I R O W ( I )
JCOLl * JCOL( I )
Y ( J C 0 L I ) I A(IROW1,J)
DO28 1 = I , N
.....
A(I,J)
DO 3 0
= Y(1)
THEN BY COLUMNS
1 = 1, N
.....
DO 2 9 J = 1, N
IROWJ = I R O W ( J )
JCOLJ = JCOL(J1
Y(IR0WJ) I A(I,JCOLJ)
DO 3 0 J = 1, N
A(1.J) = 'rf(J)
..... RETURN FOR I N D l C N E G A T I V E OR ZERO
S l M U L = DETER
.....
RETURN
tnhh Nmm
O d h
dtnN mmw
mmrl m o m
wmN mww
...
N O 0
000 ...
N W O
-or(
000
mmw Whf.
*r(m Orlh
r-mm r(WN
mmm mncl
mm*
...
m o d
000 ...
W U I N
N O 0
000
wmm
mww mmtn
m o m trtn
mww -nm
mmm
...
N w o
oorl
000 ...
mm*
m0.l
000
W h h
O r l h
r l W N
mmrl
00 m N
...
N O 0
000
oeo
000
000
000
000
N m n
mww
m o m
moo w
N W O
00-
Systems of Equations
000 0 0 mm*
000 m 0 am-
000 0 moDm
... .
000 u 0 - d m
000 X 0 WatN
Y
-
000 0 0
m x
. r
I--mm
0
0 rl
2 M.?",
400
0 - 1 0
-
X
* 0
I a
I-
.
0
0
m
d
u
X
cL
9 "0"
(1 00
I- OQ I- o a mwrc
1 1 1 K 080 I 1 0 W ONPI
* a m W
L, O n I
9 x-w C-
090
O Q O
000
000
400
-00
I . .
W b J
hh
mm
mm
mm
..
mm
M M
00
I
00
Q O Q rld
000 00
000 00
Q O O
...
000
000 ..
00
00
-INN
-a
0
V)
.-to
I
2 n
Z - W
Example 5.2 Inverse Matrix Using the Maximum Pivot Strategy
THE S T A R T I N G M A T R I X I S
DETER = 1.461457
.
THE SOLUTIONS X ( 1). . X ( 1 1 ) ARE
THE I N V E R S E M A T R I X I S
296 Systems of Equations
precision arithmetic. Results for the first three data sets Member Force Tension or
show the output for the three modes of operation of (Tons) Compression
SIMUL. The equations are those used as a numerical
Compression
example in the discussion of the maximum pivot strategy.
Tension
Equations for the fourth data set are those used as an Tension
illustrative example in Section 5.4. Compression
The coefficient matrix for the fifth data set is singular Compression
(two of the equations are identical); this is indicated by Tension
Compression
the zero determinant value. In this case, the entries in the
Compression
x vector are meaningless (left over from the previous Tension
problem), and the numbers printed under the inverse Tension
matrix label are the contents of A when the singularity Compression
was discovered.
The equations of the sixth data set are the same as Note that for the symmetrically distributed load, member
those for the fourth data set in Example 5.1. Note that forces are also symmetric. Once the inverse matrix has
the appearance of a zero on the diagonal in the a,, been computed, the member forces for the given structure
position causes no difficulty when the maximum pivot may be calculated for any combination of vertical and
strategy is employed (compare with the results in horizontal forces applied at the joints (any other applied
Example 5.1). forces can be decomposed into their horizontal and
Results for the seventh and eighth data sets show that vertical components) by evaluating the matrix product of
the order of equations is immaterial when the maximum the inverse matrix and the new right-hand side vector.
pivot strategy is employed.
Results for the ninth data set include the member
forces in the plane frame of Fig. 5.2.1. The forces are
listed in Table 5.2.1.
5.5 A Finite Form of rhe Method of iYacimarz 297
5.5 A Finite Form of the Method of Kaczmarz With these definitions, a solution of (5.9) is a solution of
We consider the solution of (5.2) under the assumption (5.2). For, if (aj,x) - v j = 0, 1 6 j 6 n, then by (5.12),
that B is nonsingular. The procedure consists in first
converting the system of (5.2) into an equivalent system,
AX=V, A*=A-l, (5.9)
such that (5.9) and (5.2) have the same solution vector x.
Then, using an arbitrary initial vector, r,, we define
Then, by (5. I3),
r =r - [(a, r ) -a , 1 <j 6 n, (5.10)
row of [Air] is
-1 2
[T,
3, . Prior to normalizing, the X, = (u, - bnlxl - bn2x2- . . - bn,n- lxn- l)/bnn*
third row is The system (5.15) can be written more concisely as
Then
which have the solution vector x = [I, 2, 3If, that is, x, = 1,
x2 = 2, and x 3 = 3.
Rewrite the equations as
=[--143
105'105'~]
229 25 '
'
There results
= [I, 2, 31'.
and arbitrarily choose a starting vector x, = [I, 1 , I]' in which
5.6 Jacobi Iterative Method the subscript denotes the zeroth stage of iteration. Using a
Consider again the solution of the linear system Bx = u: second subscript to denote the iteration number, the first
iteration gives
+
bllxl blzx2 + + blnxn= u l ,
+
b Z l x l bt2x2 + + b2,xn = u 2 ,
(5.2)
xk, == Axk + v, (5.19) The linear system considered is again that of (5.2)
rephrased in the form (5.15) or (5.17). In the iterations,
in which the subscript k is the iteration number. This however, the newly-computed components of the x vector
means that are always used in the right-hand sides as soon as they are
obtained. This contrasts with the Jacobi method, in which
x k = A k x , + [ I + AL+A2+ - . ' +Ak-']v. the new components are not used until all n components
have been found.
From this, we see that convergence normally requires that
Exanlple. The Gauss-Seidel method is applied to the short
lim Ak = 0. (5.20)
k+m example considered under the Jacobi method. The form used is
From (4.23), it is also a necessary and sufficient condition
that
with the understanding that the most recently available x's positions. A similar description applies to A,. It is seen
are always used in the right-hand sides. Again xo is chosen as . ., x,,]',
that, if x, = [xlk,x2,,.
[I, 1, I]'. The first iteration gives
xk= ALxk+ ARxk-1+ V.
11 11
XI, =--- X I - - x 1 = 2 , This can be paraphrased as
4 2 4
+
Write A = AL AR where IbiiI >~C=IbijI,
l
j+i
0 0 ... B is nonsingular. Thus a solution vector x exists such that
...
a,,. 0 x = Ax + v, whence
AL=[:
41 n.2 . ' xi - z aijxj+ vi,
n
j= 1
0 a12 ... j#i
j= 1
laijl lxjk - xjl
n
+ j = i + l laij! lxj,k-1 - xjl.
diagonal entries are the elements of A in their natural (5.29)
5.7 Gauss-Seidel Iterative Method 301
Let e, denote the maximlum of the numbers Ixik- xi(as i Taking the conjugate of both sides, (L*wi,wi)= (wi,Lwi)
varies. Then +
= Xi[(Dwi,wi) (Lwi,wi)], or
Ix~k-xlI G
n
Iu1ljIek-1G P k - 1 <'k-~. +
(wi,Lwi) = Xi[(wi,~wi) (wi,L*wi)]. (5.32)
~ = 2
Combining (5.31) and (5.32) gives
Substituting this in (5.29;) yields
2
1
a;,
a;,
3
...
.-. i
a;,
:
a;,
a;,,+,
a;,n+l
:
a:,,+1
1, (5.3.2)
computed by iterating with (5.3.4) will converge to the
solution of (5.3.1).
The convergence criterion is
Flow Diagram
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
A n r: (n + 1) augmented coefficient matrix, containing elements nip
ASTAR, XSTAR Temporary storage locations for elements of A and X, respectively.
E PS Tolerance used in convergence test, E.
FLAG A flag used in convergence testing; it has the value 1 for successful convergence, and the
value 0 otherwise.
Iteration counter, k.
The maximum number of iterations allowed, k ,.
Number of simultaneous equations, n.
Vector containing the elements of the current approximation to the solution vector, x,.
304 Systems of &utiti~m
Program Listing
APPLIED NUMERICAL METHODS, EXAMPLE 5.3
GAUSS-SEIDEL I T E R A T I O N FOR N SIMULTANEOUS L I N E A R EQUATIONS.
INTEGER FLAG
DIMENSION A(20,20), X(Z0)
C ..... B E G I N GAUSS-SEIDEL
DO 9 I T E R = 1, ITMAX
ITERATIONS .....
FLAG = 1
DO7 1 = l , N
XSTAR = X ( I
X f I ) .= A( 1,NPl)
C
C ..... F I N D NEW SOLUTION VALUE,
DO5 J-1, N
X(I) .....
I F ( I .EQ. J ) GO TO 5
201
3 MATRIX A ( 1 , l ) ... A(N+l,N+l)
FORMAT (1H0, l l F 1 0 . 5 )
IS)
202 FORMAT (36HO THE STARTING VECTOR X ( l ) . . . X ( N ) I S / (1HO. 1 0 F 1 0 . 5 ) )
203 FORMAT (35HO PROCEDURE CONVERGED, W l T H I T E R = , I I /
1 3 2 H 0 SOLUTION VECTOR X ( l ) . . . X ( N ) I S / (1HO. 1 0 F 1 0 . 5 ) )
204 FORMAT (16HO NO CONVERGENCE/ lOHO I T E R = , 1 4 /
1 3 1 H 0 CURRENT VECTOR X(l)...X(N) I S / (1H0, J O F 1 0 . 5 ) )
C
END
Exsmple 3.3 Gavss=Sei&l Method
Program Listing (Coqtiq~ed)
Data
Computer Optput
Res~ltsfor the 1st Dale lSef
SOLUTION OF SIMUQTANEQUS LINEAR EqlJATIQNS BY GAUSS-SElDEL METHOD, WITH
N 4 4
ITMA? c 15
EPS s OtOOQZO
THE COEFFICIENT MATRIX A ( I , I ) , . . A ( N + L , N * l ) IS
PROCEDURE CONVEIRGEO, W l VH !T ER 12
SOLUTION VECTOR X ( l ) , , , X ( N l IS
x, - x;! 3. X J I - 4 x 4 = -2,
Finally, note that convergence is guaranteed in all
three cases, since each coefficient matrix satisfies condi-
which have the solution x = [I, 2, 3, - 11'. Even though tions (5.28).
308 Systems of &uations
5.8 Iterative Methods for Nonlinear Equations showing that the points xk lie in R. Also, by induction,
Sections 5.8 and 5.9 are concerned with finding the from (5.37) and (5.39),
solution, or solutions, of the system ,
Ixik- uil < p max (Ix,,~- - ail)
i
< pkh.
Therefore, (5.38) is true, and the procedure converges to a
solution of (5.33). Note that if the Fi(x) are linear, we
have the Jacobi method, and the sufficient conditions of
(5.37) are the same as the second set of sufficient con-
ditions in (5.21):
involving n real functions of the n real variables For the nonlinear equations, there is also a counter-
x,, x,, . . ., xn. Following the previous notation, x = part to the Gauss-Seidel method, previously used in
[x,,x2, . . ., x,]', we shall write fi(x) =fi(xl,x2, . . ., x,). Sec. 5.7 for the linear case. We proceed as before, except
Here, and in the subsequent development, 1 < i < n. that (5.36) is replaced by
Then let a = [a,,~,,...,or,]' be a solution of (5.33),
that is, let fi(a) = 0.
Let the n functions Fi(x) be such that
That is, the most recently computed elements of the solu-
tion vector are always used in evaluating the Fi. The
implies &(x) = 0, 1 <j < n. Basically, the n equations proof of convergence according to (5.38) is much the
(5.34) will constitute a suitable rearrangement of the same as for the Jacobi-type iteration. We have
original system (5.33). In particular, let
ui = Fi(a). (5.35)
Let the starting vector xo = [ X , ~ , X. .~.,~xnolt
, be an where
approximation to a. Define successive new estimates of
the solution vector, xk = [xlk,x2,.. ., xnklr,k = 1, 2 , . . ., Elk = [a1 + <lk(~i,k- 1 - al)r . . + t ~ ( ~ n ,1k-- an)]'.
by computing the individual elements from the recursion
relations It will appear inductively that the above is true, because
the various points concerned remain in R. If ek-, is the
Xik = Fi(xl.k-1,xz,k-l, - .., Xn,k-l) = Fi(~k-1). (5.36)
largest of the numbers I x ~ , ~ --~ ail, then Ix,, -all <
Suppose there is a region R describable as Ixj - orjI < h, pe,-, < ek-I < h. It follows that
1 <j < n, and for x in R there is a positive number p,
less than one, such that
and choose the starting values xlo = 0.4, xl0 = 3.0. Within
slide-rule accuracy, the Jacobi-type iteration gives
Method of Solution When applied at all the free nodes, equation (5.4.5)
yields a system of nonlinear simultaneous equations in
For flow of a liquid from point i to pointj in a horizon- the unknown pressures. We shall solve this system by
tal pipe, the pressure drop is given by the Fanning the successive-substitution type of method described in
equation : Section 5.8. First, note that (pi - pi) is more sensitive
than (/pi- pjl)'12 to variations inpj. Thus an appropriate
Pi - Pj = j1f ~ ~ Du-r n
Z L
(5.4.1) version, analogous to equation (5.34), is
Flow Diagram
Dji + Dij
i = l,2, j = I , 2,
. .., n den t 0
T I I
I I
I
I I
> l l
I I I
I I
1 I
I I
num t nun1 + aijpi nu117
PjC-
den
I I
I I
I I
-----------I II
I
I
i := 1, 2,
'. \
iter, pi,
Qij(j=2,..,~),
i = 1,2, ...,n
-
312 Systems of Equations
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
Matrix, whose elements a i j are defined by (5.4.7).
Matrix, whose elements cij relate the flow rate to the pressure drop in the pipe joining nodes i
and j.
CONV Logical variable used in testing for convergence, conv.
D. L Matrices, whose elements D i j and Lij give the diameter (in.) and length (ft) of the pipe joining
nodes i and j.
DENOM, NUMER Storage for the denominator and numerator of (5.4.6), den and num, respectively.
EPS Tolerance, E , used in testing for convergence.
F Moody friction factor, f, (assumed constant).
FACT0 R The constant, C, in equation (5.4.3).
1, J Indices for representing the nodes i and j.
INClD Matrix of logical values, I; if Iijis T, there is a pipe joining nodes i and j; if F, there is not.
ITER Counter on the number of iterations, iter.
IPRlNT Logical variable, which must have the value T if intermediate approximations to the pressures
are to be printed.
Upper limit on the number of iterations, itmax.
Total number of nodes, n.
Vector of pressures, pi (psi), at each node.
Vector of logical values, pi, at each node. If pi is T, the pressure is specified at node i; if F, it
is not.
0 Matrix, whose elements Q i j give the flow rate (gpm) from node i to node j.
RHO Density of the liquid in the pipes, p (lb,/cu ft).
SAVEP Temporary storage for old pressure pj during convergence testing, P.
Example 5.4 Flow ih a Pye Network (Succes~ive=S~bstitutia;n
Method)
Program Listing
A P P L I E D NUMERICAL METHODS, EXAMPLE 5.4
FLOW I N A P I P E NETWORK -
SUCCESSIVE S U B S T I T U T I O N METHOD
.....
READ
READ DATA
(5,1010)
.....
N, ITMAX, RHO, EPS, F, IPRINT, (PGIVEN(I), I=l,N)
READ (5.101) (P(l). l=l.N)
DO2 l=l,N
READ (5,102) (INCID(I,J), J=l,l)
READ (5,101) ~D(I,J)~-J=~,I) -
READ (5,101) (L(I,J), J=l,l)
..... .....
SET UP UPPER TRIANGULAR PARTS OF SYMMETRIC MATRICES D,
AND I N C l D AND COMPUTE ELEMENTS OF C MATRIX
L,
FACTOR 0 8.*12.+*5+RHO*F/(3.1415926**2*32.2*(60.*7.48)**2*144.)
DO 3 l=l,,N
DO 3 J*1,1
C(I,J) = 0,
I F ( 1.EQ.J ) GO TO 3
I F ( INCID(I,JP C(I,J) = FACTOR+L(I,J)/D(I,J)tt5
D(J.1) a D(1.J)
L(J;I) = L(I;J)
INCID(J,I) = INCID(I,J)
C(J,I) = C(I,J)
3 CONTl NUE
C
C .....
WRITE
P R I N T OUT I N I T I A L INFORMATION ABOUT NETWORK
(6,200) N,ITMAX,RHO,EPS,F,IPRINT,(I,P(I),PGIVEN(I),I=l8N)
.....
WRITE (6,201)
DO 4 I =1,N
h WRITE (6,202) 1, I, N, ( I N C I D ( I , J ) , J=l,N)
WRITE (6,201)
DO5 l = l # ~
5 WRITE (6,203) I, I, N, ( D ( I , J ) , J=l,N)
WRITE (6,201)
DO6 I=l,N
6 WRITE (6,204) 1, I, N, ( L ( I , J ) , J=l,N)
314 Systems of Equations
L
C ..... P R l NT F I N A L PRESSURES AND FLOWS
WRITE ( 6 , 2 0 8 ) ITER, N
.....
DO 1 2 I=1,N
12 WRITE ( 6 , 2 0 9 ) I, P ( l ) , ( Q ( I , J ) , J=l,N)
GO TO 1
C
..... FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT( 3X,12,17X,13,1SX,FS.l,l5X,E5.0/
.....
bX,F6.3,14X,Ll /
1 (30X, 2 0 ( L l , l X ) )
FORMAT( 30X, 5F8.3
FORMAT( )OX, 2O( L 1 , l X )
FORMAT( 23HlFLOW I N A P I P E NETWORK/ lOHON
1s , 1 3 / 1 0 H RHO = , F7.3/ 1 0 H EPS I,
.
= 1 3 / 1 0 H ITMAX
~ 1 0 . 2 1 10H F I0
END
Example 5.4 Flow in a Pipe Nerwork (Successive-SubstitutionMethod)
Computer Output
FLOW I N A P I P E NETWORK
N = 5
ITMAX = 100
RHO = 50.000
EPS * 0.10E*-03
F a 0.056
IPRINT * T
316 Systems of Equations
Discussion of Results any two nodes that are directly co.~nected would be
The data used above relate to the network shown in unfortunate.
Fig. 5.4.1, with f, = 0.056, p = 50 Ib,/cu ft, and two Note that the bulk of the pressure drop occurs in the
pressures fixed: p, = 50, p, = 0 psi. pipe 2-3, and that the flow in the branch 1-4-5-2 is
appreciably greater than that in the pipe 1-2, even though
1 2 3 the latter is much shorter. Both these observations can
be reconciled by noting that pressure drop is proportional
tI2=L23= 150 ft
Lr4=L45=L25= 100 ft
to Q2/D5, and that pipe 2-3 must take the combined
D12=D23=3
in. flows along 1-4-5-2 and 1-2.
DI4=L)45=D25=4In. The method can be extended to more complex situ-
ations, in which we could allow for (a)f, being a function
of Reynolds number and pipe roughness, instead of being
Figure 5.4.1 Pipe network for example cafculdtion. treated as a constant, and (b) pumps and valves in some
of the branches, etc. Also, the logical arrays used above
Although the method is computationally straight- could find a similar application in solving for the currents
forward, it needs many iterations to give a reasonable in a network of resistors, with known voltages applied
degree of convergence. Also, referring to equation at some of the nodes (although this would lead to a set
(5.4.7), we can see that a starting guess of pi = p, for of simultaneous linear equations).
5.9 Newton-Raphson Iteration for Nonlinear Equations 319
5.9 Newton-Raphson Iteration for Nonlinear Equations Since the entries in the matrix +(xk) - $ are differences
The equations to be solved are again those of (5.33), +
of the type fij(xk) -Aj(@ tik(xk-a)), they can be kept
and we retain the nomenclature of the previous section. uniformly small if the starting vector x, lies in an initially
The Newton-Raphson process, to be described, is once chosen region R describable as Ixi - ail < h, 1 < i < n.
more iterative in character. We first define Concurrent with this is the fact that since det(+(x)) # 0,
det(+(xk)) can be bounded from zero. The net result is
that, for 0 < p < 1, Jxik- ail < hpk, 1 < i < n. Thus the
sequence (x,) converges to a .
Next define the matrix +(x) as
Example. To illustrate the procedure, the equations of the
+(XI = (fij(x)), 1 < i < n, 1 < j < n. (5.41) previous section are used, namely
Thus det(+(x)) is the Jacobian of the system (5.33)
evaluated for the vector x = [x,,x,, . . ., x,,]'. Now define
the vector f(x) as
f(x) = [h(XI,f2(x), . . ., f,(x)lr- (5.42)
With these definitions i11 mind, and with the starting
vector x, = [x,,,x2,, . . ., x,,]', let It is readily seen that
=Xk+Sk,
Xk+i (5.43) afl - --+
-- af1 - - -1
1 xz ~ o ~ ( x , ~ 2 ) -- XI cos(x,xz)
ax, 2 2 ' ax2 4.rr + 2 3
where 6, is the solution vector for the set of simultaneous
linear equations
+(xk) fik = -f(xk). (5.44)
The fundamental theorem concerning convergence is The increments Ax, and Ax2 in X I and x2 are determined by
much less restrictive than those of the previous sections.
We have the result that if the components of +(x) are
continuous in a neighborhood of a point a such that
f(a) = 0, if det(+(a)) # 0, and if x, is "near" a , then
lim,,, xk = a .
An outline for a meth~odof proof follows. By (5.42)
Or, writing the determinant D of the coefficient matrix (the
and (5.44), since fi(a) = 0,
Jacobian),
+-
6, = '(xk)[f(a) - f(xk)]. (5.45) D = - afl
- - - af2
- afl afz
where 0 < ti, < 1. For the ith row of a matrix \Ir use
[fil(a + (ik(~k- a))? . . - ~ f ; . + ~ -
n (<ik(~k For ease in verification, detailed results are tabulated in
Then Table 5.1. Once again, calculations have been carried out by
+
x ~ -+a =~ xk - a tik := +-'(xk)[+(xk) - +](xk - a). slide rule. The entries -0.0000 designate tiny negative values.
Note that despite using the: same initial value, this solution differs from that obtained in Section 5.8. However, the starting
values xl0 = 0.6, xzo= 3.0 do lead to the alternative solution x, = 0.5, x2 = rr. Values are given in Table 5.2.
320 Systems of Equations
I::[
Table 5.2 Newton-Raphson Solution fir x, =
EXAMPLE 5.5
CHEMICAL EQUILIBRIUM
NEWTON-RAPHSON METHOD
or removed from the reacting gases, the enthalpy (H) of derivatives of (5.40) may be found by partial differen-
the reactants must equal the enthalpy of the products. tiation of the seven functions,f,(x), with respect to each
of the seven variables. For example,
afl - -1
-- -- -af,
= - x,
ax, 2' ax, ax, x:'
Flow Diagram
Main Progranz
Evaluate elements
a,] of augmented '
Solve system of ~i
d,k,62~9.. 6"k
-9
I calculate I
elements all
i = 1,2, .,,,i?
j - l 3 2 , , , . , t t - I -1
of matrix A
I (see (5.5.24)). (
324 Systems of muations
FORTRAN Implementation
List of Principal Variables
Program Symbol Dejinition
(Main)
A Augmented matrix of coefficients, A (see (5.5.24)).
DETER d, determinant of the matrix 4 (the Jacobian).
EPS1 E ~ minimum
, pivot magnitude permitted in subroutine SI M U L.
EPS2 ez , small positive number, used in convergence test (5.5.23).
I Subscript, i.
IPRINT Print control variable, iprint. If iprint = 1, intermediate solutions are printed after each itera-
tion.
Used in convergence test (5.5.23). ITCON = 1 if (5.5.23) is passed for all i, i = 1 , 2 , . . ., n;
otherwise ITCON = 0.
ITER Iteration counter, k.
ITMAX Maximum number of iterations permitted, itmax.
N Number of nonlinear equations, n.
XlNC Vector of increments, 6,.
XOLD Vector of approximations to the solution, x,.
SIMUL Function developed in Example 5.2. Solves the system of n linear equations (5.44) for the
increments, Sik, i = I , 2, .. . , n.
(Subroutine
CALCN)
DXOLD Same as XOLD. Used to avoid an excessive number of references to subroutine arguments in
CALCN.
1, J i and j, row and column subscripts, respectively.
NRC N, dimension of the matrix A in the calling program. A is assumed to have the same number of
rows and columns.
Pressure, P, atm.
Example 5.5 Chemical Equilibrium (Newton-Raphson Method)
Program Listing
Main Program
C A P P L I E D - N U M E R I C A L METHODS, EXAMPLE 5.5
C
C
CHEMICAL E Q U I L I B R I U M -NEWTON-RAPHSON METHOD
C T H I S PROGRAM SOLVES N SIMULTANEOUS NON-LI NEAR EQUATIONS
C I N N UNKNOWNS BY THE NEWTON-RAPHSON I T E R A T I V E PROCEDURE.
C I N I T I A L GUESSES FOR VALUES OF THE UNKNOWNS ARE READ I N T O
C XOLO( 11.. .XOLO(N). THE PROGRAM F I R S T CALLS ON THE SUBROUTINE
C CALCN TO COMPUTE THE ELEMENTS OF A, THE AUGMENTED M A T R I X OF
C P A R T I A L D E R I V A T I V E S , THEN ON FUNCTION S I M U L (SEE PROBLEM 5 . 2 )
C TO SOLVE THE GENERATED SET OF L I N E A R EQUATIONS FOR THE CHANGES
C I N THE SOLUTION VALUES X I N C ( l ) . . . X I N C ( N ) . DETER I S THE
C JACOBIAN COMPUTED BY SIMUL. THE SOLUTIONS ARE UPDATED AND THE
C PROCESS CONTINUED U N T I L ITER, THE NUMBER OF ITERATIONS,
C EXCEEDS ITMAX OR U N T I L THE CHANGE I N EACH OF THE N VARIABLES
C I S SMALLER I N MAGNITUDE THAN EPS2 ( I T C O N = 1 UNDER THESE
C CONDITIONS). E P S l I S THE MINIMUM Pl.VOT MAGNITUDE PERMITTED
C I N SIMUL. WHEN I P R I N T = 1, INTERMEDIATE SOLUTION VALUES ARE
C PRl NTED AFTER EACH ITERATION.
C
DIMENSION XOLD(21), XINC(211, A(21,21)
C
C
1
..... READ AND PR l NT DATA
READ ( 5 , 1 0 0 )
.....
ITMAX,lPRINT,N,EPSl,EPS2,(XOLD( I), I=l,N)
WRITE ( 6 , 2 0 0 ) ITMAX, I P R I N T , N , E P S l , E P S 2 , N , ( X O L D ( I 1, I = l , N )
I T E R A T I O N .....
C
C ..... NEWTON-RAPHSON
DO 9 I T E R = 1, ITMAX
A(5,5)
A(5,8)
A(6,l)
A(6,3)
A(6,b)
A(6,S)
A(6,8)
A(7,l)
A(7,2)
A(7,3)
A(7,4)
A ( 7,8)
RETURN
C
END
Example 5.5 Chemical Equilibrium (Newton-RaphsonMethod)
Computer Output
Results for the 1st Data Set
ITMAX = 50
IPRINT = 1
N I 7
EPSl = 1.OE-10
EPS2 = 1.OE-05
ITER = 1
DETER = -0.97077E 0 7
XOLD(l)...XOLD( 7)
2.210175E-Oil 2.592762E-02
2.591652E-01 3.343250E-01
ITER = 2
DETER =
XOLD( I).
3.101482E-01
.
-0.10221E 1 0
.XOLD( 7 )
7.142063E-03
4.812878E-02 4.681466E-01
lTER = 3
DETER = -0.41151E 0 9
XOLD(I)...XOLD( 7)
3.202849E-01 9.554777E-03
1.048106E-02 5.533223E-01
ITER = 4
DETER = -0.22807E 09
ITER = 5
DETER a -0.20218E 0 9
XOLD(l)...XOLD( 7)
3.228708E-01 9.223551E-03
3.716873E-03 5.767141E-01
ITER = 6
DETER = -0.20134E 0 9
XOLD(l)...XOLD( 7)
3.228708E-01 9.223547E-03
3.716847E-03 5.767153E-01
Systems of Equations
ITER = 6
XOLD(l)...XOLD( 7)
ITER = 1
DETER = -0.61808E 0 8
XOLD[l).. .XOLD( 7 )
6.951495E-01 -8.022028E-02 1.272939E-02 1.217132E 00
-8.447912E-01 1.314754E 00 5.969404E 0 0
lTER = 2
DETER = 0.12576E 09
ITER = 3
DETER = 0.77199E 0 7
XOLD(l)...XOLO( 7)
4.559822E-01 -9.799302E-04 -7.583648E-04 9.107630E-01
-3.650070E-01 2.509821E 0 0 1.107038E 0 1
ITER = 4
DETER = 0.53378E 0 7
XOLD(l)...XOLD( 7)
4.569673E-01 -4.071472E-04 -2.142648E-03 9.152630E-01
-3.696806E-01 2.608933E 0 0 1.149338E 0 1
ITER = 5
DETER = 0.49739E 0 7
XOLD(l)...XOLD( 7)
4.569306E-01 -4.071994E-04 -2.125205E-03 9.151721E-01
-3.695704E-01 2.610552E 0 0 1.150046E 0 1
ITER = 6
DETER = 0.49611E 0 7
XOLD(l)...XOLD( 7)
4.569306E-01 -4.071984E-04 -2.125199E-03 9.151720E-01
-3.695703E-01 2.610549E 0 0 1.150045E 0 1
SUCCESSFUL CONVERGENCE
ITER = 6
Example 5.5 Chemical Equilibrium (Newton-Raphson Method) 329
Discussion of Results in the feed gases, and the total number of moles of pro-
Results are shown for the first and third data sets only. duct per mole of CH, in the feed are tabulated in Table
For the first two data sets, the Newton-Raphson iteration 5.5.2. Thus the required feed ratio is 0.5767 moles of
converged to the same solution, one that satisfies the oxygen per mole of methane in the feed gases.
side conditions (5.5.16). Results for the third data set To establish if carbon is likely to be formed according
cannot be physically meaningful, because the solution to reaction (5.5.7) at 2200°F for a gas of the computed
has negative mole fractions for CO,, H,O, and CH,. composition, it is necessary to calculate the magnitude of
The equilibrium compositions, reactant ratio 02/CH4
Forsythe and Moler [14] point out that the residuals r, must
generally be ~omputedwith a higher precision than that used
when the elements of B are known exactly, but the elements of for the rest of the calculations. The iterative improvement
u are not known with certainty. In particular, suppose that algorithm may be terminated when li6k!I is sufficiently small
+
a vector u 6u is used as the right-hand side vector (pre- (typically when the single-precision results for xk stabilize).
sumably the elements of 6u would be small, so that u 6u is+ Consider the equations
+
fairly close to u itself). If x 6x is the solution of the system
Here, cond(B), the condition number [14], is given by carry out one iteration of the correction scheme to find
x,,,, retaining six significant digits in the computation of
rk, and three significant digits elsewhere.
If cond(B) is small (of order unity), then B is said to be well 5.7 How would you modify the programs of Examples
conditioned,while if cond(B) is large, then B is said to be poorly 5.1 and 5.2 to accommodate the iterative improvement of the
conditioned or ill conditioned. solution vector outlined in Problems 5.5 and 5.6?
Pri
5.8 Assume that an approximate inverse, Qk, of matrix B Table P5.10
is available. Using techniques analogous to those outlined in
Problems 5.5 and 5.6, show that if a residual matrix Rk is
defined to be
Rk = I - BQk,
then the next iterate should be
can be used to calculate it. Use the 2nd, 4th, and 7th entries in Table P5.10 to determine
How would the function SlMUL of Example 5.2 have to be the constants A, B, and C in Cauchy's equation for refractive
modified to employ this iterative improvement algorithm for index :
evaluation of B - I ? Make the changes, and test the program
thoroughly. Among the test matrices, include the Hilbert
matrix.
In-festigate the merits of Cauchy's equation for predicting
the remaining entries in the table.
for n = 4, 5, and 6. The I-Iillbert matrix is very ill conditioned, 5.11 When a pure sample gas is bombarded by low energy
even for small n [IS], and is often used as a test matrix for electrons in a mass spectrometer, the galvanometer shows
demonstrating effectiveness of inversion routines. peak heights that correspond to individual mje (mass-to-
5.9 Write a function, named DPOLY, that returns, as its charge) ratios for the resulting mixture of ions. For the ith
value (see Problem 2.51), peak produced by a pure sample j, one can then assign a
sensitivity siJ(peak height per micron of Hg sample pressure).
.These coefficients are unique for each type of gas.
A distribution of peak heights may also be obtained for an
n-component gas mixture that is to be analyzed for the partial
The routine should have the argument list pressures p,, p 2 , . . .,pn of each of its constituents. The height
hi of a certain peak is a linear combination of the products of
(N, X, Y, M, I, A, Q, NQROW, NQCOL, TRUBL),
the individual sensitivities and partial pressures:
where N and M are equivalent to n and m, respectively, X
is an array containing xo, , . ., X , in X(l), . . ., X ( N + I), Y is 2 SijPj = hi.
an array containing the furictional values f (xo), . . .,f (x.) in j= 1
.
Y ( l ), . . , Y(N + 1,) and I is the subscript of the desired
+
argument, X(I) (note that I = i 1). Q isa matrix dimensioned In general, more than n peaks may be available. However, if
to have NQROW rows and NQCOL columns in the calling the n most distinct ones are chosen, we have i = 1,2, . . ., n, so
program (to insure a compatible storage arrangement). that the individual partial pressures are given by the solution
DPOLY should set up the augmented matrix of coefficients of n simultaneous linear equations.
of the simultaneous linear equations whose solutions are the Write a program that will accept values for the number of
a,, j = 0, . . ., n, in the first N + 1 rows and N + 2 columns of components N, the sensitivities S(1,l) ... S(N,N), and the
the matrix O (see Problem 2.51) and call on an appropriate peak heights H(l) . . . H(N). The program should then com-
linear equation solver (such as the function Sl M U L of Example pute and print values for the individual partial pressures
5.2) to evaluate the a,. DPOLY should store ao, ..., a. in P(1). . . P(N). An elimination procedure should be used in the
A(1). .. .,A(N + I ) , evaluate the appropriate derivative at the computations.
specified argument, and return to the calling program.
TRUBL (logical) should be set to .FALSE. if no computational Suggested Test Data
problems are encountered and to .TRUE. otherwise.
Write a short main program that reads and prints essential The sensitivities given in Table P5.11 were reported by
data, calls upon DPOLY to evaluate the required derivative and Carnahan [9], in connection with the analysis of a hydro-
coefficients A(l ), ..., A(N + 1 ), prints the results, and returns carbon gas mixture.
to read more data. As trial problems, generate the formulas
developed in Problems 2.49 and 2.50.
5.10 Jenkins and White [8] give precisely determined
-
A particular gas mixture (sample #39G) produced the
-
following peak heights: h , 17.1, h2 65.1, h3 = 186.0,
h4 = 82.7, hs = 84.2, h6 = 63.7, and h, = 119.7. The measured
values, shown in Table P5.10, for the refractive index, n, at total pressure of the mixture was 39.9 microns of Hg, which
various wavelengths, X (angstrom units), for borosilicate can be compared with the sum of the computed partial
crown glass. pressures.
332 Systems of Equations
Table P5.11
Component Index, j
Peak
Index mle 1 2 3 4 5 6 7
i Hydrogen Methane Ethylene Ethane Propylene Propane n-Pentane
SY
Figure P5.17~
(a) Under the same hypotheses, A may be factored uniquely Suggested Test Data
as Use the network of Example 5.1 and also that shown in
A = LU, Fig. P5.24, in which the resistances are in ohms.
where Uz is an upper triangular matrix and L is a lower tri-
angular matrix whose diagonal elements are all unity.
(b) The matrix Uz of part (a) may be factored uniquely as
Uz = DU
where U is an upper triangular matrix whose diagonal ele-
ments are all unity, and D is a diagonal matrix whose ele-
ments are the corresponding elements of U2.
5.22 Since the leading submatrices of a symmetric,
positive definite matrix A have nonzero determinants (see
Section 4.5), A satisfies the hypotheses of Problem 5.21. Show
that: Figure P5.24
(a) A can be written in the form 5.25 Consider the radiant heat transfer to and from the
two surfaces iand j shown in Fig. P5.25. Define T = absolute
A = LDU = (LD1'Z)(D1'2U)= S'S
H w e P5.25
temperature, E = ernissivity, a = absorptivity, p = l - a =
reflectance, a = Stefan-Boltzmann constant, A = area, E =
&AaT4,G =total rate of radiation arriving at a surface
(BTU/hr, for example), and J = total rate of radiation leaving
a surface (emitted plus reflected), with subscripts indicating
the appropriate surface. Also let the geometric view factor Fil
This algorithm is known as Chofesky's merhod or the square- be the fraction of the radiation leaving surface i that is directly
root method for factoring a positive definite matrix [14]. intercepted by surface j.
Problems 335
Now consider an enclosulre consisting of n surfaces (one o r Based on the discussion in Problems 5.25 and 5.26, write a
more of which will comprise the enclosing surface). At steady program that will compute (a) all the view factors needed (the
state, show that functions developed in Problem 3.17 should help), (b) Ei, C i ,
and J , for each surface,@) Q,,the rate of heat supply or removal
for each heating element and pipe, and (d) T,, the refractory
temperature (assumed uniform over all four walls). Assume
that the problem is essentially two-dimensional; that is,
If E , a, T, and hence E are known for every surface, show neglect longitudinal temperature variations along the furnace.
that the J, are given by the solution of the n simultaneous Base all calculations for areas and heat fluxes on unit length of
linear equations: the furnace. Investigate both the arrangement shown in Fig.
P5.27 and also that in which heater 2 and pipe 4 are inter-
changed.
Suggested Test Data
where d = 1 in., T3 = T4 = 950°F, E , = E~ = 0.75, E , = t4= 0.79,
6 s = 0.63, with gray surfaces ( a = E ) throughout; investigate
(a) TI = T2 = 160O0F,h = 4, w = 6 in., (b) T, = Tz = 1600QF,
h = 6, w = 9 in., and (c) T , = 1700, Tz = 1500"F, h = 6, w = 9
in. Note that in all radiation calculations, the temperature
Give an expression for Q i , the rate at which heat must be
supplied (or removed, if negative) internally to each surface in
must be converted to 'R(=OF + 460"). The Stefan-Boltzmann
constant is u = 0.171 x BTU/hr sq ft OR4.
order to maintain its temperature constant. 5.28 In Problem 5.27, the entire refractory wall was
5.26 Extend Problem 5.25 t o the case in which m of the assumed to be at a uniform temperature. Check the validity of
n surfaces are reflactory or insulating. A refractory surface i this assumption by subdividing the refractory into four
radiates and reflects at the same rate that energy falls on it; separate refractory surfaces, each with its own individual
that is, Ji = Gi. temperature, T, through T,, for example. (The subdivisions
If the surfaces i are numbered so that the rn refractories are need not coincide with the four individual walls.) Repeat the
i=n-m+l,n-m+2, ..., n,showthattheJiareagainthe calculations with the ~ r e v i o u stest data.
solution of the simultaneous equations given in Problem 5.25, Investigate the possibility of writing a general program that
except that the coefficients olf the last m equations are now will handle n subdivisions of the refractory, where n can be
ail = Fji for i f j, read as data. If this appears feasible, implement it on the
a ,I, . = F I., . - 1 t i=n-m+l,n-m+2 ,..., n. computer in preference to writing a program that can only
handle exactly four subdivisions.
b, = 0,
5.29 Solve Problem 5.27 (or 5.28) with either of the fol-
How can the individual refractory temperatures be deter- lowing modifications:
mined? (a) A third pipe (also at 950°F, for example), running along
5.27 Figure P5.27 shows the cross section of a long experi- the middle of the furnace.
mental hydrocarbon-cracking furnace; heat is radiated steadily (b) With both T3 and T4 fixed (at 950°F, for example),
from the cylindrical electrica.1 heating elements 1 and 2 to the determine the necessary heater temperature that would
deliver a specified heat flux (1000 BTU/hr per foot length, for
example) to each of the pipes.
5.30 Figure P5.30 shows two parallel horizontal pipes,
each of outside diameter d, and separated by a distanced, that
are located centrally in a horizontal thin metal shield whose
cross section is a rectangle of height H a n d width w. The pipes
carry a hot fluid, and their surfaces are maintained at tempera-
tures TI and Tz. The pipes lose heat by radiation to the metal
shield, with subsequent radiation and convection to the
A Metal shield B
Figure P5.27
pipes 3 and 4, through which a fluid iscirculating. The elements
and pipes have a common diameter d, and are located cen-
trally in their respective quadrants. Assume that T I , T,, T,,
T4, h, w, and d have been specified, and that E and a are
known for all surfaces. All view factors can be obtained by
using (a) the string method (see Problem 3.17). (b) the recipro-
z;=
city relation A I F i ,= AjFji, and (c) the fact that
for all surfaces i.
,Fij- 1
Figure P5.30
336 Systems of Equations
atmosphere outside, which behaves as a black-body enclosure If v,, R, and R, are specified, devise a numerical procedure
at a temperature T.. There is negligible temperature drop for computing v., ,.i v,, and A (defined in Problem 3.20). Write
across each wall of the shield, but the shield temperature is not a program that implements the method, making use of the
necessarily uniform all the way round. The local rate of heat functions already developed in Problems 1.42 and 2.48 for the
loss q from unit area of the outside of the shield to the atmos- 655 triode.
phere is given by
Suggested Test Data (v, in V, R and R, in kQ)
q = E ~ ( T-. ~ +
Ta4) h(T, - T,),
us = 300, R = 10, R, = 0.47; v, = 300, R = 22, Re = 0.47;
where E, is the emissivity of the shield and a is the Stefan- v,=300, R = 2 2 , R,=1.5.
Boltzmann constant. The convective heat transfer coefficient h, 5.33 A horizontal pipe of internal and external diameters
BTU/hr sq ft OF, depends on the particular surface, the tem- dl and d2,respectively, is covered with a uniform thickness r of
perature difference AT = T, - T., OF, and the height H, feet, insulating material, which has an external diameter d,. The
according to the following dimensional correlations (Perry thermal conductivities of the pipe wall and insulation are
[131): k , and k,, respectively. The inside surface of the pipe is
AB: h = 0.38(AT)0.25, maintained at a high temperature TI by a rapid stream of hot
CD: h = 0 . 2 0 ( ~ ~ ) ~ . ~ ~ , gases. Heat is lost at a rate Q BTU/hr per foot length of pipe
A D and BC: h = 0.28(AT/H)0.ZS. by conduction through the pipe wall and insulation, and by
subsequent convection and radiation to the surrounding air.
Assume that TI, Tz, T,, H, w , and d have been specified, and If E = emissivity of the outer surface of the insulation, Ti
that E and u are known for all surfaces. View factors inside the and T3 = temperatures of the outer surfaces of the pipe and
shield can be obtained by using (a) the string method (see insulation, respectively, a = the Stefan-Boltzmann constant,
Problem 3.17), (b) the reciprocity relation AfFlj = AjFIr, and 0.171 x 10- BTU/hr sq ft OR4, and T. = temperature of the
(c) the fact thatx;= IFij = 1 for all surfaces i. Assume that the
problem is essentially two-dimensional; that is, neglect longi-
surroundings, assumed to behave as a black-body radiator, we
have :
tudinal temperature variations. Base all calculations for areas
and heat fluxes on unit length of the pipes.
Write a program that will extend the method discussed in
Problems 5.25 and 5.26 to compute (a) all the relevant view
factors (the functions developed in Problem 3.17 should help),
(b) E f , G I ,and J , for each surface, (c) the net rate of heat loss
for each pipe, and (d) the temperature or temperatures of the
shield. Subdivide the shield surface into as many individual
The extra subscript R emphasizes that in the radiation term,
the absolute or Rankine temperature must be used ("R
+
OF 460").
-
sections as seem desirable, and neglect conduction between The heat transfer coefficient h, BTU/hr sq ft OF, for convec-
such sections. tion between the insulation and air is given by the dimensional
correlation (Rohsenow and Choi [12]):
Suggested Test Data
T. = 60°F, d = 3 in., E, = E Z = 0.79, E , = 0.66 (both sides),
with gray surfaces (a = E ) throughout; investigate the four
possible combinations of (a) TI = T2 = 900"F, and (b)
in which AT = T3 - T. OF, and d3 is in feet.
TI = 900, T2 = 6W°F, in conjunction with (a) H = 6, w = 12
If TI, To,dl, dz, d3 or t , k,, k t , and E are specified, devise a
in., and (b) H = 10, w = 20 in. Note that in all radiation cal-
scheme for solving the above equations for the unknowns AT,
culations, the temperature must be converted to OR(=OF
TZ, T3,h, and Q. Test the method for TI = 1000, T. = 60°F,
+ 460"). The Stefan-Boltzmann constant is a = 0.171 x 10.-
k , = 25.9 (steel), k f =0.120 (asbestos) BTU/hr ft OF, with
BTU/hr sq ft OR4.
(a) dl = 1.049, d2 = 1.315 in. (convert to feet for consistency)
For a modification that allows for conduction around the
and (b) dl = 6.065, dz = 6.625 in. For both pipes, consider all
perimeter of the shield, see Problem 6.34.
combinations o f t = 0 (no insulation), 0.1, 0.5, 1, 2, and 6 in.
5.31 Extend the situation of Problem 3.22 to n similar
(again convert to feet), with E =0.93 (untreated surface) and
CSTRs in series. The relevant equations will now be
E = 0.52 (coat of aluminum paint). Plot the rate of heat loss
and the outer temperature of the insulation against the insula-
tion thickness for the four combinations of pipe and emis-
sivity.
Using the same parameters as in Problem 3.22, find V when 5.34 The following equations can be shown to relate the
n = 2, 3,4, 5, and 10. temperatures and pressures on either side of a detonation wave
5.32 Referring to Problem 3.20, we can dispense with the that is moving into a zone of unburned gas:
grid-bias battery by replacing it with a short circuit and insert-
ing instead a resistor R, between the cathode and ground. The
srid voltage then becomes
u,, = -i,R,,
where .i is the anode current (unknown as yet).
Problems 337
Here, T = absolute temperature, P = absolute pressure, 5.37 Write the system of equations (5.2)in matrix form as
y =ratio of specific heat at constant pressure to that at con-
stant volume, rn = mean n~olecular weight, AHR = heat of
Bx = u.
reaction, c, =specific heat, and the subscripts 1 and 2 refer (a) Show that the Jacobi iteration of (5.15) may be written
to the unburned and burned gas, respectively. in the form
Write a program that will accept values for rnl, m 2 , y 2 ,
AH,,, c,,, T I ,and PI as data, and that will proceed to com- Xr+l =D-'u-- D-I(L+ U ) X ~ ,
pute and print values for T 2 and P 2 . Run the program with the where xk and x k + ,are the estimated solution vectors before and
following data, which apply to the detonation of a mixture of after the kth iteration, respectively, U is a strictly upper-
hydrogen and oxygen: ml = 12 g/g mole, rn2 = 18 g/g mole, triangular matrix containing the superdiagonal elements of B,
y 2 = 1.31, AHRl = -58,300 cal/g mole, c p 2= 9.86 cal/g L is a strictly lower-triangular matrix containing the sub-
mole O K , T I = 300"K, and P, = 1 atm. diagonal elements of B, and D is a diagonal matrix containing
5.35 Read Sections 8.19 and 8.20 as an introduction to this the elements on the principal diagonal of B.
problem. Then consider a regression plane whose equation is (b) Let
C =-0-'(L +U),
but now suppose that the rn observed points (x,,y,,z,),i = 1, 2, so that the iteration may be rewritten as
. . ., m, contain random errors in all the variables. As an alter-
native to the usual least-squares procedure, it is plausible to X ~ + =
I D-'U +C X ~ .
choose cc, ,i3, and y so as to minimize the sum of the squares of Let a be the solution of (5.2) and E~ be a vector of displace-
the normal distances of each point from the regression plane. ments
Let P be the point in the plane that is closest to the origin 0,
and denote the spherical coordinates of P as (r,6,+). The equa- Ek = u - Xk.
tion of the regression plane can then be rewritten as Show that if xo is the starting vector, then the error vector for
xk + is given by
e k f l= C k + ' ~ , , ,
Show that the problem now amounts to minimizing
so that convergence normally requires that lim C k = 0, and
k-.P
+
2.31(p4- p,) 8.69 x ~ o - ~ Q ~ = L 0,
~ / D ~ X k + 3 = X k + 2 f Sk+2,
etc.
Write a program that will accept values for U A , PA, a,, BB, Develop criteria for deciding when to recompute the elements
zs- z4, DC,LC, Do, Lo, DE, and LE, and that will solve the of +(x) and its inverse.
above equations for the unknowns Qc, QD, QE,p2, pnV andp,. 5.44 The calling program in Example 5.5 is well suited
One suggested set of test data is z, - z4 = 70 ft, with: for the general problem of solving n simultaneous nonlinear
equations by the Newton-Raphson method. since all informa-
tion about the specific equation set (except for the initial
guess for the solution vector) is contained in the subroutine
CALCN. In most practical problems, however, the equations
contain parameters (such as the pressure P in CALCN) which
the user would also like to read in as data. How would you
modify the calling program and the essential structure of
Pipe D, in. L, ft
CALCN to allow this, so that further modifications of the
calling program would be unnecessary for other systems of
equations with different parameters?
5.45 The principal chemical reactions occurring in the
production of synthesis gas are listed in Example 5.5 (see
(5.5.1), (5.5.2), and (5.5.3)). Write a program (modelled closely
Assume that the above pipe lengths have already included the
on the programs of Example 5.5) to find the Oz/CH, ratio
equivalent lengths of all fittings and valves.
that will produce an adiabatic equilibrium temperature of
5.41 Rework Example 5.4 (flow in a pipe network, solved
TeOFat an operating pressure of P atm if the inlet CH4 gas is
by the successive-substitution method) using the Newton-
preheated to a temperature of TmOF and the oxygen, introduced
Raphson technique instead. IS one method decidedly better
in the form of an oxygen-nitrogen mixture (possibly air) con-
than the other in this case from the viewpoints of (a) simpli-
taining xo mole percent oxygen, is preheated to TPF.
city, and (b) computational efficiency?
The heat capacities for the seven possible gaseous compo-
5.42 Expand each of the fr, i = 1, 2, . . ., n, of (5.33) in a
nents can be computed as a function of temperature from the
Taylor's series in n variables, xl, xz, . . ., x,, about the kth
iterate, xk = [xk,,,xk,,,. . .,x,..]', of the Newton-Raphson general relation
iteration to yield cp,(Tk) = a l + biTk+ c1T?+ dl/T*Zcal/g mole OK,
Problems 339
where i = 1, 2, 3, 4, 5, 6, and 7 for CO, COz, HzO, H Z ,CH4, 5.46 Extend Example 5.4 (flow in a pipe network) so that
OZrand N Z ,respectively, and Tkis in OK ("K = "C 273.15). + the program can handle one or more of the following addi-
Table P5.45a [13] also shows the standard heat of formation at tional features:
29S°K, AHf.298 cal/g mole, for each component.
(a) Elevation change between nodes. If z, and ZJ denote the
Table P 5 . 4 5 ~ elevations in feet of nodes i and j, the Fanning equation,
(5.4.1), will become
i a, b, ci di AH%,,,
a b
Figure 6.1 Numerical solution of a first-order differential equation.
Let the true solution y(x) at the indicated base points which does the calculations, the order of the machine
be denoted by y(x,), and the computed approximation of operations used to implement the algorithm, etc. Some
y(x) at these same points be denoted by y,, so that upper bound can usually be found for the discretization
error for a particular method; on the other hand, round-
Yi = xi). (6.6) off error-generation is extremely complex and unpredict-
The true derivative dyldx at the base points will be able. However, because of this very unpredictability,
approximated by f(xi,yi), abbreviated as fi, so that numerical analysts have been fairly successful in develop-
ing a probabilistic theory of round-off error, on the
assumption that local round-off error, that is, the error
When the requisite numerical calculations are done caused by round-off in integrating a differential equation
exactly, that is, without round-off error (see below), the across one step, is a random varlable (see [2] for an excel-
difference between the computed value yi and the true lent description of this work). The only errors which will
value y(xi) is termed the discretization or truncation be examined in any detail here are those related to dis-
error, ci : cretization, that is, those inherent in the numerical
procedures.
The common numerical algorithms for solving a first-
The discretization error encountered in integrating a dif- order ordinary differential equation with initial condition
ferential equation across one step is sometimes called the y(x,) are based on one of two approaches:
local truncation error. The discretization error is deter- 1. Direct or indirect use of Taylor's expansion of the
mined solely by the particular numerical solution pro- object or solution function ~ ( x ) .
cedure selected, that is, by the nature of the approxima- 2. Use of open or closed integration formulas similar
tions present in the method; this type of error is to those already developed in Chapter 2.
independent of computing equipment characteristics.
An inherently difl'erent kind of error results from The various procedures can be classified roughly into
computing-machine design. In practice, computers have two groups, the so-called one-step and multistep methods.
only a finite memory and therefore a finite number size One-step methods permit calculation of y,,, given the
(scientific computers usually have a jixed word-length, differential equation and information at x i only, that is,
that is, the number of digits retained for any computed a value y,. Multistep inethods require, i n addition, values
result is fixed, usually 7-12 significant digits). Thus any of y j andlor fj at other (usually several) values x, outs~de
irrational number, or indeed any number with more the integration ipterval under consideration, [x,,x,+ ,I.
signlhcant digits than can be retained, that oc;cur>i n a Onc disadvantage of the multistep methods 1s that
sequence of calculations must be approximated by more information is required to start the procedure than
"rounded" values. The error involved is termed round-off is normally directly available. Usually an initial con-
error, and for any particular numerical method is, deter- dition, say y(~,), is given; subsequent values, y ( ~ ! ) ,
mined by the computing characteristics of the machine y(x,), etc., are qot known. Some other method (usually a
6.2 Solution of First-Order Ordinary Differential Equations 343
one-step method) must be used t o get started. Another Analytic integration of (6.11) after separation of variables
difficulty encountered in the multistep methods is that gives
it is rather difficult to change the step-size h once the
calculation is under way. On the other hand, since each
new application of a one-step method is equivalent to
restarting the procedure, such a change of step-size
causes no trouble. The multistep methods require con-
siderably less computation, compared with the one-step which is identical to (6.13). There is no truncation error for
methods, to produce results of comparable accuracy. the algorithm of (6.13) because all high-order derivatives
The advantages and disadvantages of each group of f (")(x,y),n > 3, vanish.
methods will become more apparent with the develop-
ment of the numerical procedures. Example. Consider a case for which f(x,y) is a function of
Taylor's Expansion Approach. One method of approxi- y alone:
mating the solution of ( 6 . 4 ) numerically is to express the
solution y ( x ) about some starting point xo by using a
Taylor's expansion :
subject to the initial condition y(xo) = y o . Differentiating
(6.15) by using the chain rule (6.10) yields:
subject to the initial condition y(xo) = y o . From (6.10), Since {l + 2h + [(2h)2/2!] + . . .) is the Taylor's expansion of
e Z habout h = 0 , the two solutions (6.17)and (6.18) agree with
f ' ( x , ~=
) 2x, f'(xo,yo) = 2 x 0 ; an accuracy determined by the number of terms retained in
f"(x,y) =2, f "(XO,YO)
=2 ; the series. If terms up to that including /'"-I' are retained,
f " ( x , ~=) 0 , f '"(XO,YO)
=0 ; (6.12)
then the error is given by
Expansion of y ( x ) about xo by substitution of (6.12) into the Exanlple. Consider a more general, but still simple, example
Taylor's series of (6.9) yields for which f ( x , y ) is a function of both variables,
344 The Approximation of the Solution of Ordinary Differential Equations
subject to the initial condition y(xo) =yo. Differentiation of Xitl = xi + h can be based upon the Taylor's expansion
(6.19) yields : of y(x) about x i :
where
AS an exampie, consider the differential equation of F,, the given ecluation,j(x,y)= + y, the derivative in
(6.191, (6.29) is given by
dy d2y
-=x+y, f '(x,y) = - = ex.
dx dx2
subject to the initial condition xo = 0, y(x,) = y o = 0
Since the maximum value of e x , xi < x < x i + , occurs at
(see Example 6.1). The solution already developed in
x = x i + , , the maximum value of the local truncation
(6.23) for this initial condition is
error (6.29) is given by
y=e"-X-1. hZ
lerlmax= - e x i + I . (6.30)
The Euler solution is shown in Table 6.1, using a 2!
= and an upper limit of integration Unfortunately, this error bound is valid only for the
xl0 = "0. Column 3 'ontains the of yi 'ornputed algorithm of (6.2ga) and that obtained from (6.23,
from (6.28) with all figures retained in the calculation
(no round-off error). Column 4 contains the computed Yi+ I = xi) + h f (xi>y(xi)). (6.31)
y(C1) = 0 h = 0.1
Overall Truncated YI Local
Trunca- at Rounded Value Trunca-
True y tion Error Four to Four Computed tion Error h2
Rounded Rounded Figures Figures Using Using e'ax -
2!
i xi y1 f (xl,~i) xi) EI = yi -A x i ) YI YI y(xi - 1) Y ( X -, I)
(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (11)
346 The Approximation of the Soliltion of Ordinary Differential Equations
For the general integration between xi and xi+,, that is, Then, from (6.33) and (6.34),
the results of column 3, the actual algorithm is given by
(6.28b) as
Yi+ I = Yi + hf'(xi,~i).
The value of y, used for every interval except the first,
where yo = y(x,), is inexact, being the result of previous
calculations which involved earlier truncation errors.
6.4 Error Propagation in Euler's Method Since lei+ll < lei+, - si(+ lsil, (6.39) can be rewritten as
Let us examine the propagation of local discretization
errors in Euler's method of (6.28) applied to the integra-
tion of the initial-value problem
To determine Isil, (6.40) can be applied i times with
the starting value so = 0. However, (6.40) has a general
solution of the form
Assume that f(x,y) and its first-order partial derivatives
are continuous and bounded in the region a < x < b,
- co c y < co, and that a c xo < x, c b. Assume also
that a solution y(x) exists. Then there must exist constants That (6.41) is a solution of (6.40) is not immediately
M and K such that apparent, but this can be proved by induction as follows.
Consider a general inequality of the form
Flow Diagram
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
H Step size, h.
I Step counter, i.
IPRINT Number of steps beiween printout, k.
NSTEPS Total number of steps, xmax/h.
TRUEY True solution, y(xi).
X Independent variable, xi.
XMAX Maximum value of the independent variable, x,,,.
Y Computed solution, yi.
Example 6.1 Euler's Merhod
Program Listing
A P P L l ED NUMERl CAL METHODS, EXAMPLE 6 . 1
E U L E R ' S METHOD
3
TRUEY = DEXP(X) X- -
I F (I/IPRINT*IPRINT.EQ.I)
1.
WRITE ( 6 , 2 0 1 ) X, Y, TRUEY
GO TO 1
C
C
100
..... FORMATS FOR I N P U T AND OUTPUT STATEMENTS
FORMAT ( lOX,F10.6,17X,F10.6,20X, 15 1
.....
200 FORMAT ( 1 0 H l X M A X = , F12.61 10H H = , F12.61 10H IPRINT =
1 1 5 / 1H0, 6X, lHX, 15X, lHY, 13X, 5HTRUEY/ 1 H )
2 0 1 FORMAT ( l H , F10.6, 2F16.6
C
END
Data
XMAX l PRINT
XMAX l PRI N T
XMAX IPRINT
XMAX IPRINT
XMAX IPRINT
XMAX IPRINT
XMAX IPRINT
XMAX IPRINT
Computer Output
Results for the 1st Data Set
XMAX = 1.OOClOOO
H I 1.000000
IPRlNT 1
TRUEY
0.0
0.718282
350 The Approximtrtion of the Solution of O r k y OrdinoryifferentialEquations
Computer Output (Continued)
Results for the 2nd Data Set
XMAX ' = 1.000000
H = 0.500000
IPRINT = 1
TRUEY
XMAX
H
lPRlNT=
-
Results for the 5th Data Set
9
1.000000
0.010000
10
TRUEY
Example 6.1 Euler's Method
0.0 0.0
0.100000 0.005116
0.200000 0.021281
0.300000 0.049656
0.400000 0.091527
0.500000 0.148309
0.600000 0.221573
0.700000 0.313048
0.800000 0.424651
0.900000 0.558497
1.000000 0.716924
TRUEY
X Y TRUEY
0.0 0.0
0.100000 0.005170
0.200000 0.021402
0.300000 0.049857
0.400000 0.091822
0.500000 0.148717
0.600000 0.222113
0.700000 0.313746
0.800000 0.425532
0.900000 0.559592
1.000000 0.718268
352 The Approximation of the Solution of Ordinary Differential Equations
Discussion of Results
Equation (6.19) has been solved on the interval [0,1] 1.0 -
using Euler's method with several different step sizes,
h = 1.0, 0.5, 0.25, 0.1, 0.01, 0.001, 0.0001, and 0.00001.
The errors in the computed solution at x = 1 as a function 0.1
of the step size are shown in Table 6.1.1 and Fig. 6.1.1.
As expected from the esror analysis of Section 6.4, the
/ ;1
error decreases linearly with h for small h (see (6.46)). . .-. 0.01
II
% !
u
Table 6.1.1 Error in Euler's m
Method Solution at x = 1 5s 1
/I
0.001
1.O
0.5
0.25
0.1
0.71 8282
0.468282
0.276876
0.124540
v4- !
!
I
* ?:is temperature in "K (Kelvin). Thus the total number of moles flowing at any point in
the tubular reactor is n,(l + z) and the corresponding
Method of Solution mole fraction of ethane is x = ( 1 - z)/(l + z).
The problem is stated in mixed units, but will be solved We now establish steady-state material and energy
using t h e BTU, lb mole, OR (Rankine), ft, and h r system. balances over a differential element dL of reactor length,
Adopt the following notation: shown in Fig. 6.2.1.
A = Cross-sectional area of tube, sq ft.
c = Concentration of ethane, Ib moles/cu ft.
c, = Specific heat ca~pacity,BTU/lb moleOR.
k = Reaction rate constant, sec-'.
L = Length measured from reactor inlet, ft.
no = Inlet molal feed rate of ethane, Ib moleslhr. Figure 6.2.1 Differeztiai e l m z t of t u b u b reactar.
354 Z h Approximation of the Solution of Ordinary Differential Equations
Material balance. The material balance for ethane.over Then the change in temperature as a function of
the differential volume element dV = AdL is: length is described by the first-order ordinary differential
equation
Flowing In + From Reaction = Flowing Out
nc2~6 + rdV =nsH, + d n ~ ~ ~ s .
(6.2.2)
Rearranging (6.2.2),
Provided that the temperature T is computed from
temperature T, the heat capacity relationships from
Table 6.2.1 can be introduced directly into the denomi-
But for the given first-order irreversible reaction, the nator of (6.2.9).
rate, r, is The heat of reaction, AHR, varies with temperature
according to
r = - 3600kc, (6.2.4)
where the conversion constant 3600 sec/hr is introduced
for dimensional consistency. At the low pressure of the
reacting gas mixture, the ideal gas law holds, so that The heat of reaction at 298°K can be calculated from the
(6.2.4) becomes heats of formation of Table 6.2.1 as 12496 + 20236 =
32732 cal/g mole0K. Introducing the heat capacity
relationships of Table 6.2.1 into (6.2.10), and integrating,
yields the heat of reaction at any temperature T (OR),
From (6.2.3), (6.2.5), and Table 6.2.1, the conversion z
as a function of reactor length, L, is described by the
solution of the first-order ordinary differential equation
+ 1.28 x 10-6(T3 - 2983)] BTU/lb mole. (6.2.11)
Algorithm. Equations (6.2.6) and (6.2.9) are two
coupled nonlinear first-order ordinary differential equa-
tions which must be solved simultaneously. The length L
is the independent variable, and z and Tare the dependent
For a given tube I.D., reactor pressure, and inlet ethane (solution) variables. The initial conditions are
flow rate, the first factor on the right-hand side of (6.2.6)
is constant; the second factor is a function of temperature z(LO)= zO= ~ ( 0 =
) 0 (no conversion at inlet),
only. T(Lo) = To = T(0) = T, (inlet feed temperature).
Energy balance. The energy balance over the differential
volume element dV must account for heat liberated due The two differential equations can be solved in parallel
to reaction, heat introduced from the furnace through using Euler's method of (6.28). Let the step size be
the tube wall, and sensible heat effects (because .of denoted by AL. Then (6.28) becomes
temperature change) in the flowing gas stream. For a
change dz in conversion in the differential element, the
heat liberated by the reaction is nodz(- AH,). The energy
introduced into the differential element through the tube
wall is qdL. The corresponding gain in enthalpy of the
flowing gases is given by
Here, zi and Ti are, respectively, the conversion and
temperature at L, = iAL. At the beginning of the ith step
the values of zi-, and Ti-,, have already been calculated.
The values of dz/dL and dT/dL for equations (6.2.12)
and (6.2.13) can be computed from (6.2.6) and (6.2.9).
where dT is the temperature change across the differential Then zi and Ti can be computed from (6.2.12) and
element. The energy balance is (6.2.13). The process is repeated for subsequent steps
until zi exceeds some desired upper limit z,,, 0 < z,, g
1. The program contains provision for printing values for
Li, z , and Ti (converted to OF) at specified intervals in i.
Example 6.2 Ethane Pyrolysis in a Tubular Reactor
k
i
I
T+-T1,1/1.8 It
04 2 zmo
L,, Ti,+ AHR t- eqn. (6.2.11)
(2)
-
+ eqn. (6.2.6)
T
($1
i-1
\I eqn. (6.2.9)
1-1
zi +- + AL($) i-l
I-1
FORTRAN Implementation
List of Principal Variables
Program Symbol Defiition
AL Length, L,,ft.
CONV Desired conversion fraction for cthane, z,,,.
CP Denominator of equation (6.2.9), BTU/lb mole OR.
DH AEI,, BTU/lb molc (see equation (6.2.11)).
DI Internal diameter of reactor tube, D, in,
DL Length increment, AL, ft.
DTDL (dT/dL)i, l , "R/ft.
DZDL (d8/dL)f-l, ft-',
FACTOR 2.075 x 1OZ0AP/no~ (see equation (6.2.6)).
I Step counter, I,
IPRINT Intermediate print control. Results are printed after every IPRINT steps.
P Pressure in the reactor, P, psia.
Q qln, , BTU/lb mole #.
QPERSF Heat input from furnace, BTU/hr sq ft (of inside tube surface area).
RATEMS Inlet mass feed rate of ethane, Ib/hr.
T, TF, TK Temperature, OR, OF,and "K,respectively.
z Fraction of ethylene converted, z, .
356 The Approximation of the Solution of Ordinary Differential Equations
Program Listing
C A P P L I E D NUMERICAL METHODS, EXAMPLE 6.2
C PYROLYSIS OF ETHANE I N A TUBULAR REACTOR
C
C T H I S PROGRAM USES EULER'S METHOD TO SOLVE A SYSTEM OF TWO
C F I R S T ORDER ORDINARY D I F F E R E N T I A L EQUATIONS D E S C R I B I N G THE
C A X I A L TEMPERATURE ( T I AND CONVERSION ( Z ) PROFILES FOR
C PYROLYSIS OF ETHANE I N A TUBULAR REACTOR. THE DISTANCE FROM
C THE TUBE ENTRANCE, AL, I S THE INDEPENDENT VARIABLE AND D L I S
C THE S T E P - S I Z E USED I N THE INTEGRATION PROCEDURE. DTDL AND
C DZDL ARE THE D E R I V A T I V E S OF TEMPERATURE AND CONVERSION W I T H
C RESPECT TO LENGTH AT THE BEGINNING OF EACH STEP. T F I S THE
C FAHRENHEIT AND TK THE K E L V I N EQUIVALENT OF THE TEMPERATURE
C T WHICH HAS U N I T S OF DEGREES RANKINE. INPUT DATA INCLUDE
C THE I N L E T TEMPERATURE TF, I N L E T PRESSURE P, MASS RATE OF
C ETHYLENE FEED RATEMS, INTERNAL DIAMETER OF THE TUBE D l ,
C HEAT INPUT RATE FROM THE FURNACE QPERSF, THE S T E P - S I Z E DL,
C THE MAXIMUM CONVERSION DESIRED CONV, AND THE FREQUENCY OF
C PRINTOUT I P R I N T . DH I S THE HEAT OF REACTION AND CP A HEAT
C CAPACITY TERM. Q, FACTOR AND CP ARE DESCRIBED I N THE TEXT.
C INTEGRATION PROCEEDS DOWN THE TUBE U N T I L THE I N D I C A T E D
C CONVERSION FRACTION CONV I S REACHED. I I S THE STEP COUNTER.
C
C .....
READ AND P R I N T DATA
1 READ ( 5 , 1 0 0 )
-
COMPUTE CONSTANT PARAMETERS
TF, P, RATEMS, D l , QPERSF, CONV, DL, I P R I N T
.....
WRITE ( 6 , 2 0 0 ) TF, P, RATEMS, D l , QPERSF, CONV, DL, l P R I N T
Q = QPERSF*3O./RATEMS*3.14159*DI/12.
FACTOR = 2.07504E20*3.14159*Dl*DlqP+30./(144.+4.tlO.73*RATEMS~
C
C .....
SET I N I T I A L CONDITIONS
A L = 0.
.....
Z = 0.
T = TF + 460.
WRITE ( 6 , 2 0 1 ) AL, TF, Z
C
C
2
.....
DO 3
INTEGRATE EQUATIONS ACROSS I P R I N T STEPS
1 = 1, I P R I N T
.....
C
C ..... D E R I V A T I V E S FROM M A T E R I A L AND ENERGY BALANCES
TK = T / 1 . 8
.....
1 *TK-6.28E-6*TK*TK)
DZDL = FACTOR+EXP(-41310./TK)r(l.-Z)i(T*(l1+Z))
DTDL = (Q-DH*DZDL)/CP
I:-
C .....
APPLY EULER'S ALGDRITHM
T = T + DTDL*DL
.....
Z = Z + DZDL*DL
AL = A L + D L
I F (Z.GE.CONV) GO TO 4
3 CONTINUE
C
C
b
..... -
TF = T
P R I N T SOLUTIONS, CONTINUE INTEGRATION I F NOT DONE
460.
.....
WRITE ( 6 , 2 0 1 ) AL, TF, Z
I F (Z.LT.CONV) GO TO 2
GO TO 1
C
C
100
.....
FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT ( 9X,F8.3,19X,F8.3,19X,F8.3/
.....
9X,F8.3,19X,F8.3,19X,F8.3/
1 9X,F8.3,19X,14
2 0 0 FORMAT ( l O H l T F = , F10.4/ 10H P = , F 1 0 . 4 / 1 0 H RATEMS = ,
1 F10.4/ 10H D l = , F 1 0 . 4 / 1 0 H QPERSF = , F 1 0 . 4 / 1 0 H CONV =
2 , F10.4/ 10H D L = , F 1 0 . 4 / 1 0 H I P R I N T = , I S / 1H0, 3X,
3 lHL, 12X, ZHTF, 13X, 1HZ / 1H 1
201 FORMAT ( 1H , F 7 . 2 , F 1 4 . 2 . F 1 4 . 6
,.
I.
END
Example 6.2 Ethane Pyrolysis in a Tubular Reactor
Computer Output
Results for the Ist Data Set Results for the 2nd Data Set
TF = 1200.0000
I TF * 1200.0000
P = 30,,0000 P = 30.0000
RATEMS = 1800.0000 RATEMS a 1800.0000
DI - 4.0260 DI 5 4.0260
QPERSF = 5000.0000 QPERSF = 5000.0000
CONV =
- 0.7500 CONV -- 0.7500
DL 0.1000 DL u 0.5000
IPRINT = 500 IPRINT 100
358 The Approximation of the Solution of Ordinary Differential Equntions
Results for the 5th Data Set Results for the 6th Data Set
TF 1200.0000
I TF =
P = 30.0000 P a
RATEMS = 1800.0000 RATEMS =
DI a 4.0260 DI I
QPERSF = 5000.0000 QPERSF =
CONV = 0.7500 CONV =
DL = 10.0000 DL P
IPRlNT = 5 IPRINT =
Example 6.2 Ethane Pyrolysis in a Tubular Reactor
6.5 Runge-Kutta Methods where p and q are constants to be established later. The
The solution of a differential equation by direct quantities hk, and hk, have a simple geometric interpreta-
Taylor's expansion of the object function is generally not tion, which will become apparent once p and q are
practical if derivatives of higher order than the first are determined.
retained. For all but the simplest equations, the necessary First, expand k , in a Taylor's series for a function of
higher-order derivatives tend to become quite complicated. two variables*, and drop all terms in which the exponent
In addition, as shown by the preceding examples, each of h is greater than one:
problem results in a specific series for its solution. Thus,
when higher-order error terms are desired, no simple
k2 = f (xi + Ph, Yi 9 h f (xityi))
algorithm analogous to Euler's method can be developed =f ( x i , ~ i+
) Phfx(xi>~i>
directly from the Taylor's expansion.
Fortunately, it is possible to develop one-step pro-
+ q h f ( x i y ~ i > f ~ ( x i+, ~O(h2).
i> (6.54)
cedures which involve only first-order derivative evalua- From (6.53) and (6.54), (6.52) becomes
tions, but which also produce results equivalent in accur-
acy to the higher-order Taylor formulas. These algorithms Y i +I ' Y i + h [ a f (xi>yi)+ b f (xi,Yi)I
are called the Runge-Kutra methods. Approximations + h2CbPfx(xi7Yi>+ b q f ( x i , ~ i > f y ( x i , ~ +i > O(h3).
I
of the second, third, and fourth orders (that is, approxima- (6.55)
tions with accuracies equivalent to Taylor's expansions Next, expand the object function y ( x ) about x i by using
of y ( x ) retaining terms in h2, h3, and h4, respectively) Taylor's series (6.25), as before:
require the estimation off ( x , y ) at two, three, and four
values, respectively, of :c on the interval x , < x < x i + , . Y(xi + h? = y ( x i + l ) = y ( x i ) + hf(xi,~(xi))
Methods of order m, where m is greater than four, require
h h3
derivative evaluations at more than m nearby points [14]. + T fY x ~ > Y ( x+~ )3)' f " ( t . ~ ( C ) ) ,
All the Runge-Kutta methods have algorithms of the
form
Yi+ 1 =Yi + h4(xi,Yi,h). (6.50)
By chain-rule differentiation (6. lo), f '(xi,y(xi))is given by
Here, 4, termed the increment function by Henrici [2], is
simply a suitably chosen approximation to f ( x , y ) on f '(xi,Y(xi)) =fx(xi,Y(xi)) +fy(xi,Y(xi>>f(xi>Y(xi)).
the interval x i < x < Because there is a consider-
able amount of algebra involved in the development of Finally, equate terms in like powers of h in (6.55) and
(6.56) :
For b = +.a = 3, p = 1, q = 1. Then (6.52) becomes equations, (6.60) and (6.59), leads to the simplest of the
so-called predictor-corrector methods which are described
= yi + 7h Cf(xi,yi) + f ( ~ +i h,yi + hf(xiy~i))I, in more detail in Section 6.1 1.
For b = 1.a = 0, p = 112, q = 112. Then (6.52) becomes
(6.58)
which can also be written ~i+l=~i+hf(xi+:,Ji+,,~), (6.61)
h
where j i + 112 = Yi + f (xi~~i). (6.62)
ji+ I = yi + h.f(xi,~i). (6'60) The one-step algorithm of (6.61) and (6.62) is called the
The one-step algorithm of (6.59) and (6.60) is known as improvedpolygon method or the modified Euler's method,
the improved Euler's method or Heun's method, and has illustrated in Fig. 6.36. Again, Euler's method is employed
the geometric interpretation shown in Fig. 6.3~. twice in sequence. First, from (6.62). an approximation
Essentially, Euler's method is employed twice in Ji+,l, is obtained at the halfway point xi + h/2. Second,
sequence. First, equation (6.60) is used to predict Ji+,, (6.61) evaluates f(x,y) for x = xi + h/2, y = Ji+1,2,and
a preliminary estimate of yi+,. That is, Yi+, is the ordi- uses this as the average derivative for proceeding over
nate, at x = xi+,, of the straight line @, passing through the whole interval.
(xi,yi) with slope f(xi,yi) = k,. Second, an improved The higher-order Runge-Kutta methods are developed
estimate yi+, is obtained from equation (6.59); the slope analogously. For example, the increment function for the
of line Q, used for this purpose, is the weighted average third-order method is
of approximations to f at the two ends of the interval.
Note that although the true derivative at xi+, is 4 = ak, + bk, + ck,,
f (xi+,,y(xi+,)), it is approximated by f (xi+l*Ji+l),since where k,, k,, and k, approximate the derivative at
y(xi+,) is unknown. various points on the integration interval [xi, xi+,I. In
Eu1,er's algorithm of (6.60) may be viewed as a predict- this case,
ing eiuation for JI:), (the first approximation to yi+,),
whereas (6.59) may be considered a correcting equation k1 =f(xi,~i),
to produce an improved estimate of yi+,. Equation (6.59)
may be used iteratively to produce a sequence of corrected kz =f (xi + ph,yi + phkl),
y i + t Values, jf:),, yj:\, . . ., J!:',. In this case, the pair of k, =f(xi + rh,yi + shk, + ( r - s)hk,).
6.6 Truncation Error, Stability, and Step -Size Control in the Honye-Kutta Akorithrns 363
The third-order Runge-Kutta algorithms are given by This reduces to Simpson's second rule (2.21~)if f(x,y) is
a function of x only.
yi+, = yi + h(ak, + bk, + ck,). (6.63)
The most widely used fourth-order method (and very
To determine the constants a, b, c, p, r, and s, we first likely the most widely used single-step method for solving
expand k2 and k, about (xi,yi) in Taylor's series as func- ordinary differential equations as well) is the one credited
tions of two variables. The object function y(x) is expan- to Gill [6]:
ded in a Taylor's series as before, (6.25). Coefficients of
like powers of h through the h3 terms in (6.63) and (6.25)
are equated to produce a formula with a local truncation
error of order h4. Details of the argument are essentially
the same as in the development of the second-order
methods.
Again, there are feweir equations than unknowns:
at-b+c=l,
+
bp cr = 4,
bp'! + cr2 = 3,
cps = 4.
Two of the constants a, b, c, p, r, and s are arbitrary. For
one set of constants, selected by Kutta, the third-order
+
(1 --y2hk, 1,
method is:
Again, note that (6.66:) reduces to Simpson's rule if where K depends (in a complicated way usually) upon
f(x,y) is a function of x only. Another fourth-order ,f(x,y) and its higher-order partial derivatives. If one
method, also ascribed to Kutta,.is: assumes that h is sufficiently small, so that the error is
dominated by the first term in (6.69). it is possible,
h though not at all simple, to find bounds for K [7, 81. In
Y ~ + I= ~ ~ + ~+ 3( k k2 +,3 k 3 + k,), general, such bounds depend upon bounds for f (x, y) and
its various partial derivatives, and upon the particular
Runge-Kutta method used. Ralston [8] shows that par-
ticular choices of the free parameters in the under-
determined equations for the constants in the algorithm
[see P6.151 will tend to minimize the upper bound on K.
364 The Approximation of the Solution of Ordinary Dzfferential Equations
In order to choose a reasonable step size, one needs over the number required for integration using just one
some estimate of the error being committed in integrating step size, h,. As a compromise, we could use the monitor-
across one step. On the one hand, the step size should be ing procedure less frequently, for instance, for every kth
small enough to achieve required accuracy (if possible); step.
on the other, it should be as large as possible in order to Another criterion, suggested by Collatz [9] for the
keep rounding errors (a function of the number of arith- Runge-Kutta method of (6.66), is to calculate l(k, - k,)/
metic operations performed) under control and to avoid (k, - k,)l after each integration step. If the ratio becomes
an excessive number of derivative evaluations. This latter large (more than a few hundredths [lo]), then the step
consideration is very important, particularly when the size should be decreased. This is only a very qualitative
differential equation is complicated and each derivative guideline, but has the virtue that the added computation
evaluation requires substantial computing time. For the is negligible.
mth-order methods of the previous section, the derivative If m is odd, Call and Reeves [11] suggest integrating in
must be evaluated m times for each integration step. the reverse direction, from x,+, to xn with h replaced by
One approach to this problem is to assume that the - h, after having integrated across the step in the forward
local truncation errors have the form Khm+l with K direction. The truncation error is estimated as half the
constant, and that the local truncation error, committed difference between yn and y,*, where y,* is the solution
in traversing one step, dominates the change in total error found as a result of the reverse integration. Unfortunately,
for the step. Then an estimate of the local truncation error when m is even, the method fails, since the truncation
can be found by integrating between two points, say xnand errors in one direction exactly cancel those in the other
xn+,, using two different step sizes h1 and h, to evaluate and, aside from rounding errors, y, = y;.
y,+, ; let the corresponding solutions be yn+,,, and Determining a bound for the accumulated or propaga-
yn+,,. Then if y;, is the "true" solution, we can employ ted error for the Runge-Kutta algorithms is difficult
Richardson's extrapolation technique described on page [12,13]. Reported bounds are usually very conservative
78 as follows*: [7]; in addition, the parameters essential for their com-
putation are only rarely available. In general, if the local
truncation error for a one-step method is of O(hm+'),
then the accumulated error will be of O(hm),[3,4], that
is, the reduction in the order of the error is similar to that
observed for Euler's method.
Dividing the first of these equations by the second, and All the Runge-Kutta methods can be shown [2] to be
solving for yX+, yields convergent, that is, lim,,, (y, - y(xi)) = 0 (see page 347).
Another criterion for selecting an algorithm for the solu-
tion of a differential equation with given initial conditions
is stability. Stability is a somewhat ambiguous term and
appears in the literature with a variety of qualifying
If we choose h, = h,/2, (6.71) becomes
adjectives (inherent, partial, relative, weak, strong, abso-
lute, etc.). In general, a solution is said to be unstable if
errors introduced at some stage in the calculations (for
example, from erroneous initial conditions or local trunca-
and an estimate of the local truncation error for the tion or round-off errors) are propagated without bound
solution y,+ ,,,,
assuming that (xn+, - x,) = h,, is given throughout subsequent calculations.
by (6.70) and (6;72) as Certain equations with specified initial conditions
cannot be solved by any step-by-step integration pro-
cedure without exhibiting instability, and are said to be
inherently unstable. For example, consider the equation
For the fourth-order Runge-Kutta method, m = 4 and of (6.19),
(6.73) becomes
Since a single high-order equation If the equations can be ordered so that, for all j,
dyjldx = f j ( ~ , ~ 1 ,.~.., .. .,fi-l), then the in-
2 ~n,j;,f2,
,
tegration schemes of the preceding sections can always
be applied. If such an ordering is impossible, then one
may compute the particular (dyj/dx) which cannot be so
with appropriate initial conditions ordered from
can always be rewritten as a system of first-order equa- where the starred derivatives must be known or assumed
tions of the form of (6.77) [see, for example, (6.2), (6.3)1, at x,. Thereafter, one can usually use the most recently
the numerical methods developed in this chapter may be computed values for them.
applied indirectly to solve higher-order initial-value Error analyses comparable to those of Section 6.4 are
problems as well. Initial-value problems involving virtually impossible to implement for the higher-order
systems of equations of mixed order may also be reduced Runge-Kutta schemes for systems of differential equa-
to the form of (6.77) in most cases. Depending on how tions. The step-size control mechanisms and stability
the differential equations are coupled, some of the deriva- considerations outlined in the preceding section carry
tives in (6.77) may be functions of other derivatives, over to the multiple-equation case without appreciable
that is, change, In practice, we often solve the equations using
different step sizes and observe the behavior of the
solutions with regard to apparent convergence and
stability.
EXAMPLE 6.3
FOURTH-ORDER RUNGE-KUTTA METHOD
TRANSIENT BEHAVIOR OF A RESONANT CIRCUIT
they will result from applications of the Runge-Kutta 3. Begin accumulation of the values $j, j = 1,2, . . ., n,
method on the (i - 1)th interval. For a system of n in (6.3.8a).
equations, the one-step integration across the ith inter-
$jtFj=kjl, j = l , 2 ,..., n. (6.3.11)
val may be described by :
4. Compute the values Y;., j = 1,2, . . ., n, in (6.3.8~)and
assign them to elements of the vector Y.
kjl =fj(xi,yli,~2ir. . .t~ni), (6.3.8b)
+
yTi = yji fhkjl,
* *
(6.3.8~)
+
kj2 = fj(xi +h,yli,y2i,.. ., Y:), (6.3.8d)
j..
11
= y..
I'
+ 'hkj2, (6.3.8e) 5. Increment x to the value needed in (6.3.8d).
kj3 =fj(xi + *h,jli,72i,. . jni), (6.3.8f)
jj*i= yji -I- hkj3, (6.3.8g)
-* -* . ., Y,*ii).
+ h,yli>yzi,.
kj4 =fj(xi (6.3.8h) 6. Calculate the values f,, j = 1,2, . . ., n, using the
The relationships in (6.3.8) are applied in parallel at current x and Yj values. These are equivalent to the
each point in the algorithm for all n equations, that is, for values kj2, j = 1, 2, . . ., n, of (6.3.8d).
j = 1,2, ..., n. F j +fj(x, Yl, I.;,. . ., Y,) = kjz
Because the Runge-Kutta method is a one-step method,
h * *
the subscript i throughout (6.3.8) is, in a sense, super-
fluous. In addition, because the kj, are not needed after the
= fj(xi + Z,yli,y2i,. , j = ~ 2 . . .,. n.
yTi are computed, and the y;i in turn are not needed after (6.3.14)
the kj, are computed, etc., it is possible to write a general- Pass 3
purpose Runge-Kutta function and calling program
which require relatively few memory locations for 7. Add the contribution of kj2 to $j, j = 1,2, . . ., n, in
retention of the many variables appearing in (6.3.8). The (6.3.8a).
entire algorithm of (6.3.8) will be implemented in pro- #j dj + 2Fj = kjl + 2kj2. (6.3.15)
4-
gram form as outlined below.
Let four vectors of length at least n be denoted by the 8. Compute the values j j i ,j = 1, 2, . . ., n, in (6.3.8e) and
names Y, F, and 4. Before carrying out the Runge- assign them to elements of the vector Y.
Kutta integration for the ith step, the following variables
must be initialized:
x t xi, value of the independent variable.
h +- h, step size for integration across the ith step,
Xi+l - Xi. 9. Calculate the values fj, j = 1, 2, . . .,n, using the
n t n, number of first-order differential equations. current x and Yj values. These are equivalent to the
Yj +- yji, j = 1, 2, . . ., n, solution values for the n equa- values kj3, j = 1,2, . . ., r1, of (6.3.8f).
tions at xi. Fj+fj(x,Yl,Y2, . . ., Y,) = kj3
Then (6.3.8) may be described by a five-pass procedure.
Pass 1
1. Calculate the values f;., j = 1, 2, . . ., n, using the
current x and Yj values. These are equivalent to the Pass 4
values kjl,j = 1, 2, . . ., n, of (6.3.8b). 10. Add the contribution of kj3 to $j, j = 1,2, . . ,,n, in
F j +--f,(x,Yl,Yz,. . ., Y,) = kjl (6.3.8a).
=fj(~iryli?y2i,. . ., y,i), j = 1, 2, . . -,n.
(6.3.9)
Pass 2
2. Save the current values Yj, j = 1, 2, . . ., n, in another
.
1 1. Compute the values Jj*i,j = 1, 2, . ., n, in (6.3.8g)
and assign them to elements of the vector Y.
vector of equal length, 7, This assigns the solution
values at the beginning of the ith step to the vector
E.vample 6.3 Rruige-Kirtta Metllod-Transient Behavior of a Resorlarrt Circrtil 369
R U N G E signal the calling program to indicate whether tile
i2. Increment .x to the value needed in (6.3.831). Fj,j = 1, 2, . . ., 17, of (6.3.24) are to be computed (fol-
lowing the first four passes) or not (when integration
across one step is completed following the fifth pass). Let
the value returned be 1 when the Fj are to be evaiuated
i i.Calculate the values .fj,j = I, 2, . . ., n, using the and 0 when one complete integration step is conlpleted.
current x and Y, values. These are equivalent to the The main program used to test the function R U N G E
values k j 4 ,j = 1, 2, . . ., n, of (6.3.8h). solves the second-order ordinary differential equation
(6.3.2) subject to initial conditions (6.3.3). Since the
charge, q, on a,capacitor is related to the capacitance, C,
and voltage, V, by %?
q = CV, (6.3.25)
Pass 5
the current, i, into the capacitor is given by
14. Complete the evaluation of q5,, j = 1, 2 , . . ., n, in
(6.3.8a).
and are the only ones that refer directly to the n differen-
tial equations, f,,j = 1, 2., . . ., n, of (6.3.1). Therefore, it
is possible to write a general-purpose function called
R U N G E that implements all parts of the procedure out- x = t.
lined, except for initialization of n, x , h, and Yj, j = 1, 2, Then
..., n, and steps (6.3.9), (6.3.14), (6.3.17), and (6.3.21).
The calling program will then contain all information
about the specific system of differential equations, and
be responsible for printing results, changing the step size, dYz d2V
-
RdV 1
rr--- R y 1
2 -
terminating the integration process, and evaluating the dx dt2 L dt LC L --
LC'7l
F, when needed. (6.3.31)
The five passes of the algorithm can be handled by five The initial conditions of (6.3.29) are
different calls upon RUNGE, as shown schematically
in Fig. 6.3.2. Let a step counter, m, preset to 0, be main-
tained by the function RUbdGE,and let thevaluereturned by
The Approximation of the Solution of Ordinary Differential Equations
Initialize
x, h, n,
Y j ,j = 1, . . ., 11
Flow Diagram
Main Program Y r
Vl '-Vo
t4-0 v2 4- 0
~2+---
1 R2
CL 4L2
r--I----------
I
-- 1
I
v
-0
i
I
71" yj
cPj+Fj X4-x+-
h Return
h 2
Yj+ Y j + I F j
I
CPjccPj+2Fj Return
h
Yj4- Y'j + Fj
_---------------
ajc4, + 2Fj Return
Y j + Yj f hFj
C
m is assumed to be: preset to zero, before RUNGE is called for the.first time.
372 The Approximation of the Solution of Ordinary Differential Equations
FORTRAN Implementation
List of Principal Variables
Program Symbol Dejinition
(Main)
ALPHA, ALPHSQ and ii2, respectively.
cc
c Capacitance, C, farads.
F Vector of derivative approximations, Fj (see (6.3.24)).
H Step size, h.
HL Inductance, L, henries.
ICOUNT Step counter.
IFREQ Frequency of intermediate printout. Solutions are printed at t = 0 and after every IFREQ steps
thereafter.
Variable to control plotting of solutions on printer. If IFPLOT = I, a plot is prepared by calling
on PLOTI, PLOTZ, etc.; if IFPLOT # 1, no plot is prepared.
IMAGE Large vector used to store image of plot before printing.
K Value returned by RUNGE. If K = 1, the elements of F are to be calculated, if K # 1, one step
of the integration is completed.
PLOT1, PLOT2, Subroutines used for preparing on-line graph of V against t. See Examples 7.1 and 8.5 for further
PLOT3, PLOT4 details.
R Resistance, R, ohms.
R02L Rl(2L).
T Time, t , sec.
TMAX Upper limit of integration, t,,,, sec.
TRUV True voltage at time t , V,, calculated from analytical solutions.of (6.3.2) subject to initial condi-
tions (6.3.3).
Vector of solutions of(6.3.2) computed by the function RUNGE. V(1) = V, volts. ~ ( 2 = ) dV/dt,
volts/sec.
VZERO Initial voltage across capacitor, V,, volts.
(Function
RUNGE)
J Subscript, j
M Pass counter for the Runge-Kutta algorithm, m. Must be preset to 0 before first call upon
RUNGE.
N Number of equations, n.
PHI Vector of values, cjj.
SAVEY Vector of initial conditions, Yj (see (6.3.10)).
A Independent variable, x.
Y Vector of dependent variable (solution) values, Yj.
.Example 6.3 Runge-Kutta Method-Transient Behavior of a Resonant Circuit
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 6 . 3
C ELECTR I CAL TRANS l ENTS US l NG THE RUNGE-KUTTA METHOD
I-:
T H I S TEST PROGRAM CALLS ON THE FUNCTION RUNGE TO SOLVE
THE D I F F E R E N T I A L EQUATION V"
TO THE I N I T I A L CONDITIONS V(O.0)
= -R+V1/HL - V / ( H L * C ) SUBJECT
= VZERO AND V ' ( O . 0 ) = 0.0.
V ( 1 ) AND V ( 2 ) ARE THE VALUES OF V AND V' RESPECTIVELY. F(1)
AND F ( 2 D ARE THE D E R I V A T I V E S OF V ( 1 ) AND V ( 2 ) RESPECTIVELY.
R, HL, AND C ARE THE RESISTANCE, INDUCTANCE, AND CAPACITANCE
( I N OHMS, HENRIES, AND FARADS) OF A C I R C U I T (SEE F I G U R E )
I N WHICH THE CAPACITOR I S CHARGED TO A VOLTAGE VZERO A T T I M E
ZERO. T ( T I M E I N SECONDS) I S THE INDEPENDENT VARIABLE, H I S
THE STEPSIZE, AND TMAX THE UPPER INTEGRATION L I M I T USED I N
THE RUNGE-KUTTA INTEGRATION. THE EQUATION W I T H THE G I V E N
I N I T I A L CONDITIONS DESCRI BES THE DAMPED OSCl L L A T l O N OF VOLTAGE
ACROSS 'THE CAPACITOR UPON CLOSURE OF THE C I R C U I T . TRUV I S
THE ANAI-YTI CAL SOLUTION WHICH A P P L I E S FOR THE UNDER-DAMPED,
CRl T I CALLY DAMPED OR OVER-DAMPED CASE DEPEND1 NG ON THE VALUE
OF A L P H S Q = l / ( C * H L ) - R * R / ( 4 * H L * H L ) ( P O S I T I V E , ZERO, AND NEGATIVE
VALUE RESPECTIVELY). K I S THE VALUE RETURNED BY THE FUNCTION
RUNGE. I T EQUALS 1 WHEN THE D E R I V A T I V E S ARE TO BE
CALCULATED AND 0 WHEN INTEGRATION ACROSS ONE STEP I S
COMPLETE. ICOUNT I S A STEP COUNTER. RESULTS ARE PRINTED
AFTER EVERY IFREQ INTEGRATION STEPS. I F I F P L O T = 1, THE
RESULTS ARE ALSO 'PLOTTED USING THE LI BRARY SUBROUTINES
PLOT1, PLOTZ, PLOT3, AND PLOT4.
I M P L l C l T WEAL*8(A-H, 0-2)
l NTEGER RLINGE
DIMENSION F ( 2 ) , V(2), IMAGE(1500)
C
C .....
READ AND P R I N T DATA
1 READ ( 5 , 1 0 0 ) R,HL, C,VZERO,H,TMAX,
..... I FREQ, l FPLOT
WRITE ( 6 , 2 0 0 ) R,HL,C,VZERO,H,TMAX, IFREQ, I F P L O T
C
C .....
T = 0.0
I N I T I A L I Z E T, V(1), V(2), AND ICOUNT .....
V ( 1 ) 0 VZERO
V ( 2 ) = 0.0
ICOUNT = 0
C
C ..... COMPUTE ALPHSQ AND ALPHA, P R l N T HEADINGS
ALPHSQ = l . / ( C * H L ) -
R*R/(4.0*HL*HL)
.. ..,
ALPHA DSQRT(DABS(ALPHSQ))
R02L = R/(Z.*HL)
I F ( IFPLOT.NE.l GO TO 3
CALL P L O T l ( 0, 5, 11, 6, 1 9
CALL PLOT2( IMAGE,TMAX,O., DABS(VZERO),-DABS(VZER0)
3 WRITE ( 6 , 2 0 1 )
C
C
C
..... COMPUTE
..... I S C l RCUl T OVER-, CRI T I CALLY-, OR UNDER-DAMPED .. ...
A N A L Y T I C A L SOLUTION, P R I N T AND PLOT .....
4 I F (ALPHSQ) 5, 6, 7
5 TRUV = VZERO*DEXP( - R O Z L * T ) * ( (1. +ROZL/ALPHA)+DEXP(ALPHA+T)
1 +(I.-ROZL/ALPHA)*DEXP(-ALPHA*T))/2.0
GO TO 8
6 TRUV = VZERO+DEXP(-R02L*T)+(1. + ROZL*T)
GO TO 8
7 TRUV = V Z E R O * D E X P ( - R O Z L * T ) * D C O S ( A L P H A t f - D A T A N ( R O Z L / A L P H A ) )
1 /(ALPHA*DSQRT( C+HL)
8 I F ( IFPLOT.NE.l GO TO 1 0
CALL PLOT3( l H + , T, V ( l ) , 1, 8
10 WRITE ( 6 , 2 0 2 ) T,V(l),TRUV,V(Z)
A
L
C
11
.....CALL ON THE FOURTH-ORDER RUNGE-KUTTA FUNCTION
K = RUNGE( 2, V, F, 1, H )
.....
374 The Approximalion of the Solution of Ordinary Diferenlial Equations
C
C
13
.....
IF
I F T EXCEEDS TMAX, TERMINATE
T.LE.TMAX
( GO TO 1 6
INTEGRATION .....
I F ( IFPLOT.NE.l ) GO TO 1
WRITE (6,203)
CALL PLOT4( 7, 7HVOLTAGE
WRITE (6,204)
GO TO 1
16 ICOUNT = ICOUNT + 1
C
C .....
IF
PRINT RESULTS OR
ICOUNT.NE.IFREQ
( )
CALL DIRECTLY ON RUNGE
GO TO 11
.....
ICOUNT = 0
GO TO 4
C
C
100
..... FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT ( 9X, F7.2,14X,F6.2,14X,E6.1/ lOX,F6.2,14X,F7.5,13X,F6.3/
.....
200
201
1
1
2
l o x , 14,16X,ll
FORMAT ( l O H l R
E14.1
= ,F14.5/
/ 1 0 H VZERO = ,F14.5/
F14.5/ 1 0 H IFREQ = , I 8
FORMAT ( 64HO T
10H HL
10H H
= ,F14.5/10H C
,F14.5/10H
/ 10H I F P L O T = , 1 8
CALC. V
- TMAX
TRUE V
•
I
=,
1 CALC. V' / 1H
202 FORMAT ( 1H , F10.5, 2F18.8, F18.5 )
C
203
204
FORMAT ( 1 H 1 )
FORMAT ( 1H0, 54X, l 6 H T l M E -
(SECONDS) 1
END
Function RUNG E
FUNCTION RUNGE( N, Y, F. X, H
C
C THE FUNCTION RUNGE EMPLOYS THE FOURTH-ORDER RUNGE-KUTTA METHOD
C WITH KUTTA'S COEFFICIENTS TO INTEGRATE A SYSTEM OF N SIMULTAN-
C
C
C
(J=1,2, ...,
EOUS F I R S T ORDER ORDINARY DIFFERENTIAL EQUATIONS F(J)=DY(J)/DX,
N), ACROSS ONE STEP OF LENGTH H I N THE INDEPENDENT
VARIABLE X, SUBJECT TO I N I T I A L CONDITIONS Y(J), (J=1,2,...,N).
C EACH F ( J ) , THE DERIVATIVE OF Y(J), MUST BE COMPUTED FOUR TIMES
C PER INTEGRATION STEP BY THE CALLING PROGRAM. THE FUNCTION MUST
C BE CALLED F I V E TIMES PER STEP (PASS(l)...PASS(S)) SO THAT THE
C INDEPENDENT VARIABLE VALUE ( X I AND THE SOLUTION VALUES
C (Y(l)...Y(N)) CAN BE UPDATED USING THE RUNGE-KUTTA ALGORITHM.
C M I S THE PASS COUNTER. RUNGE RETURNS AS I T S VALUE 1 TO
C SIGNAL THAT ALL DERIVATIVES (THE F C J ) ) BE EVALUATED OR 0 TO
C SIGNAL THAT THE INTEGRATION PROCESS FOR THE CURRENT STEP I S
C FINISHED. SAVEY(J) I S USED TO SAVE THE I N I T I A L VALUE OF Y ( J )
C AND P H I ( J ) I S THE INCREMENT FUNCTION FOR THE J ( T H ) EQUATION.
C AS WRITTEN, N MAY BE NO LARGER THAN 50.
C
I M P L I C I T REAL*8(A-H, 0-2)
REALe8 Y, F, X, H
INTEGER RUNGE
DIMENSION P H l ( 5 0 1 , SAVEY(SO), Y(N), F(N)
DATA M/O/
C
M = M + l
GO TO (1,2,3,4,5), M
-
t?
C! .....
PASS 1 .....
1 RUNGE = 1
RETURN
Example 6.3 Runge-Kutta Method-Transient Behavior of a Resonant Circuit
.....
DO 33 J
PASS 3 .....
1, N
P H I ( J ) = P H I ( J ) + 2.O*F(J)
Y(J) = SAVEY(J) + 0.5*H*F(J)
RUNGE = 1
RETURN
..... PASS 4
DO 44 J = 1, N
.....
PHI(J) = PHICJ) + 2.O*F(J)
Y(J) = SAVEY(J1 + H*F(J)
X = X + 0.5*H
RUNGE = 1
RETURN
..... PASS 5
DO 5 5 J = 1, N
.....
Y ( J ) = SAVEY(J) + ( P H I ( J ) + F(J))*H/6.0
M - 0
RUNGE = 0
RETURN
END
Data
R
VZERO
1FREQ
R
VZERO
1FREQ
R C
VZERO TMAX
l FREQ
R C
VZERO MAX
IFREQ
R -C
VZERO TMAX
l FREQ
R C
VZERO TMAX
l FREQ
R C
VZERO TMA X
l FREQ
R C
VZERO TMAX
l FREQ
R C
VZERO TMAX
l FREQ
R C
VZ ERO TMA X
l FREQ
The Approximation of the Solution of Ordinary Differential Eq~iations
Example 6.3 Runge-Kutta Method-Transient Beha~iorof a Resonant Circlril
a013
- o m
N r l -
m o m
-3.0
...
O N N
I
mmID m o r
W N r l m 3 a
m o m f Dl0
0 0 m 0 0 0 m o m I D d d
OOOOri O
00 I 0 0 0
O O D O O N
O m N O O O
-
<
L
a u u u u
00000000000000000000
00000000000000000000
r l N m = m w r - m r n o - + ~ m f ~ w - - m ~
L
G, n u u +
O O O O O O O O O O O O O O O O O O O O
00000000000000000000
rlNmfmwP--marl-mfmwr-o.
..
8 Y ,I C- tr It Y 11 tl 0,s
'1
-r
C-
0 0 0 O O O O O O r l r l r l ~ r l d r l d d r l N
.....................
000000000000000000000 *
u
4 0 a0
C
0 0 0 0 0 0 0 0 0 4 r l d . + 3 ~ 3 3 r+ N
.....................
O O O O O O O O O O O O O O O O O C C O O
rz O0 O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O C
3
,- W
X W - 1
dMCL 2 DI
W
X W - I
d m -
m w w f N h n m n
m w o mmm rlmm
mLOn 0 a 0 OIDO
m*N N h N mmw
* m a m h m -001
ID*+ m a Ln
W f N m o m m m N
....
m f h rlmm
... ...
0 0 0
mwm - d m o m ~ m
m o m o m - o r l a m rml m
ID
0,-it - m a O O f N mm
mmm m m w o a m w mm
am"? O m N O f m m
IDID4 m f 3 o w a r l Im D3W
m n o OIDf N rlm
......
Po*-
mmw
WNm
m f rl
-rim
....
o m a h
Ohm",
r(
..
0 0
0
I I I rl
I-
z
0 a0
X W - I
w acc~
A N ruu
LLZU>IC--
Computer Output (Continued)
Results for the 6th Data Set Results for the 7th Data Set
R I 100.00000 R = 300.00000
HL = 0.50000 HL I 0.50000
C I 0.2D-05 C I 0.2D-05
VZERO = 10.00000 VZERO = 10.00000
H = 0.00010 H = 0.00100
TMAX = 0.02000 TMAX = 0.02000
IFREQ = 10 IFREQ = 1
IFPLOT = 0 IFPLOT = 0
0.0
-7627.57558
-7516.16529
-1161.44732
5009.23693
5886.98405
1699.77815
-3144.90741
-4490.63369
-1850.20820
1853.43882
3341.19041
1774.91974
-986.54239
-2425.31507
-1582.17716
426.61390
1715.76066
1341.41766
-82.92239
-1179.97185
Results for the 8th Data Set Results for the 9th Data Set
R I 100.00000
HL I 0.50000 R =
C I '0.2D-05 HL .
i
VZERO = 10.00000 C I
H I 0.00200 VZERO =
TMAX = 0.02000 H .L
-
IFREQ = 1 TMAX =
IFPLOT = 0 IFREQ =
IFPLOT
T CALC. V TRUE V CALC. V'
CALC. V TRUE V CALC. V'
Example 6.3 Runge-Kutta Method-Transient Behavior of a Resonant Circuit
cision arithmetic. Only the plotted output is shown for Numerical Analytical Error
the under-damped solution resulting from the input Step size, h Solution, V Solution, V, V- V,
(Set) (Volts) (Volts) (Volts)
parameters of the 1st data set. Results for the 2nd, 3rd,
and 4th data sets correspond to an undamped (R = O),
critically-damped (R = 1000), and over-damped soiu-
tion, respectively. For the step size used, h = 0.0001, the
numerical solutions agree with the appropriate analytical
solution of (6.3.5), (6.3.6), and (6.3.7) to five or six
significant figures.
Results for data sets 5 through 10 show the influence of For small step sizes, the solutions computed by the
the step-size h, on the numerical solution for an under- Runge-Kutta fourth-order method are extremely accu-
damped case (see plotted output for data set 1). Table rate. The truncation error increases with increasing step
6.3.1 shows the calculated solution, V, the true solution, size, until the solution eventually "blows up" and bears
V,, and the error, V - V,, at time t = 0.02 sec. Because no resemblance to the true solution. This is not surprising,
double-precision arithmetic has been used throughout, in view of the fact that the period of oscillation for the
and the total number of integration steps is no larger solution is 2411 = 0.00628 sec. As the step length ap-
than 2000 fcr any case, the error may be attributed solely proaches the period of oscillation, virtually all local
to truncation effects; any round-off error'is negligible in information about the curvature of the solution function,
comparison. V,, is lost.
6.9 Open Integration Formulas
I
with initial condition yo = y(xo). This has been accom-
plished for Euler's method (6.28) by integration across a
series of single intervals to yield successively,
and yi,l will not yet have been computed. All the com-
mon multistep methods are described by
For an integration involving k + 1 intervals terminating Xi+ I
at x i + l , this can be written as
it 1 = ~ +J
i - r
xi-k
4 ( x )dx, (6.82)
where 4 ( x ) = zr=o
ajxi. Here, r is the degree of the
interpolating polynomial.
where t,hi(x)is a step-functio~nwith ordinates& =f ( x j , y j )
on the half-open intervals [ x j , x j +,), j = i - k, . . ., i. The 6.9 Open Integration Formulas
integral in (6.81) can be viewed as the area between the Since the xi are evenly spaced, and the values fi, f i - l ,
limits xi-, and x i + , shown in Fig. 6.4. fi- 2 , .. .,A-,, are known,
$(x) is given in simplest form
It seems clear that replacement of the function t,bi(x) in by Newton's interpolation formula based on the back-
(6.81) by an interpolating yolynominal 4 ( x ) that passes ward finite differences of xi, already developed in
through the points ( x j , f j )for j near i'might well lead to (1.61):
more accurate algorithms. VZf
The derivations are similar to those used in generating $(xi + ah) =fi+ aV fi + a(a + 1 ) -2!
i
That is,
382 The Approximation of fh@ Sofutbti of Ordinary Differential Equations
With a suitable renumbering of subscripts, (6.84) can integration is [xi- ,,xi+,I. Similar statements hold for
be shown to be equivalent to the open Newton-Cotes the other members of (6.85). All the information required,
integration formulas of (2.30). that is, yi,f (xi,yi), yi- l , f( x i - ,,yi- ,) . . . etc., is known,
Fork = 0,1,2, and 3, equation (6.84) leads to the follow- since the integration is presumed to have proceeded to
ing algorithms : x i already.
Note that for the odd values of k, the coefficient of the
kth backward difference is zero. For this reason, the
most commonly used formulas of this type are for k odd
+
with just k l terms retained (that is, r = k). The
+
(k I)th term is zero in these cases, so that the inter-
polating polynomial is actually of degree r - 1 rather
than of degree r as would be expected. Of course, any
number of terms could be retained. When the formula is
terminated with the (r + 1)th term, that is, when the last
included term involves V"f,/r!, the error term is
h"'1
-k
a(a + l ) ((ra ++2)l ) .!. . ( r + r) IC/""'(()da,
< ( < xi+ ,. (6.86)
From (6.85), the most important open formulas are:
k=O,r=3:
h
Yi+t =Yi-1 +j(fi+l +4/,+/,-,), R=o(~').
(6.95b)
k=3,r=5:
2h
For these formulas, the error term for truncation after Yi+l = yi-3 + -45( 7 f i + l + 32fi + 12fi-1
the term involving the rth difference is
-
(a - l)(a)(a+ l ) ( a + 2 ) . .( a + r - 1)
+ 32fi-2 + 7 f i - , ) , R = 0(h7).
(6.9%)
hr" 1-L +-
( r I)! The situation for the case k = ,I,r = 3 is shown in Fig.
6.7.
x I)('+')(<) da, x i - , < 5 < x i + l . (6.93)
For k odd, the coefficient of V k + * f i +vanishes.
, There-
fore, the most frequently used formulas of this type are
for k odd, with r = k + 2. Three of the more important
closed formulas are :
k=O,r=3;
starting values are needed at just one point, and that Modijied Adants or Adams-Moulton method:
the step size can be adjusted from step to step with little Predictor:
difficulty. On the other hand; the fourth-order method of
(6.96) has the disadvantage that it is not self-starting,
since values of the solution are needed at both xo and x1
before the method can be applied for the first time; in
addition, as described in the next section, a change in the Corrector:
step size, while possible, is rather cumbersome. The
principal advantage of (6.96) is that it can be used to
produce solutions to differential equations (with accuracy
comparable to that for a fourth-order Runge-Kutta
method) with as few as two derivative evaluations per Many other predictor-corrector methods are also used
s t e P , f ( x i + l , ~ i + ~a, n~d) ,f ( x i + ~ , ~ i + l , l ) . (see Section 6.13 for another important method). The
Fortunately, we already have very good algorithms for general naming conventions for the integration methods
estimating yi+,,,, namely, the open formulas of Section that employ the open and closed integration formulas
6.9. The usual practice is to select an open and closed are as follows:
formula with comparable order for the local truncation
error. The open formula is used to predict the value Name of Method Mode of Operation
yi+,,,, and the closed formula is then used to correct the
estimate by an iterative computation similar to (6.96). Adams or Adams-Bashforth Use of predictor equa-
The open formula is usually called the predictor and the tions only.
closed formula is called the corrector; algorithms which Moulton Iterative use ofcorrector
use the predictor and corrector as,outlined above are equations only.
called predictor-corrector methods (see also page 362). Modified Adams Use of predictor fol-
Three of the commonly used predictor-corrector methods lowed by iterative use
are the fourth-order and sixth-order Milne methods [5] of corrector, k = 0 for
and the fourth-order modijied Adams or Adams-Moulton both equations.
method which use predictors and correctors already Milne Use of predictor fol-
developed in Sections 6.9 and 6.10. lowed by iterative use
of corrector, k # 0 for
Fourth-order Milne method: either equation.
Predictor :
6.12 Truncation Error, Stability, and Stepsize Control
in the Multistep Algorithms
One of the virtues of the predictor-corrector methods
of the preceding section is that we can estimate and then
correct for local truncation errors, by assuming that the
Corrector :
error terms [for example, (6.100) and (6.101)] apply.
The approach is probably best illustrated by an example.
Consider the fourth-order Milne method of (6.88~)and
(6.95b). Given the differential equation dyldx =f (x.y), a
specified step-size h, and starting values for yo, y,, y,, )I,,
Sixth-order Milne method: fo,fi, fi, and f3 (usually yo is given, and y,, y,, and y, are
Predictor : computed by using a fourth-order Runge-Kutta method).
the algorithm proceeds step-by-step for i = 3.4. 5. ...
(here x, = x, + ih) as follows:
1. Calculate yi+,,, using the predictor (6.88~).
Fortunately, relationships such as (6.103) and (6.107) Subsequent analysis has shown that, under certain
provide sufficient information to determine when the conditions, some of the multistep methods exhibit
step size should be increased or decreased. Unfortu- catastrophic instabilities which render the numerical
nately, the mechanism for implementing such changes is solution meaningless. Such instabilities develop even
not very straightforward. The difficulty is that when the though the equations are inherently stable (see page 364),
step size is changed, the necessary starting values for the and cannot in general be removed by step size adjustment
predictor and corrector will not usually be available. (hence the instability cannot be a partial instability as
Assume that integration has proceeded without difficulty described on page 365).
to base point xi using step-size h,, and that integration The nature of the stability problem is easily illustrated
across the interval [xi,xi+,]leads to convergence prob- by an analysis of the solution of the simple linear ordinary
lems for the corrector (for example, if more than one or differential equation with constant coefficient a,
two iterations are required) or to a truncation error larger
than desirable. Then one approach would be to decrease
the step size by some amount and restart the integration
procedure at xi using the new step-size h,. For an arbi- using a multistep algorithm. Many analyses reported in the
trary h,, about the only choice available is to use a one- literature begin with an arbitrary equation, but assump-
step method to generate the necessary starting values tions to retain only linear terms and to require that dfldy
yi+,, yi+,, . . ., etc., required to reintroduce the multistep be constant often follow, and the equation actually being
method for subsequent integration. A similar procedure being studied is (6.1 11).
can be followed if the estimated truncation error is much
If the corrector equation in a predictor-corrector
smaller than actually required and the corrector equation
method is iterated to convergence for each integration
requires only one or two iterations for convergence,
step, then any error in the observed solution can be
except that the new step-size h, is now larger than h,.
attributed solely to the corrector. Hence, it is sufficient
If the new step-size h, is chosen to be 2h1 and a suf-
to study the propagation of error by the corrector
ficient number of "old" values, yi-l, yi-2,. . ., and
equation alone. When the correttor is not iterated to
fi-,, fi-,, . . ., have been retained, then the change is
convergence, but is employed just once (often the case
relatively simple. One need only reassign subscripts so
in practice), then the stability analysis must include
that the "old" yi-, becomes the "new" yi-,, the "old"
errors generated by both the predictor and corrector
yi-, becomes the "new" yi-,, etc.
equations [7]. To illustrate, we shall assume that the
If the new step-size h, is chosen to be h,/2, then some
corrector is iterated to convergence.
but not all of the solution and derivative values for the
Since the corrector equation (6.95b) for the fourth-
predictor and corrector will be available. The old yi-,
order Milne method is observed to produce catastrophic
becomes the new yi-,, the old yi-, becomes the new
instabilities for solution of some differential equations
yi-,, etc.; certain values, yi-,, yi-,, etc., will be missing.
(but excellent results for others), a stability analysis will
One approach is to use a one-step method to compute
illustrate the general approach. Other multistep methods
yi-, starting with the new yi-,, and to compute yi-3
can be analyzed similarly.
starting with the new yi-,; another approach is to inter-
The Milne corrector is
polate on the available new values yi, yi-2, yi-,, . . ., to
estimate the missing new values yi-,, yi-,, . . ..
In practice, the step-size h is usually changed by doub-
ling or halving it as described above. Clearly, too-frequent Substitution of (6.11 1) leads to
changes in the step size will vitiate the principal advantage
of the multistep methods-their computational speed.
In the early 1950's, when computers were first widely
used for solving ordinary differential equations, investi- (6.1 12)
gators discovered that for some equations certain of the which is a linear homogeneous difference equation of
multistep methods led to computational errors far larger order two. Note that for a fixed h, the coefficients are
than expected from local truncation errors (equations constants, and that the convergence criterion of (6.98)
witti k ~ i o w ~analytical
i solutions were used in these requires that
studies). It was also discovered that a decrease in step
size often resulted in an increase in the observed error,
even when round-off errors were known to be insigni-
ficant. In some cases, the numerical solution showed little, The theory of the solution of linear difference equations
if any, relationship to the true solution of the equation such as (6.112) is closely related to the theory for the
being solved. solution of linear ordinary differential equations. We
6.12 Truncation Error, Stability, and Si!ep-Size Conlrol in the Multistep Algorithms 389
shall give only a brief outline of the theory here; those Milne and Reynolds [31] have tabulated the values of
unfamiliar with it are referred to the excellent introduc- these two roots for values of ah between - 1 and 1.
ticii to difference equations by Conte [30]. Root y, i s positive for all ah in this range and is monotone
If we let yk be a function defined for a set of integers k, increasing from 0.366 at ah = - l to 2.732 at ah = 1.
then a linear drfference equation of order n is a linear Root y2 is negative for all ah in this range and is monotone
.
relation involving yi, y,,,, . ., y,,,, that is, it is of the increasing from - 1.366 at ah = - 1 to -0.732 at ah = 1.
form A critical feature of y, is that for negative ah, it is smaller
than - 1 and for positive ah, it is larger than - 1. If we
set h equal to zero, the roots are y, = 1 and y, = - 1.
where the coefficients a!o, . . ., a, and b may be functions Since the convergence criterion (6.1 13) requires that luhl
of k but not of y. If b is zero, the equation is considered be smaller than 3, and for rapid convergence preferably
to be homogeneous; otherwise it is called nonhomogeneous. much less than 3, values of ah between - 1 and 1 are
The theory for solution of homogeneous linear dif- those which would be encountered in practice.
ference equations with constant coefficients is similar to Now, if y, and y, are expanded in a power series [31],
that for homogeneous linear differential equations with they are, respectively,
constant coefficients. In this case, we look for a solution (ah)' (ah)3 (ah)4 (ah)'
of the form y, = yk. Substitution of this solution into y1 = l + a h + - + - +- +- + ...
2! 3! 4! 72
(6.1 14), with b = 0 and a,, . . ., an constant, yields
First consider the case a > 0. Since h is positive, ah more rapidly. Jf the true solution of (6.11 1) grows with
will be positive, and the solution of the difference equa- increasing i, then the parasitic solutions must either decay
tion associated with y, will grow exponentially as ceuxg, or grow less rapidly than the true solution.
approximating a true solution to the differential equation. A method is called strongly stable if
For positive ah, the root y, is a negative fraction greater
than - 1. Therefore, the particular solution y\ will decay
with increasing i, and will have only minor influence on Thus, for a method to be strongly stable, all parasitic
the complete solution. Thus errors introduced at various solutions must decay with increasing i.
stages during computation (by local truncation errors or Dahlquist [32] has shown that if the truncation error
round-off errors) will not be amplified in succeeding for a multistep method is of O(hP+'),and n is the order
steps because of the presence of the parasitic solution. of the difference equation, then to achieve either strong
Next, consider the case a < 0. Since h is positive, ah will or marginal stability, p must satisfy the relationship
be negative, and the solution of the difference equation
associated with yl will decay exponentially as ceuxz,
approximating a true solution to the differential equation. +
Moreover, p. = n 2 is possible only when n is even and
For negative ah, the root y, is a negative number less the method is marginally stable (for example, Milne's
than - 1. Hence the particular solution y: will grow in fourth-order corrector for which n = 2 and p = 4). Thus
magnitude with increasing i. In fact, because y, is nega- one can increase the accuracy of a method (increase the
tive, the solution will oscillate in sign from step to step. order of the truncation error) only by increasing the
In this case any errors introduced during the computation value of n, and consequently, the number of parasitic
will be amplified during succeeding steps with alternating solutions associated with the difference equation. Thus,
signs. Eventually, this parasitic solution will swamp the diminished stability is the price one must pay for increased
true solution and the numerical results will be meaningless. accuracy in a multistep method. Stability analyses for
Methods which exhibit stable behavior for the solution several new predictor-corrector algorithms have been
of equation (6.111) for some values of ah and unstable published in recent years [33, 34, 35, 36, 37, 391.
behavior for other values of ah are said to be weakly The preceding stability analysis has dealt with the
stable, weakly unstable, or marginally stable. Hence the solution of the very simple linear equation of (6.1 11).
fourth-order Milne corrector is a marginally stable The question of applicability of the conclusions of the
method. This does not mean that the method should not simple stability analyses to more general nonlinear
be used, but only that it should not be used when the equations remains unanswered. Henrici [2] believes that
true solution of the equation is a nonincreasing (decaying) the variability of aflax may make a significant difference
function. Under other circumstances, the Milne corrector in the stability of a method, for example, changing a
is perfectly suitable and, because of its small truncation strongly stable method into a marginally stable one for
error, even desirable. certain equations. Computational experiments have
Similar analyses can be carried out for any of the shown, however, that conclusions about stability, follow-
multistep algorithms. In each case, the appropriate ing from stability analyses for equation (6.11 l), cor-
homogeneous linear difference equation with constant relate rather well with observed behavior of the multistep
coefficients is found for equation (6.111). The character- methods when used for other equations as well.
istic equation is then solved for the roots y,, y,, . . ., y,, Simultaneous ordinary differential equations (see Sec-
where n, the order of the equation, is equal to the dif- tion 6.7) may be solved by multistep methods as well as
ference of the largest and smallest subscript which appears by one-step methods. The appropriate algorithm is
in the multistep equation. For example, for the Milne implemented for each equation in parallel at each step.
corrector, the largest subscript is i + 1 and the smallest The criteria for solution of simultaneous corrector
is i - 1; the order of the difference equation and thus the equations by the usual method of successive substitutions
number of solutions is (i + 1) - (i - 1) or 2. are those outlined in Section 5.8. Henrici has devoted an
Let y , be the root of the characteristic equation which entire book [28] to a study of the solution of systems of
is associated with the true solution of (6.1 11); then y, is equations by multistep methods.
called the principal zero or root. If
6.13 Other Integration Formulas
IyjI < IYII, j = 2, 3, . . ., n, (6.126)
Hamming [21, 221 has investigated a general class of
the method is called relatively stable. In this case, the corrector formulas of the form
approximation to the true solution will dominate the
parasitic solutions associated with the roots y j , j =
2, 3, . . ., n. If the true solution of (6.1 11) decays with
increasing i, then the parasitic solutions must decay even
6.13 Other lntegrarion Formrtlas 391
which includes the correctors for the fourth-order Milne 2. The predicted solution y i + ,,, is computed using the
and Adams-Moulton predictor-corrector methods. Five fourth-order Milne predictor as in (6.102),
of the seven constants in (6.129) can be eliminated by
requiring that the formula be exact for polynomials of Y ~ + I , O= Yi-3 + gh(2fi -fi-I + 2fi-2).
degree four or less, that is, exact for the functions 3. The predicted value is modified, by assuming that
~ ( x=) xjx2, x4. This process is the method the local truncation error on successive intervals does not
of undetermined coefficients, and leads to the following change appreciably, to yield
relationships among Ithe constants, taking a, and a, as
the parameters: 112
1
Y,*, 1.0 = Yi+ 1.0 +-
121
(~i.k- ~i.0). (6.133)
a. = 1 - a , - a, b -
O - 2 4
(19 + 13a1 + 8a2)
This modification is analogous to that of (6.110) for
1 Milne's method. For the case i = 3, this step is bypassed,
a , ==a, b - (-5
'-24 +
13a, + 3 2 ~ ~ ) since there will be no values for the elements on the right-
-
hand side of (6.133). Here, y,,, is the solution of the
1 corrector equation (6.134) from the preceding step.
a, = a 2 b - (1-al+8a2)
* -24 4. Hamming's corrector equation of (6.13 1) is solved
iteratively using the successive substitution algorithm
1
b-, = (9 - a,).
24
(6.130)
The derivation of the error term for (6.129) for y(x) not a The initial value for y i + l , j on the right-hand side is
polynomial of degree 4 or less is rather complicated y,*,, ,o from step 3. In theory, iteration is continued until
17, 221 and will not be: discussed here. some convergence test has been satisfied [for example, see
Hamming [22] has studied the stability characteristics (6.103)]. In practice, the corrector is usually applied just
of (6.129) and selected the remaining parameters a, and once; the step size is chosen to insure that convergence
a, to achieve much stronger stability than is exhibited by effectively takes place in just one iteration.
the Milne method corrector; the price paid is some in- 5. The values Y ~ + , ,from
~ step 4 and y i + , from
crease in the magnitude of the truncation error. The form step 2 are next used to estimate the truncation error e, for
of (6.129), selected by Hamming, as representing the best the corrector equation from
compromise between stability and accuracy, is
Assuming that yi, yi-,, fi, and fi-, are known exactly,
the local truncation error for (6.131) is which follows directly from the error terms for the pre-
dictor (6.104) and corrector (6.132), respectively, using
an analysis identical with that outlined on page 387 for
Milne's method [see (6.107))
For practical step sizes, (6.131) is stable in the sense of
,
6. The final value for the solution yi+ is then computed
from
(6.126).
The Hamming corrector can be used .with any suitable
predictor. Hamming's predictor-corrector method employs
the fourth-order Milne method predictor; the technique
of modifying both the predicted and corrected value of which is analogous to (6,108) for Milne's method. The
the solution already outlined for the fourth-order Milne derivative is computed at this final value and ~ a l l e d f , , ~ .
method on pages 386 and 387 is usually followed. The If the local truncation error estimate is within allow-
complete algorithm is: able limits, the counter i is advanced by one and steps 2
through 6 are repeated for the next integration interval.
1. Starting values for YO,Y I ,Y,, ~ 3fo,, f , , f2, and f3 If the local truncation error estimate from (6.135) is
must be available. Usually yo will be the only known outside allowable limits, the step size is adjusted in some
condition, and a fourth-order Runge-Kutta method will fashion (see page 388), and then the integration process is
be used to compute y,, y,, and y,. The derivatives fo, f,, continued.
f,, and f, can be computed from the differential equation
dyldx =-f(x, y). Steps 2 through 6 are then repeated This fourth-order Hamming's method is now among the
for i = 3,4, .... most popular of the multi-step methods.
392 The Approximation of the Solution of Ordinary Differential Equations
Many other one-step and multistep algorithms are for which the evaluation of derivatives requires relatively
available for solution of first-order ordinary differential little computing time.
equations. Milne [5] and Henrici [2] give particularly There is also a variety of one-step and multistep
complete coverage of the multistep methods. methods suitable for direct integration of equations of
Recently, Butcher [23, 24, 251 has developed several order two or more; the higher-order equation need not
one-step methods of orders five to seven. Gear [26] and be reduced to a system of first-order equations before
Butcher 127, 381 have developed some modified multi- carrying out the numerical solution. Henrici [2] has
step methods of orders four to seven, that have some of pointed out that solutions generated by these direct
the characteristics of both one-step methods (derivative methods are no more accurate than those found by
evaluations are made in the interior of the integration reducing the equation to a system of first order equations
step) and multistep methods (information from previous and then solving the system using methods for first-
steps is used). Waters [29] has compared the performance order equations. However, for equations of special form
of several of these methods with the commonly used (for example, second-order differential equations that do
algorithms (fourth-order Runge-Kutta method, etc.) not contain a term in the first derivative), the direct
from the standpoint of accuracy and computation time. methods may save some computation.
He solves a system of ordinary differential equations
EXAMPLE 6.4
HAMMING'S METHOD
-
dy,
dx
= : ~ , ( x , Y ~ , Y. z.,Y,),
,. 3. The predicted solutions, yj,i+l,, are modified (as-
suming that the local truncation error estimates,
using Hamming's predictor-corrector method outlined in j 11 2, . . ., n, will not be significantly different
e j , i + l >=
Section 6.13. from the estimates ej,i,j = I, 2, . . ., n) as in (6.133):
Write a main program that solves the second-order y;,i+ l , o = yj,i+l , o + 112
j =2 , . .. . (6.4.7)
ordinary differential equation
4. The jth corrector equation corresponding to (6.134)
d2Y
-= (6.4.2) is applied for each dependent variable:
-Y,
dx2
Yj,i+l,l = $C9Yj,i - Y j , i - 2 + 3h(fTi+l,0 + 2fj.i -fj,i-l)I,
subject to the initial conditions
j = l , 2 ,..., n, (6.4.8)
where
f:i+ 1,0 I,o,. . ., Y;,i+l,o>.
=f(xi+ I,Y:,~+I,o,Y~*,~+ (6.4.9)
The program should call on the fourth-order Runge-
Kutta function RUNGE, developed in Example 6.3, to The corrector equations in (6.4.8) are being applied just
find the essential starting values for Hamming's algo- once for each variable, the customary practice. The cor-
rithm and, thereafter, should call on HAMING to calculate rector equations could, however, be applied more than
estimates of y and dyldx on the interval [O,x,,,]. Evaluate once, as in (6.134). Note that the subscript j in (6.134) is
the numerical solutions for several different step sizes, an iteration counter, and is not the index, j, on the depen-
h, and compare the numerical results with the true solu- dent variables used throughout this example.
tions 5. Estimate the local truncation error for each of the
y(x) = sin x corrector equations on the current interval as in (6.135):
dY - cos x.
- ej,i+I = +(yj,i+ 1.1 - yj,i+ 1,0), J = 19 2, . . ., n.
dx (6.4.10)
One way to implement the sequence (6.4.6) to (6.4.12) is are available for the function to use upon entry to the
to separate HAMING into two parts, one to handle the +
predictor section, and the 6n 1 essential numbers, h,
prediction portion of the algorithm (equations (6.4.6) and
and (6.4.7)), and the other to handle the correction por-
tion of the algorithm (equations (6.4.8), (6.4.10), and
(6.4.11)). The function can then return to the calling
program after each portion, requesting that the derivative
estimates of (6.4.9) and (6.4.12) be calculated in the main
program or elsewhere, when needed. are available for the function to use upon entry to the
A simplified diagram of the calling procedure for corrector section.
HAMING is shown in Fig. 6.4.1. Note that all direct referen- The simplest way to communicate the necessary num-
ces to the first-order equations are confined to the calling bers in (6.4.13) and (6.4.14) is to maintain tables available
program. Therefore, the function HAMING can be written to both the calling program and the function HAMING.
to solve an arbitrary system of n first-order equations, Most of the bookkeeping tasks of updating the tables,
provided that the 5n + 2 essential numbers, xi, h, and etc., can be assigned to the function, so that the calling
program has little to do except to set up the necessary
tables priorto the first call upon HAMING, and to evaluate
the derivative estimates of (6.4.9) and (6.4.12). Let a 4 by
n matrix Y, a 3 by n matrix F, and an n-element vector C
- Call on predictor
section of HAMING.
+
Predictor section of HAMING
evaluates
~ ~ , i + l , o , 1,2,
j= ., n,
~ ? i + l , o , j =1,2, ., n,
from (6.4.6) and (6.4.7),
Calling program
respectively, and then
evaluates
updates the independent
&yi+i,o,j= 132, n,
f-
- . a ,
variable,
from (6.4.9).
+
= x i h.
A
\f
t
Figure 6.4.1 Communication between a calling program and the function HAMING.
Example 6.4 Hamming's Method
be assigned to the calling program, and available to the F is unchanged from (6.4.20),
function HAMING through the argument list. Then write
the calling program and function HAMING, so that the
matrices Y and F, and the vector Z, have the following
contents at the indicated points in the algorithm.
If the calling program uses (6.4.12) to replace the
Before entry into the predictor section of HAMING: elements in the first row of F after the return from the
corrector section of HAMING, so that
'
...
''
f:i+l,o
fj,i
fj,i- 1
"'
...
f*.
n,t
fn.i
fn.i-1
+ 1.0
I.
(6.4.20)
With (6.4.25) and (6.4.26), the matrix Y of (6.4.15) is
known for i = 3. The matrix F of (6.4.16) may be evalu-
ated from (6.4.26)and (6.4.I) for i = 3. The vector of local
truncation error estimates (6.4.17) for i = 3 is normally
unknown, and should be set to zero unless better values
d is unchanged from (6.4.17). are available from other sourdes. HAMlNG may then be
called for the first time.
After return from the corrector section of HAMING : Jn the calling program that follows, the function RUNGE,
already developed in Example 6.3, is used to generate the
solutions of (6.4.26). Since RUNGE implements the fourth-
order Runge-Kutta method, the solutions of (6.4.26)
should be comparable in accuracy with the solutions
generated by the Hamming's predictor-corrector algo-
rithm, also a fourth-order method.
396 The Approximation of the Solution of Ordinary Differential muations
Flow Diagram
Main Prograin
Implement predictor
calculations (6.4.6)
and (6.4.7) to yield
Y1,j+ ~ : ~ + l , o
j = 1 , 2 , ..., 11
(Function HAMING)
I F1,j + f j , i + ~
J = 1, 2, . . ., 71
(eqn. (6.4.12)) 1 1
Implement corrector
calc~~lations(6.4.8),
(6.4.10) and (6.4.11)
to yield
y ~ , jc Y j , i + ~
-i F1,j +-f.T.
1 r+1,0
j = l , 2 , ...,
(eqn. (6.4.9))
' j +- ' j , t + ~
j = 1,2, ..., n
(Function H A M I N G )
398 The Approximation of the Solution of Ordinary Differential Equations
Yl,i+ YlPj - ej = Y j , i + l
(modifier eqn. (6.4.1 1))
If
4 Return
(modifier eqn. (6.4.7))
I
I I
I
x t x + h Return
Example 6.4 Hamming's Method
FORTRAN Intpitmentation
List of Pritacipal Variables
Program Symbol DeJinition
(Main)
COUNT Step counter, i
F F, a 3 by n matrix of derivative estimates (see (6.4.16), (6.4.19), (6.4.20), and (6.4.23)).
FR Vector of values,A,, j = 1, 2, ..., n. Used by RUNGE.
H h, step size.
SUB 4 --i, a subscript.
INT Print control parameter, inr. Solutions are printed at x, and every int steps thereafter.
J j, index on the dependent variables.
M Value returned by the function HAMING.
N n, number of first-order ordinary differential equations.
RUNOE Function that implements the fourth-order Runge-Kutta method to solve a system of n first-
drder ordinary differential equations. See Example 6.3 for details.
TE .
Vector of local truncation error estimates, ej,i, j = 1, 2, . ., n.
X Independent variable, x,.
X MAX Upper integration limit, x.,
Y Y, a 4 by n matrix of solution values (see (6.4.15), (6.4.18), and (6.4.21)).
YR Vector of values yjSi7j = 1, 2, . . ., n. Used by RUNGE.
(Fubction
HAMING)
K k, P subscript.
K5 5-k.
PRED Logical variable, p. If true, the predictor section of HAMING is executed; if false, the corrector
s t c l i ~ nof HAMING is executed.
YPREO Vector of predicted solutions, Jj = yj,i+l j = 1 , 2, ..., n, (see (6.4.6)).
400 The Approxrmation of the Sobtion of Ordinary Differential Equations
Program Listing
Main Program
.
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 6.4
c HAMMING'S PREDI CTOR-CORRECTOR METHOD
C
C T H I S TEST PROGRAM SOLVES A SYSTEM OF N FIRST-ORDER ORDINARY
C D I F F E R E N T I A L EQUATIONS U S I N G THE HAMMING PREDICTOR-CORRECTOR
C METI'W. THE PROGRAM READS A STARTING VALUE FOR THE INDEPENDENT
C VARIABLE, X, THE INTEGRATION STEPSIZE, H, THE UPPER L I M I T OF
C INTEGRATION, XMAX, AND N I N I T I A L CONDITIONS Y R ( l ) . . . Y R ( N > . Y
C AND F ARE MATRICES CONTAINING SOLUTION AND D E R I V A T I V E VALUES
C AND ARE DESCRIBED I N THE TEXT. T E ( J ) I S THE TRUNCATION ERROR
C ESTIMATE FOR THE J T H CORRECTOR EQUATION. COUNT I S THE STEP
C COUNTER. THE FUNCTION RUNGE (SEE EXAMPLE 6 . 3 ) I S CALLED TO
C INTEGRATE ACROSS THE F I R S T THREE STEPS AND Y I E L D S THE STARTING
C VALUES NEEDED FOR HAMMING'S METHOD. THEREAFTER, THE EQUATIONS
C ARE l NTEGRATED US1 NG ALTERNATELY THE PREDl CTOR AND CORRECTOR
C PORTIONS OF THE FUNCTION HAMING. THE EQUATIONS B E I N G SOLVED
C AS AN EXAMPLE ARE THOSE OF ( 6 . 4 . 2 ) . TO SOLVE ANOTHER SYSTEM OF
C EQUATIONS, A L L STATEMENTS REFERENCING THE SYMBOLS F AND FR
C ( D E R I V A T I V E S FOR USE BY HAMING AND RUNGE, RESPECTIVELY) MUST BE
C REPLACED BY STATEMENTS D E F I N I N G THE D E R I V A T I V E S FOR THE NEW
C SYSTEM. THE SOLUTIONS ARE PRINTED AT THE I N I T I A L X AND AFTER '
C EVERY I N T l NTEGRATl ON STEPS THEREAFTER.
C
I M P L l C l T REAL*B(A-H, 0-2)
INTEGER COUNT, RUNGE, HAMING
DIMENSION T E ( 2 0 ) , YR(20), FR(20), Y(4,20), F(3,20)
C
C
1
..... READ I N PARAMETERS AND I N I T I A L CONDITIONS
READ (5,100) X, H, XMAX, INT, N, ( Y R ( J ) , J = l , N )
.....
C
C ..... PRl N T PARAMETERS, HEADING AND l N l T I A L CONDITIONS
WRITE ( 6 , 2 0 0 ) H, XMAX, INT, N, (J, J = l , N )
.....
WRITE ( 6 , 2 0 1 ) X, ( Y R ( J ) , J = l , N )
P
.I F...( .X.GT.XMAX-H/2,
I F X EXCEEDS XMAX, TERMINATE INTEGRATION .....
GO TO 1
)
Function HAMI NG
FUNCTION HAIYING( N, Y, F, X, H, TE )
C
C HAMING IMPLEMENTS HAMMING'S PREDI CTOR-CORRECTOR ALGORI THM TO
C SOLVE N SIMULTANEOUS FIRST-ORDER ORDINARY D I F F E R E N T I A L
C EQUATIONS. X I S THE I N D E P E N D E N T V A R I A B L E AND H I S THE
C INTEGRATION STEPSIZE. THE ROUTINE MUST BE CALLED TWICE FOR
C INTEGRATION ACROSS EACH STEP. ON THE F I R S T CALL, I T 1 s ASSUMED
C THAT THE SOLUTION VALUES AND D E R I V A T I V E VALUES FOR THE N
C EQUATIONS ARE STORED I N THE F I R S T N COLUMNS OF THE F l RST
C FOUR ROWS OF THE Y MATRIX AND THE F I R S T THREE ROWS OF THE F
C MATRl X RESPECTIVELY. THE ROUTINE COMPUTES THE N PRED l CTED
C SOLUTIONS YPRED(J), INCREMENTS X BY H AND PUSHES A L L
C VALUES I N THE Y AND F MATRICES DOWN ONE ROW. THE PREDICTED
C SOLUTI ONlj YPREO( J) ARE MOD I F I ED, US l NG THE TRUNCATION ERROR
C ESTIMATES T E ( J ) FROM THE PREVIOUS STEP, AND SAVED I N THE F I R S T
C ROW OF THE Y MATRIX. HAMING RETURNS TO THE CALLING PROGRAM W I T H
C THE VALUE 1 TO I N D l CATE THAT A L L D E R I V A T I V E S SHOULD BE COMPUTED
C AND STORED I N THE F I R S T ROW OF THE F ARRAY BEFORE THE SECOND
C CALL I S MADE ON HAMING. ON THE SECOND ENTRY TO THE FUNCTION
C (DETERMINE0 BY THE LOGICAL VARIABLE PRED), HAMING USES THE
C HAMMI NG CORRECTOR TO COMPUTE NEW SOLUTION EST1 MATES, EST1 MATES
C THE TRUNCATION ERRORS T E ( J ) FOR THE CURRENT STEP, IMPROVES
C THE CORRECTED SOLUTIONS USING THE NEW TRUNCATION ERROR
C ESTIMATES, SAVES THE IMPROVED SOLUTIONS I N THE F I R S T ROW OF THE
C Y MATRIX, AND RETURNS TO THE CALLING PROGRAM W I T H A VALUE 2 TO
C I N D I C A T E COMPLETION OF ONE F U L L INTEGRATION STEP.
C
I M P L I C I T REAL*8(A-H, 0-2)
REAL*8 Y, F, X, H, TE
INTEGER HAMING
LOGICAL PRED
DIMENSION YPRED(201, TE(N), Y(4,N), F(3,N)
DATA PRED 1 .TRUE. /
C
C ..... I S CALL FOR PREDICTOR OR CORRECTOR SECTION .....
I F (.NOT.PRED) GO TO 4
C
C
C
.......... COMPUTE
PREDI CTOR SECTION OF HAMING .....
PREDl CTED Y ( J ) VALUES A T NEXT POINT ... . .
DO 1 J=l,N
1 YPREDCJ) Y(4,J) + 4.*H*(2.*F(18J) - F(2,J) + 2,*F(3,J))/3.
C
C ..... UPDATE
DO 2 J=l,N
THE Y AND F TABLES .....
DO 2 K5-1,3
K u S - K 5
Y(K,J) = Y(K-1,J)
2 I F (K.LT.4) F(K,J) = F(K-1,J)
402 The Approximation of the Solution of Ordinary DiffetvnfialEquafiotw
END
Data
x = 0.0000 XMAX = 5.0000
INTI 1
YR(11.. .YR(2)= 1.00000
X = 0.0000 XMAX = 5.0000
INT= 1
YR(1). ..YR(2)= 1.00000
X = 0.0000 XMAX 8 5.0000
INT- 2
YR( l)...YR(2)= 1.00000
x = 0.0000 XMAX = 5.0000
INT= 4
YR(l)...YR(2)= 1.00000
X = 0.0000 XMAX = 5.0000
INT= 8
1.00000
-
YR(l)...YR(2)-
X = 0.0000 XMAX = 5.0000
INT 16
YR(l)...YR(2)= 1.00000
X = 0.0000 XMAX = 5.0000
INT = 32
YR(l)...YR(2)= 1,00000
Computer Output
Results for the 1st Data Set
H I 0.100D 01
XMAX = 5.0000
INT = 1
N I 2
Example 6.4 Hammlq's Method
Results for the 4th .Data Set Results for the 5th Data Set
H t 0,125D 00 H I 0.625D-01
XMAX = 5.0000 XMAX * 5.0000
INT = 4 INT = 8
N P 2 N I
2
Resultsfor rhe 6th Data Set Results for the 7th Data Set
1 = 0.312D-Ol H rn 0.156D-01
XMAX * 5.0000 XMAX = 5.0000
INT s 16 IN1 8 32
N = 2 N I 2
404 The Approximafion of the Solution of Ordinary Differential Equations
are listed in Table 6.4.1. Results for step-sizes 0.03125 and 0.015625 (data sets
Table 6.4.1 True Solutions, y(x) 6 and 7) agree with the true values to seven figures.
and dyJdx Results for the larger step sizes are not of acceptable
accuracy. The program has been run with even larger
x y(x) = sin x dyldx = cos x values of h (results not shown) as well. For h largeenough,
the solutions "blow up" in a fashion similar to that already
observed for the Runge-Kutta method in Example 6.3.
In view of the periodic nature of the solution functions,
it is not surprising that as the step size approaches the
length of the functional period, the solutions become
meaningless. Clearly, for step sizes larger than the
period, virtually all local information about the curva-
Table 6.4.2. shows the computed results at x = 5 for the ture of the function is lost; it would be unreasonable to
various step sizes used. expect accurate solutions in such cases.
6.14 Boundary.Value Problems 405
for the initial condition can be found by the linear approach is to define a nonnegative objective function
interpolation
-
Figure 6.5.1 The boundary layer on aflat plate.
(6.5.5)and its associated boundary conditions. The pro-
gram should print tabulated values of q, f, f' (= U),f ",
and V ( = qf -f), and should produce a graph of U and
V versus q on the on-line printer.
Method of Solution
The governing equations of motion and continuity are
By defining g, =L g2 =f ', and g, =f", we can replace
au a~
u--l-~-=~-
a 2 ~ (6.5.1) equation (6.5.5)by an equivalent set of three first-order
ax ay ay2' equations :
such that
* = ,hCf(rl>
successive steps Aq is achieved by the fourth-order
Runge-Kutta function RUNG E ; this is described fully in
Example 6.3,and the details will not be repeated here.
Since we have initial conditions (at q = 0) for g, and g,
only, we search for a value of g, at q = 0 that will gener-
ate a solution that yieldsg, = 1 at q = oo. This is accom-
equations (6.5.1)and (6,.5.2)reduce to a single ordinary plished by the half-interval method, discussed previously
differential equation in the dimensionless stream func- in Section 3.8 and Example 3.4.
tion f(q): In practice, condition (6512)must be replaced by the
approximate condition
We start with two limits, gjLand g,,, between which g2(qmox)exceeds 1. If it does, g,, at the next iteration is
the missing initial condition, g,,, is thought to lie. The equated to the current midpoint g,,, and g,, is not
solution of (6.5.10) is performed iteratively n times, changed. However, if g,(q,,J < 1, we equate the next
improving at each iteration the value chosen for g,,. At g,, to the current g,, and leave g,, unchanged.
+
each iteration, we set g,, = (g,, g3,)/2, in which one The following flow diagram illustrates the essential
of the limits g,, or g,, of the current interval has been basic steps. In the actual program, however, there are
adjusted according to the half-interval method. The cri- further elaborations involving arrangements for periodic
terion for the adjustment is whether or not the computed printing and plotting of graphs.
Flow Diagram
'r 4 +o
1
9 3+~g3~
I
iter = 1, 2, --+- g3° +
g, t 0 2 I
.. ., n I
92 93 930 I
I
I
- I
I
I
I
I
Call on R U N G E to I
advance it, g,, g2, and g3
to the end of a step. ,
I
I
I
Example 6.5 A Boundary-Value Problem in Fluid Mechanics
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
D ETA Step size, Aq.
DG Vector containing values of the three derivatives, dg,/dq, dg2/dq, and dg,/dq.
ETA Dimensionless distance, q.
ETAMAX Maximum value of q, q,,,, for which solutions are required.
G Vector containing values of g,, g2, and g,.
G3LEFT G3RITE Lower and upper limits, g f Land g,,, for the current interval containing the initial value of g,.
GBZERO initial value of g,, g,,.
IFPLOT Integer, having the value 1 if a graph is required.
IMAGE Storage vector used by the plotting subroutines.
lTER Iteration counter fpr the half-intervalmethod, iter.
N Upper limit on the number of half-interval iterations, n.
NCOPY Number of copies of the graph that are required.
NIBETP IVumber of half-interval iterations between printouts.
NSBETP IVumber of Runge-Kutta steps, within any one half-interval iteration, between printouts.
NSTEPS Counter on the number of steps Aq.
ORD 'Value of dimensionless velocity, V, to be plotted as the ordinate of the graph.
PLOT1, PLOTZ, !Subroutines used for preparing on-line graph of U and V against q. See Examples 7.1 and 8.5
PLOT3, PLOT4 for further details.
RUNGE Function for implementing the fourth-order Runge-Kutta procedure (see Example 6.3).
SlGNL Has the value - 1, if g2(q,,,) < 1 when g,(O) = g,,; otherwise, the value is + 1.
The Approximation of the Solution of Ordinary Differential Equations
Program Listing
Main Program
A P P L I E D NUMERICAL METHODS, EXAMPLE 6.5
A BOUNDARY VALUE PROBLEM I N F L U I D MECHANICS
ORD = 0.
WRITE (6,201) ITER,G3LEFT,G3ZERO,G3RITE,ETA,G(l),G(2),G(3),oRD
I F (1TER.NE.N .OR. IFPLOT.NE.1) GO TO 8
CALL P L O T l ( 0, 6, 9, 6 , 1 9 )
CALL PLOT2( IMAGE, ETAMAX, O., 1.25, 0. )
CALL PLOT3( l H * , ETA, G(21, 1, 8 )
8
..... CALL
I F (RUNGE(
ON RUNGE-KUTTA SUBROUTINE
3, G, DG, ETA, DETA .NE.
.....
...
1
.
GO TO 1 0
DG(1) = G(2)
DG(2) = G(3)
DG(3) = -G(l)*G(3)/2.
GO TO 8
C
C
10
.....
IF
P R I N T SOLUTIONS, PLOT G ( 2 ) AND ORD VALUES
(.NOT.(ITER/NIBETP*NIBETP.EQ.ITER.OR.ITER.EQ.l.OR.ITER.EQ.N))
.....
1 GOTO17
NSTEPS = NSTEPS + 1
I F (NSTEPS.NE.NSBETP1 GO TO 1 7
NSTEPS = 0
ORD = 0 . 5 * ( E T A * G ( 2 )
WRITE ( 6 , 2 0 2 )
- G(1))
ETA, G ( 1 ) , G ( 2 ) , G ( 3 ) , ORD
I F (1TER.NE.N .OR. IFPLOT.NE.1) GO TO 1 7
CALL PLOT3( lH*, ETA, G ( 2 ) , 1, 8
CALL PLOT3( lHX, ETA, ORD, 1, 8 )
Example 6.5 A Boundary-Value Problem in Fluid Mechanics
C
100
..... FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT ( 10X,~10.7,~0X,F10.7,i9X,F3.0/10~,F10.7,20X,F10.7,19~,l3/
.....
1 l o x , 1Z1,28X, Ii!,28X, 1 2 / l o x , 12 )
200 FORMAT ( 1 0 h l G 3 L E F T = , F l 0 . 6 / 1 0 H G 3 R I T E = , F 1 0 . 6 / 1 0 H S l G N L ,
1 F3.0/ 1 0 H DETA 1 , F10.6/ 1 0 H ETAMAX = , F 1 0 . 6 / 1 0 H N I B E T P = ,
2 1 3 / 1 0 H NSBETP * 13/ 10H N a , 13/ 10H IFPLOT = , 13/
3 1 0 H NC:OPY * 13
201 FORMAT ( 1 0 ~ 1 1 ~ ~* 6, 1 3 / 1 0 H G3LEFT = , F 1 0 . 6 / 1 0 H G3ZERO = ,
1 F 1 0 . 6 1 1OH G f R l TE = , F 1 0 . 6 / 7H0 ETA, 11X, 4HG(1), 12X,
2 4HG(2), 12X, 4HG(3), 12X, 3HORDI 1H0, F7.4, 2F16.7, 2F16.8
202 FORMAT ( 1H , F7.4, 2f16.7, 2F16.8 )
203 FORMAT ( 1H1, 52X, l ! J H f H E B L A S i U S PROBLEM/ 1HO
204 FORMAT ( 1H0, 60X, 3HETA/ 1H , i i X , 2 9 H P L O T T I N G CHARACTER ( * I = G ( 2 )
1 / 1 H ,1lX, ~ ~ H P L O T T ~ CHARACTER
NG ( X I * ORD )
C
END
Data
G3LEFT 1 0.1000000 G3RITE s 0.5000000 SlGNL = -1
DETA = 0.1000000 ETAMAX * 10.0000000 NIBETP = 10
NSBETP a 2 N a 20 IFPLOT = 1
NCOPY = 1
Computer Output
G3LEFT =
=
G3RITE
SlGNL
DETA
=
=
-
ETAMAX =
NIBETP =
NSBETP =
N =
IFPLOT
NCOPY =
412 The Approximation of the Solution of Ordinary Differential Equations
I ci-
X O
1,
*a
2s
PP
Example 6.5 A Boundary-Value Problem in Fluid Mechanics 415
and 10th iterations were 0.9345562 and 1.0007317,
Discussion of Results
respectively. The results for the final iteration agree to at
The results of the computations, performed in double- least six significant digits with those reported in Reference
precision arithmetic, are displayed above only for the 42. Observe that U essentially attains its mainstream value
-firstand 20th (final) half-interval iteration. The success of for q = 6 or greater. Since aulax is everywhere negative
the method can be seen by examining gz(q,,), which (at a given distance from the plate, the u velocity is re-
differs only marginally from the required value of 1. The tarded in the direction of flow), a positive V velocity
corresponding values for g,(q,,,) at the end of the 1st occurs in order to satisfy the continuity equation (6.5.2).
416 The Approximation of the Solution of Ordinary Differential Equations
6.2 Solve the ordinary differential equation is a third-order Runge-Kutta method with accuracy com-
parable to that of (6.64).
6.6 Develop a general formulation of the fourth-order
Runge-Kutta methods, comparable to that described in
detail for the second-order methods, and outlined for the
with initial conditions third-order methods, in Section 6.5.Starting with (6.65),
expand each of the k t , i = 2, 3, 4, in a Taylor's series as a
function of two variables, and equate the coefficient of each
power of h $ 4 in (6.65)to that of the same power of h in
(6.25).What is the system of equations describing the fourth-
using the Taylor's expansion approach described in Section order parameters, comparable to (6.57)for the second-order
6.2,and compare with the analytical solution. methods? Now many parameters must be specified to deter-
6.3 Write a program, similar to that of Example 6.1,that mine a particular fourth-order method? Show that (6.66),
employs either the improved Euler method of (6.59)and (6.60) (6.67),and (6.68)satisfy the system of equations developed
or the modified Euler method of (6.61)and (6.62)to solve the above.
first-order equation (6.19) 8
6.7 Choose, arbitrarily, a sufficient number of parameters
to specify a particular fourth-order Runge-Kutta method (see
Problem 6.6),and develop a new Runge-Kutta formula of
with initial condition y(xo)= y(0) = 0.Integrate the equation your own. Write a function, named M Y R K and modelled after
on the interval 0 < x < 2 using several different step sizes, the function R U N G E of Example 6.3,that could be used in
h = I . , 0.5,0.25,0.1,0.05,0.025,0.01,0.005,0.0025,0.001, place of R U N G E to solve systems of first-order ordinary
0.0005,0.00025,0.0001.Initially, and after every k steps of differential equations. Write a main program that calls on
the procedure, print the current results (xl, yi)the true
yi,,f(xl, M Y R K to solve equation (6.4.2)with initial conditions (6.4'31,
solutiorr, y(xi),and the discretization error, E~). for a variety of step sizes. Compare the results with those of
Plot the discretization error, at x = 2 against h, h2, and Example 6.4,for comparable step stzes.
h3, and determine the apparent order of the error for small 6.8 The differential equation
step sizes.
6.4 Consider the first-order equation,
with
order equation to be rewritten as a system of two first-order T o avoid the necessity of storing tabular information, or of
equations: having RKGILL implement the printing of solutions, the func-
tion should return to the calling program whenever solutions
are to be printed. The calling program should then print any
results desired according to any appropriate format. The
function RKGILL should return a logical value, .FALSE., to
signal that integration is not yet complete, or .TRUE., to indi-
cate that the upper integration limit has been reached. If
RKGILL returns the value .FALSE., then the calling program
should return to RKGlLL immediately after printing.
Test the program thoroughly with a variety of functions,
to insure that the step-size adjustment and printing control
features are functioning properly. Once checked out, RKGliL
The initial conditions y(xo) and yf(x0) must be specified. can be used to solve many of the equations in the problems
Derive this algorithm, and show that it is a third-order that follow.
method. 6.11 The corrector equation, (6.95c), for Milne's sixth-
6.10 Write a general-purpose function, named RKGILL, order method, can be used iteratively to produce a sequence of
that solves a system of n simultaneous first-order ordinary corrected values,
differential equations (6.77)
where
using the fourth-order Runge-Kutta method with Gill's coeffi-
cients (6.68). The function should be more general than the
function RUNGE of Example 6.3, in that RKGILL should auto- If the differential equation being solved is d ~ d = x f(x,y),
matically adjust the step-size h, based on upper "bounds" for under what conditions will this iterative procedure converge to
the local truncation errors to be supplied by the user in a a limiting value y, +, , ,?
vector argument. Use the Richardson extrapolation technique 6.12 Conduct a stability analysis of the sixth-order Milne
outlined in (6.70) to (6.74) to estimate the truncation errors. corrector ( 6 . 9 5 ~for
) the solution of (6.1 1 1 ).
Develop appropriate criteria for determining when to change (a) Find the linear homogeneous difference equation cor-
the step-size h. Halving or doubling the step size should be responding to the corrector.
acceptable in most cases. Keep in mind that unnecessary (b) Find the characteristic equation of the difference equa-
halving of h or delayed doubling of h will greatly increase the tion of part (a).
number of calculations required for a given problem solution, (c) How many roots are there for (b)?
as will too frequent estimation of the truncation errors. (d) For what range of a h should the behavior of (c) be
RKGILL should keep "historical" information to relieve the examined ?
user of unnecessary bookkeeping. Arguments for the routine (e) Investigate the behavior of the roots on the interval
should include both the lower and upper integration limits. selected in part (d), using one of the root-finding techniques
In addition, it will be convenient to have all derivative evalua- discussed in Chapter 3.
tions (equivalent to computing the F, of (6.3.9), (6.3.14), (f) If possible, expand the roots of (b) as power series in the
etc.) handled by a separate subroutine with argument list parameter ah, as in (6.120) and (6.121).
(X, Y, F), where X, Y, and F have the meanings of like symbols (g) What is the complete solution to the difference equa-
in Example 6.3. The name of this subroutine should, itself, tion ?
be an argument of RKGILL, so that RKGILL can call directly (h) Identify the solution associated with the principal root
for calculation of derivatives without returning to the calling and the parasitic~solutions(from part (g)).
program. (i) Show that the sixth-order Milne corrector is marginally
The user will normally want to print results in tabular form, stable.
for independent variable values that are integral multiples of 6.13 Conduct a stability analysis, similar to that of Prob-
the original step size. Therefore, the routine RKGILL should lem 6.12, for the corrector (6.95a) of the fourth-order modified
have as one of its arguments', an integer frequency for printing Adams method. Does this corrector give rise to parasitic
control purposes. This means that all independent variable solutions? Compare the stability of (6.95a) with the stability of
values associated with the user-specified printout of solutions (6.9%).
must occur as the right-hard side (for positive step sizes) of 6.14 Develop an algorithm, based on the modified Adams
some integration step. It may be necessary to reduce drastically predictor-corrector method ((6.88a) and (6.95a)) that will
the step size (always by some factor of two) temporarily to allow the solution of a single nth-order ordinary differential
accommodate proper printing. Note that if the printing fre- equation,
quency is one, then RKG1LL should never increase the step size
beyond its original value, even when the error criteria would
indicate that this should be done.
418 The Approximation of the Solution of Ordinary Diflerential Equations
with n initialconditions, y, dyldx, ..., d"-'y/dx"-', all specified algorithm are required to get the starting values for Ham-
at x = xo, without requiring the decomposition of the nth- ming's method.
order equation into a system of n first-order equations. Adequate "old" information regarding the y, and fi, j = 1,
How would you implement your algorithm as a general- 2, . . ., n, should be retained at all times to allow doubling of
purpose subroutine? the step size, without recomputing any functional values
6.15 Write a general-purpose function, named AUTOHM before continuing the integration with the new step size.
that solves a system of n simultaneous first-order ordinary When the step size is halved, functional information at two
differential equations (6.77), new base points will be required. Use the RungelKutta method
outlined above to find the missing values.
Test the program thoroughly with the equations used to test
RKGILL of Prpblem 6.10. Once checked out, AUTOHM can be
using the fourth-order Hamming corrector (6.131) with the used to solve many of the equations in the problems that
fourth-order Milne predictor (6.102). The function should be follow.
more general than the function HAMING of Example 6.4, in 6.16 Investigate the following procedure, related to the
that AUTOHM should automatically adjust the step-size h, principle of spline function approximation (see Problem 1.24).
based on upper "bounds" for the local truncation errors to be for approximating the solution of
supplied by the user in a vector argument. Develop
appropriate criteria for determining when to change the step
size by either halving it or doubling it. Keep in mind that too
frequent modification of the step size may cause an excessive subject to the initial condition y(xo) =yo.
number of calculations to be done. Introduce a series of equally spaced base points, X, = ih,
In the manner of the function RKGILL described in Problem i = 0, 1, .. .,n, where the spacing is h = (b - o)/n. Assume that
6.10, evaluations of derivatives should be performed by a over each interval [ X ~ , X ~ +
i=~ ]0,, 1, ..., n - 1, the solution is
separate subroutine. Arguments for AUTOHM should include approximated by the second-degree polynomial,
the upper and lower integration limits, the. name of the
function that evaluates the derivatives, a starting step size, an
integer frequency for printing control (see Problem 6.10), a Also, assume that successive such polynomials and their first
vector of error bounds, all tables necessary for communication derivatives match each other in value at intermediate base
of information, etc. AUTOHM should return the value points, so that
.FALSE. when the calling program is to print results and then
call immediately upon AUTO-HM to continue the integration,
or .TRUE. when integration to the upper limit is complete.
Starting values for the solution should be generated inter-
nally by AUTOHM using a fourth-order Runge-Kutta method. In addition, to insure that the initial condition is obeyed, and
The user should be required to supply the n solution values that the differential equation is satisfied at the end points, let
only at xo, and call upon AUTOHM directly. The function
RKGILL of Problem 6.10 could be called to do this; however, a
preferred way of starting would be to use the following Runge-
Kutta method (here written for a single equation):
yr + 1 = yr + 0.17476028226269037hk1 (a) Show that the complete solution to the problem amounts
- 0.55148066287873294kkt to solving 3n simultaneous equations in the coefficients a,, bl, CJ,
+ 1.2055355993965235 hk3 i=O, 1 ,..., n- 1.
(b) What is the most efficient way of solving these simul-
+ 0.17118478121951903hk,, taneous equations?
kl =f(~l,y;), (c) Apply the method to the solution of
+
k2 =f (XI 0.4h,yr + 0.4 hk~),
+
k3 =f(xi 0.45573725421878943 h, yr
+
0.29697760924775360 hkl on the interval [1,2] with yo = 2. Use several different step
+
0.15875964497103583 hk,), sizes such as 0.5, 0.25, 0.1, 0.05, 0.025, 0.01, 0.005, 0.001. If
possible, compare the computational work performed and
+
k+ =f(xr h,yl+ 0.21810038822592047 hkI the accuracy obtained with those for solution by the Euler and
- 3.050965 1486929308 hk2 Runge-Kutta methods for the same problem. In any event,
+
3.8328647604670103hk3). compare the results with the analytical solution.
6.17 Extend the method of Problem 6.16 to the solution
Ralston [8] shows that of all fourth-order Runge-Kutta of equations of the form
methods, this one has the smallest bound for the local
truncation error. It has rather poor stability to rounding
errors, but this is not important, since only three steps of the
Problems 419
Note that relations such as 621 Example 6,2 assumed for simplicity that the thermal
cracking of ethane yields two products only--ethylene and hy-
drogen, The situation is really more complicated, as evidenced
will now be involved, so that initial guesses must be made for by Shah [50], who discusses several additional reactions that
the unknown yi, i = 1 , 2 , . . ., n, in order to solve the system of may occur during the thermal decomposition of ethane (and
equationsfor the a,, b,, c,, i = 0 , 1 , . . ,,n - 1. Devise an iterative also of propane).
scheme and convergence criteria for the iterative improvement Shah's pager includes all of the relevant reaction rates,
of the solutions y,, i = 1 , 2, . . ., n. specific heats, and heats of reaction. Armed with this informa-
Apply the method you develop to the solution of tian, which is too lengthy to be summarized here, the reader
n a y wish to devise and solve further problems in the area of
thermal cracking.
6.22 A periodic voltage V = V,,, sin wt is applied to ter-
minal A of the rectifying and ripple-filter circuit shown in
with initial condition y(0) - y o = 0. Try the approach with Fig. P6.22. The particular diode rectifier used has essentially
various step sizes and compare thesolutions with the analytical
solution and solutions found by other integration procedures.
6.18 Extend the methods of Problems 6.16 and 6.17 by
approximating the solution y ( x ) on each interval [x,,x,+ 1 =
0 , 1 , . . ., n - 1, with the third-degree polynomial
Write a program that will compute the variation with time t tions-not the situation here-the slope dyldx is frequently
of the voltages across (a) the capacitor and (b) the resistor. neglected).
Discontinue the calculations when either t exceeds an upper
limit t,., or the fractional voltage change from one cycle to the
next (compared at corresponding times) falls below a small
value E .
An electron of charge -e and mass m enters the small hole denote distance measured along the mast from B, y = y(s) the
at A with velocity c at an angle 0 to the axis of the lens. Inside horizontal deflection at any point, x = x(s) the vertical height
the hollow cylinders, the electric field is E = -VV, and the at any point, and 8 = 8(s) the angle between the mast and the
force on the electron is F = -eE. Hence the subsequent radial vertical. Note that dylds = sin 8. The governing equation is
and axial velocity components u and v are modified according
to :
du
m-=e-
av
dt 2r ' which may be differentiated with respect to s to yield a second-
order ordinary differential equation. The boundary conditions
areO=Oats=O,andd8/ds=Oats=L.
Compute those values of the dimensionless group y = wL3/
Hopefully, the anode voltage V. and the distances Rand Zwill EI for which xA/Lequals 0.99, 0.95, 0.9, 0.5, and 0. What will
be arranged so that the electron will be travelling along the z be the corresponding values of y,/L and a (the value of 8 at
axis by the time it escapes through the small hole at B. the free end A)? Determine the value of y for which the mast
Making use of the potential distributions computed in just begins to lean over. What does this mean in practical
Problem 7.26, write another program that will investigate the terms for a light-alloy pole of O.D. 2 in. and wall thickness 0.1
effectiveness of the lens for several different values of the param- in., for which w = 0.705 Ib,/ft, E = lo7 lb,/sq in., and 1=0.270
eters c, 8, V., R, and Z. Note that e=1.602x 10-l9 in.4?
coulombs and m =9.108 x kg. Timoshenko [44]gives a simplified treatment of this prob-
6.26 The pinended strut shown in Fig. P6.26 is subjected lem, in which the curvature dB/& is approximated by d2y/dxZ
to an axial load P. The lateral deflection y is governed by [43]: (see Problem 3.46).
6.28 The installation shown in Fig. P6.28 delivers water
from a reservoir of constant elevation H to a turbine. The
surge tank of diameter D is intended to prevent excessive
where E = Young's modulus, and I is the appropriate cross- pressure rises in the pipe whenever the valve is closed quickly
sectional moment of inertia of the strut. (For small deflec- during an emergency.
Problems 421
The drag coefficient CD varies with the Mach number
M = V/c, where c =velocity of sound in air. Representative
values (see Streeter [45], for example) are:
M: 0 0.5 0.75 1 1.25 1.5 2 2.5 3
CD: 1.6 1.8 2.1 4.8 5.8 5.4 4.8 4.2 3.9
'X +
I
H The range on horizontal terrain is to be R. Write a program
that will determine if this range can be achieved and, if so, the
__________------- two possible angles of fire, the total times of flight, and the
Turbine velocities on impact. In each case, also determine the error in
the range that would result from a i10 minute of arc error in
FSgure P6.28 the firing angle.
Assuming constant density, and neglecting the effect of Suggested Test Data
acceleration of water in the surge tank, a momentum balance m = 100 lb,, g = 32.2 ft/sec2, d = 6 in., V, = 2154 ft/sec,
on the water in the pipe leads to p = 0.0742 Ib,/cuft, c = 1137 ft/sec, with R = 0.5, 1 , 2, 4,6, 8,
and 10 thousand yards.
6.30 Let the suspension of a vehicle of mass M be repre-
sented by the lumped spring-dashpot system shown in Fig.
Here, h =height of water in the surge tank (ho under steady P6.30. At time t = 0 the vehicle is travelling steadily with its
conditions), fM = Moody friction factor, u = mean velocity in
the pipe, g =gravitational acceleration, and t = time. Also, Mass M
Direction of motion
continuity requires that
Equilibrium positim
-T 7--,---
The flow rate Q, through the valve in the period 0 < t C t,
during which it is being closed is approximated by
Time
where the constant k depends on the particular valve and the Figure P6.30
downstream head h* depends on the particular emergency at
the turbine. center of gravity at an equilibrium distance ho above the
During and after a n emergency shutdown of the valve, ground, and it has no vertical velocity. For subsequent times
compute the variation with time of the level in the surge tank. (t > 0) the contour of the road (the displacement of the road
surface from the reference level at time zero) is given by an
Suggested Test Data arbitrary function x o = xo(t).
g = 32.2 ft/sec2, H = 100 ft, ho = 88 it, f, = 0.024, If the stiffness (restoring force/extension) of the spring is k,
L = 2000 ft, d = 2 ft, t , = 6 sec, k
= 21.4 ft2.5/sec,and D = 4, and the damping coefficient of the dashpot is r, then show
6, 10, and 15 ft. Take two extreme values for h*: (a) its original that x(t), the displacement of the center of gravity of the
steady value, ho - Qi0/kz, where Quo is the original steady vehicle as a function of time, is the solution of the second-
flow rate, and (b) zero. order ordinary differential equation
6.29 A projectile of mass m and maximum diameter d is
fired with muzzle velocity lVo a) an angle of fire 8, above the
horizontal. The subsequent velocity components u and v in
the horizontal and vertical directions x and y, respectively, with the Initial conditions
obey the ordinary differential equaiions
du
m - = -F 0 coso,
dt
Let the road contour function be given by
x,(t) = A(l - cos w t ) ,
Here, B =angle of projectile path above the horizontal, and where 2 A is the full displacement of the road surface from the
F D = C D A PV 2/2, where V -
g =gravitational acceleration. The drag force F D is given by
speed of projectile, A = ndz/4 =
projected area, and p = density of air. Consistent units are
reference level.
Note that the under-, critically-,, and over-damped cases
correspond to r / 2 2 / k M being less than, equal ro, and greater
assumed in the above equations. than unity, respectively.
422 The Approximation of the Solution of Ordinary Differential Equations
Write a program that uses the model outlined above to 6.33 A hot vertical wall, maintained a t a temperature Ow,
simulate the behavior of a specified suspension system, over the is situated in a fluid of infinite extent. Far away from the wall,
time period 0 it it,,,. The program should read values for the fluid has temperature 8, and zero velocity. Because of the
M , R, K, A, W, TMAX, DT, and FREQ, where W corresponds to buoyant effect on heating, natural convection occurs in the
w , DT is the step size to be used in integrating the differential fluid. Let u = u(x,y) and v = v(x,y) denote the resulting fluid
equation, and FREQ is an integer used to control printing veIocities in the x and y directions (horizontal and vertical
frequency, such that the values of t, x, dxldt, d2x/dtZ,and distances from the bottom of the wall, respectively). Also use
xo(t)are printed initially and every FREQ time steps thereafter. 8 = O(X,~) to denote the fluid temperature, and let Pr, P, and v
The remaining program symbols have obvious interpretations. be its Prandtl number, volume coefficient of expansion, and
The equation should be solved using a one-step method, and kinematic viscosity, respectively.
the program should allow for the processing of several sets of The steady motion is governed by the suitably simplified
data. equations of continuity, momentum, and energy (see Schlich-
ting [42],for example). By using the similarity transformation
Suggested Test Data
M = 3680 Ib,, K = 640 Ib,/in., A = 2 in., W = 7 radlsec,
and TMAX = 10 sec. Investigate R = 80,160, and 240 lbf sec/in.
in turn. The values of DTand FREQ will depend on the integra- it may be shown that dimensionless velocities and temperature
tion method chosen. In any event, each of the data sets listed are given by
above should be processed with more than one step size. F o r
each situation, plot x, xo, dxldt, and d2x/dtZas functions of
time.
6.31 Let the damping coefficient, r , of Problem 6.30 be a
nonlinear function of the relative velocities of the two parts of
the dashpot:
Rerun the simulation of Problem 6.30 with this definition of where the functions 5 = [(T) and T = T ( 7 )are solutions of the
the damping coefficient. Investigate all nine combinations of simultaneous ordinary differential equations
r o = 80,' 160, and 240 lb, sec/in., with c = 0.1, 1 , and 10
(sec/in.)IJ2.
6.32 Extend Example 6.5 to include heat transfer for a
plate a t a temperature 8, and a fluid whose temperature is 8,
far away from the plate. Neglecting viscous dissipation and
conduction in the x direction, the partial differential equation
governing the variation of temperature 8 is Show that the boundary conditions on 6 and T are:
Equation of State
MP
pg=-.
R T,
The following notation is used here:
a, Surface area of catalyst per unit packed
volume, ft - .
CP Mean specific heat of gas, BTU/lb, OF,
+ +
Assume that c, = (0.585 0.260n 0.269g)l A preliminary design has suggested the following
+ +
(I u 1.143g), an average value for the values (units as above): p, = 83.5, T,, = 300, 0 = 1/12,
feed gas over the temperature range of most d, = 0.0033, T,,,,, = 1010, E = 0.57, p = 0.0595, k = 0.028,
interest, holds throughout the reactor. a, = 782, PQ= 15, but these may need modification.
424 The Approximation of the Solution of Orditiary Differential Eqriatiotls
Suitable values for G, g, n, TgFo, and L ,. are still to be to the wall for its entire height. Each fin has width W, thick-
chosen. Investigate the performance of the reactor for several ness t , thermal conductivity k, and surface emissivity &., The
different combinations of these variables, bearing in mind the wall and fins transfer heat by combined convection and radia-
following desirable features: (a) high overall yield Y, (b) T, tion to the surrounding air, which has a mean temperature To
must never exceed T,,,.,, (c) dT,/dL must not be negative and also behaves as a black-body enclosure at that tempera-
at the inlet (reaction self-extinguishing), (d) P must always be ture.
positive,and(e) for control purposes, a change of 1°F in the gas
temperature at inlet should not produce too large a change
in its value at the exit (no more than 1O0F, for example).
Tentative ranges for investigation are: G = 5,000 to 40,000;
,,.,
g = 0.2 to 0.6; tz = 0 to 4; TgpO= 350 to 500; L = 2 to 6.
6.36 Figure P6.36 shows a cross section of a long cooling
fin of width W, thickness r , and thermal conductivity k, that is
Air at T,
4tk
Air at T,
Figure P6.37
Assume that (a) both wall and fins have gray surfaces, and
Figure P6.36 (b) the heat transfer coefficient for cortr.ectiot~between the wall
and fins to the surrounding air approximately obeys the corre-
bonded to a hot wall, maintaining its base (at x = 0 ) at a lation h = 0.21(AT)L'3BTU/hr sq ft 'F, in which the tempera-
temperature T,. Heat is conducted steadily through the fin and ture difference AT between the hot surface and air is in " F
is lost from the sides of the fin by convection to the surrounding (see Rohsenow and Choi [48]). Also, neglect temperature
air with a heat transfer coefficient h. (Radiation is neglected at variations across the thickness of the fins; the local fin tem-
sufficiently low temperatures.) perature T, then obeys the differential equation
Show that the fin temperature T, assumed here to depend
only on the distance x along the fin, obeys the differential
equation
where q, is the local rate of heat loss per unit area from one
side of a fin and x is distance along a fin.
Write a program that will accept values for the parameters
where T. is the mean temperature of the surrounding air. T,, T., E,, E J , W, t , d , and k , and then compute the average net
(Fourier's law gives the heat flux density as q = -k dT/dx for rate of heat loss from the wall and fins. based on unit area of
steady conduction in one dimension.) If the surface of the fin is the wall surface. Find 4 for several different representative
vertical, h obeys the dimensional correlation h = 0.21(T- T,)'J3 values of the parameters. Discuss the possibility of designing
BTU/hr sq ft OF, with both temperatures in OF (Rohsenow and fins that would maximize4 for a specified weight of metal in the
Choi [48]). fins.
What are the boundary conditions on T? Write a program 6.38 Consider two wildlifeanimal species: A, which has an
that will compute: (a) the temperature distribution along the abundant supply of natural food, and B, which depends entirely
fin, and (b) the total rate of heat loss from the fin to the air per for its food supply by preying on A. At a given time r , let N ,
foot length of fin. and Ne be the populations of A and B, respectively, in a given
natural area.
Suggested Test Data By making certain simple assumptions, show that the
following differential equations could describe the growth o r
T , = 200°F, T, = 70°F, t = 0.25 in; investigate all eight decay of the two populations:
combinations of k = 25.9 (steel) and 220 (copper) BTU/hr ft
"F, W = 0.5, 1, 2, and 5 in.
If available, compare the results with those obtained from
Problem 7.42, irl which te~liperatulevariations across the fin
are taken into account.
6.37 Note. Before attempting this problem, the reader
should become familiar with Example 2.1 and the discussion What significance d o you attach to the positive constants a, P,
in Problems 3.17 and 5.25. y, and 6 ?
Figure P6.37 shows a horizontal cross section of a very tall Write a program that will solve the above equations for a
vertical wall that is maintained at a uniformly high tempera- wide variety of initial conditions and values for a, ,L?,y, and 6.
ture T , and whose surface has an emissivity .&, A large number If possible, arrange for the program to plot NA and NB against
of vertical metalliccooling fins, spacedama pitch d, are bonded t.
Problems 425
6.39 Before attempting this problem, the reader should where N , is the number of particles collected per unit time,
have solved Problem 7.27, in the suggested dimensionless form, r,,, is the upstream radius of the stream tube that impinges on
for several dimensionless velocity ratios u ~ / u A = 0.5, 1.0, 2.0, the probe circumference and r,,, is the upstream radius of the
3.0. The dimensionless stream function Y: should be available limiting particle-trajectory envelope. In both cases, "upstream"
in tabular form for all the grid points of the finite-difference means far enough removed from the probe to ignore radial
solution for each of these dimensionless velocity ratios. velocity effects.
Vltols [49] has studied the motion of particles In flow Thus, to calculate the true particle density for spherical
regimes described by the solutions of Problem 7.27, where the particles of a given diameter, we must know r,. ,and r,, ,for
inner cylinder represents an aspirated particle-sampling probe each dimensionless velocity ratio u~/u,. The quantity r,,,
immersed in a flowing fluid containing solid particles (for will be known once the dimensionless stream function has been
example, samjling for fly ash in an industrial stack). The outer determined, as in Problem 7.27. It remains to determine up,,.
cylinder in Fig. P7.27 need not be taken as the radius of an Vitols [49] has shown that the motion of an individual
outer container (stack, for example), but simply as an imagin- spherical particle can be described by the following ordinary
ary stream tube, far enough away from the probe so that there differential equations :
is no radial velocity compolnent of any significance.
Because of inertial and (drag forces, a particle flowing at
free-stream velocity far upsfream of the probe will not neces-
sarily follow a streamline in the vicinity of the probe, where
radial and axial velocity components of the fluid may be
changing markedly. This eff'ect is illustrated in Fig. 6.39a and where
6.39b for ~ s / less
~ nthan one and greater than one, respectively.
ud2uA
K=- = particle inertia parameter,
1811.~~
pdua
Re, = -= free-stream Reynolds number.
P
Probe opening
Here,
C D = dimensionless drag coefficient for spheres
---_--- --
--- d = particle diameter, cm
--c
---
--.
Particle path
u, = free-stream velocity, cmlsec
a = particle density, gm/cm3
-----+
------ 3
p = absolute viscosity of fluid, poise
rs = probe radius, cm
p = fluid density, gm/cm3
--3
u = local fluid velocity, cm/sec
Probe opening
v =local particle velocity, cm/sec
t = time, seconds
(b)
r =radial coordinate of particle position, cm
Figure P6.39
z = axial coordinate (origin at probe) of particle position,
Thus if the estimated density of particles in the free stream cm.
is taken as the number of particles collected by the sampler The following are dimensionless:
divided by the volume of gas passing through the probe, the
calculated values may differ markedly from the true situation. ci = local fluid velocity, u / u A
The total volume of gas passing through the probe will be that d = local particle velocity, vlu,
enclosed by the stream tube that impinges on the outer circum- T = time, tuA/r,
ference of the-probe opening. For uB/uA< 1, particles from i = radiai coordinate, r/rs
outside the limiting stream tlube will enter the sampler while, i = axial coordinate, z/rs
for u ~ / u A > 1, particles originally inside the limiting stream 6; = dF/d~,radial component of particle velocity
tube will pass outside the probe. 6; = d i / d ~ axial
, component of particle velocity
Now, consider a particle that just impinges on the outer a; = dci/di, radial component of fluid velocity
circumference of the probe. All particles of the same diameter a; = dci/di, axial component of fluid velocity.
within a cylindrical envelof~egenerated by this limiting
Seve~alassumptions arc inhcrcnt in the development of this
particle trajectory will be collected by the probe. Thus the
equation, including (a) uniform particle distribution, (b) no
actual density or number of particles per unit volume in the
gravitational o r electrostatic forces of consequence, (c) mono-
sampled gas is given by
disperse spherical particles with diameter very small in relation
to diameter of probe opening, and (d) free-stream flow that is
steady, incompressible, and irrotational.
426 The Approximation of the Solution of Ordinary DifferentialEquations
Table P6.39
Figure P6.41
2~rpJ0 u2r dr
Write a program that accepts, as data, values for the dimen-
sionless velocity ratio uB/ua (possible values correspond to is constant. Also assume a solution of the form u(r,z) =
those for which the stream functions are available), K (indus- #(z) f ( l ) where
, 7 = r/z, and let
trial cases encountered usually have values of K from 1 to
loo), and Reo (normally between 1 and 100 for practical appli-
cations). The program should then integrate the two second-
order nonlinear ordinary differential equations to establish the Using the continuity equation,
position (P,i) of a given particle in the flow field at any time 7,
given an initial position (io,io)at time T = 0.The initial posi-
tion should be situated far enough upstream (several dimen-
sionless probe radii) so that the initial particle velocity in the show that
radial direction is zero and in the axial direction is the free
stream velocity.
Note that as the particle moves in time, the velocity com-
ponents for the fluid, a; and a;, must be computed as functions
of location by numerical differentiation of the dimensionless
stream function (available in tabular form from Problem 7.27). where A is a constant.
In addition, the Reynolds number and the corresponding drag
If momentum is transported only by turbulent shear, and
coefficient CD must be evaluated for local conditions.
turbulent normal stresses are ignored, a simplified Reynold's
The program should automatically adjust the initial loca-
equation results. Tollmien 1511 has studied this problem;
tion of the particle (Po,io) until it finds the radius P,,, =
assuming a Prandtl mixing length 1 of the form 1 = cz, it can
r,,,/r~ = i,. Thus the problem may be viewed as a boundary
be shown that
value problem for which three conditions are initial conditions
(io,ii;,fi;) and one is a boundary condition, namely that at some
time T > 0, the particle will hit the "target" (the lip of the
probe) at location i = 1, i = 0. The desired solution of the By substituting the above relationships into this equation
problem is i,,,. and integrating once, show that F obeys the ordinary differen-
As trial values, solve the problem for the following 1491: tial equation
Bibliography 27. J. C. Butcher, "A Modified Multi-Step Method for the Nu-
merical Integration of Ordinary Differential Equations," Journal
1. B. W. Arden, An Introduction to Digital Computing, Addison- of the A.C.M., 12, 124-135 (1965).
Wesley, Reading, Massachusetts, 1963. 28. P. Henrici, Error Propagation for Difference Methods, Wiley,
2. P. Henrici, Discrete Variable Merhods in Ordinary Differential New York, 1963.
Equations, Wiley, New York, 1962. 29. J. Waters, "Methods of Numerical Integration Applied to a
3. F. B. Hildebrand, Introduction to Nomerical Analysis, McGraw- System Having Trivial Function Evaluations," Communications
Hill, New York, 1956. of the A.C.M., 9, 293-296 (1966).
4. L. Lapidus, Digital Computation for Chemical Engineers, 30. S. D. Conte, Elementary Numerical Analysis, McGraw-Hill,
McGraw-Hill, New York, 1962. New York, 1965.
5. W. E. Milne, Numerical Solution of Differential Equations, 31. W. E. Milne and R. R. Reynolds, "Stability of a Numerical
Wiley, New York, 1953. Solution of Differential Equations," Journal of the A.C.M., 6,
6. S. Gill, "A Process for the Step-by-step Integration of Dif- 196-203 (1959).
ferential Equations in an Automatic Computing Machine," 32. G. Dahlquist, "Convergence and Stability in the Numerical
Proc. Cambridge Phil. Soc., 47, 96-108 (1951). Integration of Ordinary Differential Equations," Math. Scand.,
7. A. Ralston, A First Course in Numerical Analysis, McGraw- 4, 33-53 (1956).
Hill, New York, 1965. 33. W. E. Milne and R. R. Reynolds, "Fifth-0rder.Methods for
8. A. Ralston, "Runge-Kutta Methods with Minimum Error the Numerical Solution of Ordinary Differential Equations,"
Bounds," Math. Comp., 16, 431-437 (1962). Journal of the A.C.M., 9, 64-70 (1962).
9. L. Collatz, The Numerical Treatment of Differential Equations, 34. P. E. Chase, "Stability Properties of Predictor-Corrector
Third Ed., Springer-Verlag, Berlin, 1960. Methods for Ordinary Differential Equations," Journal of the
10. D. D. McCracken and W. S. Dorn, Numerical Methods and A.C.M., 9,457-468 (1962).
FORTRAN Programming, Wiley, New York, 1964. 35. W. B. Gragg and H. J. Stetter, "Generalized Multistep Pre-
11. D. H. Call and R. F. Reeves, "Error Estimation in Runge- dictor-Corrector Methods," Journalof rhe A.C.M., 11, 188-209
Kutta Procedures," Communications of the A.C.M., 1, 7-8 (1964).
(1958). 36. R. L. Crane and R. W. Klopfenstein, "A Predictor-Corrector
12. J. W. Carr, 111, "Error Bounds for the Runge-Kutta Single- Algorithm with an Increased Ranke' of Absolute Stability,"
Step Integration Process," Journal of the A.C.M., 5, 39-44 Journal of the A.C.M., 12, 227-241 (1965).
(1958). 37. F. T. Krogh, "Predictor-Corrector Methods of High Order with
13. B. A. Caller and D. P. Rosenberg, "A Generalization of a Improved Stability", Journal of the A.C.M., 13,374-385 (1966).
Theorem of Carr on Error Bounds for Runge-Kutta Proce- 38. J. C. Butcher, "A Multistep General~zationof Runge-Kutta
dures," Journal of the A.C.M., 7, 57-60 (1960). Methods with Four or Five Stages," Journal of the A.C.M., 14,
14. P. Henrici, "The Propagation of Error in the Digital Integra- 84-99 (1967).
tion of Ordinary Differential Equations," Error in Digital 39. J. J. Kohfeld and G. T. Thompson, "Multistep Methods with
Computation-I, (L. B. Rall, editor), 185-205, Wiley, New Y o ~ k , Modified Predictors and Correctors," Journal of the A.C.M., 14,
1965. 155-166 (1967).
15. L. Fox (ed.), Numerical Solution of Ordinary and Partial 40. H. A. Luther and H. P. Konen, "Some Fifth-Order Classical
Differential Equations, Addison-Wesley, Reading, Massa- Runge-Kutta Formulas," S.Z.A.M. Reciew, 7, 551-558 (1965).
chusetts, 1962. 41. H. A. Luther, "Further Explicit Fifth-Order Runge-Kutta
16. R. Beckett and J. Hurt, Numerical Calculations and Algorithms, Formulas," S.I.A.M. Review, 8, 374-380 (1966).
McGraw-Hill, New York, 1967. 42. H. Schlichting, Boundary Layer Theory, 4th ed., McGraw-Hill,
17. J. F. Holt, "Numerical Solution of Nonlinear Two-Point New York, 1960.
Boundary Problems by Finite Difference Methods," Com- 43. M. R. Horne and W. Merchant, The Stability of Frames,
munications of the A.C.M., 7, 366-373 (1964). Pergamon Press, New York, 1965.
18. D. D. Morrison, J. D. Riley, and J. F. Zancanaro, "Multiple 44. S. Timoshenko, Theory of Elastic Stability, McGraw-Hill,
Shooting Method for Two-Point Boundary Value Problems," New York, 1936.
Communications of the A.C.M., 5, 613-614 (1962). 45. V. L. Streeter, Fluid Mechanics, 4th ed., McGraw-Hill, New
19. D. Wilde, Optimum Seeking Methods, Prentice-Hall, Engle- York, 1966.
wood Cliffs, New Jersey, 1964. 46. Shen-Wu Wan, "Oxidation of Ethylene to Ethylene Oxide,"
20. R. Hooke and T. A. Jeeves, "Direct Search Solution of Numeri- Ind. Eng. Chem., 45,234-238 (1953).
cal and Statistical Problems," Journal of the A.C.M., 8,212-229 47. J. H. Perry, ed., Chemical Engineers' Handbook, 3rd ed.,
(1961). McGraw-Hill, New York, 1950.
21. R. W. Hamming, "Stable Predictor-Corrector Methods for 48. W. M. Rohsenow and H. Y. Choi, Hent, Mass, and Momentrrm
Ordinary Differential Equations," Journal of the A.C.M., 6, Transfer, Prentice-Hall, Englewood Cliffs, New Jersey, 1961.
37-47 (1959). 49. V. Vitols, Determination of Theoretical Collection Eficiencies of
22. R. W. Hamming, Numerical Methods for Scientists and En- Aspirated Particulate Matter Sampling Probes Under Aniso-
gineers, McGraw-Hill, New York, 1962. kinetic Flow, Ph.D. Thesis, The University of Michigan, 1964.
23. J. C. Butcher, "Integration of Processes based on Radau 50. M. J. Shah, "Computer Control of Ethylene Production,"
Quadrature Formulas," Math. Comp., 18, 233-244 (1964). Ind. Eng. Chem., 59, 70-85 (1967).
24. J:. C. Bbtcher, "Pmplicit Runge-Kutta Processes," Math. Comp., 51. W. Tollmien, "Calculation of Turbulent Expansion Processes,"
28, 50-64 (1964).
NACA TM 1085 (translation) (1945).
25. P. C: Butcher, "On Runge-Kutta Processes of Higher Order," 52. W. F. Hughes and E. W. Gaylord, Basic Equationsof Engineering
J. Austral. Math. Soc., 4, 179-194 (1964).
Science, Schaum Publishing Company, New York, 1964.
26. C. W. Gear, "Hybrid Methods for Initial Value Problems in
Ordinary Differential Equations," Journal of the S.Z.A.M.,
2, 69-86 (1965). .
CHAPTER 7
aaZT/ax2= aT/at, in which a = klpc, is the thermal dif- Vibrating Beam Equation. The tratsverse deflection y
fusivity. The introduction of new variables X = x/L and of a vibrating beam obeys
.r = mc/L2,where L. is a characteristic dimension, leads to
aZT/aXz= aT1a.r. A similar equation governs the inter-
diffusion of two substances.
Vorticity Transport Equation. The vorticity [ of an in which E = modulus of elasticity, I = cross-sectional
incompressible fluid ;.r two-dimensional motion varies moment of inertia, A = cross-sectional area, and p =
according to density.
Ion-Exchange Equation. For flow of a solution through
a packed column containing an ion-exchange resin,
Here, p, c,, and k are the density, specific heat, and ther-
mal conductivity of the fluid, and the axial velocity u is a
known function of r. Note how the character of the equa-
tion changes if the term a2T/azZ,corresponding to axial
conduction, can be neglected.
Telephone Equation. The following equation can be
used to predict variations of voltage V along a transmis-
sion cable: where the remainder term is given by
( i - 1,j + 1) l i " l(i,,j j++1)l ) By taking more and more neighboring points, an un-
limited number of other approximations can be obtained,
but the above forms are the most compact.
For convenience, the central-difference operator 6, will
be used occasionally. It is defined by
whence
Solution:
*u(r, t )
Boundary PDE:
Boundary
(7'5) condition: a.
at
,aax2? condition:
u (0,t) = go ( t ) u(1,t) = gl(t)
z 2 = (7.7) 1
(Ax)2
Figure 7.2 The differential problem.
Formulas (7.4), (7.5), and (7.6) are known as the forward,
backward, and central difference forms respectively. be described by the following differential equation and
similar forms exist for au/ay and a2u/ay'. It may also be initial and boundary conditions, also illustrated in Fig.
shown that 7.2.
a2u
-- -Ui+l,j+l -Ui-~,j+l - Ui+l,j-1 + ui-~,j-l au aZu
ax ay 4 Ax AY -=-
at ax2'
f o r o c x c 1, O < t c T, (7.12)
+ O [ ( A X + A ~ ) ~ ](7.8)
.
For a square grid (Ax = Ay), the following nine-point u(x,O) =f (x), 0 ,< x ,< 1,
approximation is availablle for the Laplacian in two u(0,l) = yo(t), 0< < T, (7.13)
dimensions and will have the specified truncation error,
provided that uxx+ u,,, = 0 is being solved: u(l ,I) = gl(t), 0 c t < T.
I
ui-l,j+l + 4ui.i+l f ui+l.j+l Here, f(x) is the initial condition. and g,(t) and p,(t) are
J2u J'u
-+-=
axZ ay2 + 4 ~ ~ -- ~~ O, U~ ~ +, 4~ ~ , + , , ~ the boundary conditions. The latter are of a particularly
simple type, since they specify the temperature itself at
+ u~-,,~-~+ ui+l,j-l the ends of the bar. On page 462, we consider boundary
AX)' conditio'ns of a more general nature which involve also
+ o[(Ax)~]. (7.9) the derivatives of the dependent variable.
432 Approximation of the Solution of Partial Differential Equations
7.5 The Explicit Form of the Difference Equation If the initial and boundary conditions do not match a t
In order to approximate the solution of (7.12) and (0,O) and (l,O), u ( x , t ) will be discontinuous at these
( 7 13), a network of grid points is first established through- cO'"e", and the question arises as to what values should
out the region 0 < x < 1 , 0 d t < T, as shown in Fig. 7.3, be assigned to, for example, v,,,. It appears reasonable in
Computed
f approximation
Boundary Boundary
condition: condition:
VO.n = (tn M,n = g~( t n ) xi-1 Xi fit1
Initial condition:_/TXi XM such a case to use the arithmetic average of the values
v i .=
~ f(x,)
given by f ( x ) as x -+ 0 and g,(t) as t -,0;in programming,
Figure 7.3 The difference problem. it is often simpler to use either one value or the other and
to recognize that a small error is thereby introduced.
with grid spacings Ax = 1/M, At = TIN, where M and N
are arbitrary integers. In this problem, it is easy to ensure Example. Consider the heat-conduction problem of (7.12)
that grid points lie on the boundaries of x and t, although, and (7.13), with the simple conditions f ( x ) = O and g,(t) =
as we shall see later, this correspondence is seldom pos- g l ( t ) = 100. Arbitrarily choose Ax = 0.2 and At = 0.01,
sible in two-dimensional problems when the boundaries corresponding to h = 114, so that (7.15) becomes
are irregularly shaped. For any grid-point (i,n) that
does not have i = 0, i = M, or n = 0, the derivatives of
(7.12) are now replaced by the finite-difference forms
suggested by (7.4) and (7.7) : We may then verify the tabulated values ofu,,,in Table 7.1,
computed to two decimal places.
as the grid spacings Ax and At tend to zero. We now NOW suppose that 0 < l < 4. The coefficients A and
show that a sufficient condition for convergence of the (1 - 2A) are nonnegative and we therefore have the
explicit method is that 0 < A < 3. The computational inequality
procedure is assumed to be capable of an exact represen-
tation of the solution of the finite-difference equation.
I~i,n+ 11 AIwi-l,nI + (1 - 2A)Iwi,nI + AIwi+ l,"I + I ~ i , ~ l .
This is not quite true in practice, since only a finite Let wmax(n)be the upper bound of IwiSjl, 0 <j < n,
number of digits can be retained by the computer and the 1 d i 6 M - 1, and let zm,,(n) be the upper bound of
phenomenon of round-off error is introduced. ( z , , ~0( <
, j d n, 1 d i d M - 1 . Then
From Taylor's expansion, supposing as usual that u
possesses a sufficient number of partial derivatives, ~max(n+ 1) 5 wrnax(n1 + zmax(n).
Therefore, over the whole region 0 ,< I < T, since
wm,,(0) = 0 and since zm,,(n) does not decrease with
time,
wrnax(N) 5 Nzmax(N- 1),
that is,
+o[(A~)']+o[(Ax)"]/ . (7.24)
(7.20) max
Problem Statement functions, the problem could be solved for arbitrary initial
An infinite parallel-sided slab (0 < x < L) of thermal and boundary conditions.
diffusivity a is initially (at time t = 0) at a uniform tem- The computations follow the explicit procedure sum-
perature 8,. Its two faces are subsequently maintained at marized by equations (7.14) through (7.17). Note that
a constant temperature 8,. Find how the temperature 0 the subscripts denoting time (n and n + 1 in equation
inside the slab varies with time and position. (7.15)) can be discarded by using Ti(TOLD([)) in the
program) to denote the known temperature at point i,
and T,I (TNEW(I)) to denote the temperature about to
Method of Solution be computed at the end of the time-step. After all the T/
The heat conduction equation is a d28/dx2= aO/at. By have been computed, they are referred to as Ti, and the
defining the dimensionless variables process is repeated over subsequent time-steps; since we
thereby avoid the storage of temperatures that are no
longer wanted, the memory requirements are considerably
reduced.
the problem can be rewritten as that of solving The input data to the program include AT (the time-
step), M (the number of increments AX), and T,,, (the
maximum temperature of interest at the center of the
slab). We avoid excessive output by printing the results
only periodically, after a certain number of time-steps
subject to the associated conditions
have elapsed. This periodic printing is achieved by
incrementing a counter once every time-step, and testing
to see if it is an integer multiple of the specified number
of steps. If so, the temperatures computed for that time
The problem is thus a special case of that stated in equa- are printed. A similar procedure is also incorporated
tions (7.12) and (7.13) ;the initial and boundary conditions into several of the subsequent examples in this chapter.
now have the simple forms f ( X ) = 0, go(?) = g,(t) = 1. We also use certain plotting subroutines, available at
The following program, however, obtains its initial and the University of Michigan computing center, for dis-
boundary conditions by calling on appropriate pre- playing graphically
- - - the compbted temperatures on the
defined functions (F, Go, GI). Thus, by modifying these printout. -
Example 7.1 Unsteady-State Heat Conduction in an Infinite,Parallel-Sided Slab (Explicit Method)
1
AX+- i
Begin * M *
Ti C
At-
A7 f( i ~ x )
(W2 $-
FORTRAN Zmplementatiorz
List of .Principal Variables
Program Symbol Definition
CONST 1 -- 21.
DX Space increment, AX.
DTAU Time-step, AT.
F Function giving the initial condition, f ( X ) .
GO, GI Functions giving the boundary conditions, g , ( ~ )and g,(z).
I Subscript denoting the ith grid point. Due to FORTRAN limitations, we have 1 < I < M + 1,
col-responding to 0 < i < M in the text.
ICOUNT Counter on the number of time-steps.
IFREQ, IFRPLT Number of time-steps elapsing between successive printings and plots of temperatures,
respectively.
M Number of intervals AX into which the slab is divided by the grid points.
PLOT?, PLOTP, Subroutines used for preparing on-line graph of computed temperatures (see below).
PLOT3, PLOT4
RATIO n == A ~ / ( A x ) ~ .
TAU Ti~ne,z.
TMAX Maximum center temperature to be computed.
TOLD. TNEW Vectors containing temperatures at the beginning and end of a time-step, respectively.
X Vector containing the X-coordinate of each grid point.
PLOTl and PLOT2 reserve a region of storage, known as the into the image. PLOT3 places the plotting character (*)
graph imnge, which will eventually contain all charac- -
for the series of points ( ~ ( 1 ) . ~ ( 1 ) ) . I I, 2,..., M + I , into
ters, blanks, etc., constituting the final graph; these sub- locations in the image governed by the coordinates of
routines also place symbols appropriate to the horizontal these points. PLOT4 controls the printing of the graph
and vertical grid lines, and to the numbers along the axes, image and inserts an appropriate label for the ordinate.
436 Approximation of the Solution of Partial Differential Equations
Program Listing
C A P P L I ED NUMERI CAL METHODS, EXAMPLE 7.1
C UNSTEADY-STATE HEAT CONDUCTION I N A PARALLEL-SIDED SLAB,
C SOLVED BY THE E X P L I C I T METHOD.
2
X ( I ) = (FLOAT!
TOLD([) = F(FLOATI*DX)
- 1.O)fFLOATK -
TAU = 0.0
WRITE ( 6 , 2 0 1 )
WRITE ( 6 , 2 0 2 ) TAU, ( T O L D ( I 1 , I = 1, MP1, I N T I
l COUNT = 0
.....
DO5
SUBSTITUTE NEW TEMPERATURES I N TOLD
I = 2 , M
.....
T O L D ( 1 ) = TNEW(1)
Data
DTAU = 0.005 , TMAX = 0.95, M = 10, IFREQ = 5, IFRPLT = 10
DTAU = 0.0025, TMAX = 0.95, M = 10, IFREQ = 10, IFRPLT = 20
DTAU = 0.001 , TMAX = 0.95, M = 10, IFREQ = 25, IFRPLT = 50
DTAU = 0.001 , TMAX = 0.95, M = 20, IFREQ = 25, IFRPLT = .50
DX = 0.05000
DTAU = 0.00100
TMAX = 0.95000
M = 20
IFREQ = 25
RATIO = 0.40000
IFRPLT = 50
DIMENSIONLESS DISTANCE X
Example 7.1 Unsteady-State Hear Conduction in an infinite, Parellel-Sided Slab (Explicit Method) 439
Discussion of Results have been added by hand. The accuracy of the computa-
The computer output is reproduced above for the 4th tions for all data sets may be checked from Table 7.1.1,
data set only. Each row of numbers represents the which compares values of the dimensionless center
temperatures computed for the indicated value of time, temperature T, with those given by Olson and Schultz
as in Table 7.1. The lines joining the points on the graph [17] corresponding to the known analytical solution:
7.7 The Implicit Form of the Difference Equation The boundary and initial conditions of the explicit
In the explicit method previously described, ui,,depends method still hold:
only on u ~ ,,-- l ~, vi,,- and v i + ,,,- ,.
Referring to Fig. U O , ~ +1 = g0(1n+ 11,
7.5, only those values of v within the pyramid-shaped
area A can have any influence on the value of vi,,, U ~ , n + l= gl(tn+l), (7.27)
whereas it is known that the solution u(x,y) of the PDE v i , ~=.f (xi).
depends also on the values of u both in A and in B for
times earlier than t,. At any one time level, equation (7.26) will be written once
for each point 1 < i < M - 1 , resulting in a system of
M - 1 simultaneous equations in the M - 1 unknowns
v i , , + , . The methods of solution for such a system will be
discussed after we consider the cdnvergence of the implicit
method.
7.8 Convergence of the Implicit Form
Following a procedure similar to that for the explicit
case, it is easily shown with the aid of Taylor's expansion
that
Ui,n+l - Ui,n =Aui-l,n+l " ?hui,n+l
+ J 3 ~ i + l , n + l + Zi,n, (7.28)
where
Figure 7.5 Limitation of the explicit method.
A
Figure 7.7 The discretization error.
Let w,,,(n) be the upper bound of Iwi,,l for 0 <j < n, + b,vl + c , ~ , +=~dl.
1 < E < M - 1, and let zmax(n)be the upper bound of
lzl,,l for 0 <j < n, 1 < 1; < M - 1. Then wma,(n + 1) d That is,
w,,,(n) + z,,,(n). Thus, over the whole region of
0 < t < T, since wma,(0) = 0 and since zma,(n) does not v1 = di - all',- 1 -
c,ul+1
I
decrease wlth time, a1c1- 1 a,c1- 1
6,-- 6, - -
w,,,(N) d Nzma,(N - 1 ) ; PC- 1 PI- 1
that is, from (7.29), which verifies the above form, subject to the following
recursion relations :
w,,,(N) < 'T[O(At+ (Ax)')]. (7.31)
aici- di - aiyi-
Therefore, we conclude that the implicit method con- p.=b.--,
1 1 yi=
verges to the solution of the PDE as At -+0 and Ax -t 0, Pi- I PL
regardless of the value of the ratio At/(Ax)'. Also, from the first equation of (7.33),
7.9 Solution of Equatio~lsResulting from the Implicit
Method
Having established the convergence of the implicit
scheme, we now return to study the solution of the M - 1 whence PI = 61 and y1 = dl/Pl. Finally, substitution of
linear equations which result at each time step, namely,
Use the implicit method to solve the same problem CALL TRIDAG (IF, L, A, B, C, D, V)
that has already been stated in Example 7.1. Here, the last five argument names are vectors that are
used to store the corresponding elements appearing in
Method of Solution equation (7.33). In order to make the subroutine more
general, two additional integers, IF and L, have been
The implicit technique employs the algorithm expressed introduced into the argument list. These correspond to
in equations (7.34) and (7.35) for the solution of the the first and last subscripts, f and 1, of the unknowns;
M - 1 algebraic equations (7.32) in temperature that that is, the unknowns are assumed to be vf, vf+,, . . .,
result at each time-step. For convenience .in later q-,, v I . In the present application of solving equation
examples, this algorithm is written as a subroutine named (7.32), f = 1 and I = M - 1.
Flow Diagram
Main Program
1
AX+- a i t -I
M + b i c l +2I
Begin
AT
Ic- - ci t -A
(AX)"
I
I
L - - - -- - - -
Ciui + I
Return + vityi--
Pi
I 4
FORTRAN Implementation
List o f Principal Variables
Program Symbol DeFnition
The variable names are the same as those listed in Example 7.1, except that TOLD, TNEW, IFRPLT, and the plotting
routines have been deleted, and the following have been added:
(Main)
A, B. C, D Coefficient vectors defined in equations (7.33).
T Vector of temperatures at each grid point.
TRlDAG Subroutine for solving system of simultaneous equations having a tridiagonal coefficient
matrix.
(Subroutine
TRI DAG)
BETA, GAMMA Vectors of intermediate coefficients pi and y i , defined in equations (7.35).
IF,L Subscripts f and I, corresponding to the first and last equations to be solved.
V Vector containing the computed solution.
Because of FORTRAN limitations, the subscripts in the text
...,M) are advanced by onewhen they appearin theprogram
(i = 0,1,
(1=1,2 ,..., M + l ) .
Example 7.2 Unsteady-State Heat Conduction in an Infinite Parallel-Sided Slab (Implicit Method)
Program Listing
Main Program
A.P
. ..P -L t.E-D NUMERICAL
- . - METHODS. EXAMPLE 7.2
UNSTEA,DY-STATE HEAT-CONDUCTION I N A PARALLEL-SIDED SLAB,
SOLVED BY THE I M P L I C I T METHOD.
GAMMACIF) = D ( I F ) l B E T A ( I F )
IFPl = IF + 1
2
I = L - K
V ( I ) = GAMMA([)
RETURN
- C(I)+V(l+l)/BETA(I)
C
END
Data
DTAU = 0.0025, TMAX = 0.95, M = 10, IFREQ = 10
DTAU = 0.0125, TMAX = 0.95, M = 10, IFREQ = 2
DX = 0.10000
DTAU = 0.01250
TMAX = 0.95000
M = 10
lFREQ= 2
RATIO = 1.25000
7.11 Consistency
The term consistency, applied to a certain finitedif-
The substitution vi,. =@(t)eJPxresults in an amplification ference procedure, means that the procedure may in
factor fact approximate the solution of the PDE under study,
1 and not the solution of some other PDE. For example,
E= 3 Ax' consider the explicit approximation,
1 + 4X sinZ/- 2
Since 141 G 1 for all A, the implicit procedure is unconditionally
' stable. of the one-dimensional heat-conduction equation
Example. The finite-difference equation proposed by
Richardson [22] for the PDE u, = u,, represents the time
derivative by the formula (7.6), in which the truncation error
is O[(At)2]:
The truncation error of the approximation is defined as the
difference between the finite differences and the deriva-
tives they are intended to represent. With the aid of
Following the usual procedure, we arrive at a quadratic Taylor's expansion, it is readily shown that the truncation
equation in the amplification factor: error corresponding to (7.40) and (7.12) is
consistent instead with an entirely different PDE, (7.43), written out in full, becomes
namely,
(4 (b)
Figure 7.8 (a) Crank-Nicolson method. (b) DuFort-Frankel method.
Also, by performing a Taylor" expansion, the following solution of ut = u,, but all can be extended to more than
approximtttion aan be derived for a2u/ax2, again at the one space dimension.
half-way point (i,n + -)): DuFort-Frankel Method [S]
aZu
-= 06,2ui,,, ,+ (1 - B)~:u~,~, (7.42)
Vi,n+l -Ui,n-1 -
-Vi-1.n-Vi,n-1 +vi+l,n
The solution of (7.50) presents no difiiculties and will not Vi.j.n + V i . j + l.n, (7.53a)
be discussed further, except to say that the following
restriction between the time and space increments must
be observed to ensure stability:
-Vi,j-l.n+l + 2(! l)Vi,j,n+l - Vi.j+l,n+l
V; + ~ i * , ~ (7.53b)
,~.
7.15 Additional Merhodsfor Two and Three Space Dimensions
Clearly, I1;I < 1 for any value of At, and the procedure is The third intermediate value v*** can actually be elimi-
unconditionally stable. Convergence occurs with a dis- nated between the three equations to produce an equiva-
cretization error O[(At)2+ AX)^]. We assume here, and lent system in which v* and v** can be regarded as suc-
in Section 7.15, that ratios such as Ax/Ay are held cessive approximations to v at the half time-step:
constant.
The implicit alternating-direction procedure also finds
an important application in the solution of elliptic PDEs
(p. 508).
with
d i = T , , i - l + f T i , j + ~ , j + l , for
d n - I = Tn-1, j - 1 +fTn-1, j + Tn-1, j + t
i=0,1,
+ Tn,j
.... n - 2 ] for j + 0,
..., n - 2
di=2T,,,+fT,,,,
4 - 1
for
=2Tn-1,1 +fTn-l,O + Tn,o
i=0,1,
I for j = 0,
where
454
Example 7.3 Implicit Alternating-Direction Method 455
Note: (a) the second form for the dipwhen j = 0, arises -
cessive columns, j = 0, 1, .. ., n 1 until all the T,fi are
from consideration of the boundary condition aT/d Y = 0 found at the end of the first half time-step.
at Y = 0, and (b) in the present problem, the boundary The temperatures at the end of the second half time-
values T,,.and T:,j are synonymous (both equal 1). step are found similarly, by applying equation (7.53b),
Equation (7.3.2) is the same as (7.33) in form, and may or its equivalent at the boundary Y = 0,to each point
be solved for the q:j (i = O,I, .. ., n - 1) by the algorithm in a row ( j= O,l, .. ., n - I), for successive rows
of (7.34) and (7.35). The procedure is repeated for suc- (i = O,l, ..., n - 1).
456 Approximation of the Solution of Partial Differential Equations
Flow Diagram
1 Ti,,+ 1 -
Tn,i+ 1
T?, + 1
I t -
(Ax)2 T,$t 1
I I
4. A
p---------------------
I
I Solve tridiagonal system having
coefficients a,, bi, ci, d,, i = 0, 1,
v
,-------
d
\
..
I
L
,,
\
1
I
I
(Subroutine TRIDAG)
FORTRAN Implementation
List of Principal Variables
Program Symbol De$nition
Because of FORTRAN limitations, all subscripts in the text are advanced by one when they appear in the program; e.g., Tosoand T,,,,,
become T(1.1) and T(N+l, N + 1 ), respectively.
458 Approximation of the Solution of Partial DifferentialEquations
Program Listing
A P P L l ED NUMERl CAL METHODS, EXAMPLE 7.3
TWO-DIMENSIONAL UNSTEADY STATE HEAT CONDUCTION I N AN I N F I N I T E
BAR OF SQUARE CROSS-SECTION, SOLVED BY THE I.A.D. METHOD,
DX -
FLOATN = N
l.O/FLOATN
RATIO = DTAU/(DX*DX)
WRITE ( 6 , 2 0 0 ) DTAU, DX, RATIO, TMAX, N, IFREQ
C
C .....
0 0 2
SET I N I T I A L AND BOUNDARY VALUES
l = l , N
.....
T(I,NPl) = 1.0
T(NP1,l) = 1.0
TSTAR( I ,NP1) = 1.0
TSTAR( N P l , I = 1.0
DO2 J61. N
TAU = 0.0
Data
DTAU * 0.05 , TMAX = 0.95, N = 10, IFREQ = 1
Computer Output
UNSTEADY STATE HEAT CONDUCTION I N A SQUARE BAR, I.A.D. METHOD, W I T H PARAMETERS
DTAU
DX =
- 0.05000
0.10000
RATIO = 5,00000
TMAX a 0,95000
N 10
lFREQr 1
AT A T I M E TAU = 0.05000
AT A T l M E TAU = 0.10000
TEMPERATURES I N CLUADRANT ARE
460 Approximation of the Solution of Partial Differential Equations
AT A T l M E TAU = 0.40000
TEMPERATURES I N QUADRANT ARE
AT A T l M E TAU = 0.75000
TEMPERATURES I N QUADRANT ARE
Example 7.5 Natural Convection at a Heated Vertical Plate
FORTRAN Implementation
List o f Principal Variables
Program Symbol Dejinition
DTAU Tirne-step, AT.
DX, DY Space increments, AX and A Y, respectively.
1. J Gmd-point subscripts, i, j.
ICOUNT Counter on the number of time-steps.
l FR EQ Number of time-steps between successive printings of temperatures.
JMAX Largest column subscript,j,,,, for which printout is requested, in case n is too large for the width
of the page.
M. N Number of grid spacings nz, n, in the X and Y directions, respectively.
PR Prandtl number, Pr.
T, TNEW Matrices of temperatures, T, T', at the beginning and end of a time-step, respectively.
TAU Time, z.
TAUMAX Largest value of z to be considered.
u, v Matrices of velocities U and V in the X and Y directions, respectively.
UNEW Matrix of velocities U' at the end of a time-step.
XMAX Height of the plate, X,,,.
YMAX Maximum distance from the plate, Y,,,.
Because of FORTRAN limitations, all subscripts in the text have
been advanced by one in the program; e.g., T,,. becomes T(M + 1.
N +I).
478 Approximation of the Solution of Partial DiffeSentiaZEquations
Program Listing
A P P L I E D NUMERICAL METHODS, EXAMPLE 7.5
FREE CONVECTION AT A HEATED VERTICAL PLATE.
NEW U V E L O C I T I E S .. ...
C
C ..... CALCULATE
. -
DOE J = 2 , N
6 UNEW(I,J) = U(I,J) + DTAU*
1
2
(((U(I,J+l)
--
(U(I,J)*(U(I,J)
-
2.0*U(10J)
--
+ U(I,J-l))/DYSQ)
U(I-l,J))/DX)
3 (V(I,J)*(U(I,J+l) U(I,J))/DY) + TNEW(I,J))
C ..... 1
DO 7
CALCULATE NEW V V E L O C I T I E S
= 2, M P l
.....
DO 7 J = 2, N P 1
7 V(I,J) = V(I,J-11 + YOVERX*(UNEW(I-1,J) - UNEW(I,J))
.....
#,
L
C ..... SUBSTITUTE
DO 8 1 = 2, M P 1
UNEW INTO U, AND TNEW INTO T
Example 7.5 Natural Convection at a Heated Vertical Plate
Data
M
YMAX
- 10
= 25.0
N 10
PR
IFREQ = 2 0
= 0.733
JMAX
DTAU
=
=
10
0.5
XMAX
TAUMAX
=
=
100.0
80.05
480 Approximation of the Solution of Partial Differential Equations
Computer Output
F R E E CONVECTI'ON A T A V E R T I C A L PLATE, W I T H PARAMETERS
N = lo
IFREQ = 20
JMAX = 10
XMAX = 100.00000
YMAX = 25.23000
PR = 0.73300
DTAU = 0.50000
TAUMAX = 80.04999
A T A T I M E TAU = 80.000
THE F I E L D OF V E L O C I T Y COMPONENT U I S
THE F I E L D OF V E L O C I T Y COMPONENT V I S
THE TEMPERATURE F I E L D I S
Example 7.5 Natural Convection at a Heated Vertical Plate 481
We can compare these results with those computed
Discussion of Results
by Hellums [ll] on a 39 x 39 grid with Ar = 0.1 ; his
The velocity and temperature fields are reproduced values agree almost perfectly with the analytical solution
above only for r = 80. A s examination of the complete to the problem given by Ostrach [is]. For X = 100,
printout, for r = 10, 20, . . ., 80, shows little change in representative steady-state values are given in Table
U, V, and T after r = 40 has been reached. Thus the 7.5.1; Hellums' results have been interpolated to corre-
results for z = 80 are essentially steady-state values. The spond to the present grid.
computations are for a 101 x 10 grid; the value P r = 0.733 The accuracy of the present results may be described
is that for air chosen by several previous investigators. as good, fair, or poor, depending on whether one is
In each case, the first column of figures corresponds to interested in the values of T, U, or V. However, note
the vertical plate, and the extreme right-hand column that the number of computations involved here (10 x 10
corresponds to Y = 25. All the values of V are negative, grid, Az = 0.5) is roughly only one seventieth of the
indicating that the horizontal velocity component is number required for a 39 x 39 grid with Ar = 0. I .
always directed towards the plate. The vertical velocity Note: It may easily be verified by subsitution that the
component U reaches a maximum a little way out from new dependent variables Ll/X1I2 and v X ' I 4 , together
the plate, except near the bottom of the plate, and then with T, are functions of just two new independent
decreases. The temperature T decreases monotonically variables, namely, Y / X 1 1 4 and r / X 1 I 2 .Thus the above
away from the plate. results may be condensed very considerably, if required.
7.21 Derivation of the Elliptic Difference Equation lying within R or on S, but which are not interior points,
are called boundary points (see Fig. 7.14).
Let R be a finite connected region in the xy - plane,
and let S denote the boundary of R (see Fig. 7.12).
We seek to determine a numerical approximation v of Figure 7.14 Interior ( 0 )and bomn&ry (0)points.
the solution u(x,y) of the boundary-value problem
We then approximate the PDE of (7.70) at each interior
poirit of the grid by the difference equation'
where k,, = k(i Ax,j Ay) and Ci,= C(i Ax,j Ay). At each
boundary point of fhe grid, we set
where k(x,y) > 0 and C(x,y) 2 0 in R.
An equation such as (7.70) would arise for steady-state
heat conduction in a flat plate, whose thermal conduc-
tivity k depends on position, with an internal heat where (i,j) is any point on S within a distance Ax of the
source (represented by f ) and a heat-transfer effeit at the boundary point (i, j).
surface of the plate (represented by C). Observe that the In the4generalease, we order the points on the grid
elliptic problem is time-independent. by assigning to each in succession an ordinal number k,
We introduce a rectangular grid on the region R, so and indicating it by Pk; we redesignate the value of v at
that every point ( i , j ) has four neighbors, as shown in this point by vk. If the total number of interior points of
Fig. 7.13. the grid in R is n, it is convenient to number the points
so that Pk is an interior point if and only if 1 g k < n.
We then eliminate from the finite-difference equations
the values of u at the boundary points by using the values
prescribed in (7.73). We are then left with a system of n
linear equations in the n values vk, k = 1,2, .. ., n for the
approximate function at the interior points. By defining
the vector
Figure 7.17 Sysrem of grid points leading to equation (7.84). 1. A is an irreducible matrix as explained on p. 299.
7.24 Iterative Methods of Solufion 485
Flow Diagram
i = 0,1, j = l,2,
Begin Ti,, + 100
...,n
4
r
"No Convergence" T
Ti,j,
i=O, 1, ..., n,
-
A F
j=O, 1, ..., n A
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
EPS Sum, E, of absolute values of deviations of temperatures from their previously computed values.
EPSMAX The largest tolerable value, emu,,of e.
HOLDT Temporary storage, T, for temperature while new value is being computed.
1. J Grid-point subscripts, i, j.
ITER Iteration counter, k.
ITMAX Upper limit, k, on number of iterations.
N Number of increments, n, into which the side of the square is divided.
T Matrix of temperatures, T.
Because of FORTRAN limitations, the subscripts in the text
are advanced by one in the program; e.g., To.othrough T.,. become
(T1.l) through T ( N t l , ~ + l ) .
488 Approximation of the Solution of Partial Differential Equations
Program Listing
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 7.6
C STEADY STATE HEAT CONDUCTION I N A SQUARE PLATE.
(6,202)
1
ITER
1 5 1, N P l
(T(I,J), J - 1, N P 1 )
..... COMMENT
WRITE (6,203)
I N CASE l T E R EXCEEDS ITMAX .....
DO 9 1 3 1, N P 1
WRITE (6,202) (T(I,J), J = 1, NP1)
GO TO 1
C
100
..... FORMATS FOR I N P U T AND OUTPUT STATEMENTS
FORMAT ( 1 1 X . 14, 11X, 14, 12X. E 8 . 1 )
.....
200 FORMAT ( 6 2 H l S T E A D Y - S T A T E HEAT CONDUCTION I N A F L A T PLATE, W I T H PAR
1AMETERSI lOHON = , 1 5 / 1 0 H ITMAX = , I S /
2 1 0 H EPSMAX = E12.2)
2 0 1 FORHAT ( ~ ~ H O C ~ N V E R G E N COND C E l T I ON HAS BEEN REACHED AFTER ,
1 13, 1 1 H I T E R A T I O N S / 34HOTHE TEMPERATURE F I E L D I S G I V E N B Y )
2 0 2 FORMAT (1H0, l l F 9 . 4 )
2 0 3 FORMAT (42HONO CONVERGENCE. CURRENT VALUES OF T ARE)
C
END
Data
N = 8, ITMAX = 100, EPSMAX = 1.OE-4
N = 4, ITMAX = 50, EPSMAX = 1.OE-5
Example 7.6 Sready-State Heat Conduction in a Square Plate
Computer Output
Results for the Is! Data Set
STEADY-STATE HEAT CONDUCTION 1N A F L A T PLATE, W I T H PARAMETERS
N P 8
ITMAX = 100
EPSMAX = 0.10E-03
THE TEMPERATURE F I E L D I S G I V E N BY
N = 4
ITMAX = 50
EPSMAX 0.10E-04
THE TEMPERATURE F l E L D I S G I V E N BY
490 Approximation of the Solution of Partial Differential Equarions
4"
T(x, Y)= 7
5 1 (2n + 1)nx
Discussion of Results .=o + 1) sin a
(2n
The printout shows the distribution of temperature in (a - y)(2n + 1)x
the plate for both 8 x 8 and 4 x 4 grids. Even with such x sinh cosech(2n + l)x,
a
coarse grids, there is fairly good agreement between the
two cases. where a is the side of the square, To (= 100) is the tem-
The computed temperatures may be compared with perature of the side y = 0, and the coordinate system is
the analytical solution given by Carslaw and Jaeger [2]: shown in Fig. 7.6.1.
EXAMPLE 7.7
DEFLECTION OF A LOADED PLATE
f f f,
Thus, for Ax = Ay, the Gauss-Seidel method amounts to
Figure 7.7.1 Loaded square plate. repeated application of
Flow Diagram
Main Prograin
Enter j = l,2,
..., n - 1 ..., n - 1
/ /
/ /
I / /'
/ 0
I / 0
0
I / / / /)
/'
/I 0
I / ' / /
'/'
& 1
1
+ 4i,j-l+ C i , j + ~-
41, ei[4i-l,j + 4i+r,j ):( 2
d'i.j] -I 1
Example 7.7 Dejection of a Loaded Plate
FORTRAN Implementation
List of Principal Variables
Program Symbol Dejnition
(Main)
D Fleitural rigidity, D, lb, in.
E Young's modulus, E, lbf/sq in.
I. J Grid-point subscripts, i, j. Because of FORTRAN limitations, we have 1 < I d N + 1. corre-
sponding to 0 d i d n, and similarly for J.
ITMAX Number of Gauss-Seidel iterations, k,,,.
L Length of side of square, L, in.
N Number, n, of grid spacings along a side of the square.
POISON Subroutine for solving Poisson's equation by the Gauss-Seidel method.
Q Load per unit area of the plate, q, lb,/sq in.
QOVERD Matrix, with values of qouerd = q/D at each grid point.
SIGMA Poisson's ratio, o.
T Plate thickness, t, in.
u Matrix of intermediate variable, u = V2w, at each grid point.
w Matrix of downwards deflection, wl, in., at each grid point.
(Subroutine
POISON)
ITER Iteration counter, k.
PHI, PSI Matrices of functions 4 and $, occurring in Poisson's equation, VZb,= I/.
494 Approximation of the Solution of Partial Differential Equations
Program Listing
Main Program
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 7.7
b
.C DEFLECTION OF A UNIFORMLY-LOADED SQUARE PLATE.
D = E*T*+3/(12.0*(1.0
RHS = ' Q / D
- SIGMA++2))
DO 2 1 = 1, N P 1
DO 2 J = 1, N P l
W(I,J) = 0.0
U(I,J) = 0.0
2 QOVERD(I,J) = RHS
C
C ..... SOLVE DELSQ(U1 = Q/D
CALL POISON (N, L, U, QOVERD,
..... ITMAX)
C
C ..... SOLVE DELSQCW) = U
CALL POISON (N, L, W, U, ITMAX)
.....
C
C ....,
WRITE
P R I N T INTERMEDIATE U ' S AND THE DEFLECTIONS W
(6,202)
.....
DO 3 1 = 1, N P 1
3 WRITE (6,203) (U(l,J), J = 1, NP1)
WRITE (6,204)
DO 4 1 = 1. N P l
C
C
100
..... FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT (3X, 12, 9X, 14, 2(6X, F4.1),
.....
lox, F0.1, 6X, FS.1, 6X,
1 E7.1)
200 FORMAT ( 8 7 H 1 SOLUTION OF BlHARMONlC EQUATION FOR DEFLECTION 0
1 F A UNIFORMLY-LOADED SQUARE PLATE)
= , 1 4 / - l l ~ , SHITMAX = , 1 0 /
201 FORMAT (IHO, l o x , 8HN
1 11X, 8HQ
2 ll~, 8HSIGMA
= , F10.5/ 11X. 8HT
, F10.5/ 11~;8HL
= . F10.5/
= , F10.5/
3 11X, 8HE = , E11.2)
202 FORMAT (35HO THE INTERMEDIATE VALUES U ARE)
203 FORMAT (1H0, 4X, 9F10.6)
204 FORMAT (33HO THE F I N A L DEFLECTIONS W ARE)
C
END
Subroutine POISON
C SUBROUTINE FOR SOLVING POISSON'S EQUATION.
C D E L S Q ( P H I 1 = PSI(X,Y),
C I N A SQUARE OF S I D E L, ALONG WHICH THERE ARE N INCREMENTS.
C ITMAX GAUSS-SEIDEL ITERATIONS ARE PERFORMED AT A L L G R I D POINTS.
Example 7.7 Deflection of a Loaded Plate
Prognm Listing (Continued)
C
SUBROUT lNE POISON (N, L, PHI, PSI, ITMAX)
REAL L
.DIMENSION PHI(l1,11), PSI(11,ll)
FN = N
DXSQ (L/FN)**2
PHIII,J)
1
1
r 0 . 2 5 * ( ~ ~ 11
RETURN
( -1,~)
+ PHI(I,J+l) -
+ PHI( I+l,J) + PHI( 1,J-1)
DXSQ*PSI(I,J))
C
END
Data
N
N
N
N
*
* 4,
= 8,
4,
8,
ITMAX =
ITMAX
ITMAX -
5,
25,
ITMAX = 25,
100,
Q = 1.0,
Q = 1.0,
Q = 1.0,
Q = 1.0,
T = 0.2,
T 0.2,
T = 0.2,
T = 0.2,
SIGMA
SIGMA
SIGMA
SIGMA
=
=
=
=
0.3,
0.3,
0.3,
0.3,
L = 40.0,
L 90.0,
L = 40.0,
L = 40.0,
E -
E = 30.0E6
30.OE6
E = 30.OE6
E = 3D.OE6
Computer Output
Results for the 2nd Data Set
SOLUTION OF BlHARMONlC EQUATION FOR DEFLECTION OF A UNIFORMLY-LOADED SQUARE PLATE
N 4
ITMAX* 25
Q 1.00000
T * - 0.20000
SIGMA = 0.30000
L = 40.00000
E = 0.30E 08
THE INTERMEDIATE VALUES U ARE
N = 8
ITMAX = 100
Q = 1.00000
T = 0.20000
SIGMA = 0.30000
L = 40.00000
E = 0.30E 08
THE I N T E R M E D I A T E VALUES U ARE
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 -0.001294 -0.002020 -0.002396 -0.002513 -0.002396 -0.002020 -0.001294
0.0 -0.002020 -0.003251 -0.003914 -0.004123 -0.003914 -0.003251 -0.002020
0.0 -0.002396 -0.003914 -0.004749 -0.005014 -0.004749 -0.003914 -0.002396
0.0 -0.002513 -0.004123 -0.005014 -0.005299 -0.005014 -0.004123 -0.002513
0.0 -0.002396 -0.003914 -0.004749 -0,005014 -0.004749 -0.003914 -0.002396
0.0 -0.002020 -0.003251 -0.003914 -0.004123 -0.003914 -0.003251 -0.002020
0.0 -0.001294 -0.002020 -0.002396 -0.002513 -0.002396 -0.602020 -0.001294
0.0 0.0 0.0 0.0 0.0 0 .o 0.0 0.0
THE F I N A L D E F L E C T I O N S W ARE
then the angle of twist 0, per unit length, is given by Figare 7.8.2 Q d r a n t of ellipse.
Hughes and Gaylord [33] as
The grid points within the ellipse are subdivided into
five main categories:
where the integral is over the whole cross-sectional area, 1 . Interior points. The appropriate finite-difference
and # is the solution of approximation of (7.8.2) at the interior points is
V2$ = -2, (7.8.2) $ij = +C$'i-l,j + $ i + l , j + $i,j-~ + #i.j+l + 2(Ax)21*
with 2. Lower Boundary Points ( y = 0). Because of sym-
metry about the x axis,
11 = 0 on the surface of the ellipse.
Since the analytical solution of (7.8.2) is
categories :
That is,
Type I: Point (i,jmaxi), if this is not of type 111 or IV.
Type 11: Points (i,j), if any, for which jmaxi+ <j < $ij = c[dt+hlej- + e$i- l , j +f$A + gt,bB+ AX)^], (7.8.5)
jmaxi.
Type III: Point (i,jmaxi), only if it is not of type IV and where
if j m a ~ = ~ jmaxi.
+~ . ab 1 1 1
Type IV: Occurs if the curved boundary produces an
intercept within kc of a grid point, where c: << 1.
c=-
a+b7
d=-
b + 1' e=a
a(a+l)'
f=-
I(i-lqJ)
to each point. The iterations are discontinued when the the RMS (root mean square) deviation of II/ from its known
sum E over all grid points of the absolute values of the analytical solution, (7.8.3).
deviations of $ from its previous value falls below some We have not attempted to write a concise flow diagram
small quantity E,,,. An upper limit is also placed on the for this example. Instead, the overall approach can be
number of iterations. understood best by reading the above description in
Finally, the function COMPAR is called to determine conjunction with the program comment cards.
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
(Main)
ALPHA, BETA Semiaxes of the ellipse, a and P.
BNDPTS Subroutine for locating the boundary points and their associated intercepts.
C, D, E. F. G, Expressions defined in equation (7.8.6).
COMPAR Function for determining the RMS deviation, RMSDEV, of the computed values II/ij from
their known exact values.
DX Space increment, Ax = Ay.
EPS Sum E of the absolute values of the deviations of the II/ij from their previously computed values.
I, J Grid-point subscripts, i , j. Because of FORTRAN limitations, we have 1 5 I I M + 1 and
I I J I N + I in the program, corresponding to 0 < i 5 m and 0 Ij 5 n in the text.
ITER Counter on the number of Gauss-Seidel iterations.
ITMAX Maximum allowable value of ITER.
ITYPE Matrix giving the type of each boundary point (see Figs. 7.8.2 and 7.8.3).
JLOW, JHIGH Vectors such that JLOWI(1) and JHIGH(1) contain the column subscripts J of the first and last
boundary points (of types I-IV) in row I.
JMAX Vector such that JMAX(I) contains the column subscript J of the rightmost grid point in row I.
JR Vector such that JR(I) contains the highest column subscript of a completely interior point in
row I.
Number of intervals, rn and n, into which the minor and major semiaxes of the ellipse are divi-
ded.
PSI Matrix containing the values of $ at each grid point.
SAVPSI Temporary storage for the current value of II/ij.
(Subroutine
B N D PTS)
EPS Small distance 6 (see Fig. 7.8.3).
(Function
COMPAR)
C +
a2P2/(aZ P2).
DEVSQ The sum of the squares of the deviations.
l PTS The total number of grid points.
TRUPSI The true value of I) at each grid point.
Example 7.8 Torsion with Curved Boundary
Program Listing
Main Program
C A P P L l ED ',,i)blERI CAL METHODS, EXAMPLE 7.8
C TORSION UF A CYLINDER OF E L L I P T I C A L CROSS-SECTION.
C
C l NVOLVES GAUSS-SEI DEL TYPE SOLUTION OF POISSON'S EQUATION,
DELSQ(PS1) = 2, -
THROUGHOUT THE UPPER RIGHT-HAND QUADRANT OF AN E L L I P S E .
THERE ARE N AND M GRID SPACINGS RESPECTIVELY ALONG THE
MAJOR AND MINOR AXES OF LENGTHS ALPHA AND BETA. PSI I S
ZERO ALONG THE CURVED PORTION OF THE BOUNDARY. INTER-
POLATION OF DEGREE TWO I S EMPLOYED AT THE BOUNDARY POINTS.
C
C
..... CALL
BOUblDARY PO l NTS AND THE1 R ASSOCIATED l NTERCEPTS .....
ON SUBROUTINE BNDPTS TO DETERMINE THE
..... CENTER P O I N T
SAVPSI = P ! S I ( l , l )
.....
= (2.0*PS1(Z81)
PSI(1,l)
EPS = EPS + A B S ( P S I ( 1 , l ) -
+ 2.0*PS1(1,2)
SAVPSI)
+ TUOXSQ)/4.0
C ..... I N T E R I O R POINTS
DO 2 1 1 = 2, M
.....
JHIGH = JRCI)
I F ( J H I G H .LT. 2 ) GO TO 2 1
DO 6 J = 2, J H I G H
SAVPSI = P S I ( I , J )
PSI(I,J) = (PSI(1-1,Jl + PSI(I+l,J) 4 PSI(I,J-I)
1 * PSI(I,J+l) + TUDXSQ)/4
6 EPS = EPS + A B S ( P S I ( I , J )
2 1 CONTINUE
SAVPSI) -
502 Approximation of the Solution of Partial Differential Equations
-,
205 FORMAT (1H0, l l F 9 . 4 )
206 FORMAT (60HO RMS D E V I A T I O N BETWEEN COMPUTED AND EXACT P S I VALU
1ES I S / 1 5 H 0 RMSDEV F10.5)
C
END
Subroutine BN D P T S
FJMl JM1.
J = JMl + 1
JMAXZI~ = J
-
--
YOVRDX = FM+SQRT( 1.0 FJMl+FJMl/FNSQ)
A = YOVRDX FIM~
B = XOVRDX FJMl
I F (ABS(A) .LT. EPS) GO TO 2
I F (ABS(B) .GE. EPS) GO TO 3
ITYPE(I,J) = 3
A = 1.0
F(I,J) = 0.5
GO TO 6
5 ITYPE(1,J) = 1
6 CON11NU E
C(I,J) = A+B/(A + 0)
D(I,J) l.O/(B + 1.0)
E(I,J) = l.O/(A + 1.0)
7 CONTINUE
C
c ..... LOCATE BOUNDARY PO INTS OF TYPE 2 .....
FlM1
J
--
DO 11 I = 2, M
I
JMAX( 1)
1
1
8
FJMl 0 J
A
-
I F ( J M A X ( I + l ) .GE. J) GO TO 1 0
FM+SQRT(l.O -
1
FJMl+FJMl/FNSQ) -
FlMl
ITYPE(1,J) = 2
C(1.J) = A / ( A + 1.0)
GO TO 8 -
10 CONTINUE
11 JRCI = J
RETURN
C
END
504 Approximation of the Solution of Partial Diferential Equations
Function COMPAR
C FUNCTION FOR COMPARING THE COMPUTED SOLUTION W I T H I T S
C KNOWN ANALYTICAL VALUE.
C
L
FUNCTION COMPAR (M, N, JMAX, PSI, ALPHA, BETA)
DIMENSION JMAX(211, PS1(21,21)
C
C .....=
1 PTS
COMPUTE THE SUMS OF THE DEVIATIONS SQUARED
0
.....
DEVSQ = 0.0
FMSQ = M*M
FNSQ = N*N
FIMl I 1-
J H l G H = JMAX(1)
DO 1 J = 1, J H l G H
FJM1 = J 1-
l PTS l PTS + 1
TRUPSI = ( 1 . 0 -
FIMl*FIMl/FMSQ
1 DEVSQ = DEVSQ + ( P S I ( I , J ) - -
FJMl*FJMl/FNSQ)*C
TRUPSl)**Z
C
C ..... COMPUTE THE ROOT MEAN SQUARE D E V I A T I O N
PTS = l PTS
.....
COMPAR = SQRT(DEVSQ/PTS
RETURN
C
END
Data
M I = 5, ITMAX = 100,
ALPHA = BETA = 8.0, EPSMAX =
M = 5, ITMAX = 100,
ALPHA = BETA a 8.0, EPSMAX =
M = = 5, ITMAX = 100,
ALPHA = BETA I 8.0, EPSMAX =
M = = 5, ITMAX = 200,
ALPHA. = BETA = 8.0, EPSMAX =
M I = 5, ITMAX = 200,
ALPHA = BETA = 8.0, EPSMAX =
M = = 10, ITMAX = 500,
ALPHA = BETA = 8.0, EPSMAXr
M I = 10, ITMAX = 300,
ALPHA = BETA r 8.0, EPSMAX =
M I = 10, ITMAX 8 500,
ALPHA = BETA = 8.0, EPSMAX =
Example 7.8 Torsion w i ~ hCurved Boundary
Computer Output
Results for the 5th Data Set
TORSION OF CYLINDER OF E L L I P T I C A L CROSS-SECTION, W I T H PARAMETERS
M 4
N 5
ITMAX 200
ALPHA = 1 0 . 0 0 0
BETA = 8.000
EPSMAX a 0.001
RESULTS ARE FOR INTERPOLATION OF DEGREE TWO, W I T H GAUSS-SEIDEL ITERATION
ITER = 75
EPS m 0.9260E-03
0.0
17.0729 15.5120 10.8291 3.0244
29.2678 27.7069 23.0240 15.2193 4.2926
36.5846 35.0237 30.3410 22.5363 11.6096
RMSDEV = 0.00042
506 Approximation of the Solution of Partial DifferentialEquations
THE FOLLOWING VALUES ENABLE THE BOUNDARY AND INTERIOR POINTS TO BE LOCATED
ITER = 232
EPS = 0.9897E-82
0.0
36.5772 36.1872 35.0170 33.0665 30.3356 26.8254 22.5328 17.4608 11.6082 1.9750
38.4057 38.0158 36.8456 34.8951 32.1654 28.6532 24.3617 19.2896 13.1371 6.80bO
39.0155 38.6252 37.4550 35.5046 32.7738 29.2627 24.9712 19.8992 14.0567 7.4137 0.6
d Ip(x)
dx
11 +c,
dy
dx
$1 +
-=O
y +c,- L ~ Y= O
dx
[q(x) + i r ( r ) l y = 0,
at x
at x
= a,
= b,
a < x < b,
(7.93)
Let the vector v be defined by
v= [I. vn
(7.98)
solutions exist only for discrete values of 1 that are and R is the diagonal matrix with elements r,, r2, . . ., rn
known as the characteristic values of the problem; the along the main diagonal. For convenience, since r(x) > 0 ,
corresponding solutions are called the characteristic we can set
functions. We study here a method for the approximate
treatment of such problems.
Consider the following slightly simplified version of
the general Sturm-Liouville problem:
and replace (7.99) by the equivalent system
Ax = Ax. (7.102)
Flow Diagram
n, and control
parameters for RUTIS (see text)
F -
Apply LR transformation to A and B.
UTISworked satisfactorily
TAG^ = F and TAG2 = F -
A Transformed matrices are Anew,B,,,.
Eigenvectors are stored in R and S.
for both transformations) (2 calls on subroutine RUTIS)
\
\
\
\
\
\
. \
\
FORTRAN Implementation
List of Principal Variables
Program Symbol Defnition
A. B Matrix A appearing in equation (7.9.7), and its transpose B.
ANEW, BNEW Transformed matrices returned by RUTIS.
c Vector of coefficients c j , defined in (7.9.10).
DR Radial grid spacing, Ar,
DT Time interval between successive printings of temperatures.
FREQ, ITMAX, EPSI, Parameters for use in subroutine RUTls (see Example 4.3).
EPS2, EPS3, EPS4,
EIGVEC, STRIPD,
SWEEP, TAG1, TAG2,
ITER
LAMBDA Vector af eigenvalues A,.
N Number of grid points, n, at which temperatures are to be computed.
P Matrix P = R'S, with elements given by (7.9.11).
R, S Matrices whose columns contain eigenvectors r and s of A and B, respectively.
RI, R 2 Radii d inner and outer cylinders, r, and r, , respectively.
RUTIS Subroutine; for finding the eiganvalues and eigenvectors of a matrix (see Example 4.3).
T Time, t,
THETA Vector of temperatures,. Q1.
TMAX ]Maximum value of time to be considered, t,,,.
514 Approximation of the Solution of Partial Differential Equations
Program Listing
A P P L l ED NUMERl CAL METHODS, EXAMPLE 7.9
UNSTEADY CONDUCTION BETWEEN CYLINDERS (EIGENVALUE PROBLEM).
FN = N
DR * ( R 2 - Rl)/FN
DUN = l . / ( D R * D R )
D = 2.*DUM
DO2 1 = 1 , N
THETA( I ) = 0.0
DO2 J = l , N
= 0.0
A(I,J)
NM1 = N
NP1 = N + 1
- 1
DO 3 1 = 1, NM1
A(1,I) a D
FI = I
A(I,I+l)
A(I+1,1)
5
=
--D U M * ( l . + O.S/(Rl/DR
DUM*(l. - 0.5/(Rl/DR
+ FI -
+ FI))
1))
A(N,N)
A(1,2)
= D
DO4 1 = l , N
- D
DO4 J = l , N
B(I,J) = A(J,I)
WRlTE ( 6 , 2 0 3 )
DO5 1 - 1 , N
WRlTE (6,204) (A(I,J), J = 1, N)
WRlTE (6,208)
DO9 1 = 1 , N
WRlTE (6,204) (BNEW(I,J), J 1, N)
WRlTE (6,209)
DO 1 0 1 = 1, N
WRlTE ( 6 , 2 0 4 ) (S(I,J), J = 1, N)
0 0 11 1 = 1, N
LAMBDA( I ) ANEW( I, I )
Example 7.9 Unsteady Conduction Between Cylinders (Characteristic-Value Problem)
DO 1 2 K = 1, N
P(I,J) = P8(I,J) + R(K,I)*S(K,?)
WRITE (6,210)
DO 1 3 1 .I 1, N
WRITE (6,204) (P(I,J), J 1, N)
.....
DO 1 4 J
DETERMINE COEFFICIENTS C ( J ) FROM I N I T I A L CONDITION
1, N
.....
C ( J ) = 0.
DO 1 4 1 1, N
C(J) = C(J) + S(I,J)/P(J,J)
WRITE (6,211)
WRITE (6,204) (CCJ), J a 1, N)
18
DO 18 J
THETA( I ) -
THETA ( I ) = 1.
WRITE (6,213)
MIN. N
THETA( I -c ( J ) * R ( I ,J)*DEXP(-LAMBDA(J)*T)
T, (THETA(J1, J = 1, NP1)
C
C
100
..... FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT (4(12X, F6.1)/
.....
3(12X, 1 6 ) / 4(12X, E6.011 3(12X, 1 6 ) )
200 FORMAT ( 6 9 H 1 UNSTEADY STATE HEAT CONDUCTION BETWEEN CONCENTRIC C
IYLINDERS, WITH/ 1HO)
201 FORMAT (8X, 1 0 H R 1 = F10.4/ 8X, 10H R2 = , F10,4/
1 8X, 10H DT = , F10.4; 8X, 10H TMAX = , F10.4/
2 8X, 10H 11 = , 15 / 8X, 10H FREQ = , IS /
3 8X, 10H IITMAX = , I S / 8X, 10H E P S l ,
= ElO.l/
4 8X, 10H EPS2 = , E10.1/ SX, 10H EPS3 = , ElO.l/
5 8X, 1 0 H EPS4 , E10.1/ 8X, 1 0 H EIGVEC , 15 /
6 8X, 1 0 H STRIPD = , LS / SX, 1OH SWEEP = L5)
202 FORMAT (lHO, 7X, 10H TAG1 a , LS/ 8X, 10H ~ A G Z = , LS/
1 8 X . 1 0 H ITER = . IS)
203 -FORMAT (24HO S T A ~ T NG I MATRl X A IS / l H )
204 FORMAT ( S X , XOFlO.6)
205 FORMAT ( 3 0 ~ 0 TRANSFORMED MATRIX ANEW I S / l H
206 FORMAT 146HO MATRIX R, CONTAINING EIGENVECTORS OF A, I S / l H 1 )
207 FORMAT (26HO TRANSPOSED MATRIX B I S / l H )
208 FORMAT (30HO TRANSFORMED MATRIX BNEW I S / l H )
209 FORMAT (46HO MATRIX S, CONTAINING EIGENVECTORS OF B, I S / l H
210 FORMAT (79HO ORTHOGONALITY REQUIRES OFF-DIAGONAL ELEMENTS OF FOL
lLOWlNG MATRIX TO BE ZERO/lH )
211 FORMAT (36HO THE COEFFICIENTS C(l),..C(N) ARE/lH 1
212 FORMAT ( 8 5 H 1 TIME TEMPERATURES AT GRID POINTS ( I N N
1ER SURFACE TO OUTER SURFACE)/lH )
213 FORMAT (1M , F 7 . 3 / ( 8 X t llF8.5))
C
END
516 Approximation of the Solution of Partial Differential Equations
Computer Output
UNSTEADY STATE HEAT CONDUCTION BETWEEN CONCENTRIC CYLINDERS, WITH
R1
R2
DT
TMAX
N
FREQ
l TMAX
EPSl
EPS2
EPS3
EPS4
E l GVEC
STR l PD
SWEEP
STARTING MATRIX A I S
TRANSPOSED MATRl X B I S
TAG1 = F
TAG2 = F
ITER = 41
M A T R I X S, C O N T A I N I N G E I G E N V E C T O R S O F B, IS
THE C O E F F I C I E N T S C ( l ) . . . . C ( N ) ARE
Problems
7.1 Verify the following finite-difference approximations
for use in two dimensions at the point (i,j):
a4u ui-2,j-4ui-~,j+6~1,j-4~1+1.j+ui+2.j
(a) -=
ax4 (Ax)4 depending on which approximation is used for u. (=au/a.u).
+ O[(AX)~I. Although these formulas are implicit and relate to a two-
dimensional problem, counterparts could easily be derived for
au - 3 ~ ~ . ~ + 4 ~u i~+ +
~ , ~] . ~ -
(b) -=
ax -2Ax
+ o[(Ax)21. explicit and/or one-dimensional problems. Also, the value of a
and/or g might be zero in certain applications.
From the points of view of accuracy and computational
convenience, investigate the desirability of this alternative way
of accounting for boundary conditions.
Suggest possible uses of formulas (b) and (c). 7.13 One-dimensional unsteady heat conduction in a
7.2 Verify equation (7.8) for the finite-differenceapproxi- medium is governed by the equation a(E2T/axZ)= aT/ar, in
mation of a2u/axay. which Tis temperature ( O F ) , x i s distance (ft), t is time (hr), and
7.3 Verify equation (7.9) for the finite-differenceapproxi- a is the thermal diffusivity (sq ft/hr) of the medium.
mation of the Laplacian during the solution of u,, +
u,, = 0.
7.4 Rework the numerical example in Section 7.5, using
the explicit method with Ax = 0.2 and At = 0.02, that is,
h = 112.
I Medium
Figure P7.13
Investigate the stability of this procedure. A heat flux density q (BTU/hr sq ft) is imposed on the
7.7 Verify the formula given on page 453 for the amplifica- boundary x = 0 of the medium shown in Fig. P7.13. If the
tion factor during the solution of u,, + u,, = u, by the implicit thermal conductivity of the medium is k (BTU/hr sq ft OF),
alternating-direction method. what is the explicit finite-difference approximation of the heat
7.8 Set up the analog of (7.52) for solvingu,, + + u,, u,,= conduction equation at grid-point 1 ?
u, by a simple extension of the implicit alternating-direction Note. Fourier's law of heat conduction is: q = -k aT/ax.
method. If Ax = Ay = Az, show that the method will be unsta- 7.14 The equation u,, +
u,, = u, is being solved explicitly
ble at least for h > 312. for the region shown in Fig. P7.14. The boundary conditions
7.9 Investigate the stability of the following two pro- are of the Dirichlet type. What formula should be used to
cedures for solving u,, + +uy, u,, = u, : (a) the alternating- compute u,,,+, ? Assume that Ax = Ay.
direction modification of the Crank-Nicolson method, (7.54),
and (b) Brian's method, (7.55).
7.10 Show that Brian's method, (7.55), for solving
u,, + +u,, u,, = u,, can be reexpressed in the form of (7.56).
7.11 The following nonlinear PDE governs unsteady heat
conduction in a bar:
Following Hughes and Gaylord [33], the required torque M section, based on the temperatures already computed in part
is given by (a). The following values are suggested: dpldz = -0.05 lb,/cu
ft, =5 x lb, seclsq ft, c = 8000°, d = 460°, and
a = 213 ft.
where the integral is over the cross section, and Il,is the solution (c) Finally, write an additional extension to the program
of that will estimate the total flow rate of oil, Q cu ftlsec, by
v2* = -2 evaluating numerically the integral
Note. the elliptic equations in parts (a) and (b) may also
be solved by the implicit alternating-direction method (page
452).
7.31 A deep region of liquid is at a uniform initial tem-
perature T o . At a time t = 0, the temperature at the surface is
lowered to T,, at which value it is held constant. The liquid
freezes at a temperature Tf, where T, < Tf < To, so that a
frozen region grows into the liquid, as shown in Fig. P7.31.
T, Surface
Figure P7.30
Figure P7.32
At the end of the summer, when injection is complete, the can be found from equation (4). Ifp,, < p,, then of course the
reservoir pressure is uniformly at a high value PO.Gas is then scheme becomes unworkable within the framework of mini-
to be withdrawn from A at a well pressure pwa that must at mum delivery pressure as specified above.
least equal a specified delivery pressurepa. Over the subsequent Note that when developing a finite-difference formulation of
period 0 d t < t,.,, the gas is scheduled to be withdrawn at a equation (I), m will be zero for all blocks except A, in which we
volumetric flow rate Q (referred to standard pressure and then have the relation r n ( A ~ ) ~=hm,.
temperature pS and T,) that conforms to the pattern of anti-
cipated demand shown k Fig. P7.346. Following the guide- Suggested Test Data (Not in Corzsistent Units)
Ax = Ay = 400 ft, h = 27 ft, E = 0.148, k = 168 md (milli-
darcies; 1000 md = 1 darcy E 1 centipoise sq cmlsec atm),
p = 00.128 centipoise, M = 16 Ib,/lb mole (that for methane),
R = 10.73 psia cu ft/lb mole O R , T = 545"R, r,= 4 in.,
p a = 1185 psia, pd = 520 psia, t,,, = 100 days, T, = 520°R,
and p, = 14.65 psia.
7.35 Perform more elaborate calculations on the lines of
Problem 7.34, but now allowing for one or more of the follow-
ing modifications :
(a) Permeability and porosity no longer uniform, but
varying from block to block.
(b) Multiple wells, all coming on stream simultaneously,
with identical well pressures.
(c) Multiple wells, scheduled to come on stream in succes-
Figure P7.346 sion, so that 'the peak withdrawal rate is maximized.
(d) Nonideal gas behavior.
lines below, write a program that will estimate the maximum (e) Operation over several yearly cycles, with the reservoir
feasible peak supply rate Q,,,;the output from the program pressure not necessarily uniform at the end of the injection
should also include the corresponding well pressure as a period.
function of time. (f) Rectangular grid (Ax # Ay), often useful if the rock
The equations governing the variation of pressure through- formation extends appreciably further in one horizontal
out the reservoir are: direction than in the other.
a a ap 7.36 An underground rock formation of porosity E and
Continuity: - (pu) + - (pv) + m = - E - . permeability k is initially saturated with water of viscosity y o
ax ay 2t
and density p, at a pressure po. Part of the formation is to be
sealed by injecting into it a grout solution at a constant pres-
Darcy' s law:
k -
u= -- ap v = - - -k ap
ax' P ay' sure p, from a vertical well. The well is fairly deep so that the
flow is predominantly radially outward from the well bore,
MP whose radius is r,. The grout solution is made up in one batch,
Ideal gas law : p = F~
and its viscosity p1 increases everywhere with time f according
to the relation
Here, t = time, E = rock porosity, k = rock permeability,
p = gas density, p = gas viscosity, p = pressure, u and v =
superficial velocities in the x and y directions, m = mass rate of
withdrawal of gas per unit volume of rock, M = molecular
where a, b, and c are experimentally determined constants.
weight, R = gas constant, T = absolute temperature, and con-
sistent units are assumed; E , k, p, M, and T are assumed Assuming that both the grout solution and the water are
constant. slightly compressible and obey the same equation of state,
The general practice for solving such problems is to intro- Saville [40] presents the following governing equations:
duce grid points, such as (i,j), at the center of each block;p,, is
a ap
then viewed as the average pressure for the block. Although Continuity : -r -
ar
(rpu) = - E - .
at
the well is located in block A, the well pressure p,, will be
different from the average block pressure p,. According to.a
simplified treatment (see Henderson, Dempsey, and Tyler Darcy's law: u = - - - k ap
[39], for example), in which the exact location of the well P ar .
within the block is immaterial, the two pressures are related by P
Equation of state : In - = C(p - pa).
Po
Here, r = radial distance, p = pressure, p - dcnsity, (7 = com-
in which m, = QMp,/RT, is the total mass rate of gas with- posite compressibility of liquid and rock, u = superficial
drawal from the well, r,= radius of the well bore, and velocity, and p = local viscosity (of grout solution or water, as
.rrr: = Axhy. For a given p, and m ~ the
, corresponding p,, appropriate).
Problems
The radius R of the groutlwater interface progresses present problem. The Airy stress function $ is the solution of
according to the biharmonic equation
the water side of the interface. Pressure and velocity are con-
ends A D and BC; a, = r,, = 0 along the sides A B and C D ;
tinuous across the interface.
on the surface of the hole, both the normal and shear stresses
Write a program that uses a finite-difference scheme for
are zero.
predicting the location of the interface as a function of time
Write a computer program that will use a fin~te-difference
until it virt~lallyceases to advance.
method to approximate the distribution of stresses inside the
Suggested Test Data (Not ~n Cotisisteirt Units) plate.
Suggested Input Dafa
7.2 u l o w b psla-', k 235 md (millidarcies; 1000 md 1
darcy I 1 cp sq cm/sec atm), po = 480 psia, and p, = 850
-
r , = 3 in., ~ = 0 . 1 5 . p 0 = 1 cp, p0=62.4 lb/cu ft, C =
- w = 5 i n . , L = 5and IOin.,a==0.5,] . a n d 1.5 in., T . 1000
Ib,/sq in., together with appropriate values for m and n (the
psia. Investigate two different grout solutions reported in [40]: number of grid spacings AX and Ay to be used along A B and
AM-9, with rr = 1.0 cp, b = 3.5 cp/min, c = 74 min; and DA, respectively), N (upper limit on number of iterations to be
Siroc, with a = 5.3 cp, b = 4.9 cp/hr, and c = 6.7 hr. performed), and E (a tolerance used in testing for convergence,
7.37 A circular hole of r a d ~ u sa is drilled through the as in Example 7.6).
center of a rectangular pllate of length L and width w . A For comparison, an approximate solution to the problem
uniform tens~lestress T IS exerted at both ends of the plate, as is given on page 80 of Timoshenko and Goodier [41].
shown in Fig. P 7 . 3 7 ~ . 7.38 Investigate the possibility of extending Problem 7.37
to the cases of elliptical holes with major axes oriented (a)
along the plate, and (b) across the plate. (For large eccentri-
cities, the solution is of particular interest because it approxi-
mates the effect of a crack in the plate.)
7.39 Figure P7.39 is a simplified view of the cross section
of a wide concrete dam. The internal stresses a,, a,, and T,,
obey the PDE given in Problem 7.37, except that the potential
function is now = -p,yx, where p, is the density of con-
crete. The boundary conditions are zero normal and tangen-
tial stresses along ABCD, with T,, = 0 and u, = -p,gx along
Figure P7.37a AE, where p, is the density of the water behind the dam.
Along DE, assume as an approximation that T,, is constant
The internal stresses rs,, a,, and r,, (considered positive as and that a, at any point is proportional to the height of con-
shown in Fig. P7.37b) are given [33] by crete above that point.
Figure P7.39
The conversion factor 32.2 Ib, ft/Ib, secZwill also be needed in Here, k is the thermal conductivity of the bar, n is distance
order to express the stresses in lb,/sq in. measured normally inwards to the bar from the surface, 8, is
7.40 Write a computer program that uses either the the current local surface temperature, and all temperatures are
Crank-Nicolson method or one of the unconditionally stable absolute.
explicit methods of Section 7.13 to solve the problem of Write down in detail the PDE, initial and boundary con-
unsteady heat conduction across a slab, stated in Problem 7.1. ditions that govern 0 = 8(x,y,t), the temperature inside the bar
Compare your results with those of Examples 7.1 and 7.2. as a function of position coordinates x and y, and time r.
7.41 Solve Problem 1.22, concerning a laminar-flow heat Rewrite these governing equations in terms of the dimension-
exchanger, by treating it as a characteristic-value problem. A less variables
procedure, such as that given in Example 4.2 or 4.3, will be
needed for finding the eigenvalues and eigenvectors of a x = - X,
a
y = -Y
a'
7=-
at
a2 '
and -
T = 0 - 8,
8, - 8, '
matrix.
7.42 Figure P7.42 shows a cross section of a long cooling Hence show that the general solution is of the form T =
fin of width W , thickness t , and thermal conductivity k, that T(X, Y , ~ , p , y )where
, the dimensionless parameters /? and y
is bonded to a hot wall, maintaining its base (at x = 0) at a are given by
temperature T,. Heat is conducted steadily through the fin in
the plane of Fig. P7.42, so that the fin temperature T obeys.
p=- k y=-
00
~ u a e '; 0, '
Laplace's equation, aZT/ax2+ a2T/ay2= 0. (Temperature
variations along the length of the fin, in the z direction, are Let T,, be the dimensionless time taken for'the dimensionless
ignored.) center temperature Tc to rise to a specified fractional value f.
Write a computer program that will enable plots to be made of
TC, against /?, with y as a parameter.
A steel bar has a = 0.1 ft, a = 0.322 sq ftjhr, Bo = 520°R,
k = 25.9 BTU/hr ft OF, and E = 0.79. It is placed inside a
Wall at ; black-body enclosure with 8b = 2520°R; u equals0.171 x 10-
Tw BTU/hr sq ft O R 4 . HOWlong will it take for the center tempera-
ture to rise to 1520°R (Tc = 0.5)? How long, if a = 0.2 ft, with
all other quantities unchanged?
7.44 In an experiment for simulating the effect of a hot
refractory wall close to a tube in a pipestill, a long metal pipe is
Figure P7.42 placed parallel to a very large wall that behaves as a black-
body radiator at an absolute temperature T,. The pipe, which
Heat is lost from the sides and tip of the fin by convection
has inside and outside radii rl and rz, is separated by a dis-
to the surrounding air (radiation is neglected at suEciently
tance D from the wall. The pipe wall has a thermal conduc-
low temperatures) at a local rate q = h(T, - To) BTUjhr sq ft.
tivity k and the outer surface has an emissivity e. A well-
Here, T, and T,, OF are the temperatures at a pbint on the fin
mixed fluid at a temperature T, flows rapidly through the
surface and of the air, respectively. If the surface of the fin is
pipe; the local heat flux density (BTUjhr sq ft, for example)
vertical, the heat transfer coefficient h obeys the dimensional
from the inner pipe wall to the fluid is
correlation h = 0.21(Ts - given by Rohsenow and
Choi [42].
Write a program that will compute: (a) the temperature where h is the relevant heat transfer coefficient and TI = T,(+)
distribution inside the fin, and (b) the total rate of heat loss is the local inner-wall temperature. The polar coordinates
from the fin to the air per foot length of fin. (r,&are shown in Fig. P7.44.
Suggested Test Data
T, = 200°F, T. = 70°F, t = 0.25 in.; investigate all eight
combinations of k = 25.9 (steel) and 220 (copper) BTU/hr ft
OF, W = 0.5, 1, 2, and 5 in. Surroundings
at T,
If available, compare the results with those obtained from
Problem 6.36, in which temperature variations across the fin T(r, 9)
are ignored.
7.43 An infinitely long bar of thermal diffusivity a has a
square cross section of side 2a. It is initially at a uniform tem-
perature eo when it is placed quickly inside a furnace that
behaves as a black-body enclosure at a temperature I!&. If u is
the Stefan-Boltzmann constant and E is the emissivity of the
surface of the bar, the heat flux density (BTU/hr sq ft, for Figure P7.44
example) into the surface of the bar at any point is given by The corresponding radiant flux density to a point on the
outer surface where the temperature is TZ= Tz(& is
Problems 529
The geometric view factor FZw= FZw($)is the fraction of Assume that the problem is essentially two-dimensional, in the
radiation leaving a small area on the outer pipe surface that is plane of Fig. P7.44.
directly intercepted by the wall; the remaining fraction,
1 - Fz,, is absorbed by the remainder of the surroundings. Suggested Test Data
F2,can be evaluated by the method discussed in Problem 3.17,
modified so that one surface is a differential element of area. Tw= 1500°R, Tf = 760°R, T, = 540"R, E = 0.79, k = 12.8
Ignore heat transfer by convection outside the tube. BTU/hr ft OR,r2 = 1 in. Investigate all eight combinations of
Write a program that will compute the steady temperature r l = 0 . 5 and 0.9 in., D = 0 . 5 and 2.5 in., h = 2 0 and 200
distribution T = T(r,$) throughout the pipe wall and the net BTU/hr sq ft OR. The Stefan-Boltzmann constant is u = 0.171
sate of heat transfer to the fluid, per unit length of pipe. x l o - @BTU/hr sq ft OR4.
530 Approximation of the Soluiion of Partial Differential Equations
Statistical Methods
8.1 Introduction: The Use of Statistical Methods probably have to consider their distribution in small
samples, as opposed to the statistics in a muck larger
In most branches of science and industry, methods of population.
experimental measurement may be inexact, and measure- 4. Finally, making the required inferences. For
ments themselves may be restricted in quantity. For example :
example, even simple linear measurement is subject to
inaccuracies, and the results of a complicated experi- (a) An estimate of the unknown parameters of the
mental procedure may be influenced by many disturbing assumed population distribution, together with
factors; also, the testing of mechanical failure of working confidence limits for these parameters.
parts is necessarily destructive, so usually only a small (b) A statement as to our confidence that the original
fraction is tested. In such cases, statistical methods may be mathematical model was a reasonable one.
used to advantage to obtain the best interpretation of the
data. A statistical approach to a particular problem may The most frequently encountered statistical problems
enable the experimenter to design a method of solution are those which involve one or more of the following
that minimizes the effect of experimental error; it will also features :
enable him to estimate the reliability of the results.
Frequently, in statistical problems, the technique is to 1 . Reduction of data. Much numerical information
examine relatively small amounts of experimental data may often be condensed into a simple relationship, to-
and thus to generalize about larger amounts of data. In a gether with a statement as to the confidence we may place
typical statistical investigation which permits certain in the relationship.
inferences to be drawn, we are usually confronted with 2 . Estimates and tests of significance. From experi-
the following sequence of steps: mental data, certain population parameters can be esti-
mated. It is usually possible to determine whether these
I. Specifying a mathematical model which represents
estimates differ significantly from preconceived values.
the situation. This involves:
3. Reliability of inferences depending on one or more
(a) Assuming a distribution function for the data, variables. For example, the total sulfur content in a bulk
based either on experience or on a distribution shipment is predicted from samples taken throughout
which might reasonably be expected to fit the the shipment, each of which is analyzed for sulfur, .
8.2 Definitions and Notation The cumulative frequency function, F(x,), shown in
Fig. 8.2, and also known as the distribution function, is
Statistics is the branch of scientific method of col- defined as the probability that x shall not exceed a certain
lecting, arranging, and using numerical facts or data
arising from natural phenomena or experiment. A statistic value x,. Note that F(x,) = Pr(x C x,) =
-m
1%
f (x) dx,
-
is an item of information deduced from the application of F(- co) = 0, and F ( m ) = I. A discontinuous frequency
statistical methods. A population is a collection of objects distribution is shown in Fig. 8.3. Note that
having in common some observable or measurable
characteristic known as a variate. An individualis a single
member of a population. A sample is a group of indivi- and that xz f (x) = 1. The corresponding cumulative
duals drawn from a population, usually at random, so frequency function is given by F(xo) = r 2 ,f(x).
that each individual is equally likely to be selected. A The term ave(y), where y = y(x), means the arithmetic
random variable is a numerical quantity associated with average of y, weighted according to the frequency dis-
the variate; its value for a given individual being deter- tribution, so that
mined by the value or nature of the variate for that par-
ticular individual. A continuous variable is one which can
assume any value within some continuous range. A dis-
conlinuous or discrete variable is one which can assume The integral sign would be replaced by a summation sign
only certain discrete values. for a discontinuous distribution. The notation E(y), in-
The probability, denoted by Pr, that a random variable dicating the expected value, is also used for ave(y).
x, belonging to an individual drawn from a population, Referring to a particular frequency distribution: (a) the
shall have some particular value A equals the fraction of mode is the most frequently occurring value of x, (b) the
individuals in the population having that value A mean p is the arithmetic average of x defined by
associated with them. The frequency function, f(x), also m
known as the probability density functi~n,of the random
variable x is defined by
p = ave(x) =
J- ,xf (x) d x ,
and (c) the median p, is that value of x such that half the
1. f (x,)dx = probability that the ccntinuous random population lies below it and half above it [that is,
variable x shall have any value between x, and x, + dx.
2. f(x,) = probability that a discontinuous random Fbe) = 1/21.
These three statistics coincide for symmetrical distri-
variable x shall have the value x,. butions. For discontinuous distributions, the mean and
For a continuous distribution, a typical dependency of median may lie between two possible values of x.
f ( x ) on x, known as the frequency distribution, is shown
For a population, it is also convenient to define the rth
in Fig. 8.1. Although special cases usually have some moment coeficients, p: and p,, about the origin and mean
restriction on the range of x (for example, x 2 0), we respectively. They are: (a) about the origin, p; = ave(xr),
+
consider here the general case of - co < x < co. Note, and (b) about the mean, p, = ave[(x - p)7. Note that the
mean p = pi. The moment p 2 is an important statistic
Pr(x, < x < x,) =
and
L2f (x) dx = shaded area of Fig. 8.1,
f (x) dx = 1, since all values of x must lie some-
known as the variance of x; its square root is called the
standard deviation o. We have
where between the extreme limits.
Figure 8.1 Continuous frequency distribution. Figure 8.2 Curnularive continuousfrequency distribution.
8.5 Population Statistics 533
that is,
var(x) = ave(x2) - p2. (8.7)
Figure 8.3 Discontinuous frequency distribution. 2. For two random variables x and y, consider for the
sake of argument a discontinuous distribution, and let
The mean of a particular distribution serves to locate it
as a whole, whereas its variance indicates the magnitude f(xi,yj) = frequency function for the pair of values x i , yj,
of its spread about the mean. f(xi) = frequency function for the value xi,
regardless of the value of y,
8.3 Laws of Probability
f(yj) = frequency function for the value yj,
Let A,, A,, A, represent either single numerical values regardless of the value of x .
or sets of numerical values; if the latter, let x = A, mean
that x has some value within the set A,. Then, Note that:
c(n,x) =
n!
(n-x)!x!
(also written
, ()' or "c,) axy = ave(xy) - P#,. (8.9)
The covariance is a measure of the dependency of r and y
on each other. In particular, if x and y are independent,
3. If n items are made up of x,, x,, x,, . . . items of f (xi,yj) 'f (xi)f (yj),
types 1,2, 3, . . . respectively, then the number of different that is,
arrangements of all the n items is
ave(xy) = C xiyjf ( x i * ~ j=) C xif(xi) C ~ j(yj)
f = Pxlry.
ij I i
The above results can be reproduced for a continuous Then, since ave(x - pJ = ave(y - py) = 0:
distribution by replacing summations with integrals.
3. A linear combination z of random variables
x,, x,, ...,x,, is defined by
Example. As an illustration of (I), (2), and (3) listed under
Section 8.5, consider a population consisting of five cards
where the a's are constants, and the summation is under-
numbered 0, 1,2, 3, and 4 placed in a hat. We have
stood to be over i = 1,2, . . ., n unless otherwise stated.*
Let pi = ave(xi), a? = var(xi), aij = cov(xi,xj). Then, by 1. One random variable x. Let x = number on a card which
an extension of (8.8), is drawn at random from the hat and then replaced. Clearly,
p = ave(z) = ave (1aixi) = zai ave(xi) = 1aipi, (8.1 1)
By using (8.7) and (8.9), the reader can verify that this
leads to
2. Two random variables. Let x and y be the numbers from
the first and second draws. As for (I), p, = py = 2, 0: = u,2 =
2. Also, cov(x,y) = a,, = ave(xy) - p,py. Suppose the second
In particular, if all the xi are mutually independent, draw is made before the first card is replaced,
aij= 0 and aZ= ~a;a,2. 0(1+2+3+4)+1(0+2+3+4)+...
4. The mean and variance of an arbitrary function a,, = - 22 = -0.5
20
z(x,y) of the two random variables x and y may be ob-
tained approximately as follows. Taylor's expansion about However, if the first card is replaced before the second card
z(pX,py),neglecting second-order terms, gives is drawn.
* Note. Throughout this chapter, the summation parameter and confirming that for this case x and y are independent of each
its range will often be omitted for brevity, if the intended meaning is other.
unambiguous. For example, the right-hand side of equation (8.12) +
3. Linear combination. Suppose z = (x y), without
is, more fully,
replacement. Then
ave(z) = 2 + 2 = 4,
Also, a summation such as x;=lxi may be written as Z x r or E x . var(z) = 2 + 2 + 2(-0.5) = 3.
EXAMPLE $.1
DISTRIBUTION OF POINTS IN A BRIDGE HAND
Table 8.1.1
The cyclical pattern is easily generated by using integer division, in which the quotient is rounded
down to the next lower integer. For example, we use the formula q+ i/25 - 5((i/25)/5)for the
number of queens in hand i; this gives the pattern q = 0, 1, 2, 3, 4, 0, 1, 2, etc., in which the
changes occur every 25th hand.
536 Statistical Methods
Note that the rN may be generated from the recursion the probability of obtaining N honor cards composed
relation of any j jacks, q queens, k kings, and a aces is
Flow Diagram
I
13! 36! 39! I
r i t X- X- I
(13 - i ) ! (23 + i ) ! 52! I
1
I
I
(using integer division) I
I
I
I
I
-----l
Example 8.1 Distribution of Points in a Bridge Hand
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
AVG, VAR Mean p, and variance a2, of the point-count distribution.
Ct Vector containing the values ci= C(4,i), i = 0, 1, 2, 3, and 4.
CUMPRBt Vector containing the probabilities F, of obtaining any point count from 0 to p in any one
hand.
N J , NO., NK, Number of jacks, queens, kings, and aces (j,q, k, and a), respectively.
and NA
N PTS Point count, p.
NHONS Nuinber of honor cards, N.
PROBf Vector containing the probabilities f, of obtaining exactly p points in any one hand.
Rt Vector containing values r, given by equation (8.1.1).
Program Listing
C A P P L l ED NUMERI CAL METHODS, EXAMPLE 8.1
C D I S T R I B U T I O N OF POINTS I N A BRIDGE HAND.
.....
DATA C/ 1.0,
SET THE C ARRAY AND I N I T I A L I Z E PROB ARRAY
4.0, 6.0, 4.0, 1.01
.....
DO 1 I = 1, 3 8
P R O B ( I ) = 0.0
NK = l / 5
NA = I --((1/5)/5)*5
(1/5)*5
NPTS = N J + 2*NQ + 3*NK + 4*NA
NHONS = N J + NQ + NK + NA
b
C ..... COMPUTE
-.... PROBABI L I T 1 ES OF A L L P O I N T COUNTS
I F (NHONS .GT. 1 3 ) GO TO 5
.....
PROB(NPTS + 1) a PROBCNPTS + 1) + C ( N J + l ) * C ( N Q + l)*C(NK + 1)
1 *C(NA + l)*R(NHONS + 1)
5 CONTINUE
CALL E X I T
Example 8.1 Distribution of Points in a Bridge Hand
Computer Output
DISTRIBUTION OF POINTS I N A BRIDGE HAND
MEAN = 9.9999994
VARIANCE = 17.0588225
540 Statistical Methods
Discussion of Results
The computed probabilities, of obtaining any specified But E(y,y2) may be obtained by considering all the pos-
number of points in a bridge hand, are shown as the sible combinations of two honor cards in positions 1
vertical lines of Fig. 8.1.1. Together, they constitute the and 2, such as: (a) two queens, giving y,y2 = 4, which
frequency function f ( p ) for the random variable p, the may occur in C(4,2) = 6 ways, or (b) one ace, one king,
point count. The computed values for the mean (10.000) giving y,y, = 12, in 4 x 4 = 16 ways, etc. The total
and variance (17.059) can actually be deduced theoretic- contribution to y,y2 is 8 x (4 3 2 + + + -2 x
ally as follows, without having to consider the exact +
(4' + 32 + 22 1') = 740, and there are C(52,2) =
form of the frequency function. 52 x 5112 possible pairs of cards occupying places 1 and
Regard the point-count p as the linear combination 2. Hence,
P
Figure 8.1.1 Distribution ofpoints in a bridge hand. The curve shows the frequency
function for the normal distribution with mean = 10.0 and variance = 17.059
(standard deviation = 4.130).
Exomple 8.1 Distribution of Points in a Bridge Hand 541
since negative point counts are impossible, whereas on with mean p = 10 and variance a2 = 17.059. The normal
the high side they may run up to 37, although with very distribution will be discussed in more detail later; note
small probability. here, however, that even though its frequency function is
The smooth curve drawn on Fig. 8.1.1 represents the continuous, it does give a fairly good approximation to
frequency function, (8.261), for the normal distribution f(p) for the discontinuous point-count distribution.
542 Statistical Merhods
e2 +.
that is, + 7L f J - ,
x2f (x) dx
Thus,
\ ,
Example. A bag contains a large number of balls of which
Hence, the number of successes x is a random variable 50% are red, 30% black, and 20% white. A sample of 5
whose frequency distribution is balls is drawn. What is the probability that 3 will be red, none
black, and 2 white? We have fi = 0.5,f2 = 0.3,f3 = 0.2;
whence
Note that in contrast to the binomial distribution, there Alternatively, if we take the MGF for the binomial dis-
is no upper limit to the number of incidents that might tribution, equation (8.23), and let n -P a,np -,1, we
occur in a second, even though the chances of a large obtain
number would be very small. In other words, we cannot +
M,(O) = [l p(ee - I)]"
say how many incidents did not occur in a given second.
The MGF of the Poisson distribution is
that is,
p; = (dM/dO)e,o = I , and pi = (d2~/d02),=,= 12+ 1.
Thus
p = ave(x) = p; = A, and a2 = var(x) = pi - p2 = 1.
EXAMPLE 8.2
POISSON DISTRIBUTION RANDOM NUMBER GENERATOR
In the present example, we choose the values: m = 220, used. For convenience, the above method is written as a
a = 21° + 3, and x, = 566,387. Thus, the conditions subroutine named RANDOM. Note finally, that once xi
mentioned in (a) above are satisfied, and we are also sure has been computed, xi-i is no longer needed. Thus, all
that the product axi-, will not exceed Z3l - 1, which is the xi can be stored successively in the same memory
the maximum allowable integer on the machine being location.
Flow Diagram
Main Program (Excluding details of sorting and comparing numbers that are generated)
xcl
k t -1
X t XZ
Y T
i
x<c + i, k
F
z c random variable
uniformly distributed
between 0 and I.
(Subroutine RANDOM)
o-+j*l
Return
Example 8.2 Poisson Distributlan Random Number Generator
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
(Main)
C The constant c = B".
FACT Vector whose kth element FACT(K) contains k!
IPRINT Number of individual random numbers to be printed.
K Random variable k obeying the Poisson distribution.
LAMBDA Mean value, 1.
N Total number, n, of rand~rnnumbers to be generated.
NOBS Vector containing observed frequenoies of particular random numbers. NOeSi! is the observed
frequency of zeros.
RANDOM Subroutine that gives a random number z between Q and 1 with uniform probability.
THEORN Vector containing the theoretical frequencies of particular random numbers. THEORZ is the
theoretical frequency of zeros,
..
Repeated product, xk = zozt . 2,.
Random number z, uniformly distributed between 0 and 1.
(Subroutine
RANDOM)
A Multiplier, a.
I An integer switch, that is pmset to 1 by using the DATA statement. It identifies the Grst entry;
thereafter, it has the value 0,
M Modulus, m.
x Current random integer, x,.
548 Statistical Methocis
Program Listing
Main Program
C APPL l ED NUMERI CAL METHODS, EXAMPLE 8.2
C FOISSON D I S T R I B U T I O N RANDOM NUMBER GENERATOR.
L
C THE SUBROUTINE RANDOM PRODUCES A RANDOM NUMBER UNIFORMLY
C D I S T R I B U T E D BETWEEN 0 AND 1. T H I S I S THEN TRANSLATED I N T O
C A RANDOM VARIABLE K FOLLOWING THE ,POISSON D I S T R I B U T I O N W I T H
C MEAN LAMBDA. N SUCH NUMBERS ARE GENERATED. NOBS(K) AND
C THEORNCK) ARE THE OBSERVED AND THEORETICAL COUNTS FOR A
C PARTICULAR VALUE OF K.
C
DIMENSION NOBS(501, THEORN(501, FACT(50)
.....CALL ON F L A T R.N.G.
CALL RANDOM ( 2 )
FUNCTION RANDOM .....
X = X*Z
K = K + l
GO TO 3
END
Subroutine RANDOM
C SUBROUTINE FOR GENERATING RANDOM NUMBERS HAVING A UNIFORM
C DISTRIBUTION, BY THE MIXED M U L T I P L I C A T I V E CONGRUENTIAL METHOD.
C
SUBROUTINE RANDOM (Z)
DATA 1 /1/
INTEGER A, X
I F ( I .EQ. 0 ) GO TO 1
I = o
M = 2*+20
FM = M
X = 566387
A = 2++10 + 3
C
1 X = MOD(A*X, MI
FX = X
Z = FX/FM
RETURN
END
Computer Output
N = 1000 N = 1000
IPRINT = 20 IPRINT = 20
LAMBDA = 2.09000 LAMBDA = 5.00000
THE F I R S T FEW RANDOM NUMBERS ARE THE F I R S T FEW RANDOM NUMBERS ARE
THE OBSERVED AND THEORETICAL FREQUENCIES ARE THE OBSERVED AND THEORETICAL FREQUENCIES ARE
Discussion of Results
One thousand random numbers have been generated
for each of the cases A = 2 and L = 5. The observed
distributions seem to cofiform reasonably to those pre-
dicted theoretically; this conclusion is further substan-,
tiated by using a )I2 test in Example 8.4.
552 Statistical Methods
4 4 @ 4 d @
--
0.0 0.3989 0.5000 2.0 0.0540 0.9772
0.1 0.3970 0.5398 2.1 0.0440 0.9821
0.2 0.3910 0.5793 2.2 0.0355 0.9861
0.3 0.3814 0.6179 2.3 0.0283 0.9893
0.4 0.3683 0.6554 2.4 0.0224 0.9918
0 !J
*x 0.5 0.3521 0.6915 2.5 0.0175 0.9938
0.6 0.3332 0.7258 2.6 0.0136 0.9953
Figure 8.4 The normal distribution. 0.7 0.3122 0.7580 2.7 0.0104 0.9965
0.8 0.2897 0.7881 2.8 0.0079 0.9974
0.9 0.2661 0.8159 2.9 0.0060 0.9981
fact, the mean and variance of t h ~ sdistribution. It is
1.0 0.2420 0.8413 3.0 0.0044 0.9986
shown in the next section that the frequency function 1.1 0.2178 0.8643 3.1 0.0033 0.9990
(8.26) is in complete agreement with the concept of a 1.2 0.1942 0.8849 3.2 0.0024 0.9993
large number of small random fluctuations, characterized 1.3 0.1714 0.9032 3.3 0.0017 0.9995
by the parameter o, about a central value, p. The normal 1.4 0.1497 0.9192 3.4 0.0012 0.9997
distribution can be used to represent a random variable, 1.5 0.1295 0.9332 3.5 0.0009 0.9998
1.6 0.1109 0.9452 3.6 0.0006 0.9998
such as the height of men, not having negative values, 1.7 0.0940 0.9554 3.7 0.0004 0.9999
provided that f (x) has already fallen to a negligibly small 1.8 0.0790 0.9641 3.8 0.0003 0.9999
value for small positive values of x. 1.9 0.0656 0.9713 3.9 0.0002 1.0000
The statistics of the distribution are obtained from the 2.0 0.0540 0.9772 4.0 0.0001 1.0000
MGF. Noting that
P 0.20 0.10 0.05 0.02 0.01
tP 0.843 1.282 I .647 2.056 2.329
1 -(x - pI2
M,(O) = -
ffJ% jmexoexp[
-m
~~2 ]dx The normal distribution is probably the most important
distribution in the whole of statistical theory. It is easily
= exP[p0 + 71. (8.27)
shown via the MGF that the linearcombinationz = x a i x i
of normally distributed variables x i is itself normally
Example 8.11 The Normal Distribution 553
distributed (with mean aipi and variance a?o?). In small errors 6, of which X are in the positive direction;
particular, for an N(p,a) population, the sample mean 3 +
that is, x = rn (2X - n)6. Let the probability of any
is an N(p,az/n) variable. one error being in the positive direction be p. From the
binomial distribution (8.22),
Example. A population is known to be distributed as
N(40,9). What value would the mean of four items drawn at
random from the population have a 1% probability of
exceeding ?
Assuming that the population is sufficiently large so that the so the MGF for the distribution of x is
items are independent of one another, then the mean of the
+ +
four items is X = (x, x 2 x 3 + x4)/4, which is a linear
combination of normally distributed variables and is itself
normally distributed.
f!
mc Sample mean P
Now, if positive and negative errors are equally likely,
p = 112, so that
+ nS202+ (2/3)nS303+ . - -
- ernee - "68
nSf3
n I.
Figure 8.5 Population and sample (n = 4) distributions. Now let n -+ oo and 6 -+ 0,while 2nd2 (= c2, for instance)
remains finite, so that terms of O(nJ3) tend to zero. The
Then, a: = 0 2 / n= 914, or u; = 1.5. From Table 8.1, the value MGF then becomes
of f which has a P = 0.01 probability of being exceeded is
tp= 2.329 = (X - p)/u;. Thus the required value is I = 40 +
2.329 x 1.5 =43.49 (see Fig. 8.5). That is, in the long run,
the sample mean will exceed 43.49 once in every 100 samples.
M,(B) = exp [me + 71.
But for m = ,u and c2 = a 2 this is identical with the form
8.12 Derivation of the Normal Distribution obtained by the integration of
Frequency Function
Assume that superimposed on the "true" value m for
any measurement x, there is a large number n of very
EXAMPLE 8.3
TABULATION OF THE STANDARDIZED NORMAL DISTRIBUTION
Problem Statement The problem is to construct tables of: (a) 4 and 0
For a standardized normal variable t, the frequency versus t , for 0 < t < nh, with increments in 6 of 2,and
function 4, the cumulative frequency function (P, and (b) tpversus P, for certain values PI, P2, . . ., P,, with the
the probability P that a certain value tp will not be knowledge that no value of t higher than nh will be
exceeded are illustrated in Fig. 8.3.1 and are defined by involved.
Method of Solution
Note that owing to symmetry about the origin, only
one-half of the distribution is considered. The computa-
tion is performed in three main steps. First, values of
4j are calculated corresponding to =jh, for j = 0, 1,2,
..., n. Second, values of cPj are obtained at the alternate
points j = 0,2,4, . .., n, where n is even, by repeated
applications of Simpson's rule :
Flow Diagram
Begin
FORTRAN Zmplemeniation
List of Principal Variables
Program Symbol Definition
I F ( C A P P H I ( J P 1 ) .GT. Y ( K ) ) GO TO 4
3 CONTINUE
4 X(K) = XI(JP1-2) + (2.0*DXl)*
1
5 CONTINUE
(Y(K) - CAPPHI(JP1-2))/(CAPPHI(JPl) -
CAPPHI(JP1-2))
C ..... .....
ARRANGE THE HEADINGS PROPERLY
WRITE (6,200)
C
C ..... AND PRINT THE RESULTS .....
NOVER2 = N / 2
NOV2Pl = N / 2 + 1
DO 6 J P l = 1, NOV2P1, 2
ISUB = J P 1 + NOVER2
6 WRITE (6,201) XI(JP11, PHI(JPl), CAPPHI(JPl), XI(ISUB), P H I ( ISUB),
1 CAPPHI(ISUB)
C
C ..... NOT FORGETTING THE PROBABl L l T I E S
WRl TE (6,202
.....
DO 7 J = 1, NPROBS
7 WRITE (6,203) PROB(J), X ( J )
CALL E X I T
C
C
100
.....FORMATS FOR INPUT AND OUTPUT STATEMENTS
FORMAT (4X, 14, 13X, 13, lox, F6.2/ /(5F10.5))
.....
200 FORMAT ( 1 H 1 / 7X, 60HTABULATION OF VALUES OF THE STANDARDIZED NORM
1AL DISTRIBUTION/lHO, 6X, 6HS.N.V., 2X, SHFREQUENCY, ZX, 10HCUM.DIS
2TR., 7X, 6HS.N.V., 2X, SHFREQUENCY, ZX, 1lHCUM. D I S T R . / 8 X , ~H(XI),
33X, 8HFUNCTION, 4X, IHFUNCTION, lox, 4H(XI 1, 3X, 8HFUNCTION, 4X,
48HFUNCTION/lH / )
2 0 1 FORMAT (7X, F5.3, 4X, F7.5, 4X, F7.5, lox, F5.3, 4X, F7.5,
14X, F7.5)
2 0 2 FORMAT (1H0, lox, 4HPROB, 8X, 2 H X I / l H d )
2 0 3 FORMAT (7X, F8.4, 6X, F6.4)
C
END
Example 8.3 Tabulation of the Standardized Normal Distribution
Computer Output
T A B U L A T I O N OF VALUES OF THE STANDARDIZED NORMAL D I S T R I B U T I O N
x
Figure 8.6 xZ distribution frequency function.
560 Statistical Methods
Degrees of freedom, v
Figure 8.7 Probability points of the x2 distribution.
8.14 X2 as a Measure of Goodness-of-Fit Example. Suppose that 100 tosses of a coin produce 40
heads and 60 tails, and that we wish to know if the coin is
Consider a random variable which can fall into any biased in some way. On the assumption or null hypothesis
one of k different classes with respective probabilities that the coin is not biased, we should have expected 50 heads
f,,f,, . . .,f,. For a total of n observations, the expected and 50 tails. The number of restrictions imposed on the f,
number falling in the ith class is nfi. Let the actual in this case is r = I, since if the expected probability of
observed number in the ith class be x i . The xi would obey obtaining a "head" ( = A , for instance) is stated to be 112,
the multinomial distribution (8.24), and on this basis it then f2 is automatically 1 - 112 = 112 since there are no other
can be shown [3] that the variable alternatives. Hence there is just v = k - r = 2 -: 1 = 1 degree
of freedom:.'We have,
(Observed - Expected)' (xi - nfi12 (8.33)
'' = Expected =C
;=I nfi
obeys the X 2 distribution approximately. The approxima-
tion improves as the expected frequency nf, in each class Notice that 112 has been added to the 40 and subtracted from
becomes greater. For every nfi > 20, there is hardly any the 60. This procedure, known as Yates's correction, generally
loss of accuracy. The relevant number of degrees of adds 112 to those frequencies falling below expectation, and
subtracts 112 from those falling above it. Yates's correction
freedom is k - r, where r is the number of restrictions
compensates for the fact that a discontinuous distribution
imposed on the fi (see examples which follow). (binomial in this case) is being represented by the continuous
The expected frequencies are usually based o n the xZ distribution. Figure 8.7 or statistical tables give the follow-
hypothesis of a particular distribution. Therefore, this ing values:
hypothesis can be tested by evaluating X' and checking t o
see if its value is reasonable in view of: (a) the number of
degrees of freedom involved, and (b) the confidence level
required, that is, how "sure" we wish to be.
8.15 Contingency Tables 561
That is, the observed value of x2 = 3.61 (or greater) can be We shall use the 'X test for goodness-of-fit. As a null
expected to occur, on the average, about 6% of the time. hypothesis we assume A and B have equal effects and
This is as far as statistics goes; it leaves the interpretation to us. pool the results to give the chance of a failure as
Although we personally may believe that the coin is biased, 221157 = 0.140, whence the expected numbers of successes
we would want stronger evidence before making such a and failures for A and B can be calculated. These are
statement public. The levels P = 5%, I%, and 0.1 % are
shown in Table 8.3.
sometimes described as "probably significant," :'significant,"
and "highly significant." Table 8.3 Expected Frequencies on Basis of
However, if 1000 tosses produced 400 heads and 600 tails, Null Hypothesis
then
Success Failure Totals
Treatment A 81.7 13.3 95
a figure which so far exceeds even the "highly significant" Treatment B 53.3 8.7 62
level that we should have little hesitation in stating that the Totals 135 22 157
coin was biased in favor of tails. Even so, it should be recog-
nized! that there is a possibility, although an exceedingly There is only one degree of freedom, since, for example,
remote one, of our being wrong. having specified that we expect treatment A to yield 13.3
It so happens that in the above example we could have failures, all the remaining entries can be obtained by
predicted, directly from the binomial distribution, the prob- difference from the subtotals. Taking into account Yates's
ability of obtaining, for instance, 40 or fewer heads in 100
tosses. However, this would involve a fair amount of work in correction, we have
evaluating factorials and the x2 approach is preferred.
8.15 Contingency Tables
Suppose the success or failure of some experiment is
classified as to whether treatment A or treatment B was
used in the experiment. Table 8.2 shows such a cross
classification, known as a contingency table.
Table 8.2 Contingency Table: For v = 1 d.f., X'= 6.63 at the 1 % level and 7.88 at the
Observed Results
0.5% level. That is, on the basis of our null hypothesis,
Success Failure Totals there is a probability of about 1 in 150 of the observed X 2
or higher occurring. Hence, we conclude that the null
Treatment A 88 7 95 hypothesis is incorrect and that treatment B has a sig-
Treatment B 47 15 62 nificantly higher failure rate than treatment A.
Totals 135 22 157
The above is the simplest possible example of a con-
tingency table. For an m x n table in which m treatments
Can treatment I3 be correlated with a significantly higher are classified according to n results, the appropriate
failure rate than treatment A ? number of degrees of freedom is v = ( m - I)(n - 1).
EXAMPLE 8.4
xZ TEST FOR GOODNESS-OF-FIT
Flow Diagram
FORTRAN Implementation
List of Principal Variables
Program Symbol Definition
CHIS0 zZ, defined by equation (8.4.1).
F Vector containing values df fi.
SUSTF Switch, with value 0 (the xr to be read) or 1 (thef, to be read).
K Number of classes k; becomes KNEW after a possible regrouping of data.
L b a s t number I expected to fall into a class.
N Number of observations, n.
NU Degrees of freedom, v,
xLxr Vector containing theoretical frequencies x f ; becomes YEXP (with the y;) after a possible
regrouping,
Vector ~ontainingobserved frequencies xi; becomes YOsS (with the yi) after a possible regrouping.
564 Statistical Methods
Program Listing
A P P L l ED NUMERl CAL METHODS, EXAMPLE 8.4
CHI-SQUARE FOR GOODNESS-OF-FIT.
CONTl NUE
YOBS(J-1)
KNEW = J
--
J E J + 1
1
YOBS(J-1) + YOBS(J)
Y E X P ( J - 1 ) = Y E X P ( J - 1 ) + YEXP( J)
.,
C ..... P R I N T VALUES OF YOBS AND YEXP
WRITE ( 6 , 2 0 1 ) KNEW, ( Y O B S ( I ) ,
.....
I = 1, KNEW)
WRITE (6,202) KNEW, ( Y E X P ( I 1, I = 1, KNEW)
C
C ..... COMPUTE CHI-SQUARE AND NUMBER OF DEGREES OF FREEDOM
C H l S Q = 0.0
.....
DO 9 1 = 1, KNEW
FYOBS = YOBS( I )
9 CHlSQ
NU = KNEW
C H l S Q + ((ABS(FY0BS
- 1
-
YEXP(I))) -
0.5)**2/YEXP(I)
Computer Output
Results for the 1st Data Sei
DETERMINATION OF CHI-SQUARE, WITH
N = 1000
K = 8
L = 20
JUSTF = 0
N = 1000
K = 13
L
JUSTF -
= 20
0
.
THE VALUES OF YORS( 1). .YOBS( 1 0 ) ARE
59 88 159 179 1 6 1 135 100 54 38 27
566 Statistical ~ e t h o d s
N = 5000
K = 38
L = 20
JUSTF = 1
THE INPUT DATA ( P O S S I B L Y REARRANGED) NOW FOLLOW
8.16 The Sample Variance limit of a 2 is 10 x 100/18.31 = 54.6, and its upper limit is
10 x 100/3.94 = 254. (This is not the only 90% confidence
The sample variance has been defined by (8.15) as interval; it is the one which is symmetrical with respect to the
probabilities on x2.)
because
k
The distribution is very similar to N(0,1), which it
1
ave(s2) = -
N-k
ave C (ni - l)s? approximates closely for all but small values of v.
i=l Figure 8.8 shows values of t, plotted against v, with P
as a parameter such that P is the probability that It1 > I,.
To illustrate the case in which 0' is unknown, consider
a population N(p,02). The sample mean X is N(p,a2/n).
Hence, 4 = (Z - p) ,/;/a is N(0,l); also, X2 = (n - l)s2/a2
is a chi-square variable with (n - 1) d.f. That is,
If the populations are normally distributed, each term has the t distribution with (n - 1) d.f., which provides a
on the right-hand side of (8.36) behaves as X2, with test of significance for the deviation of a sample mean
(n, - 1) d.f. Hence the whole of the right-hand side be- from its expected value when the population variance is
haves as. X2,with C:= (ni- 1) = (N - k) d.f. That is, unknown and must be estimated from the sample
the variable variance.
s A simple extension provides a test of significance be-
X2 =(N-k)- (8.37) tween two sample means ?, and I,, which will determine
a2
whether 2, and 3, could have come from the same
also behaves as X2 with (N - k) degrees of freedom. population.
Assume first that the samples come from populations
Example. In a certain experiment, s 2 = 100 with v = 10 d.f.
having a common variance a 2 ; the validity of this assump-
Establish an interval in which we can be 90% certain that the
population variance u' lies. tion can be checked by the F test in Section 8.18. Then
Since v s 2 / 0 2- x Z , then o2 = vs21X2. From Fig. 8.7 or the linear combination (2, - 2,) has the normal distri-
tables [4], for v = 10 d.f., xZ has a 5% chance of exceeding bution with mean (pl - p2) and variance at(l/nl l/n2).+
18.31 and a 95% chance of exceeding 3.94. Thus, the lower Thus
8.17 Student's Distribution
(XI - X2) -(PI-~ 2 ) and will, with specified probability, be expected to fall
within the appropriate tabulated values, unless the null
( rnlJ+ -~1 "2
hypothesis is incorrect and p , # p2.
Example. Repeated analyses show that two batches of a
is N ( O , l ) . Funher, if the joint estimate of (r2 from the manufactured chemical contain the following percentages of
samples is an impurity X. Is there a significant difference between the
s2 =-( n l - 1)s: + (n2 - 1)s; X-content of the two batches?
n, + n2 - 2 9
+
has the t distribution with v = ( n , n2 - 2 ) d.f.
Finally, as a null hypothesis, assume that the samples
do come from the same population and hence that p, and
p2 are equal. That is,
In Table 8.4 the new variables x, and x 2 are given by x = 10
x (%X - 3.00). This makes the arithmetic a little easier,
especially if the calculation is being done by hand, but does
not alter the final conclusions. Various sums are next calcu-
lated as shown in Table 8.5.
570 Statistical Methods
Table 8.5 Cnlculation of Batch Means method of deriving xl and x z from the percent X in the two
and Variances batches, the best estimate we have is that the percent X is
(0.702 - 0.394) = 0.308 higher in Batch 2 than in Batch 1.
Batch 1 Batch 2 Finally, we can qualify this statement by giving a confidence
interval within which, with 95 % probability, for instance, the
difference lies. Now t = 2.31 with 8 d.f. at the P = 5 % level.
Thus the percent X in Batch 2 exceeds that in Batch 1 by an
amount that has a 95 % probability of lying within
+
The joint estimate of u Z is sZ = (4 x 1.578 4 x 0.707)/8= 8.18 ~h~ l; ~ i ~ t ~ i b ~ t i ~ ~
1.1425; that is, s = 1.069. On the basis of the null hypothesis
that there is no difference between the X-content of the two The ratio F = s:/s; of two estimates of the variance of
batches,. .M I = and a normal population based o n v, and v, d.f., respectively,
has the frequency function
f -f2 - 3.94 - 7.02 = -4,555, with 8 d.f.
t = s ~ ~ - 1 . 0 6 9
nl nz
---.
(v11v2)*1"
f(F) = B(v,/2,v2/2)
F(vI/2)-l (I + 2 F)
-(v1 + v 2 ) / 2
, (8.43)
But, from tables of the t distribution [4], It1 based on 8 d.f. where
has a 0.2% probability of being greater than 4.50. Thus we
conclude, with very little doubt, that the null hypothesis is
incorrect and that there is a definite difference between the
B(m,n) = r(m)r(n)/r(m + n) =I
o
1
xm-'(I - x)"-' dx
X-content of the two batches. In fact, taking into account the is the beta function.
v2
y2
Figures 8.9 and 8.10 show Fpas a function of v , and v,, Assume that each yi is an observation from a normal
such that F, has a probability P of being exceeded. +
population with mean a px, and constant variance a',
Evaluating F provides a test of significance between two and that the corresponding values xi are known precisely.
estimates of a population variance. Note that a value For example, y might be the result of a chemical analysis
F, -,,,,,,, (such that there is a probability P of F falling or the estimate of a product yield, whereas x might be an
-,
below it) is given by F, ,,,,,, = l/Fp,v,,v,. accurately known time, an accurately weighed amount of
catalyst, or a carefully controlled temperature. The
Example. In our example of the t distribution, the two
sample variances s f = 1.578 and s: =0.707, each having situation is indicated in Fig. 8.12, in which y = u + px is
4 d.f., were pooled to give a joint estimate s2 of a population the equation of the regression line. Using the experi-
variance. Was this pooling justified? mental data, we wish to obtain estimates a, 6 , and s 2 of
F = s:/s: = 1.57810.707 = 2.23. From Fig. 8.9 or tables the model parameters a, 8, and a2. Assuming that the
[4], for v , = 4, v, = 4, there is a 5% probability that F will measurement of y locates it within a small interval of
exceed 6.39, and a 5% probability that F will fall below extent Ay, the probability of observing the value y,, is,
116.39 =0.1565. Our results are well within these limits and for instance, from the normal distribution,
there is, therefore, no reason why the sample variances
should not be pooled.
and
'T a = (Zy - bCx)/m = J - bX.
I 0
(8.46)
Also, the variance o2 about the regression line is estimated
o o
0 by
.o
- Cy2 - aCy - bCxy . (8.47)
0 0
C(y - a - bx)'
's =
0 m-2 m-2
Note that the denominator of (8.47) has the value m - 2,
because both a and b have been estimated from the data;
sZ is now said to be based on (m - 2)d.f. and (m - 2)sZ/oZ
has the X 2 distribution with (m - 2) d.f.
We now show that a and b are unbiased estimates of
Figure 8.11 Experimental points. ct and p, and expressions will be derived for var(a) and
var(b). From (8.45),
The regression line is considered the best representation
of the data points if P is a maximum, which will occur when C(x - X)(y - p) - C(x - X)y - Z(X - X)j
b=
u and p are chosen to minimize the sum of squares C(x - x)' C(x -
. .
X1 xp .. . .. .. Xm
Figure 8.12 Model for linear regression. has the Student t distribution with (m - 2)d.f., which may
be used either as a test of significance to see if B is likely
Rearranging, we obtain the simultaneous normal equations to have some preconceived value, or to establish a con-
fidence interval for P.
ma + bCx = Zy, Also, ave(a) and var(a) are obtained from (8.461, as
aZx + bCx2 = Cxy, follows. We have a = j - bX, that is,
whence
mCxy - CxCy - ( x - ( y - ) COV(X,~)
b= =- , (8.45)
mCx2 - (EX)' - C(X - z ) ~ vaf(x)
Problems 589
random variable y that obeys the exponential distribution (b) Write a program that implements the above procedure.
f(y) = 7 c n Y with
, mean l / v Anticipate that the call for the The values f p x should be estimated by making a reasonably
function will be large number N of random walks from each point P, keeping
track of how many times the walk terminates at each point k.
Y = REXPON (X, ETA)
A random number generator with a flat distribution should be
in which X, ETA, and Y have obvious interpretations. used to decide which direction to take at each step of the
8.17 Discuss the possibility of generating an N(p,u) walk.
random variable based on the method given in Problem 8.15. (c) What are the advantages and disadvantages of this
8.18 If x, and x z are a pair of independent random vari- method for solving Laplace's equation, compared with
ables uniformly distributed between 0 and 1, Box and Muller conventional relaxation methods?
1141 indicate that the pair of values (d) Could the method be extended to obtain solutions for:
(i) Poisson's equation, or (ii) a region with a curved boundary?
yl = a(-2 In x1)lI2 cos 2vxz + p, 8.20 A chemical company is faced with the problem of
y , = 4 - 2 In x , ) ' / ~sin 2xx2 + p, disposing of a potential waste product. One possibility is to
convert it into x tons per annum of a saleable product. The
will be normally distributed according to N(p,u). cost of the operation would b e y $/ton of product, all of which
could then be sold at z $/ton. The annual profit would be
(a) Write a subroutine named RNORML that implements P = x(z - y) dollars. Bearing in mind the uncertainties of
Box and Muller's procedure. The call will be of the form production and marketing, the actual value of x is thought to
CALL RNORML ( X I , X2, MU, SIGMA, Y1, Y2) be uniformly distributed between lower and upper limits
in which the arguments have obvious interpretations.
+
x, and x,, y is N(a b/x, a:), and z is N(c - xd, a:), where
estimated values are available for x l , x,, a, b, c, d, u:, and a:.
(b) Investigate the theoretical justification for the pro- Before proceeding with the project, the company wishes to
cedure. estimate the frequency function f(P) for the annual profit.
8.19 Here, we investigate a statistical method for approxi- Since an analytical approach may be difficult, an alternative
mating the solution of Laplace's equation V Z u = 0 in a rect- is to use a random number generator (see Example 8.2 and
angular rcgion with Dirichlet boundary conditions. Problems 8.12, 8.13, and 8.18) to simulate the distributions of
x, y, and z. An approximation to f(P) may then be constructed
from the results of a large number of trials.
Write a program that will implement the above technique,
also known as risk analysis. Investigate the effect on f(P) of
different values for the various parameters. Also investigate
the possibility of estimating the mean and variance of P by
using a method similar to that in Section 8.5(4).
8.21 Write a program to simulate the formation of queues
at the check-out stands of a supermarket, based on the
following model.
The time-interval t , elapsing between the arrival of succes-
sive customers at' the check-out stands, has the exponential
distribution (see Prob. 8.4) f(t) = qe-"', in which q is the
average number of customers arriving per unit time. There are
n stands open, and each customer chooses the stand that has
Introduce a square grid as shown in Fig. P8.19, and let Ur be the least number of people waiting to be served. The time
the known value of u at the boundary point k (k = I, 2, . . ., n). T taken to pass through the stand, after waiting to be served,
Consider a random walk, in which we start from any point P is normally distributed with mean p and variance u2.
and proceed, at random, along a series of grid lines until a The program should simulate the passage of N customers
point on the boundary is eventually reached. The steps of the through the stands. Exponential and normal distribution
walk are such that at any point there is an equal probability of random number generators, such as those developed in
proceeding to each of the four neighboring points. Starting Problems 8.16 and 8.18, should be used to generate successive
from P, let fPX be the probability of reaching point k at the values for t and 7. The program should read values for
end of the walk. Then n, 7, p, u2 and N as data. The printed output should consist
of (a) the observed frequency function for the number of
customers waiting at a stand at any time, and (b) the observed
frequency function for the total time taken to wait and be
is an approximation to up,the solution of V 2 u = 0 at P. served.
Note. Many variations of this problem are obviously
(a) Verify the approximation up by showing that it satisfies: possible, and might include: (a) customer chooses the queue
(i) the boundary condition ur for P coincident with k, and (ii) that he estimates has the least total number of purchases to
equation (7.79), the finite-difference approximation of be processed, (b) periodic closing down or addition of stands,
V2u = 0. (c) T uniformly distributed between T,,, and T,,,, etc.
11Methods
8.22 Write a program that simulates the random dealing (a) Perform the linear regression y = u + fix on each of
of n successive bridge hands, based on the following method. these two sets of data, with y =nicotine content and x = tar
First establish a code whereby the integers 1 through 52 content.
represent the 52 cards in the deck, for example, let 1 = 2 of (b) Test the hypothesis that is the same for both cases.
.
clubs, 2 = 3 of clubs,. ., 13 = ace of clubs, 14 E 2 of diamonds, (c) For a given tar content, do the regular cigarettes
etc. Let these integers occupy, in any order, the 52 elements of contain significantly less nicotine than the filter variety?
the integer vector DECK(1) . . . DECK(52). Also, obtain a +
8.25 In the linear regression y = a fix, the method of
random number gene rat^; that gives a sequence of values least squares assumes that the values x,, i = 1, 2 , . . ., rn are
X I , X Z ,. . ., uniformly distributed between 0 and 1. The first known exactly, whereas the y , are subject to random error.
card is "dealt" by computing i l = 1 + 52x1, rounding down Using the computer, perform experiments to see what
to the next lower integer, and observing the card that is in happens if the Xr are also subject to random error. To achieve
D E C K ( i l ) . The card so dealt is then effectively removed from this, assume a model with known u and p. Then use a random
the deck by interchanging D E C K ( i l ) and DECK(52). To deal number generator (see Example 8.2, and Problems 8.12, 8.13,
+
the second card, compute i, = 1 51x2, again rounded down, and 8.18) to provide rn "exact" values x i over some interval,
and examine DECK(i2); then interchange DECK(i2) and together with corresponding values y i , distributed with con-
DECK(51). The process is repeated, and eventually the coded stant variance about a mean a + px,. Next, superimpose
form of the first hand will be in D E C K ( 4 0 ) . . . D E C K ( 5 2 ) . random errors on the xi, and use these "inexact4' values when
In addition, at least, the program should keep track of the computing the estimates a and b. Repeat the process many
distribution of point counts in the successive hands. These times, and finally compare the mean of the several values of a
point counts can then be compared with those predicted in and b thus computed with the known parameters a and p.
Example 8.1. Also, depending on the imagination and ability 8.26 Nedderman [6] used stereoscopic photography of
of the programmer, successive hands may be printed in a tiny air bubbles to determine the velocity profile close to the
format similar to those found in bridge articles, that is, a wall for flow of water in a 1 in. l:D. tube. At a Reynolds
listing of the hands sorted by suit and value. number of 1200, he obtained the values given in Table P8.26.
8.23 During the batch saponification reaction between
equimolar amounts of sodium hydroxide and ethyl acetate, Table P8.26
the concentration c (gm.moles/liter) varies with time t (min)
according to the equation y, Distance u, Velocity Y u
1 1 from Wall (cm) (crn/sec)
-=-
c co
+ kt,
where co is the initial concentration, and k (liter/gm.mole.min)
is the reaction rate constant. The following results were
obtained in the laboratory, at a temperature of 77°F:
Table P8.27
k: 1 2 3 4 5
nk: 4 4 4 4 4
8.28 For the matrix formulation of multiple regression in numbers, r is the ratio of the viscosity at the mean fluid
Section 8.21, verify that equations (8.63) can be rewritten as temperature to that at the wall temperature, and a,/I,and
y,
(8.67). 8 are constants.
8.29 In Section 8.22, multiple regression was discussed in Table P8.31 represents part of the data reported by Katz
terms of orthogonal polynomials. In this connection, verify and Williams 1161, and reexamined by Briggs, Katz, and
the folloaing: Young 1191, for heat transfer outside 314 in. O.D. plain
tubes :
(a) That the polynomials of (8.77) satisfy the orthogonality
condition (8.75). (Hint. Suppose that Pk is about to be com- Table P8.31
puted, and that all lower-order polynomials have already been
proved to be mutually orthogonal. Multiply the first of
equations (8.77) through by P,, and sum over all the data
points x,, i = I, 2, . .., m. Then consider the individual terms
-
of the resulting equation for j < k 3, j = k - 2, and j =
k - 1, in turn.)
(b) That equation (8.73) giving the regression coefficients,
can be rewritten as (8.76).
8.30 Write a program that will perform the orthogonal
polynomial regression discussed in Section 8.22. The program
should accept the following input values: m (total number of
data points), x,, ~ 2 , .. ., x,, y ~y ,z , . . ., ym, and n (order of
regression).
The printed output should consist of values for:
(a) The estimated regression coefficients, bo, b l , ..., b..
(b) The variance-covariance matrix V.
(c) The variance s2 of the data about the regression line.
(d) The coefficients of the various powers of x appearing
in all the orthogonal polynomials so that they can be recon-
Obtain least-squares estimates of a, /3, y, and 8, and indicate
structed, if necessary.
how one might determine the confidence that could be placed
in each such estimate.
592 Statistical Methods
The following is an explanation of the various subdivisions function, second subroutine or function, etc. Var~ablesEa a
appearing in the documentation of each computer example: subroutine or function whose meanings are ide~tical'hi~+tr
those already listed for an earlier program (for example, I ~ G
1. Problem Statement. Contains a statement of the prob-
main program or another subroutine or functioa?) are L23:
lem to be solved, and may refer to the main text if appropriate.
repeated.
Occasionally preceded by an introductory section.
In addition, we include here any particular programming
2. Method of Solution. Refers to algorithms already de- points such as (a) descriptions of special subroutines, ($1
veloped in the text whenever possible. Also gives notes on shifting of subscripts by one in order to accommodate, for
any special problems which may occur, and how they will be example, a. in the algebra as A(1) [and not as the illeg,~al
overcome. A(Q)] in the program, etc.
All programs have been run on an IBM 360/67 computer
3. Flow Diagram. The authors have avoided a flow dia- using the IBM G or H level compilers. We have endeavored
gram that merely repeats the program, step by step, Rather, to write programs that follow the language rules for
the flow diagram is intended to clarify the computational FORTRAN IV as outlined by the American Standards
procedure by reproducing only those steps that are essential Association (ASA-FORTRAN),* and have not attempted to
to the algorithm. Thus, in the final program, there may be
take advantage of special nonstandard features, such as
several add~tionalsteps that are not given in the flow diagram.
mixed-mode expressions, of the G or H level FORTRAN HV
Such steps frequently include: (a) printout of data that have languages,
just been read, often for checking purposes, (b) manipulations,
such as the floating of an integer when it is to be added to a 5. Program Listing. Contains a printed list of the o~.ig!~nsP
floating-point number, that are caused by limitations of FORTRAN IV program.
FORTRAN, (c) calculation of intermediate constants used
6. Data. Contains a printed list of the data cards, if any,
only as a computational convenience, (d) return to the
beginning of the program to process another set of data, (e) 7. Computer Output. In this section, the printed computer
printing headings and comments, (f) arranging for printout output is reproduced. However, if the complete output is
at definite intervals, during an iterative type of calculation, rather lengthy, only certain selected portions may be given,
by setting up a counter and checking to see if it is an integral In this case, the remaining output is usually summarized
multiple of the specified frequency of printout, etc. The flow somehow. Sometimes, clarifying notes, lines, etc., are added
diagram convention is explained at the end of this appendix. by hand to the printout. Occasionally, the printed output may
be cut and reassembled if its clarity is thereby enhanced.
4. FORTRAN Implementation. This section serves as the
main bridge between the algorithm of the text or flow diagram 8. Discussion of Results. Contains a short critical discussion
and the final FORTRAN program. It contains a list of the of the computed results, including comments on any particular
main variables used in the program, together with their programming difficulties and how they might be over,come,
definitions and, where applicable, their algebraic equivalents.
These variable names, etc., are listed alphabetically under a * Subcommittee X3 of the American Standards Association.
heading describing the program in which they first appear, "FORTRAN VS. Basic FORTRAN," Communicationsofthe ACM*
typically in the order: main program, first subroutine or Vol. 7, No. 10, 590-625, 1964.
Flow -Diagram Convention
The following boxes, each of characteristic shape, are used for constructing the flow diagrams in this text.
Substitution
LPbeI
1. When a path leaves from it, the label serves merely as an identification point in
the flow diagram; 9' is usuaIly the same as the statement number in the corresponding
program.
5. Indicate the start and finish of computations in a function. The value of the
expression 8 is returned by the function. .
Conditional Branching
Iteration
The counter 9 is incremented uniformly (in steps of $2 -9,) between its initial
and final limits 9 1 and $., respectively. For each such value of 9, the sequence of
computations Cis performed. The dotted line emphasizes the return for the next value
of 9, and the small circle, which is usually inscribed with the corresponding statement
number in the program, serves as a junction box,
The values for the variables or expressions comprising the list 9 are printed. A
message to be printed is enclosed in quotation marks.
Occasionally, there are special cases (particularly, calls on subroutines and functions) which do not fit conveniently into the
above arrangement. However, the inte~dedmeaning is conveyed readily by suitable modification of the flow diagram. The flow
diagram for a subroutine or function is separate from that for the calling program, and is started and concluded with the words
"Enter" and "Return," as explained above. The arguments for subroutines and functions are also indicated.
Index
m umbers prefixed by E refer to Computer Exannples; nysnbers prefixed by P refer to end-ofchapter Problems.
Absolute enor, 365 Beam, bending of, P6.26 principal zero of, 390
AdamsBashforth method, for solution of transverse vibrations of, 430, P3.27, P4.31, roots of, 389
ODE, 386 P4.32 Characteristic function, for statistical distri-
Adams method, for solution of ODE, 386 Beams and columns, buckling of, P4.27- tions, 542
modified, 386 P4.30 Characteristic function or polynomial of a
Adams-Moulton predictorcorrector method, Beattie-Bridgeman equation of state, E3.3 matrix, 220
for solution of ODE, 386 Bending, of a beam, P6.26 by Danilevski's method, 261, P4.35
Adiabatic flame temperature, P3.49, P3.50, of a loaded pile, P6.42 by Faddeev's method, P4.17
P5.45 of a mast, P6.27 by Leverrier's method, P4.16
Adjoint matrix, 212 of a spring, P2.29 Characteristic-value problems, 508, E7.9,
Airy stress function, P7.37 Bernoulli's method, 142, 196, P3.7 P7.24, P7.41
Aitken's delta-squared process, P3.24 Beta function, 570 Chebyshev ewnomization, 43, E1.3, P1.44-
Aitken's method, Pl.11-P1.13 Biharmonic equation, 430, E7.7, P7.28, P1.48
Algorithm, 1 P7.37, P7.39 Chebyshev polynomials, 4, 39, 100, E1.3,
Alternatingdirection methods, for elliptic Binomial distribution, 543 P1 .so, P1.5 1
PDE, 508, P7.20 Blasius equation, E2.4, P3.38 and Chebyshev quadrature, P2.27, P2.28
for parabolic PDE, 452, E7.3 Blasius problem, E6.5 and GaussChebyshev quadrature, 115, E2.4
Amplification factor, 449,450,453 Boundary conditions, for ODE, 341,405 expansion of functions as linear combina-
Anaiysis of variance, 531,585 for parabolic PDE, 431,462, P7.12, P7.13, tions of, P2.11
Anodes, distribution of potential between, P7.43 monomials in terms of, 4 1
P7.26 for PDE, at interface between different orthogonality property of, 100, P2.17
Approximation, of functions, 1 media, 462 recursion relation for, 40, 101
by Chebyshev polynomials, 39,43, P1.50, at irregularly shaped boundary, 463, E7.8 relationship to minimax polynomial, 43
P1.51 homogeneous, 508 roots of, 40,115
by interpolating polynomials, 3, 9, E l . l , types of, 462 table of, 40,100
27, E1.2, 35, 39, P1.3-P1.23 Boundary points, types of, 482,483,499 use in economization of polynomials, 43,
by least-squares polynomials, 3 Boundary-value problems, 341,405,508, E1.3, P1.44-P1.48
by minimax polynomials, 4,42, P1.44 E6.5, P6.32, P6.33 Chemical reaction, between oxygen and
by power series, 4, P1.l, P1.2 finite-difference methods, 405 methane, E5.5, P5.45
by rational functions, 2 shooting methods, 405 decomposition of s u l f w l chloride, P6.43
by spline functions, P1.24-P1.27 Brian's method, 453, P7.9, P7.10 in ionexchange column. 430, P7.33
multidimensional, P1.28-P1.41 Bridge hand, chi-square test involving, 567 involving simultaneous equilibrium, E5.5,
Arithmetic average, 532 dealing, P8.2, P8.22 P5.45
Asymptotic convergence factor, Newton's distribution of points in, E8.1 oxidation of ethylene, P4.35
method, 171 Buckling, ofbeamsandcolumns, P4.27 -P4.30 pyrolysis of ethane, E6.2
successive-substitution method, 168, 385, of mast, P3.46 saponification of ethyl acetate, P8.23
388 with diffusion, P7.24
Augmented matrix, 212,270 Cam follower, displacement of, E3.5 Chemical reactor, for pyrolysis of hydrocar-
Canonical boxes, 222 bons, P6.21
Back substitution, 270 Cantilever, flexibility matrix for, P5.16 optimum cyclic operation of, P3.21
Backward differences, multistep algorithms transverse vibrations of. P4.32 parallel-plate,, P7.24
in terms of, 381, 383 CauchySchwarz inequality, 223 residence times in, P8.5
Backward finite difference, 36 Cauchy's equation for refractive index, P2.47, stirred tanks in series, P3.22, P5.31
operator, 35, 36 P5.10 tubular, far oxidation of ethylene, P6.35
table, 36, P1.10 Cayley-Hamilton theorem, 223 for pyrolysis of ethane, E6.2, P6.20
Bairstow's method, 156, P3.6 Centraldifference operator, 35, 37,431 for sulfuryl chloride decomposition, P6.43
Band-pass filtcr circuit, P. 3.1 1 Central finite difference, 37 Chi-square distribution, 559, P8.6, P8.7
Barakat and Clark method, 452 operator, 35, 37 tabulation of, P8.8
Base points, 1 table, 38, P1.10 test for goodness-of-fit, 560, 561, E8.4
in numerical integration, 70, 100, 103, Centrifugal pump, for transfer between tanks, Cholesky's methad, P5.22, P5.23
113,115,116, P2.4-P2.7 P3.39, P3.40 Cigarettes, tar and nicotine content of, P8.24
interpolation, with arbitrarily spaced, 9, 27 in piping network, P5.40, P5.46 Circulants, P4.9, P4.10
with equally spaced, 35 Characteristic equation, of a matrix, 145, Closed integration formulas, 70, 71, P2.8,
Basis of vectors, 214 220, P3.8, P3.9 383
Closed multistep methods, for solution of in a laminar-flow heat exchanger, 430, error terms for, 129
ODE, 383 97.22, P7.23, P7.41 higher-order derivatives, 129
as correctors in predictorcorrector meth- inside reactor tubes, P6.35, P6.43 of polynomials by synthetic division, 7,
ods, 386 natural, at a heated wall, E7.5, P6.33 P1.4, P1.5
relationship to NewtonCotes closed inte- to fluid inside furnace tubes, P6.43, P7.44 Dimension of vector space, 213
gration formulas, 383 Convergence, of methods for ODE, 347 Dirichlet boundary contition, 462
Coefficient matrix, 269 of methods for PDE, 433,499 Discontinuous distribution, 5 3 2
augmented, 270 explicit method, 432 Disaete distribution, 532
Coefficient of expansion of aluminum, P1.47 implicit method, 440 Discretization error, in solution of ODE, 342,
Cofactor, 212 Convergence factor, asymptotic, for Newton's P6.4
Colebrook equation, P3.38 method, 171 in solution of PDE, 433
Combinations, 533 for solution of corrector equations, 385, Distribution function, 532
Companion matrix, 227 388, 391, P6.11 Divided difference, 9, P1.6-P1.9
\
Complex roots, 141, 142, 169,171, 196, for successive substitution methods, 168 interpolating polynomial, 9, E l . l , P1.8,
P3.1, P3.5, P3.7 Cooling fin, radiation from, P6.37 P1.9
Composite integration formulas, 77, P2.6, temperature distribution inside, P7.42 relationship to finite difference, 35
P2.7, P2.9, P2.10 Corrector equations, in solution of ODE, 362, symmetric form for, 10
Gaussian quadrature, P2.21 386,390, P6.11 table, 12, 14, 15, El.l.Pl.8-P1.9, P1.17
multidimensional, P2.35, P2.36 bound for stepsize in, 385, P6.12 table of definitions, 1 0
repeated interval-halving and Romberg extraneous solutions for, 389, P6.12, Divideddifference table, 12, 14, 15, E l . l ,
integration, 90, E2.2 P6.13 P1.8, P1.9, P1.17
Simpson's rule, 79, E2.1, 90, P2.10, P2.35, in predictor-corrector methods, 386 alternate paths across, 15
P2.36 solution by method of successive substi- detecting errors in, P1.21, P1.22
trapezoidal rule, 78,90, P2.6 tutions, 385, 388, 391, P6.11 interchanging base-point indices in, 15
Compressibility factor for gases, 173, P2.16 Covariance, 5 3 3 interchanging base-point values in, 15
for ammonia, P2.16 between regression parameters, 573-575 Dot product of two vectors, 213
for methane, P2.16 Crank-Nicolson method, 45 1, P7.11, P7.40 DuFort-Frankel method, 45 1
Compressible flow of gas, in detonation Cumulative frequency function, 532 Duhamel's theorem, P2.30
wave, P5.34 Curved boundary, see Irregularly shaped
in porous medium, P7.34 boundary Economization of polynomials, 43, E l 13,
in submarine explosion, P3.35 Curvilinear regression, see Regression P1.44-P1.48
through converging-diverging nozzle, P3.34 Eigenvalues, 21 9
Computer examples, methods for present- Danilevski's method, 145,153,261, P4.35 complex conjugate pair, 249
ing, 593 Darcy's law, P7.34, P7.36 determination of, by Danilevski's method,
Condensation, of vapor on a cooled tube, Data, reduction of, 531 261, P4.35
P2.14 Deferred approach to the limit, Richardson's, by Givens-Householder method, P4.36
Condition number of a matrix, P5.3 78,90, 364, P2.10 by Jacobi's method, 250, E4.4
Conduction, steady-state, across a hollow Definite matrices, 224 by power method of Mises, 226, E4.2,
duct, P7.16, P7.17 Degree of precision, in numerical integration, P4.34
between cylinders, E7.9 76 by roots of characteristic equation, E3.1,
in a flat plate, E7.6 Degrees of freedom, 55 9 P3.8, P3.9
in cooling fin, P6.36, P7.42 in analysis of variance, 585 by Rutishauser's method, 236, E4.3
in radiation shield, P6.34 in contingency tables, 561 dominant, 226
through oil in a pipeline, P7.30 in regression, 572, 573 for solving differential equations, 221, P4.15
unsteady-state, equation for, 429, P7.11 Density of water, P1.23 in buckling problems, P4.28-P4.30
in a semi-infinite medium, P2.30, P3.41 Determinants, 212 in characteristic-value problems, 509
in a slab, 431, E7.1, E7.2 computation of, 271,273, E5.1, E5.2 in vibrational problems, 145, P4.23-P4.26,
in a solidifying alloy, E7.4 of elementary matrices, 269 P4.31-P4.33
in a square bar, E7.3 Vandermonde, 8 , 1 4 3 Eigenvectors, 2 19
inside a cylinder, P7.21 Detonation wave, P5.34 determination of, see Eigenvalues, determina.
in the Earth's surface, P2.30 Diagonal dominance, 298 tion of
in liquefied natural gas, P7.25 Diagonal matrix, 21 1 orthogonality of, 220,224,s 11
with change of phase, E7.4, P3.48, P7.31, Diagonal pivot strategy, 274, 281 Elasticity, situations involving, see Beam;
P7.32 Difference equations, linear, 388, P6.12 Bending; Buckling; Cantilever;
Conduction equation, eigenvalue approach to characteristic equation for, 389 Flexibility matrix; Frame; Torsional oscil-
stability of methods for solving Crank- homogeneous, 389 lations; and Vibrations
Nicolson method, P4.21 solutions for, 389 Electrical circuit, transient behavior of, E6.3,
explicit method, P4.20 Differential equations, see Ordinary (ODE) P3.11, P3.12, P6.22-P6.24
Confidence intervals, 568,570 differential equations; Partial (PDE) dif- Electrical network, E5.1, P5.24, P6.24
Consistency of methods for PDE, 449,450 ferential equations analysis by Laplace transforms, P3.11, P3.12
Contingency tables, 561 Differential mean-value theorem, 9, 346 Electronic vacuum tube, circuits involving,
Continuous distribution, 532 Differentiation, numerical, 128, P2.46-P2.52, P3.20, P5.32
Convection, at a flat plate, P6.31 P5.9 operating characteristics of, P1.42, P2.48
combined with radiation, P3.42, P5.30, and the interpolating polynomial, 128 Electron lens, distribution of potential inside,
P5.33, P6.34, P6.37 approximations for first derivatives, 129, P7.26
in heat exchangers, P2.15, P3.45, P6.19 130 motion of electron inside, P6.25
Elementary matrices, 269,271 table, 35,36,38, P1.10 error term for, 116
Elliptic PDE, 429,482 Finitedifference approximations for partial for arbitrary integration limits, E2.4
iterative methods for solving, 484,508, derivatives, see Partial derivatives welght factors for, 115
E7.6-E7.8 Finitedifference methods for boundary-value Gauss forward formula, 38, P1.10
Equal ripple property, 42 problems, 405,509, P4.28, P4.30, P4.31 error term for, 38
Equation of state, Beattie-Bridgeman, E3.3 Finite divided difference, see Divided differ- Gauss-Hermite quadrature, 115, P2.23
Van der Waals's, P3.30 ence error term for, 116
Equations, Solution of, Chapter 3 Fixed word length, for computers, 342 table of base points for, 116
Systems of, Chapter 5 Flash vaporization of a hydrocarbon mixture, table of weight factors for, 116
Equilibrium, of simultaneous chemical reac- ~3.36 Gaussian elimination, 270
tions, E5.5, P5.45 Flexibility matrix, P5.13, P5.16, P5.17 Gaussian quadrature, 100, 101, E2.3, 113,
Equivalent matrices, 270 Flowdiagram convention, 594 115, 116, E2.4, P2.19-P2.23, P2.25,
Enor, inherent, 1 Fluid mechanics, situations involving, com- P2.26, P2.37, P2.38
round-off, 1 , 6 pressible flow,P3.34-35, P5.34, P7.34 Gauss-Jordan' elimination, 272, E5.1
truncation, 1 flat plate, flow past, E6.5, P6.32 effect of small pivot, 273, 281
in solution of ODE, 342 friction factor, determination of, P3.37, with maximum-pivot strategy, 281, E5.2,
absolute, 365 P3.38 P5.2
discretization, 342, P6.4 hydraulic jump, P3.31 Gauss-Laguerre quadrature, 113, P2.20
local truncation, 342,345, 347,363, 365, jet, P6.41 error term for, 115
387,391 natural convection at heated wall, E7.5, for arbitrary lower integration limit, 115,
propagation of, 346,365 P6.33 P2.22
relative, 365 networks of pipes, E5.4, P5.40, P5.41, table of base points for, 113
round-off, 342,345,365 P5.46 table of weight factors for, 113
truncation, 342, 347,363,365, 387, 391, particle-sampling probe, P6.39, P6.40, weight factors for, 113
P6.15 P7.27 Gauss-Legendre quadrature, 101, E2.3, E2.4,
Error function, P2.19, P3.44 porous medium, flow in, P7.34, P7.36 P3.44
Ethane, pyrolysis in a tubular reactor, E6.2 pressure drop in pipes, E5.4, P3.38-P3.40, base points and weight factors, by half-inter-
Euler load, P2.29, P4.27 P5.40, P5.41, P5.46, P7.30 val method, E3.4
Euler's method, for solution of ODE, 344, pressure drop in tubular reactors, P6.20, composite formula for, P2.21
E6.1, E6.2, P6.4 P6.35, P6.43 error term for, 105
bound for propagated error in, 347 pumping and piping operations, E5.4, for arbitrary integration limits, 104
convergence for, 347 P3.39, P3.40, P5.40, P5.46 multidimensional, P2.37, P2.38
improved, 362, P6.3 stream function, E6.5, P3.47, P7.27 table of base points for, 103
local truncation error for, 345,347 submarine explosion, P3.35 table of weight factors for, 103
modified, 362, P6.3 surge tank, P6.28 weight factors for, 103
propagation of truncation error in, 346 velocity profiles, determination of, E2.4, GaussSeidel method, 299, E5.3, P5.38
Expected value, 532 E6.5,E7.5,P6.41,P7.30, P8.26 for PDE, 484, E7.6-E7.8
Explicit method for PDE, 432, E7.1, E7.5, vorticity transport equation, 430 Gill, coefficients for Runge-Kutta method, 363,
P7.4 FORTRAN, 6; see also individual Computer P6.10
consistency of, 450 Examples; Appendix; and Preface Givens-Householder method, P4.36
convergence of, 432 Forward finite difference, 35 Goodness-of-fit, chi-square test for, 560
in two space dimensions, 452 operator, 35 Graeffe's root-squaring method, 141, E3.1,
limitations of, 440 table, 35, P1.10 P3.1
stability of, 449 Fourier coefficients, using Romberg integra- Gram-Schmidt orthogonatization, 297
unconditionally stable methosds, 45 1 tion, E2.2 Grid point, 429,43 1
Explicit multistep methods, for solution of Fourier functions, 2,43, P1.50, P1.51 Grouting of underground rock formation, P7.36
ODE, 385 relationship to Chebyshev polynomials, 40
Exponential distribution, P8.4, P8.16,P8.21 Frames, minimization of strain energy in, Half-interval method, 178,406, E3.4, E6.5,
Exponential integral, P2.22 P4.18 P3.32
Extraneous solutions, for multistep meth- statically determinate, E5.2, P5.19 Hamming's method, 390, E6.4, P6.15
ods in the solution of ODE, 389, P6.12, statically indeterminate, P4.18, P5.13- stability of, 391
P6.13 P5.15, P5.18 stepsize for convergence of corrector, 391
Extrapolation, 16, 385, E l . l , 1'1.3 Freezing problem, P3.48, P7.31, P7.32 truncation error for, 391
Richardson's, 78,90, 364, P2.10 Frequencies of vibration, see Vibrations Heat exchanger, condensation of vapor in, P2.14
Frequency function, 532 laminar flow in, 430, P7.22, P7.23, P7.41
Factorization of matrices, 214, P5.21 Friction factor, for flow in a rough pipe, with temperaturedependent physical prop-
Faddeev's method for characteristic poly- P3.38 erties, P2.15, P3.45, P6.19
nomials, P4.17 for turbulent flow in a smooth pipc, P3.37 IIeat loss, fiom insulated pipe, P5.33
False position method, 178, E31.5 Fugacity, P2.16 from wall of combustion chamber, P3.42
Fanning equation, E5.4, P5.46 Furnaces, see Radiation Heat transfer, see Conduction; Convection; and
F distribution, 570 Radiation
tabulation of, P8.11 Gamma function, 115, P2.20, P2.22,559 Heat transfer coefficients, correlation of, P8.27,
test for sample variances, 571, 586 Gauss backward formula, 38 P8.31
Finite difference, 35 error term for, 38 Hermite polynomials, 101
operators, 35, 36, 37 GaussChebyshev quadrature, 115, E2.4 and Gauss-Hermite quadrature, 116
relationship to fmite divided difference, 35 base points for, 115 orthogonality property of, 101
recursion relation for, 101 Gauss-Laguerre quadrature, 113, P2.20, Jacobi method, 298, P5.37
roots of, P3.33 P2.22 for simultaneous nonlinear equations, Newton
table of, 101 Gauss-Legendre quadrature, 101, E2.3, E2.4, Raphson, 319, E5.5, P5.42, P5.43
table of roots of, 116 P2.21, P2.37, P2.38 successive substitution, 308, E5.4
Hermitian form, 224 improved trapezoidal rule, P2.2, P2.3
Hermitian matrix, 211, 224 Lobatto quadrature, 116, P2.25 Jacobian, 156, 319
Heun's method, 362 multidimensional quadrature, P2.3 1-P2.38 Jacobi's methods, for eigenvalues, 250, E4.4
Homogeneous boundary conditions, 50'8 NewtonCotes closed formulas, 71, P2.8, for simultaneous equations, 298,484, P5.37,
Homogeneous equations, 212 P2.9 P7.18
Honor-point count, E8.1 NewtonCotes open formulas, 75 Jet, velocity profile in, P6.41
Horner's rule, 6, P1.4, P1.5 open formulas, 70, 75 Jordan canonical form, 222
Hydraulic jump, P3.31 Radau quadrature, 116, P2.26
Hydrocarbon mixtures, cracking of ethane, Romberg integration, 90, E2.2 Kaczmarz's method, 297, P5.36
E6.2 Simpson's rule, 73,79,90, E2.1, E8.3, Kirchoffs current law, 274
flashing of, P3.36 P2.5, P2.7, P2.10, P2.12, P2.34-P2.36 Kutta, coefficients for Runge-Kutta methad,
furnace for cracking, P5.27-P5.29 stepsize for, 71, 78, 100 363
general cracking of, P6.20 trapezoidal rule, 7 1, 78, 90, E2.2, P2.1-
mass-spectrometric analysis of, P5.11 P2.4, P2.6 Lagrange interpolation coefficients, for multi-
Hyperbolic PDE, 429 with equally spaced base points, 70 dimensional quadrature, P2.31
Interpolating polynomial, 3, 8, 9, E l . l , 27, Lagrange's interpolating polynomial, 9, 27,
Ideal gas law, 173, P7.34 E1.2,35, 39 E1.2,P1.8, P1.16,Pl.lS
Identity matrix, 211 differentiation of, 128 error term for, 27
Ill-conditioned matrix, 297, P5.3 Gauss backward formula, 38 multidimensional, P1.35-P1.39
Implicit methods for PDE, 440, E7.2, E7.4, Gauss forward formula, 38, P1.10 Laguerre polynomials, 100
P7.5 in multistep methods for solution of ODE, and Gauss-Laguerre quadrature, 113
alternatingdirection, 452, E7.3, P7.6-P7.8 381 orthogonality property of, 100
convergence of, 440 integration of, 69, 71, 75 recursion relation for, 100
Crank-Nicolson, 45 1 Lagrange's,9,27,E1.2,P1.8,P1.16,P1.18 roots of, P3.33
in two dimensions, 452 multidimensional, P1.35-P1.39 table of, 100
solutions of tridiagonal equations resulting Newton's backward formula, 37, P1.10 table of roots of, 113
from, 441 Newton's divideddifference, 9, E l . l , P1.8, Laplace's equation, in a rectangle, 483, E7.6,
stability of, 450 PI .9 P7.15, P7.20
Implicit multistep methods, for solution of Newton's forward formula, 36, P1.10 solution by random walk, P8.19
ODE, 385 Newton's fundamental formula, 13, P1.ll Laplace transformation, P3.10-P3.12
Improved Euler's method, 362, P6.3 Stirling's formula, 38, P1.23 Laplacian, approximation of, at irregular bounc
Improved polygon method, 362 using derivatives at base points, 39 ary, 463,483, E7.8, P7.17
Improved trapezoidal ruie, P2.2 with equally-spaced base points, 35 in a rectangle, 483
Incidence matrix, 310 Interpolation, 3,8,9,27, 35, 39, 385, E l . l , nine-point, 431, P7.3
Increment function, in solution of ODE, 361 E1.2, P1.3-P1.23 Larkin's method, 452
Individual, in a population, 532 inverse, P1.14, P1.15, P3.16 Latent-heat effects, E7.4, P3.48, P7.31, P7.32
Inherent error, 1 iterated linear, P1.ll-P1.13 Least squares, method of, 3,571
Inherent instability, in solution of ODE, 364 linear, 10, P1.3 weighted, 4
Initial basis, 214 multidimensional, P1.28-P1.41 see also Regression
Initial condition, for parabolic PDE, 431,450 of degree two at a boundary, 483 Legendre polynomials, 100
Initial-value problem, 341 Interpolation and Approximation, Chapter 1 and Gauss-Legendre quadrature, 101
Inner product of two vectors, 213 Interval-halving and Romberg integration, 90, orthogonality property of, 100
Instability, see Stability EL.2 recursion relation for, 100
Insulated boundary, 462, E7.4 Inverse error function, P3.44 roots of, E4.3
Integral equations, in theory of radiation Inverse interpolation, P1.14, P1.15, P3.16 table of, 100
scattering, P2.44 Inverse matrix, 211, P4.2 table of roots of, 103
simultaneous, for radiation between parallel computation of, 271, 272, E5.1, E5.2 Length of a vector, 213
plates, E2.1, P2.45 improvement of estimate for, P4.1, P5.8 Leverrier's method for characteristic polynomi
Integral mean-value theorem, 72 Ion-exchange equation, 430, P7.33 als, P4.16
Integration, numerical, 69 Irreducible matrix, 299,484 L'Hospital's rule, P7.21
as a smoothing process, 69, 128 Irregularly shaped boundaries, 463,483, E7.8, Liebmann method, 484
Chebyshev quadrature, P2.27, P2.28 P7.17 Limit, Richardson's deferred approach to, 78,
closed formulas, 70, 71, P2.8 Irrotational flow, stream function in, P7.27 90, 364, P2.10
composite formulas, 77,90, E2.1, P2.6, Isometric matrix, 224 Linear combination, 534
P2.7, P2.9, P2.10, P2.21,P2.35,P2.36 Iterated linear interpolation, Pl.11-P1.13 of approximating functions, 2
degree of precision in, 76 Iterated synthetic division, P3.2-P3.4 of normally distributed variables, 552
error estimation in, 77 Iterative factorization of polynomials, 156, of orthogonal polynomials, 101, P2.11
GaussChebyshev quadrature, 115, E2.4 E3.2 of vectors, 214
Gauss-Hermite quadrature, 116, P2.23 Iterative methods, for elliptic PDE, 484,508, Linear dependence, 21 3
Gaussian quadrature, 100,101,113, 115, P7.15 Linear interpolation, 10, P1.3
116, E2.3, E2.4, P2.19-P2.23, P2.25, for simultaneous linear equations, Gauss- iterated, P1.ll-P1.13
P2.26, P2.37, P2.38 Seidel method, 299, E5.3, P5.38 Linear operator, 35
Linear transformations, 219 MuUer's method, P3.19 Normalized vector, 213
Lin's iteration, P3.4 Multidimensional approximation, P1.28-P1.41 Normal regression equations, 572-574
Lin's method, P3.5 Multidimensional interpolating polynomial, Nozzle, flow in convergingdiverging, P3.34
Loaded plate, deflection of, 430, E7.7, P7.28 P2.31-P2.36 Null hypothesis, 560
stress distribution in, P7.37 Multidimensional quadrature, P2.31-P2.35 Nullity, 219
Lobatto quadrature, 116, P2.25 Multinomial distribution, 543,560 Sylvester's law of, 219
Local truncation error, see Truncation error Multiple regression, see Regression Null matrix, 210
Multiple roots, 141, 142, 156, 169, P3.7 NuU space, 219
Marginal stability, in solution of ODE by Multistep methods, for solution of ODE, 342, Numerical Integration, Chapter 2
multistep methods, 390 381,383,386,391 Numerical method, 1
Mass spectrometer, interpretation of data characteristic equation for, 389
from, P5.11 closed integration formulas, 383 Ohm's law, 274
Mass-spring systems, vibrations of, E3.1, extraneous or parasitic solutions for, 389, Oil, nonisothermal flow in a pipeline, P7.30
P4.23, P4.24 P6.12, P6.13 One-step methods, for solution of ODE,342,
Mast, bending of, P6.27 in predictor-corrector methods, 384 361,392
buckling of, P3.46 open integration formulas, 381 Open integration formulas, 7 0 , 7 5 , 382
Matrices and Related Topics, Chapter 4 relationship to Newton-Cotes integration Open multistep methods, for solution of ODE,
Matrices and vectors, operations involving, formulas, 382, 383 381
E4.1 truncation error in, 387,391 as predictors in predictor-corrector methods,
Matrix, augmented, 212, 270 386
basic defiitions and operations concerning, Natural convection at a vertical plate, E7.5, relationship to NewtonCotes open integra-
17, 210-213, E4.1 P6.33 tion formulas, 382
coefficient, 269 Natural gas, storage of liquefied, P7.25 Optimization methods, in solution of boundary
elementary, 269, 271 underground storage of, B7.34 value problems, 406
equivalent, 270 Nested evaluation of polynomials, 6 Ordinary Differential Equations (ODE), Chap-
factorization of, 214, P5.21 Network, electrical, E5.1, P3.11, P3.12, P5.24, ter 6
flexibility, P5.13, P5.16, P5.17 P6.24 numerical solution of, 341
Hilbert, P5.8 of pipes, E5.4, P5.41 Adams method, 386
incidence, 310 and pumps, P5.40, P5.46 Adams-Bashforth method, 386
inversion of, 271,272: E5.1, E5.2 Neumann boundary condition, 462, P7.23 Adams-Moulton method, 386
partitioning of, 270 FJewtonCotes closed integration formulas, 7 1 , boundary value problems, 341,405, E6.5
Maximum-pivot strategy, 281, ES.2, P5.2 383, P2.8 closed multistep methods, 383
Maxwell-Boltzmann distribution, P8.6 composite formulas for, 7 7 , P2.9 convergence, 347
Mean, 532 error term for, 7 3 corrector equations, 362, 386, 390
for a sample, 542 estimating the error for, 76 discretization error in, 342, P6.4
of arbitrary function, 534 table of, 7 3 eigenvalue approach to, 221, P4.15
of linear combination, 534 see also Simpson's rule; Trapezoidal rule errors in, 342,345,347,363,365,387,391
Mean-value theorem, differentia!,, 9,346 NeWonCotes open integration formulas, 7 5 , Euler's method, 344, E6.1, E6.2, P6.4
integral, 7 2 382 extraneous solutions for, 389, P6.12, P6.13
Mechanical quadrature, see Internation, error term for, 76 finitedifference methods for, 405
numerical estimating the error for, 76 Hamming's method, 390, E6.4, P6.15
Median, 5 32 table of, 76 Heun's method, 362
Membrane, transverse vibrations of, P4.33 Newton-Raphson method, 319, E5.5, P5.42 improved Euler's method, 362, P6.3
Milne predictor-corrector methods, for solu- efficient application of, P5.43 improved polygon method, 362
tion of ODE, 386 in factorization of polynomials, 156, P3.6 increment function in, 361
characteristic equation for fouxth-order Newton's backward formula, 37,381,383, initial value problems, 341
corrector, 389 P1.10 local truncation error in, 342, 345, 347, 363,
extraneous or parasitic solutiorrs for, 389, error term for, 37 387,391
P6.12 Newton's divideddifference interpolating poly- Milne methods, 386, P6.11, P6.12
fourth-order method, 386 nomial, 913, P1.8, P1.9 modified Adams method, 386, P6.13, P6.14
sixth-order method, 386, P6.11, P6.12 error for, 1 3 , 1 4 modified Euler's method, 362, P6.3
stability of, 390 Newton's forward formula, 36, 7 1 , 7 5 , P1.lO, multistep methods, 342, 381,383, 386, 391
Minimax, polynomial, 4 , 4 2 , P1.44 P1.ll one-step methods, 342, 361, 392
principle, 4 , 4 2 , P1.43 error term for, 36 open multistep methods, 381
Minor, 212 Newton's fundamental formula, 13 order of, 341
Mode, 532 error term for, 13, 14 parasitic solutions for, 389, P6.12, P6.13
Modified Adams predictor-corrector method, Newton's method, 171, E3.3, P3.14, P3.15 predictor-corrector methods, 362, 384, 386,
for solution of ODE, 386, P6.13, P6.14 Nine-point approximation for Laplacian, 431, 390, E6.1, P6.11-P6.15
Modlfied Euler's method, for solution of ODE , P7.3 predictor equations, 362, 386
362, P6.3 Nonlinear PDE, 464, E7.4, E7.5, P7.11 propagatior, factor in, 365
stability of, 388, 391, P6.12, P6.13 Nunsingular matrix, 21 1 Kunge-Kutta methods, 361, 363, E6.3, E6.4,
Moment coefficients, 532 Norm, P5.3 E6.5, P6.5-P6.10, P6.15
Momentgenerating functions, 542 Normal distribution, 552 simultaneous first-order equations, 341, 365,
Monic polynomial, 40 derivation of frequency fuirction for, 553 390, E6.3, E6.4
Monomials, in terms of Chebyshev polynomi- tabulation of standardized values, 552, E8.3 stability in, 364, 388, 391,P6.12,P6.13
als, 41 Normalizztion steps, 271,273,274,282 step-factor in, 365
stepsize, 341,364,385,387,391,P6.10, Polynomial regression, see Regression stability of, 388,391, P6.12, P6.13
P6.15 Polynomials, 2 stepsize control in, 385,387, 391, P6.15
systems of fixst-order equations, 342,347, as approximating functions, 3,4,27, 35, truncation error in, 387, 391
363,365,387,391 39,42, El.1, E1.2 Predictor equations, in solution of ODE, 362,
Taylor's expansion approach to, 343,361, Chebyshev, 4, 39,100,115, E1.3, P1.50, 386
P6.2, P6.6 P1.51, P2.11,P2.27,P2.28 in predictorcorrector methods, 386
truncation error in, 342, 346, 387, P6.4, derivatives of by synthetic division, 6, P1.4, Presentation of Computer Examples, 593
P6.15 P1.5 Pressure drop, in pipes, E5.4, P3.38-P3.40,
Orthogonality, of eigenvectors, 5 11, 5 19 differentiation of, 128, P5.9 P5.40, P5.41, P5.46, P7.30
property, for polynomials, 100, 121, P2.17 economization of, 43, E1.3, P1.44-Pl.48 in tubular reactors, P6.20, P6.35, P6.43
Orthogonakation, Gram-Schmidt procedure, equations involving, 141 Probability, 532
297 evaluation of, by Horner's rule, 6, P1.4, lawsof, 533
Orthogonal matrix, 211 P1.5 Probability density function, 532
Orthogonal polynomials, 100 Gauss backward formula, 38 Producer gas, combustion of, P3.50
Chebyshev, 100, P2.17 Gauss forward formula, 38, P1.10 Projectile, fhght of, P6.29
expansion of monomials as linear combi- Hermite, 101,116 Propagation factor, in solution of ODE, 365
nations of, 101, P2.11 in a matrix, 221 Pseudorandom number generator, see Randon
Hermite, 101 in multistep methods for solution of ODE, number generator
Laguerre, 100 381 Pump, see Centrifugal pump
Legendre, 100 integration of, 69, 71, 75
use in regression, 574 interpolating, 3 , 8 , 9 , 2 7 , 35, 39, E l . l , QD (quotientdifference) algorithm, 196, P3.5
Orthogonal vectors, 213 E1.2 Quadratic convergence, 171, P3.14
Orthonormal set of vectors, 213, P4.7 iterative factorization of, 156, 171, E3.2 Quadratic factors for polynomials, 156, E3.2,
Overrelaxation, successive, 508, P7.19 Lagrange's interpolating, 9,27, E1.2, P1.8, P3.5
Oxidation, of ethylene, P6.35 P1.16, P1.18 Quadratic form, 224
of methane, E5.5, P3.49, P5.45 Laguene, 100,113 Quadrature, see Integration, numerical
of producer gas, P3.50 least-squares, 3, 571,573,574 Quadratic formulas, determination of roots
Legendre, 100, 101 needed for, E3.4, P3.32, P3.33
Parabolic PDE, 429,431,452 minimax, 4,42, P1.44 Quasidiagonal matrix, 222
Crank-Nicolson method, 451 monic, 40 Queues, simulation of, P8.21
explicit method, 432, E7.1, E7.5, P7.4 multidimensional interpolating, P1.35 -
implicit alternatingdirection methods, 452, P1.39 Radau quadrature, 116, P2.26
E7.3 near-minimax, 4 3, P 1.44 Radiation, between multiple surfaces, P5.25,
implicit method, 440, E7.2, E7.4, P7.5 Newton's backward formula, 37, P1.10 P5.26
in two and three space dimensions, 453, E7;5 Newton's divided-difference interpolating, between parallel plates, E2.1, P2.43, P2.45
Richardson method, 450 9, El.1, P1.8, P1.9 emission between wavelengths, P2.13
stable explicit methods, 451 Newton's forward formula, 36, PI.lO,P1.11 from cooling fins, P6.37
Parasitic solutions, for multistep methods in Newton's fundamental formula, 13, P1.ll from insulated pipe wall, P5.33
solution of ODE, 389, P6.12, P6.13 orthogonal, see Orthogonal polynomials from wall of cornbustion chamber., P3.42
Partial derivatives, approximation of, 430, splitting ratio of into partial fractions,P3.10 involving refractories, P5.26-5.29, P7.44
462, P7.1, P7.2 Stirling's formula, 38, P1.23 most intense, P3.43
Partial Differential Equations (PDE), Chap- transformation of, from one variable to scattering of, P2.44
ter 7 another, 44, E1.3, P1.49 shielded, P5.30, P6.34
Partial instability, in solution of ODE, 364 Populations, 532 to bar inside furnace, P7.43
Particle-sampling probe, P6.39, P6.40, P7.27 statistics concerning, 533 to reactor tube, P6.43
Partitioning of matrices, 21 1, 270 wildlife, P6.38 to tube near refractory wall, P7.44
PDE, classification of, 429 Portal frame, P5.18 to tubes in furnace, P5.27-P5.29
examples of, 429 Positive definite matrix, 224-226, 301,483 view factors, by the string method, P3.17,
for methods of solution, see Characteristic- Cholesky's method for factoring, P5.22, P3.18
value problems; Elliptic PDE; and Parabolic P5.23 computation as integrals, P2.39-P2.43
PDE Power method of Mises, 226, E4.2, P4.34 definition of, P2.39, P2.41, P5.25
Permutations, 533 Power series, 4, P1.l, P1.2 with absorbing gas, P2.42, P2.45
Pile, bending of, P6.42 telescoping or economization of, 43, E1.3, Random number generator, additive method,
Pipe, see Friction factor; Network; Pressure P1.44-P1.48 P8.12
drop; and Velocity profiles Precision, degree of, 76 for arbitrary distribution, P8.15
Pivot element, 273 Predictor-corrector methods, for solution of for normal distribution, P8.17, P8.18
effect of small value, 273, 281 ODE, 362,384,386,390, E6.4 for Poisson distribution, E8.2
selection of, 282 Adams-Moulton method, 386 mixed multiplicative congruential method,
Planck's law, P3.43 extraneous or parasitic solutions for, 389, P8.13
Plotting subroutines, E6.3, E6.5, E7.1, E8.5 P6.12, P6.13 multiplicative congruential method, 545
Point count, of a bridge hand, E8.1, E8.4, Hamming's ~ n e t l ~ u 390,
d , E6.4, P6.15 Random variable, 532
P8.22 Milne fourth-order method, 386 Random walk, P8.19
Poisson distribution, 543, P8.4 Milne sixth-order method, 386, P6.11, Rank of a matrix, 212, 214
random number generator for, E8.2 P6.12 Rational functions, 2
Poisson's equation, 430, E7.7, E7.8, P7.19, modified Adams method, 386, P6.13, Reaction, see Chemical reaction
P7.29 P6.14 Reactor, see Chemical reactor
Rectifier, circuits involving, P6 2 2 , P6.23 propagated error for, 364 Stability of methods, for ODE, 364,388
Reduction step, 271, 273,274,282 relationship to Taylor's expansion of the marginal, 390
Refractive index, of glass, P2.47, P5.10 solution function, 361, P6.6 multistep methods, 388, 391, P6.12, P6.13
of sucrose solutions, P1.23 Runge's coefficients for, 363 relative, 390
Refractory surfaces, P5.26, PS.28 secondader methods, 361 Runge-Kutta methods, 364
Regression, for families of straight lines, P8.27 stability of, 364 strong, 390
in terms of orthogonal polynomials, 574, step-factor in, 365 weak, 390
P8.29, P8.30 stepsize control in, 364, P6.10 for PDE, 449, P7.6-P7.9
involving normal distances, P5.35 thirdarder methods, 362, P6.5, P6.8, explicit method, 449
linear, 571, P8.23-P8.25 P6.9 implicit method, 450
matrix formulation of, 574, P8.28 truncation error in, 363, P6.15 Richardson's method, 450
multiple and polynomial, 573, E8.5, P8.26 Run test, for random digits, P8.14 simultaneous PDE, 475
situations involving, 531, P8.23-P8.31 Rutishauser's method, 236, E4.3, P4.22 Standard deviation, 532
Regula-fasi method, 179, P3.44 acceleration of convergence in, 239 Statically determinate and indeterminate frames,
Relative error, 365 application of, 5 11 see Frames
Relative stability, in solution of ODE by Rutishauser's QD algorithm, 196, P3.51 Statistic, 532
multistep methods, 390 statistical Methods, Chapter 8
Relaxation, 301 Sample, 532 Statistics, definition of, 532
methods for elliptic PDE, 484,508 mean, test of significance for, 568 Stefan-Boltzmann constant, P2.13
Remainder, for Taylor's formula, 4., 430 statistics concerning, 542 Step-factor, in solution of ODE, 365
Residence times in a stirred tank reactor, P8.5 two variances, ratio of, 570 Stepsize, for numerical integration, 71, 78, 100
Rhombus rules, 196 variance, joint estimate of, 568,571 in solution of ODE, 341, 364,385, 387,391
Richardson's extrapolation, 78,90, 364, P2.10 Saul'yev method, 451 control in multistep methods, 385, 387, 391,
Richardson's method, 484 Scalars, 211 P6.15
Ripple-filter circuit, P6.22 Schur's inequality, 223 control in Runge-Kutta methods, 364, P6.10
Risk analysis, P8.20 Semi-infinite medium, heat conduction in, Stiffness matrix, P5.16
Roue's theorem, 13 P2.30, P3.41 Stirling's formula, 38, P1.23
Romberg integration, 90, E2.2 scattering of radiation in, P2.44 Strain energy in frames, P4.18
error term for, 9 1 Serial association, of random digits, P8.14 Stream function, in flow past a flat plate, E6.5
tableau for, 91 Shaft, oscillation of rotating masses on, in irrotational flow between coaxial tubes,
Roots, of characteristic equation, for linear P4.25, P4.26 77.27
difference equations, 389 Shooting methods, in solution of boundary- near cylinder, with circulation, P3.47
of Chebyshev polynomials, 40,115 value problems, 405 String method for radiation view factors, P3.17,
of equations, 141 Significance, tests of, 531 P3.18
of Hermite polynomlds, 116, P3.33 between sample means, 569 Stresses, in a concrete dam, P7.39
of Laguerre polynomials, 100, 103, E3.4 for sample means, 568 in a loaded plate, P7.37, P7.38
of Legendre polynomials, 100, 103 for slope of regression line, 572 Strong stability, in solution of ODE by multi-
Roots of an equation, methods for finding, Similar matrices, 221 step methods, 390
Bernoulli, 142 Simpson's rule, 73, 363, E8.3, P2.5, P2.12 Structures, see Frames
false position, 178 composite formula, 79, E2.1,90, P2.10 Student's t distribution, 568
Graeffe, 141, E3.1 error term for, 73, 79 for test in h e a r regression, 572
half-interval, 178, E3.4 multidimensional, P2.3442.36 tabulation of, P8.10
Muller, P3.19 Simultaneous linear algebraic equations, 269 Submarine explosion, P3.35
Newton, 171, E3.3, P3.14, P3.15 direct solution of, 270, 272,297, E5.1, Subspaces, 219
quotient-difference, 196, P3.51 E5.2 Successive overrelaxation, 508, P7.19
regula falsi, 179, P3.44 Gauss-Seidel method, 299,484, E5.3, E7.6- Successive substitution, method of, 168, P3.13,
successive substitution, 168, P3.13, P3.23, E7.8, P5.38 P3.32
P3.24 iterative solution of, 298, 299, E5.3 acceleration of convergence in, P3.24
Ward, 169, P3.29 Jacobi method, 298,484, P5.37, P7.18 asymptotic convergence factor for, 168
Root-squaring method, Graeffe's, 141, E3.1 Simultaneous nonlinear equations, 269, 308 in solution of corrector equations, 385, 388,
Round-off error, 1 , 6 , 342,345, 365 iterative methods for solving, 308, 319, 391, P6.11
accumulation of, 7 E5.4, E5.5 Successive substitution method, in solution of
bound for, 7 Simultaneous ODE, 341, 365,390, E6.3, corrector equations, 385. 388.391, P6.11
effect in solving simultaneous equations, E6.4 asymptotic convergence factor for, 385,
P5.5 -P5.7 Simultaneous PDE, E7.5 388
Runge, coefficients for Runge-Kutta method, Smoothing process, integration as a, 69 Surge tank,P6.28
363 Solution of Equations, Chapter 3 Sylvester's law of n d t y , 219, P4.14
Runge-Kutta methods, for solution of ODE, Specific heat capacity of nitrogen, P1.46 Symmetric matrix, 21 1,224
361 Specific volume of superheated methane, Synthetic division, 7, P1.4, P1.5
coefficients, for minimum truncation error, R1.29 by quadratic factor, P3.5
P6.15 Spline functions, P1.24-P1.27 iterated, P3.2-P3.4
fourth-order methods, 363, E6.3, E6.4, differentiation of, P2.52 Systems, of first-order ODE.341,365,390,
E6.5, P6.6, P6.7, P6.15 in the solution of ODE, P6.116-P6.18 E6.3, E6.4
Gill's coefficients for, 363, P6.10 multidimensional, P1.40, P1.41 Systems of Equations, Chapter 5
increment function for, 361 Spring, bending of, P2.29
Kutta's coefficients for, 363 Spur of a matrix, 220 Table look-up procedure, 466
Index
Taylor's expansion, approach to solution of Tridiagonal matrix, eigenvalues of, E4.3, Vehicle suspension, vibrations of, P6.30,
ODE, 343,361, P6.2 P4.19 P6.31
for boundary conditions for PDE, 462-464 Tridiagonal system, algorithm for solving, Velocity profiles, in a jet, P6.41
for approximating partial derivatives, 430 441 inside tubes, E2.4, P7.30, P8.26
for two independent variables, 361,430, subroutine for solving, E7.2 near flat plate, E6.5, E7.5
P1.32, P1.33, P6.6 Truncation error, 1 Vibrations, of a beam, transversely, 430,
Taylor's formula with remainder, 4, P1.l, in solution of ODE, 342 P3.27, P4.31, P4.32
P1.2 bound for, in Euler's method, 347 of a membrane, P4.33
r distribution, see Student's t distribution for Euler's method, 345, P6.4 of mass-spring systems, E3.1, P4.23,
Telephone equation, 430 for multistep methods, 387, 391 of rotating masses, P4.25, P4.26
Telescoping a power series, 43, E l .3, P1.44- for Runge-Kutta methods, 363, P6.15 of vehicle suspension, P6.30, P6.31
P1.48 for Taylor's series approach, 344 View factor, see Radiation
Thermal conductivity of carbon dioxide,P1.19 local, 342,345,347,363,387,391 Viscosity of liquid ethylene glycol, P1
Thermocouple emf, interpolation in table of, propagation of, 346,364 Von Neumann stability analysis, 449.4 -
E1.2, P1.14 Truss, forces in, E5.2 475, P7.7-P7.9
Third boundary condition, 462, P7.12 Vorticity transport equation, 430
Torsional oscillations of rotating masses, P4.25, Undetermined coefficients, method of, P2.5 1
P4.26 ., Unitary matrix, 21 1, P4.4 Ward's method, 169, P3.29
Torsion of a cylinder, E7.8, P7.29 Unit vector, 213 Wave equation, 430
Trace of a matrix, 220 Weak stability, in solution of ODE by multi-
Transfer rule, 219 Vandermonde determinant, 8,143 step methods, 390
Transformation of a vector space, 219 Vapor pressure of aqueous ammonia solu- Weierstrass approximation theorem, 3
Transpose of a matrix, 210, P4.3 tions, P1.29 Weight factors, for Gaussian quadrature
Trapezoidal rule, 71,9O, P2.1, P2.4, P2.6 Variable, random, 5 32 formulas, 102, 113,115,116
and Romberg integration, 90, E2.2 Variance, 532,533 Weighting function, and orthogonality
composite formula, 78,90, P2.6 for a sample, 542,568 property for polynomials. 100
error term for, 72, 78 of arbitrary function, 534 Weights of males in United States, distribu-
improved, P2.2, P2.3 of linear combination, 534 tion of, P8.9
Triangular decomposition of matrices, 236, of points about regression line, 572-575 Wien's displacement law, P3.43
E4.3 Variate, 532
Triangular matrix, 2 11 Vectors, basic definitions and operations con- Yates's correction, 560
cerning, 17,213-215, E4.1
Camahan, Bnce &!x ' P ~ L J ~
49- Jk.4 +%I)
Applied numerical methodsf [Brice Carnahan H.A.
Luther, James O.WlrA'.l. - &J :dl,@
.,.'I. . Y = \!"AT
.>I>+,J,+ L,F: 9.7 'xvii
_@









