You are on page 1of 27

A1

AlphabeticDescriptionof
SubroutineLibrarv

All subroutinescalledby the programsin this book appeareither at the end of the
main programsor are held in a subroutinelibrary. In this appendix,all the library
subroutinesare describedtogetherwith their argumentlists.Underlinedarguments
are thosereturnedby the routinesas output. Other argumentsare providedto the
routinesasinput, althoughin somecasesthesameargumentsare usedfor both input
and output.Namesin parentheses indicatesubroutinesnormally usedin conjunction
with the onesthey follow.

Subroutine Description
BILIN Computesvaluesof the bilinearshapefunctionsand their derivativeswith
respectto local coordinatesover a quadrilatcral,at Gaussianintegration
points

Arguments
DER Shapefunction derivativesin local coordinates
FUN Shapefunctions
SAMP Array holding sampling points (column l) and weighting coefficients
(column 2) for Gauss-Irgendre quadrature

ISAMP Sizeof SAMP in main program


I,J CountersidentifyingGaussianintegrationpoints

Subroutine Description
CHECK Checks the change in a scalar from one iteration to the next to seeif
convergence is achieved. X0 is updated to Xl

Arguments
X1 New value

XO Old value

TOL Convergence tolerance

ICON Convergence satisfied (: 1), not satisfied(:Q)


304 A P P E N D I X1

I
Subroutine Description
CHECON Checks the change in a vector (column array) from one iteration to the
n€xt to see if convergenceis achieved.OLDLDS is updated to LOADS

Arguments
LOADS Vector of new values

OLDLDS Vector of old values

N Length of vectors to be compared

TOL Convergence tolerance

ICON Convergence satisfied (: l), not satisfied (:0).

Subroutine Description
CHOF/TC Factorisesa lower triangular symmetrical banded matrix (stored as a
(cuosue) rectangle)usingCholesky'smethod

Arguments
LB (N rows,IW + I columns).
Symmetricalbandedmatrixstoredasa rectangle
Holds Choleskyfactorson output

ILB Sizeof LB in main program

N Number of equations

IW Half bandwidth
h
I r Subroutine Description
i CHOSUB Performsforward and back substitutionusing Choleskyfactorsproduced
(cHorec) by cHonec

Arguments
LB Array holdingCholeskyfactorson whichbacksubstitutionis to beperformed
t; ILB Sizeof LB in main program
q Right hand sidevector,overwrittenby solution vector

N Number of equations

IW Half bandwidth
A L P H A B E T I CD E S C R I P T I O N
O F S U B R O U T I N EL I B R A R Y 305

Subroutine Dexription
GAULAG Generatesweights and sampling points for Gauss-Laguerre quadrature

Arguments
SAMP Array holding sampring points (column r) and weighting coefficients
(column 2) for Gauss_Laguerrequadrature.

ISAMP Size of SAMP in main program

NGL Requirednumberof Gauss-Laguerre


points
Subroutine Description
GAULEG Generates weights and sampling points for Gauss-l,egendre quadrature.

Arguments
SAMP Array holding sampring points (corumn l) and weighting coefficients
(column 2) for Gauss_lrgendre quadrature

ISAMP Sizc of SAMP in main program

NGP Requirednumber of Gauss-lrgendre points

Subroutine Description
LDLFoR Performs forward substitution on factors in LDLr method
(sunnac)

Arguments
A Array holding upper triangular factorsstoredas a lower triangleon which
forward substitution is to be performed
IA Sizeof A in main progrnm

P Righchandside vector,overwrittenby factoredvalues


N Number of equations

Subroutine Description
LDLT Factorisesa symmetricalmatrix usingLDLr method
(LDLFoR)
(suBBAc)

Arguments
4 Array holding symmetricalmatrix on input. Holds U and Ur on output.
IA Sizeof A in main program
p Vectorcontainingdiagonalsof D
N Number of equations
JUO A P P E N D I X1

Subroutine Description
LUFAC Factorisesa matrix using LU method
(suBFoR,
(su n nnc)

Arguments
Array holdingequationcoefficients

UPTRI Array holdinguppertrianglefactorsU

LOWTRI Array holdinglower trianglefactorsL

IA Sizeof A, uprRI and Lowtnt in main program

N Numberof cquations

Subroutlhe Description
LUPFAC Factorisesa matrix using LU method with pivoting
(LUPSoL)

Arguments
Array holding equation coefficients on input. Holds LU factors after
pivoting on output

IA Size of A in main program

N Number of equations

F'
I
ROW

Subroutine
Vector of integers holding reordered row numbers

Description
I LUPSOL Performs forward and back substitution on factors in LU method with
(lunrrc) pivoting
i
lr Arguments
Array holding LU factors
i ,
IA Size of A in main program

B Right-hand side vector

SOL Solution vector

N Numbcr of equation

ROW Reordered row numbers


D E S C R I P T I OO
ALPHABETIC NF SUBROUTINE
LIBRARY 307

Subroutine Description
MATINV Invertsa non-singularmatrix

Arguments
4 Array on input and the inverseon output

IA Sizeof A in main program

N Number of rows and columnsin A

Subroutine Description
MATMUL Multiplies matricesA and B to give C

A First array (L rows, M columns)


a
IA Sizeof A in main program

B Secondarray (M rows,N columns)

IB Sizeof B in main program


q Product of A and B (L rows, N columns)

IC Sizeof C in main program


I )

;f Number of rows and columnsof A, B and C

NJ
Subroutine Descriptton
MATRAN Forms matrix A which is the transposeof matrix B

Arguments
4 Transposeof array B

IA Sizeof A in main program

B is required
Array whosetransPose

IB Size of B in main Program

M Number of rows in B

N Number of columnsin B
A P P E N D I X1

