A PROGRAMMING APPROACH
t
t
I
I
i
I
Frontispiece (opposite title page). Train crash at Montparnasse Station in 1895. Numerical modelling of
short duration events such as this impact problem could.be tackled using an explicit one-step method to
solve the differential equations ofmotion (seeChapter 7). Full scale physical modelling on the other hand,
can be rather time-consuming and expensive.(Photograph courtesy of Editions Gendre, Paris.)
rr
' t
t
I
Numerical Methodsfor Engineers
A PROGRAMMING APPROACH
I
I
*
t
OXFORD
ul
To Valerie, Janet and Catherine
@ l9l by D I S T R IB U T O R S
Blackwcll Scicnti6c Publications
Marston Book Scrviccs Ltd
Editorial offic:
PO Box 87
Osncy Mcad, Oxford OX2 OEL
Oxford OX2 ODT
25 John Strccr. London WCIN 2BL
(Ordrs Tel: 0865 791t55
23 Ainslic Placc, Edinburgh EHI 6AJ
Fax: 0865 791927
3 Cambridgr Ccntcr, Cambridgc
Tclcr:837515)
Massachusctts 02142, USA
54 Univcrsity Strcct, Carlton USA
Victoria 3053, Australia Blackwcll Scicntifrc Publietions. Inc.
3 Cambridgc Crntcr
All rights rcscrucd. No part of this Cambridgc, MA 02142
publietion may bc rcproduccd, storcd (Or da s'lel: 800 759{1 02)
in a rctricval systcm, or transmittcd,
Canada
in any fom or by any mcans,
Oxford Univcnity Prcs
cletronic, mrchanical photmpying
70 Wynford Drivc
rccording or othcruisc without thc
Don Mills
prior pcrmission of thc mpyright
Ontario M3C lJ9
owncr.
(Ordus Tcl: (416) 441-2941\
First publishcd l99l Auslralia
Blackwcll Scicnti6c Publications
Sct by Intcrprint Lrd, Malta (Autralia) Pty Ltd
Printcd and bound in Grcat Britain 54 Univcrsity Str€t
by Hartnolls Ltd, Bodmin Carlton, Victoria 3053
(Ord.as'f cl: (03) 3474100)
British Library
Cataloguing in Publication Data
ISBN 0{3242751-7
ISBN G63242753-3 pbk
Library of Congrcss
Cataloging in Publication Data
Griffithr D.V.
Numcrical methods for enginccn: a programming
approach/D.V. criffi ths, I.M. Smirh.
p. m.
Includcs bibliographial rcfcrcnccs.
ISBN 0-53242751-7. - ISBN 0-63242753-3 (pbk.)
l. Enginering mathcmatics-Data prmsin&
2 Numcrical analysis-Data proccssing. I. Smith
I.M. II. Title.
T4335.G75 l99l
62(I.001'51*-dc20
1v
!
Contents
List of Programs,ix
Preface,xi
a
xiii
Acknowledgements,
2 Linear AlgebraicEquations,11
2.1 Introduction,I I
2.2 Gaussianelimination" I I
2.2.1Observationson the eliminationprocess,l5
2.3 Equationsolution usingLU factorisation,16
2.3.1 Observationson the solution processby factorisation,20
2.4 Equations with symmetricalcoefficientmatrix, 20
2.4.1 Quadratic form and positive definiteness,24
2.4.2 Cholesky'smetho4 26
2.5 Bandedequations,27
2.6 Compact storagefor variable bandwidths,30
2.7 Pivoting 33
2.7.1lll-conditioning 35
2.8 Equationswith prescribed'variables', 36
2.9 Iterativemethods,38
2.9.1 The iterative process,39
2.9.2Yery sparsesystems, 44
2.9.3The Gauss-Seidel method,44
2.9.4 Successive 48
overrelaxation,
vi CONTENTS
2.10 Gradientmethods,5l
2.10.1The methodof 'steepest descent',5l
2.10.2The method of 'conjugategradients',54
2.10.3Convergence of iterationmethods,56
2.10.4Preconditioning, 56
2.ll Comparisonof directand iterativemethods,57
2.12 Exercises,58
2.13 Further reading,60
3 NonlinearEquations,62
3.1 Introduction,62
3.2 Iterativesubstitution.65
3.3 Multiple roots and other difficulties,67
3.4 Interpolationmethods,68
3.4.1Method of bisection,69
3.4.2Falsepositionmethod,7l
'
3.5 Extrapolationmethods,74
3.5.1Newton-Raphsonmethod,74
3.5.2A modifiedNewton-Raphsonmethod,26
3.6 Accelerationof convergence, 79
3.7 Systemsof nonlinearequations,80
3.7.1Iterativesubstitutionfor systems,80
3.7.2Newton-Raphsonfor systems,82
g6
3.7.3Modified Newton-Raphsonmethodfor systems,
3.8 Exercises,89
3.9 Further reading,91
4 Eigenvalue Equations, 92
4.1 Introduction,92
4.2 Orthogonalityand normalisationof eigenvectors, 93
4.3 Soluticnmethodsfor eigenvalue equations,94
4.4 Vectoriteration,94
4.4.1Shiftediteration,97
4.4.2Shiftedinverseiteration.99
4.5 Calculationof intermediateeigenvalues - dcflation,103
4.6 The generalised eigenvalue problemAx:18x, 105
4.6.1Conversionof generalised problemto standardform, 108
4.7 Transformationmethods,111
4.7.1Commentson Jacobidiagonalisation,l17
4.7.2 Householder's transformationto tridiagonalform, 117
4.7.3 LR transformationfor eigenvaluesof tridiagonal matrices,l2l
4.7.4 l-anczosreduction to tridiagonal form, 124
4.8 Characteristic polynomialmethods,127
4.8.1 Evaluatingdeterminantsof tridiagonalmatriccs,127
4.8.2 The Sturm sequenceproperty, 128
4.8.3 Generalsymmetricmatrices,e.g.band matrices,133
4.9 Exercises. 133
4.10 Further reading,135
5 Interpolationand Curve Fitting, 137
5.1 Introduction,137
CONTENTS
Index.327
List of Programs
Chapter2
2.1 Gaussianelimination,l3
2.2 Equationsolution by LU factorisation,19
2.3 Symmetricalequationsolutionby LDLT factorisation,23
).4 Symmetricalequationsolutionby Cholesky'smethod,29
2.5 'skyline' solution of symmetricalequationsby Cholesky'smethod,3l
2.6 Equationsolution by LU factorisationwith pivoting,34
2.7 Equationsolutionwith prescribed'variables', 37
2.8 Equationsolution by Jacobiiteration,42
2.9 Equationsolution by Gauss-Seidel iteration,46
2.10Equationsolution by successive overrelaxation,49
2.11Equationsolutionby'steepcstdescent', 52
2.12Equationsolutionby conjugategradients,54
Chapter3
3.1 Simpleiterationfor a nonlinearcquation,66
3.2 Bisectionmethod.70
3.3 Falsepositionmethod,72
3.4 Newton-Raphsonmethod,75
3.5 Modified Newton-Raphsonmethod,78
3.6 Simpleiteration for a systemof equations,8l
3.7 Newton-Raphsonmethod for a systcmof equations,85
3.8 Modified Newton-Raphson rnethod for a systemof equations,88
Chapter 4
4.1 Vectoriterationto find the'largest'eigenvalue,96
4.2 Shiftediteration.98
4.3 Shiftedinverseiteration. 101
4.4 Iterativesolutionof Ax: lBx, 106
4.5 Conversionof Ax:lBx to'standard form', ll0
4.6 Jacobidiagonalisation,I l5
4.7 Householder'sreduction to tridiagonal form, 120
4.8 LR transformation,123
4.9 Lanczosreduction to tridiagonal form, 125
4.10Characteristicpolynomialmethodfor symmetric,positivedefinitetridiagonalmatrices,131
Chapter5
5.1 Interpolationusing Lagrangianpolynomials,140
IX
L I S TO F P R O G R A M S
5.2 Interpolationusingcubicsplinefunctions,150
5.3 Curvefitting using'leastsquares',161
Chapter6
6.1 RepeatedNewton{otes rules,178
6.2 RepeatedGauss-lrgendrerules,187
6.3 Gauss-Laguerre integration,191
6.4 Integrationover a generalquadrilateralarea,203
Chapter7
7.1 One stepmethodsfor a singlefirst order equation,221
7.2 ()ne step methodsfor a systemof first order equations,229
7.3 Predictor{orrector usingAdams-Moulton-Bashforthfourth order method,24o
7.4 Shootingmethodfor a secondorder linear boundaryvalueproblem,253
7.5 shooting methodfor a secondorder nonlinearboundaryvalueproblem,259
Preface
XI
xir PREFACE
academic symposia. The first author recently spent fifteen months at princeton
University teaching and conducting researchin the area of finite element modellins
of the responseof dams to earthquake loading.
W.F. Ames
P.rofessor GeorgiaTech
ProfessorZ.P.Bazant NorthwesternUniversity
Dr D.N. Fenner King's College,London
ProfessorG.M.L. Gladwell Universityof Waterloo
ProfessorJ.G. Hartley GeorgiaTech
ProfessorW. Miller Jr. Universityof Minnesota
ProfessorN. Whitaker Universityof Massachusetts
ProfessorR. White North CarolinaStateUniversity
1.1 Introduction
Thereare manyexistingtextsaimedat introducingengineers
to the useof numerical
methods.Increasingly, thesecontain computercode which enabresa particular
problem to be solved.In the presentbook, this idea
is taken to a logicalconclusion,
namelythat the naturalway of learninghow numericalmethods
work is to codethem
for a digital computer,and then to do numericalexperiments.
In order to achievethis
aim efficiently'it is arguedthat it paysto adopta styleof programming
whichfacilitates
transferof expertisefrom one numericaranalysistask to
another.
1.3 Mathematicalsubroutinelibraries
Nearly all computermanufacturerssupply some kind
of .library, of mathematical
softwarewith the machine.Thus, while it would be perfectly
feasiltefor eachuserto
write programsto work out the sineof an angle,for example
by summinga series,thisis
a task which occursso frequentrythat it makessenseto
havethe codepermanently
storedin everymachineof that make.In FoRTRAN machines,thelanguage providesfor
about forty 'intrinsic'or 'library' functions:ABs,ACos,
ATMAG, ArNr, ANINT,ASrN,
ArAN, etc.' which enable users to carry out simple
but commonly occurring
mathematical tasks.
2 C H A P T E R1
Tabie1.1.Contents
of nec mathematical
subroutine
library
'Chapter'
Subject area Nature
M01 Sorting
POl Error Trapping
S Approximationsof SpecialFunctions Utility
X01 MathematicalConstants routines
X02 MachineConstants
XO3 Innerproducts
X04 Input/Output Utilities
t
I
1.4 Functionsand subroutines
I
In the previoussection,we remarkedthat the FoRTRAN languagecontainsa list of
'intrinsic' or 'library functions'for carrying out simple tasks like taking sinesand
I
I
cosines of angles.A runcrloN in rontRaNis a specialsubprogramhavinga specific
'main'
structure,and any numberof thesecan be appendedby programmersto their
programs.
?
Suppose,for example,we wishedto refermany timesin a'main'program to the
t functionf(x):3x2+15x-23.To savewriting all of the algebraout eachtime,we
I couldcreatea FoRTRAN FUNcrIoN.as follows:
FUNCTION F(X)
c
c THIS IS AN EXA},IPLE OF A FUNCTION CALLED F
THE INPUT IS X
c
F : 3 . O * X * X + 1 5 .0 * X - 2 3 . 0
RETURN
END
I
C H A P T E R1
Then in the main program, as long as the'argument' of F has a value, we can refer to
F as many times as we like, for example in statementslike A: F(xl)*F(X2)/F(X3). The
'returns' a single quantity (the
FUNCTToN subprogramis particularly simple since it
'called' from that main
value of the function /(x)) to the main prograrn each time it is
program.
If more than one quantity is to be returned to the main program from a subprogram
call (evenif the argument,although a singlename, is an array) then a more complicated
that
type of subprogramcalleda suBRourlNEmust be used.This also has a name' but
'parameters' are
name cannot be used in cxpressions.Instead, Several arguments or
used to pass information into and out of the subprogram'
As an example,our ruNcttON subprogramcould be written as a SUBRoUTINe in the
following way:
a
SUBROTJITINEFI,'N(F, X)
c
THIS IS AN EXAHPLE OF A SUBROUTINE CALLED T'UN
c THE TNPUT TS X AND THE OUTPUT IS F
c
F = 3 . O * X * X + 1 5 .O * X - 2 3 . 0
RETURN
END
In the main program, we would then have to'call'the susnourtNs with its different
arguments in order to work out the previously determined A, for example:
CALL FUN(F1,X1)
CALL FUN(F2,X2)
CALL FrJN(F3,X3)
A=F1*F2 / F3
in subroutines
1.4.1Arrays as parameters
PROGRAM DECI,AR
STOP
END
I N T R O D U C T I OANN D P R O G R A M M I N GP R E L I M I N A R I E S
In order to avoid the need to be forever altering lots of parameters of arrays for
problems of different sizes, the language allows a pARAMETEnstatement which
alleviates this difficulty somewhat. Using this statement, the above program can be
written:
PROGRAM DECLAR
c
U DECI,ARATTON OF ARRAY SIZES USTNG PARAMETER STATEMENT
P A R A M E T E R( I A = 1 0 0 , I B = 1 0 0 0 r I c = 5 0 )
c
REALA(rA),8(rB, IC),C(rc, rA)
STOP
END
s u B R o r . J : u N E v D o T v ( V 1 , V 2 , D O T P R ,N )
c
DOT PRODUqT V1*V2
REAL V1(*),V21*1
DOTPR: 0.0
DO 1 I : 1,N
I DoTPR = DoTPR + v1(r)*V2(r)
RETURN
END