Subroutine Description
MSMULT Multipliesmatrix A by scalarC

Arguments
4 Array on input and aftermultiplicationby scalarC on output

IA Sizeof A in main program

C Scalarmultiplier

M Number of rows in A

N Number of columnsin A

Subroutine Description
MVMULT Multipliesmatrix M by vectorV to give vectorY
a

Arguments
M Array

IM Sizeof M in main program

v Vector(lengthL)

K Number of rows in M

L Number of columnsin M

Y Productof M and V QengthK)

Subroutine Description
NEWCOT Providesweightingcocfficientsfor Newton{otes quadrature

Argunents
WEIGHT Vector of weightingcoefficientsfor Newton{otes integration rules
I
I
NNC Requirednumbcrof points
I

Subroutine Description
NULL Nulls a twodimensionalarray

Arguments
4 Array on input and nulledarray on outPut

IA Sizeof A in main program

M Number of rows in A
N Number of columnsin A
A L P H A B E T I CD E S C R I P T I O NO F S U B R O U T I N EL I B R A R Y 309

Subroutine Description
NULVEC Nulls a vector (column array)

Arguments
VEC Vectoron input and nulled vector on outpul

N Lcnglh of vector

Subroutine Description
PRINTA Prints an array to the requircd output channel

Arguments
A Array to be printed to output channetICH, with format 6EI2-4

IA Sizeof A in main progr-am


a
M Number of rows in A

N Number of columnsin A

ICH Output channel

Subroutine Description
PRINTV Prints a vcctor (column array) to the required output channel

Arguments
VEC Vector to be printed to output channelICH, with format 6812.4
N I-ength of vector
ICH Output channel

Subroutine Description
SKYFAC Factorisesa symmetricalbandedmatrix storedasa vectorusinga'skyline'
(SKYSUB) storageapproach and Cholesky'smethod

Arguments
4 Vector of 'skyline' coefficientson input and Choleskyfactors on output

N Number of equations

KDIAG Vector of integersholding locations of diagonal terms in A


310 A P P E N D I X1

Subroutine Description
SKYSUB Performs forward and back substitution using Cholesky factors from
(sxvrrc) 'skyline'storageapproach

Arguments
A Vector of Choleskyfactors

E RighGhandsidevectoron input overwrittenby solutionv@toron output

N Numbcr of equations
KDIAG Vector of integersholding locations of diagonal terms in A

Subroutine Description
SOLVE Solves a system of equations using Gaussian elimination with partial
a pivoting

Argumcnts
K Array of equation coefficients

IK Size of K in main program

g Solution vector

F Right-hand side vector

N Number of equations

Subroutine Description
SUBBAC Performs back substitution on factors following forward substitution
(suBFoR) in LDLr or LU methods
(LDLFoR)

Arguments

r;
A Array of upper triangular factors for back substitution

IA Sizeof A in main program

E Right-handsidevectorfrom susroR on input, solutionvectoron output

N Number of equations
I A L P H A B E T I CD E S C R I P T I O O
N F S U B R O U T I N EL I B R A R Y 311

Subroutine Description
SUBFOR Performs forward substitution on factors from LU method
(suBBAc)

Arguments
A Array of lower triangular factors for forward substitution
IA Sizeof A in main program

E Right-handsidevectoron input, factoredv@tor on output


N Number of equations

Subroutine Description
VDOTV Forms dot product DOTPR of vcctors Vl and V2

Arf,uments
VI First vector
v2 Secondvector
DOTPR Dot product
N kngth of Vl and V2

Subroutine Description
VECADD Adds vectors A and B to give C

Arguments
A First vector

B Second vcctor

q Sum of first two vectors

N I.ength of vectors

Subroutine Description
VECCOP Forms vector copy B of vector A

Arguments
A Vector to be copied

E Copy of A

N I"rngfh of vectors

\
312 A P P E N D I X1

Subroutine Description
VECSUB Forms vectorC by subtractingB from A

Arguments
A First vector

B Secondvector
q Resultof subtractingB from A

N Lcngth of vectors

Subroutine Description
VSMULT Multiplies vector V by scalarSCAL

Argument5
v Vector on input and after multiplicationby scalarSCAL on output

SCAL Scalarmultiplier

N lrngth of vector

Subroutine Description
VVMULT Forms vector product of vcctors Vl and V2 to give matrix A

Arguments
vl First vector (lengfh M)

v2 Second vector (length N)

4 Array formed by vector product of Vl and V2 (M rows, N columns)

IA Size of A in main program

M Number of rows in A

N Numbcr of columns in A
A2
AlphabeticListing of subroutineLibrary
i n F O R T R A N7 7

c
c

c
a^

SUBROUTINE BILIN'(DER, FUN, SAMP, ISA}TP, I, J)


c
c SHAPE FUNqTIONS AND DERTVATTVES
c FOR QUADRII,ATERAL TRANSFORMAUON
c
R E A L D E R ( 2 , 4 ) , F U N ( 4 ) , S A r { p( r s A l , r p , 2 )
ErA = SAHP(r,1)
Xr = sA.lIP (J r 1)
ETAH - .2s* (\.-ETA)
ETAP : .25* (I.+ETA)
XrM = .2s* (1-_XI)
XIp = .25* (1.+XI)
F L , N( 1 ) : 4 - * X I M * E T A ] I
?UN(2) : 4.*XJM*ETAP
FUN(3) : 4.*XIP*ETAP
FUN(4) : 4. *XJP*EIiAlt
DER(1,1) = -Era-u
DER(1,2) : -ETAP
DER(I-,3) = EraP
DER(1,4) : Erau
DER(2,1) : -XrM
DER(2,2) = XIM
DER(2,3) = xrP
DER(2,a) : -xrp
RETURN
END
c
c
c
S U B R O U T I N E C H E C K( X 1 , X O , T O L , I C O N )
c
c SETS ICON TO O IF REI,ATIVE CHANGE IN X
c IS GREATER THAN TOL
c
ICON = 1
IF (ABS(Xl-Xo)/ABS(Xl-).GT.ToL) ICoN = o
X O = X 1
RETURN
END
c
c
C
S U B R O U T T N EC H E C O N( L O A D S , O L D L D S ,N , T O L , I C O N )
c
C SETS ICON TO ZERO IF THE RELATTVE CHANGE
J l $ A P P E N D I X2

C IN VECTORS 'LOADS' AND 'OLDLDSI IS GREATER THAN ITOLI


c
R E A L I , O A D S( * ) , O L D L D S ( * )

BIG = 0.
Do 1 I = 1,N
I IF (ABS(LoADS(I) ).GT.BIG) BIG = ABS(LoADS(I) )
DO 2 I = 1,N
' ICoN = 0
IF (ABs(LoADs(I)-oLDLDs(I) )/BIG.Gr.rol,)
2 oLDLDS(I) = LoADS(I)
RETURN
END

suBRotltrNE cHoFAc (LB, rLB, N, rW) .

c CHOLESKI FACTORISATION OF BANDED IOWER TRIANGLE LB


c
REAL LB(ILB,*)
. DO 1 f : 1,N
A : U . U
D O 2 J : l , I W
X - X + L B ( I , J ) * * 2
2 CONTINUE
LB(I, In+1) = SQRT(LB(I, IW+1)-X)
D O 3 K = 1 , I W
X = 0.O
IF (I+K.LE.N) THEN
IF (K.NE.W) THEN
D O 4 L = I W - K , 1 , - 1
X : X + LB(I+K,L)*LB(I,L+K)
4 CONTINUE
END IF
I A = I + K
I B = I W - K + 1
LB(IA,IB) : (LB(rA,IB) -x) /LB(I, Iw+1)
END TF
3 CONTINUE
]- CONTINUE

l
RETURN
END
c
c
c
S U B R O U T I N E C H O S U B( L B , I L B , B , N , I W )
; ; c
c CHOLESKI FORWARD AND BACKWARD SUBSTITTJ:IION COMBINED
c
REAL LB(rLB,*),8(*)
B(1) = B(1)/LB(1,rw+l)
DO 1 I = 2,N
X = 0.o
^ = I

IF (I.LE.IW+1) K = Iw - I + 2
D o 2 J = K , I W
X : X + LB(I,J)*B(I+J-IW-1)
2 CONTINUE
B(I) = (B(I)-x) /LB(I,Iw+1)
r CONTTNUE
B(N) = B(N) /LB(N,rw+1)
DO 3 I = N - 1,1,-1
X = 0.O
L = I + I W
rF (I.GT.N-IW)L=N
M = I + 1

{
LISTlNG OF SUBROUTINELIBRARY IN FORTRAN77 315

D O 4 J = M , L
X = X + LB(J,IW+I-J+1)*61'f1
CONTTNUE
B(I) : (B(I) -x) /LB(I, Iw+1)
CONTINUE
RETURN
END

c
c
SUBROTITINE GAUI"AG( SA}.IP, ISAUP, NGL)
c
c WEIGHTS AND SAMPLTNG POINTS
c FOR GAUSS-I,AGUERRE QUADRATTTRE
c
REAI SAUP(rSA],IP, *)
GO TO ( L . 2 , 3 , 4 , 5 ) , N G L
1 SAHP( 1 , 1 ) = 1 .
sAlrP ( L , 2 1 = 1 -
GO TO 1 0 0
2 sAr{P ( 1 , 1 ) = O . 5 A 5 7 A 6 4 3 7 6 2 7
SAHP ( 2 , ! ) = 3.4142\3562373
SAMP(L , 2 ) = 0 . 8 5 3 5 5 3 3 9 0 5 9 3
SAHP ( 2 , 2 , = o . 1 4 6 4 4 6 6 0 9 4 0 7
GO TO 1 0 0
3 SAUP( 1 , L ) = o . 4 L 5 7 7 4 5 5 6 7 4 3
SAHP( 2 , )', = 2 . 29 42Ao3 6027 9
SAHP( 3 , 1 ) = 6 . 2 A 9 9 4 5 0 A 2 9 3 7
sAl.{P ( L , 2 l = o . 7 1 1 0 9 3 0 0 9 9 2 e
sAr.{P( 2 , 2 , = O . 2 7 A 5 L 7 7 3 3 5 6 9
SA},{P( 3 , 2 1 : 0 . 0 1 0 3 8 9 2 5 6 5 0 1 6
GO TO 1 0 0
4 SAMP(1 , 1 ) : O . 3 2 2 5 4 7 6 a 9 6 I 9
SAMP ( 2 , L ) = 1 . 7 4 5 7 6 1 1 0 1 1 5 8
SAHP ( 3 , 1 ) = 4 . 5 3 6 6 2 0 2 9 6 9 2 1
sAuP( 4 , 1 ) : 9 . 3 9 5 0 7 0 9 1 2 3 0 1 '
SAMP ( L , 2 , : 0 . 6 0 3 1 5 4 1 o 4 3 4 2
sAuP( 2 , 2 1 : o . 3 5 7 4 1 8 6 9 2 4 3 8
SAHP ( 3 , 2 ) : O . 0 3 8 8 8 7 9 0 8 s 1 5
sA_l,lP( 4 , 2 ) = o . o o 0 5 3 9 2 9 4 7 0 5 5 6 1
GO TO 1 0 0
5 SAMP 1 , 1 ) = 0 . 2 6 3 5 6 0 3 1 9 7 1 8
SAMP 2 , L l = 1 . 4 1 3 4 0 3 0 5 9 1 o 7
SA}IP 3 , 1 ) = 3 . 5 9 6 4 2 5 7 7 I o 4 I
SAHP 4 , 1 ) = 7 . 0 8 5 8 1 0 0 0 5 8 5 9
SA},tP 5 , 1 ) : l - 2 . 6 4 0 8 o 0 8 4 4 2 7 6
SAI'{P I , 2 ) = o . 5 2 1 7 5 5 6 1 0 5 8 3
SA],1P 2 , 2 ) : o . 3 9 8 6 6 6 8 1 L o 8 3
SAHP 3 , 2 ) : O - 0 7 5 9 4 2 4 4 9 6 4 ] . 7
sAl.rP 4 , 2 ' t : 0 . 0 0 3 6 1 1 7 5 8 6 7 9 9 2
SAUP ( 5 , 2 ) : o . 0 0 0 0 2 3 3 6 9 9 7 2 3 8 s 4
100 c o N T r NUE
RETURN
END
c

c
SUBROUTINE GAULEG ( SAMP, I SAHP , NGP)
c
c WEIGHTS AND SA}IPLING POTNTS
FOR GAUSS_LEGENDRE QUADRATURE

REAL SAUP(ISAHP, *)
co To (1,2,3,4,5,6,7),NGP
I sA.l,lP(1,1) = o.
SAfiP(l,2) = z.
316 A P P E N D I X2

GO TO 100
2 SA],IP(1,1) = 1. /sQRr(3. )
S A M P( 2 , 1 ) : -SAHP ( 1, 1)
SAMP(1,2)
SA],IP(2,2)
co To 100
3 S A H P( t - , 1 ) : .2*SQRT(15.)
SAMP(2,1) : .0
SAHP(3,1) = -SAHP(1,1)
sAl,rP(1,2) = s.le.
sAl,rP(2,2) = 8.le-
sAtlP(3,2) : SAHP(1,2)
GO TO 100
4 SAUP(1,1) = .861136311594053
SAHP(2,1) : .339981043584856
sAl.IP(3,L) : -SAHP (2 r l)
sAr'IP(4,1) = -SAUP ( 1, 1)
SAMP(1,2) : .347854845L37454
SA],IP(2,2) = .652145154862546
SAMP(3,2) : sAuP(2,2)
r SA}IP(4r2) : SAUP(1,2)
co To 100
5 SAl,lP(1,r.) = .906179845938664
SAHP(2,1) : .538469310105683
sAIlP(3,1)
sAl,tP(4,L) = -sAl,IP(2,1)
s A l ' I P( 5 , 1 ) = -SA-MP(1,1)
SAMP(1,2) : -236926Aa5O56189
sAuP(2,2) :.47a62a6'70499366
sAr.rP(3,2) : .568888888888889
sAxP(4,2) : sAr{P(2,2)
SAI'{P(5,2) : sAuP(1,2)
GO TO 100
6 sA],lP( l, 1 = -9324695L42O3I52
sAl{P(2,1 : .661209386466265

h, l#ili;i
: .238619185083197
: -sAl4P (3, 1)
sAl4P(5,1 = -sAuP(2,1)
sAuP ( 6, 1 : -SAHP(1,1)
S A M P( 1 , 2 :.171324492379]-7o
SAI.{P(2,2 : .360761,573048139
SAHP(3,2 : .4679L393457269I
sAr.rP(4,2 = SAUP(3,2)
SAfiP(5,2 : SAHP(2,2)
1i
sAHP(6,2 = S A } { P( 1 , 2 )
GO TO 100
7 SAflP ( 1, 1) = -949LO79L2342759
s A l , l P( 2 , 1 ) : .741531-185s99394
sAr'1P(3,1) = .4o584515I377397
S A H P( 4 , l , )
SA],IP(5,1) : -SAHP(3,1)
SAMP(6,1) = -SAHP(2,1)
S A I , I P( 7 , 1 ) = -SAl'fP(1,1)
sAilP(1,2) :.L29484966168870
SAI-{P(2,2) = .2797O53914a92'77
SAHP(3,2) : .381830o5050s119
SAHP(4,2) = .4L7959La3673469
SAHP(5,2) = SAHP(3,2)
sAl,IP(6,2) = SAHP(2,2)
sAr.rP(7,2) : SAUP(1,2)
IOO CONTINUE
RETURN
END
c
C
c
I LISTINGOF SUBROUTINE LIBRARY IN FORTRAN
77 J t /

tI c
c

c
SUBROUTINE LDLFOR(A, IA, B, N)

FORWARD SUBSTITUTION ON A LOWER TRIANGLE


STORED AS AN UPPER TRTANGI,E
c
REAL A(rA, *) ,B(*)
DO 1 f = 1,N
SUM = B(I)
rF (I.cr.1) THEN
DO 2 J = 1,I - 1
SUM : SUM - A(J,I) *B(J)
CONTINUE
END TF
B(I) = stJ}{/A(I,I)
CONTINUE
RETURN
END

a SUBROUTINE LDLT (A, TA, D, N)


c
C L*D*LT FACTORTSATION OF A SQUARE MATRIX A
c LT OVERWRTTES A
C
REAL A(IA, *) ,D(*)
DO 1 K = l,N - 1
D(1) = A(1,1)
rF (ABS(A(K,K) ) .cT.1.E-6) THEN
DO 2 I : K + 1,N
x : A(I,K) /A(K,K)
DO 3 J = K + 1rN
A(r,J) : A(r,J) - A(K,J)*x
3 CONTINUE
D(r) : A(r,r)
CONTINUE
ELSE
wRrTE (6,1OOO)
wRrTE (6,*) X
END IF
1 CONTINUE
1000 FORMAT (TZERO PIVOT FOIJNDIN THfS LINE:')
RETURN
END

c
SUBROUTTNE LUFAC (A, UPTRT, LOWTRI , TA, N)
c
L*U FAqIORTSATION OF A SQUARE MATRIX A
C
REAL A(rA, *),upTRr(IA, *),LOWTRI (ra, *1
CALL NULL (UPTRI, TA,N, N)
CALL NULL (LOI{TRT, IA, N, N)
DO 10 I=L,N
UPTRI(1,I):A(1,r)
10 LowTRI (I, r1 =1. p
Do 1 K:1,N-1
IF(ABS (UPTRI(X,K) ) .GT. 1. E-6) THEN
DO 2 f:K+].rN
I.OWER TRTANGUI,AR COMPONENTS
DO 3 J:1,I-1
S U M = o .O
DO 4 L:1,J-1
S U M = S U M - I O W T R I( I , L ) * U p T R r ( L , J )
4 CONTTNUE
318 A P P E N D I X2

L o w t R I ( I ' J ) = ( A ( I ' J ) + S U r ' l )/ U P T R I ( J , J )


3 CONTINUE
UPPER TRIANGUI,AR COMPONENTS
Do 5 J:I,N
S U H = O .0
DO 5 IF1,I-1
SIIM:SW-LoWTRI (1' L) *UPTRI (L' J)
6 CONTINUE
UPTRr ( I, J) =A ( I, J) +sItM
5 CONTINUE
2 CONTINUE
E!5L

WRITE(6,1000)
WRITE(6,*)K
STOP
ENDTF
1 CONTINUE
1OOO FORMAT('ZERO PIVOT FOIJND IN THIS ROWI)
RETIJRN
.END
c
c
C
SUBROUTINE LUPFAC(A, TA, N, ROW)
C
c L*U FACTORISATION OF A SQUARE MATRIX WITH PIVOTS
c
REAL A(rA, *)
TNTEGERROW(*)
DO 1 I : 1,N
1 Row(I) : I
DO 2 I : 1,N - 1
I P : r
PVAL = A(Row(IP),IP)
DO 3 J = I + J.,N
rF (ABS(A(RoW(J),r) ).GT.ABs(PVAL) ) THEN
IT _ U
pvAL = A(Row(J) ,I)
END IF
3 CONTINUE
rF (ABS(PVAL).LT.1.E-1O) THEN
WRITE (6,1OOO)
STOP
END IF
F; IH - Row(IP)
Row(IP) = Row(I)
Row(I) = 111
DO 4 J : I + 1,N
IE : Row(J)
PIVoT : A(IE,I)/PVAL
A(IE,I) : PIvoT
IRoW : Row(I)
DO 5 K = I + 1rN
A(IE,K) = A(IE,K) - A(IRow,K)*PIVoT
5 CONTINUE
CONTINUE
) CONTINUE
r F ( A B S ( A ( R o w ( N ), N ) ) . L T . 1 . E - 1 0 ) THEN
wRrTE (6,1OOo)
STOP
END IF
1 0 0 0 FORMAT ('STNGUI,AR EQUATIONS DETECTEDI )
RETURN
END
L I S T I N GO F S U B R O U T I N EL I B R A R YI N F O R T R A N7 7 319

SUBROUTINELUPSOL(A,TA, B, SOL, N, ROW)


c
FORWARD AND BACKWARD SUBSTITUTION COMBTNED WITH PIVOTS
c
REALA(IA, *),8(*),SOL(*)
INTEGER ROW(*)
DO l- I = 1,N
r R o W= R o w ( I )
S(J}{: B(IRow)
rF (r.cT.1) THEN
DO 2 J = 1,I - 1
SIJM = SIIM - A(IROW,J) *B(Row(J) )
2 CONTINUE
B(IRow) = 56a
END IF
1 CONTINUE
D O 3 I : N , 1 , - 1
IRow = Row(I)
silH = B(IRow)
rF (r.LT.N) THEN
DO 4 J = I + l,N
SLIH = SUl.t - A(TRow,J) *B(ROW(J) )
4 CONTINUE
END IF
B(IRow) = sUM/A(rRow, I)
3 CONTINUE
DO 5 f = l,N
5 sol(r) : B(Row(I) )
RETURN
END
c
c
SUBROUTINE MATI}N/ (A, IA, N)
c
FORMS THE I}IVERSE OF A I{,ATRIX
USING GAUSS-JORDAN TRANSFORMATTON
c
REAL A(rA,*)
DO 1 K = 1,N
coN = A(K,K)
A(K,K) = 1.
Do 2 J = 1,N
2 A(K,J) = A(K,J)/coN
DO 1 I = 1,N
rF (r.EQ.K) GO TO 1
coN - A(I,K)
A(I,K) = e'
DO 3 J = 1,N
3 A(I,J) = A(I,J) - A(K,J)*coN
]. CONTTNUE
RETURN
END
c
c
S U B R O U T I N E M A T M U L ( A ,I A , B , T B , C , I C , L , M , N )
c
c PRODUCT OF TWO MATRICES
c
REALA(IA, *),8(rB, *),c(rc. *)
Do 1 I = 1,L
DO 1 J = 1,N
X = O.0
DO 2 K = 1,M
320 A P P E N D I X2

X = X + A(I,K)*B(K,J)
c(I,J) = x
CONTINUE
RETURN
END
c
c
c
S U B R O U T I N E M A T R A N( A , I A , B , I B , M , N )

c FORMS THE TRANSPOSE OF A MATRIX

REAL A(rA, *) ,B(rB, *)


DO l- I = 1,M
DO 1 J : 1,N
A(J,I) : B(I,J)
RETURN
END

c
a

S U B R O U T I N E M S M U L T( A , I A , C , H , N )

MULTIPLIES A MATRIX BY A SCALAR


c
REAL A(IA, *)
D O1 I : 1 , M
DO 1 J : 1,N
A(I,J) : A(I,J)*c
RETURN
END

c
S U B R O U T I N E M W T U L T ( H ,T H , V , K , L , Y ) -:

MULTIPLIES A MATRIX BY A VE TOR

REAL M(rM,*),V(*),Y(*)
DO 1 f : 1,K
X : O .
DO 2 J : 1,L
x=X+l{(I,J)*v(J)
Y(I) : X
1 CONTINUE
RETURN
END

c
S U B R O I I T I N E N E W C O T( W E I G H T , N N C )

WEIGHTING COEFFICIENTS
C FOR NEWTON_COTES QUADRATTIRE
c
REAL WEIGHT(*)
co ro (1,2,3,4,5) NNC
t WEIGHT(I) = 1.
GO TO 100
WETGHT(1) : .s
WEIGHT(2) : .s
GO TO 100
WEIGHT(1): 0.333333333333333
WEIGHT(2)= 1.333333333333333
W E I G H T ( 3 ): o . 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
GO TO 100
I

I
I
I

I w E T G H (T1 )
WETGHT( 2 )
o.375
L. T25
L I S T I N GO F S U B R O U T I N E
L I B R A R YI N F O R T ' R A 7
N7 JZI

r^rErcHT( 3 ) L . L Z )
wETGHT (4)
co To 100
wETGHT ( 1) 0 . 3 1 1 1 1 1 1 1 l- 1 1 1 1 1 1
wErcHT(2 ) L.422222222222222
wErcHT( 3 ) o . 53 333 33 33 33 333 3
wErcHT( 4 ) r.422222222222222
wErcHT( 5 ) o . 3 11 111 111 11 I 111
1 0 0 CONTINUE
RETURN
END
c
c
S U B R O U T T N EN U L L ( A , I A , M , N )
c
c NULLS A 2-D ARRAY
c
REAL A(rA,*)
f l 6 l T = 1 M

DO 1 J = 1,N
A(I,J) = 6.6
RETURN
END

S U B R o U T I N E N U L V E C( v E C , N )
c
NULLS A COLUMN VEqTOR
c
REAL VEC(*)
Do r f : 1,N
vEc(I) - o-
RETURN
END

c
suBRou:frNE PRTNTA(A, rA,lI, N, ICH)

c WRITES A 2_D ARRAY TO OUTPUT CTIANNEL 'ICHI

RF){L A(rA, *)
DO 1 I = 1,M
1 WRITE (rcH,2) (A(r,J),.r=1,N)
FORMAT(1X,6E12.4)
RETURN
END

c
c
SUBROUTINE PRINTV (VEC, N, ICH)
C
c WRITES A COLUI.IN VECTOR TO OUTPUT CHANNEL 'TCH'
c
REAL VEC(*)
wRrTE (rcH.1) (vEc(I) , I:1,N)
FORMAT(1X,6E12.4)
RETURN
END
322 A P P E N D I X2

suBRouTrNE S K Y F A C( A , N , K D I A G )
c
c CHOLESKT FACTORISATION OF VARTABLE BANDWIDTH
c A STORED AS A VECTOR AND OVERWRTTTEN
c
REAL A(*)
INTEGER KDIAG(*)
A(1) : sQRr(A(r) )
DO 1 I = 2rN
K I = K D T A G ( I ) - I
L=KDIAG(I-I) -Kr+1
Do 2 J = L,I
x = A(KI+J)
KJ:KDTAG(J) -J
rF (J.NE.1) THEN
LL=KDIAG(J-I) -KJ+1
LL = l.rAxo(L,LL)
rF (LL.NE.J) THEN
M = J - 1
D O 3 K = L L , H
. X=X-A(Kr+K)*A(KJ+K)
CONTTNUE
END IF
END IF
A(KI+J) = X/A(KJ+J)
CONTTNUE
A(KI+r) = sQRr(x)
CONTINUE
RETIJRN
END
c
c
S U B R O I j : I I N E S K Y S U B( A , B , N , K D I A G )

CHOLESKI FORWARD AND BACKWARD SUBSTITUTION COMBTNED


c VARTABLE BANDWIDTH FACTORED A STORED AS A VECTOR
c
REAL A(*),B(*)
TNTEGER KDIAG(*)
B(1) = B(1)/A(1)
Do I I = 2,N
KI=KDIAG(r) -I
or L=KDTAG(I-1)-KI+1
x = B(r)
I
rF (L.NE.I) THEN
M = I - 1
D O 2 J = L , M
X=X-A(Kr+J)*B(J)
CONTINUE
END TF
B(r) = x/A(KI+I)
CONTINUE
D o 3 I T : 2 , N
I : N + 2 - I T
K I = K D I A G ( r ) - r
x = B(I)/A(KI+I)
B(I) : X
L:KDTAG(I-I) -KI+1
rF (L.NE.I) THEN
M - r - 1
D O 4 K : L , H
B(K) =B(x) -x*A(KI+K)
CONTINUE
END IF
CONTTNUE
..
L I S T I N G O F S U B R O U T I N EL I B R A R \ I : . ; C ' : - A h L-l

B(1) = B(1)/A(1)
RETURN
END
a

c
S U B R O U : T I N ES O L V E ( K , I K , U , F ' N )
WITH
PERFORMS GAUSSIAN ELIMINATION
N*N MATRIX
c PANTTAI PIVOTING ON A FULL

REALK(rK,*),F(*),u(*)
c
c PIVOTING STAGE
c
- 1
DO 1 I = 1,N
BIG = ABS(K(I,I) )
IHOLD : I
D O l O J = I + 1 , N
IF (ABS(K(J,I) ) .GT.BIG) THEN
BIG = ABS(K(J,I))
IHoLD = J
END IF
10 CONTINUE
IF (IHOLD.NE.I) THEN
D O 1 2 J : I , N
HoLD = K(I,J)
K(I,J) : K(IHoLD'J)
K(IHoLD,J) = HoLD
L2 CONTINUE
HoLD = r(I)
F(I) = F(IHoLD)
F(IHoLD) = HoLD
END IF

ELIMINATION STAGE
c
DO 3 J : I + 1,N
FAc = K(J'I)/K(I,I)
DO 4 L = I,N
- X(I'r';*P1g
4 K(J,L) = K(J,L)
- F(r1*Pnq
F(J) : F(J)
3 CONTINUE
I CONTINUE

BACK-SUBSTITUTION STAGE
?
D o g I = N , 1 , - l
SUM = o.
DO 6 L = I + 1,N
su}l: SUM + K(r,L)*u(L)
u(I) = (F(I)-suM)/K(I'I)
9 CONTINUE
RETURN
END

S U B R O U T I N E S U B B A C( A ' I A , B ' N )
c
BACKWARD SUBSTITUTION ON AN U P P E R T R I A N G L E
c
c
REAL A(IA, *) ,B(*)
D o l T = N , 1 , - 1
suM = B(I)
IF (I.LT.N) THEN
324 A P P E N D I X2

DO 2 J = I + 1,N
suM = SUM - A(I,J) *B(J)
2 CONTINUE
END IF
B(r) : suM/A(r,r)
1 CONTINUE
RETURN
END
c
C
c
S U B R O U T I N E S U B F O R ( A ,I A , B , N ) -.
U
c FORWARD SUBSTITT]ITION ON A I-OWER TRIANGLE
c
REALA(IA,*),B(i)
Do 1 I : 1,N
sljl,l = B(I)
rF (r.cr-1) THEN
Do 2 J = 1,I - 1
r S U I , I: S U l . { - A ( I , J ) *B(J)
CONTINUE
END IF
B(I) : sgM/A(I,I)
CONTTNUE
RETURN
END
c
c
c
S U B R o U T I N E V D O T V( V l , V 2 , D O T P R ,N )

DOT PRODUCTV1*V2
C
REAL Vl(*),V2(*)
DOTPR = 0.0
DO 1 I = 1,N
1 DoTPR = DoTPR + v1(I)*V2(I)
RETURN
END
c
c
c
S U B R O I . ] I T I N EV E C A D D( A , B , C , N )

ADDS VECTORS A+B=c


c
R E A LA ( * ) , 8 ( * ) , c ( * )
Do 1 f = l,N
1 c ( I ) = A ( I ) + B ( I )
RETURN
END
c
c
c
SUBRoUTINE VECCOP(A,B,N) -
c
COPIES VECTOR A INTO VECTOR B
c
REALA(*),8(*)
DO 1 I = 1,N
1B(I) = A(I)
RETURN
END
L I B R A R YI N F O R T R A N7 7
L I S T I N GO F S U B R O U T I N E 2)q

c
S U B R O U T I N E V E C S U B( A , B , C , N )
c
c VECTOR SUBTRACT C:=A-B
c
R E A LA ( * ) , B ( * ) , C ( * )
DO 1 I = l,N
c ( I ) = A ( I ) - B ( I )
RETURN
END
c
C
c
S U B R O U I T I N E V S M U L T( V , S C A L , N )
c
c MULTIPLY A VECTOR BY A SCAI,AR
c
REAL V(*)
DO 1 I = l,N
v(I) = v(I)*5941
RETIJRN
END
c
a
c
S U B R O U T I N E V V M U L T( V l , V 2 , A , I A , M , N )
C
FORMS A VECTOR PRODUCA

REAL V1 (*) ,V2 (*) ,A(rA, *)


DO I I : 1,H
DO 1 J = 1,N
A(I,J) = v1 (I) *V2 (Jr
RETURN
END
lndex

Accelerationmethods79 Crank-Nicolson 232


Adams-Moulton-BasMorthmethod 237 Curvefitting 159
Program 7.3 239
Array declarations 4-7
Atray storage 6
Deflation 103
Diagonaldominance 39
Diagonal matrix 112
Back-substitution 16, 100,l@
Differencemethodsfor interpolatingpolynomials
Backwarddiffercnccs 147,153,154,244,285
T4L
Bandedequations 27
Diffusion cqn 277
Biharmonic equations 277, 285
Direct methods ll,57
BtLrN 303.313
Bisectionmethod 69, 128
'10
Program 3.2
Boundaryvalueproblems 2M Eigcnvalueequations92
Elliptic rors 282,286
Errors 7-9
Canccllation 9 in differenccformulae 158
Centraldifferences 153,156,245,285 in Newton-Cotesrules I74
Charactcristiclines 278 in Gauss-lrgendrc rules 188
Charactcristicpolynomial methods 93, 105, 127 in Euler'smethod 215
Program4.10 130 in onc-stepmethods 222
cHEcK 303,313 in predictor-correctormcthods236-9
cHEcoN 304,313 propagation 242
cHoFAc 304,314 in wcightedrcsidual mcthods 269
Cholesky'smethod 26, 108 Euler'smethod 214
Program 2.4 29 Euler-trapezoidalmethod235
cHosuB 304,314 Explicit schemes 297
Collocation 2U
Conjugategradients 54,124
Program2.12 54 Factorisation 15, 16
Convergencccriterion 4\ 56, 241, 2ffi Falscpositionmethod 7L,256
Computationalmoleculesin finite differences 284, Program3.3 72
285 Finite differenccmethods 245,276
Conductioncquation 291 in 2-d 283
Consolidationequation 291 Finite elementmethod 276,283
Conversionto standardeigenvalueequation 108 Fixed weightingcoefficients 192
Program4.5 109 Forwarddifferences 143,144,153,154,155,245,
Correctorformulae 235 285

327

l
328 INDEX

Forward-substitution16,100,109 Jacobiiteration 4l
Functionsin nontnl^- 3 Program2.8 42

Galerkin's method 267 l.agrangianpolynomials 137,146


cAULAG 305,315 Program5.1 139
GAULEG 305,3 5 l.anczosreduction 124
Gauss-Chebyshevrules 192 Program 4.9 125
Gaussian rules 169 Laplace'sequation 277,285
Gauss-Irgendre 180, 189 LDLr factorisation 20-21, 133
l-point l8l,217 Program 2.3 23
2-point 182 LDLFoR305,317
3-point 183 LDLr 305,317
Program 6.2 186 kast squarcs 159
Gauss-Laguerre rules 189, 190 Program5.3 161
Prograrn 6.3 190 in method of weightedresiduals 266
Gauss-Seidel method 44 Libraries I
Program 2.9 46 Limits of integration 184
Gaussian elimination II Linear algebraicequations ll, 286
Program 2.1 l3 l-ocal error 223
Generalisedeigenvalueequation 105 Lower triangular matrix l\ 16
Program 4.4 106 LR transformation l2l
Civens's method 117 Program 4.8 122
Global error 223 LU factorisation l6
Gradient methods 51 Program 2.2 18
LUFAC 3M,31'I
LUPFAc 306,318
LUPSoL 306,319
Half-bandwidth 28
Hilbert matrix 35
Householder'smethod ll7
MArrNv 307,319
Program 4.7 I 19
MATMUL 307,319
Hybrid integration rules 193
MATRAN 307,320
" l Hyperbolic rors 283, 295
Midpoint method 217
Midpoint rule l8l,2l7
I
Milne's method 236
Ill-conditioning 35 Mixed derivatives 276,285
Implicit schemes 298 Modified Eulermethod 216
Initial value problems 212 Modified Newton-Raphson 76, 86
Integration over a quadrilateral 200 Program 3.5 (singlccquation) 78
Program 6.4 2Oz Program 3.8 (systcmofequations) 88
Integration over a rectangle 195 MSMULT 308,320
Interpolating polynomials 137, l5l Multi-stcp mcthods 213,244
Iterative methods for linear equations 11, 38, 57 Multiple fint order cquations 226
Iterativesubstitution 65 Multiplc integrals 194
Program 3.1 (single equation) 65 Multiple roots 67
Program 3.6 (system of equations) 8l MvMULT 308,320

J a c o b id i a g o n a l i s a t i o n 1 1 3 NAc library 2
Program 4.6 ll4 NEwcor 308,320
r
l.
INDEX 329

Newton{otes rules 169,175,Ig0 Repeatedrules 176


Program6.1 I78 Residual 51,262
Newton-Raphsonmethod 74,92 Rotationmatrix ll2
Program3.4(singleequation) j5 Roundoff 7,35
Program3.7(systemof equations) g5 Rungc-Kutta methods 219, 226, 255
Nondimensionalequations 2gl,296
Nonlinearequations 62
Nuu- 308,321 Samplingpoints 169
NULvEc 309,321 Outsidc rangeof intcgration 193,237
Numericaldiffcrentiation l5l Shiftediteration 97
Numerical integration l6g Program 4.2 98
Numericalstability 242 Shiftedinvcrseiteration 99
of finite differenceequations 292 Program 4.3 l0l
Shooting methods 252
Program 7.4flincar) 253
Ordinarydifferentialequations 2lO Program 7.5(nonlinear) ZS8
.
Linearity 2l I Simpson'srule l7l
Order 2l I Repeated 177
One-stepmcthods 213,244 Singularmatrix 25, 35
Program7.1(singleequation) 220 SKYFAc 3W,322
Program 7.2 (systemof cquations) 22g Skyline storage 30
Orthogonalmatrices l12 Program 2.5 3l
Orthogonalityof eigenvectrrrs
94, lO4 sKYsuB 310,322
Solutiondomain 278
soLvE 310,323
Parabolicpors 283,291 Sparsesystems 44
P A R A M E T E RS t A t C M C N t5 Splinc functions 146
Partial differential equations 276 Program 5.2 149
linearity 276 Steepestdescent 51
order 276 Program2.11 52
first order 277 Stiffequations 242
sccond order 281 Stride 6
Pivoting 33 Sturrn sequenceproperty I28
Program 2-6Y suBBAC 310,323
Poisson's cquation 277 SuMomain 265
Positive definitencss 24-26, 35,93 suBFoR 311,324
Preconditioning 56 Succcssive overrelaxation 48
Predictor formulae 235 Program 2.10 49
Predictor-corrector methods 233, 244 Systcmof nonlinearcquations 80
Prescribed'variablcs' 36 Subroutinesin rontnex 3
Program 2.7 37
PRTNTA 3CE,321
PRrNrv 3@,321 Taylorscries 158,215,219,222
Theta (d) methodsfor linear equations 231
Transformationmethods lll
Quadratic form 24-26 Trapczium rule 170,216
Quadrature 168 Repeated l'16
Trial functions 262
Trial solution 262
Rectangle rule 170,214 Tridiagonalmatrix ll'1, 124,L27,148
Reduction of high order equations 224 Truncation 8
330 INDEX

Undeterminedparameters 262 Program4.1 95


Upper triangularmatrix lZ, 16 vsMULr 312,325
vvMULr 312,325

vDorv 3I1,324
vEcADD 3It,3Z4 Wavecquation 277
vEccoP 311,324 Weightingcoe6cients 169
vEcsuB 3l2,3Zs Weightedresidualmethods 261,269
Vcctor itcration 94

'r
I

You might also like