Advanced BASIC Scientific Subroutines
Advanced BASIC Scientific Subroutines
B. V. Cordingley
and
D. J. Chamund
M
MACMILLAN
EDUCATION
© B. V. Cordingley and D. J. Chamund 1988
Published by
MACMILLAN EDUCATION LTD
Houndmills, Basingstoke, Hampshire RG21 2XS
and London
Companies and representatives
throughout the world
British Library Cataloguing in Publication Data
Cordingley, B. V.
Advanced BASIC scientific subroutines.
1. Science - Data processing 2. BASIC
(Computer program language).
I. Title II. Chamund, D. J.
502'.8'55133 Q183.9
Every c·are has been taken in the writing and testing of the programs contained in this book.
It has not been possible, however, to test the programs under all conditions and with the many
machines that are available. There will also be interaction between the user's own program and
the subroutines taken from this book. Users should therefore satisfy themselves that the oper-
ation of the programs and subroutines is suitable for the intended application. No liability for
any damage or injury that may result from the use of the material contained in this book can
be accepted by the authors or the publishers.
Contents
Preface viii
1 Introduction 1
1.1 Who Should Use this Book 1
1.2 BASIC, Style, Structure and Speed 1
1.3 The Subroutines and their Presentation 3
1.4 Syntax, Variables, Statements and Functions 4
1.5 Software and Rounding Errors 6
1.6 How to Use this Book 8
2 The Subroutines 9
2.1 Generation of Random Numbers 9
RNDBIN - Binomial random number generation 9
RNDPSN - Poisson random number generation 12
RNDNRM - Normal random number generation 15
RNDEXP - Exponential random number generation 18
2.2 Probability, Density and Distribution Functions 20
BINOPD - Binomial probability and distribution function 20
POISPD - Poisson probability and distribution function 22
NORMDT - Area under the normal curve 25
XPONDD - Exponential density and distribution function 29
LNGAMM - Natural logarithm of the complete gamma function 31
GAMMFN Ratio of the incomplete gamma function 34
BETAFN Ratio of the incomplete beta function 37
CHISQD Area under the chi-squared curve 42
FDISTR Area under the F-curve 45
TDISTR - Area under Student's t curve 47
2.3 General Statistics 50
MNVRNC Mean and variance 50
MAXMIN - Sorting data, percentiles and cumulative frequency
distribution 53
COMMNS t method of comparing the difference between two
means for paired and unpaired data 58
CONTIN - m x n contingency table with chi-squared test 64
PERCOM - Factorials, permutations and combinations 69
v
vi Contents
References 174
Index 176
The use of computers today for scientific and engineering purposes is commonplace.
School pupils studying science·based subjects will almost certainly have had some
hands-on experience of computing by the time they are ready to sit their final
examinations. Those leaving university with a science or engineering degree are
likely to have a working knowledge of more than one high-level language.
In the mid 1960s computer programming was just beginning to feature in the
syllabuses of some undergraduate courses. The emphasis on programming at that
time was to save memory, increase speed and if possible make the program code
understandable to the author and perhaps even other users. Advances in micro-
electronics have today made possible the production of machines of such memory
capacity and speed that under many conditions of use, memory space limitations
and computing time place little constraint on the programmer. The current emphasis
is on structure and style of programming.
What has not changed so dramatically is the effort required to design and develop
computer software, and this is reflected in the changes in the relative costs of soft-
ware and hardware over the same interval. Every machine requires software to drive
it, and for large jobs or tasks of a specialist nature there is probably no real alterna-
tive to the purchase of commercial software or its production by those highly
proficient in this task. Commercial software, however well written, is likely to
suffer from several limitations: it is first of all expensive; it tends to be machine
specific and so can suffer from limited portability and is often accompanied by
copyright restrictions; it is rigid and not generally amenable to modification by the
user and input and output are predetermined. The software, to obtain wider market-
ability, is often far more powerful and consequently complex than the user requires.
If it has to be purchased, then the right type of software has to be found and
studied - all points that make it difficult to justify for those smaller jobs. It is these
and other limitations that contribute towards the reasons why many engineers and
scientists write some software themselves - the need to do this is implicitly recog-
nised by the proportion of time devoted to this task in the formal training that they
currently receive.
What we have attempted to do in this book is to provide a collection of sub-
routines which can function as the building blocks for scientific programs of the
user's own creation. We have written them in a uniform style and presented them
in a manner which we anticipate will make them easy to use. BASIC has been
viii
Preface ix
selected as we believe it is the language with which potential readers are still most
likely to be familiar and the one that will be compatible with their computer both
at home and in the workplace.
One of the problems encountered in compiling a book of this nature is to know
what material to include and what to exclude. Subroutines which would be relevant
but which only occupy a few lines of code and which also are likely to cause no
problem to the user have been omitted, as have those which would be regarded as
trivial by the anticipated readership. Other work has had to be eliminated through
restrictions on space, or because it was thought to be too narrow in its application.
We have attempted to retain only what we consider to be the most generally useful
material.
In the preparation of this book, help has been received from several sources.
Here we should like to acknowledge with gratitude the assistance of Michael J.
Morris of the School of Economic and Social Studies, University of East Anglia;
Martin Wilson of the Department of Statistics and Operational Research, Coventry
Polytechnic, for assistance with the details of some of the statistical subroutines;
and Juliet Davison for her help in kindly typing the manuscript.
1 Introduction
A quick skim through the pages of this book will reveal its nature - it is principally
a library of subroutines written in BASIC which would find use in the solution of
many engineering and scientific problems.
The subroutines contained in this publication have been designed for use by
students who are studying mathematics and statistics in preparation for university
entrance and who have an interest in scientific computing. The subroutines are also
intended for use by undergraduates who are pursuing science or engineering studies
at university and for practising engineers and scientists who do at least a proportion
of their own programming. It is anticipated that these groups of individuals are
likely to have access to small personal or home computers and occasional use of
larger machines. Previous experience of writing programs containing subroutines
will be required if the reader is to make full use of this book.
Mathematics and statistics are difficult subjects and no attempt is made to teach
them here. There are many excellent books on these topics and we feel that dupli·
eating the work in this volume would be both unnecessary and inappropriate.
Similarly, this is not a text on BASIC programming; for readers who wish to brush
up their BASIC we can recommend Practical BASIC Programming (Gosling, 1982).
BASIC is the most widely available high-Ievellanaguage and is supplied for the
overwhelming majority of modern small computers, as well as being provided on
larger machines. It remains likely to be the language first studied by those learning
programming. BASIC is easy to use and, because it is usually entered via an inter·
preter, program development is assisted by the availability of excellent fault diag-
nostics. The facilities available with the BASIC language are continually being
enhanced. It is an endorsement of BASIC that it is the language chosen for writing
a significant amount of professional scientific software.
The BASIC language is still changing and evolving. Procedures are included
among the more powerful features now being introduced but this facility is not
sufficiently widely available at the present time to make it appropriate to use them
in this book. The more experienced programmers should find it a relatively easy
1
2 Advanced BASIC Scientific Subroutines
task to rewrite the subroutines as procedures in a form suitable for their machines.
The detractors of BASIC for use in scientific programming argue principally
that the language lacks 'structure' and favour FORTRAN, C and sometimes ALGOL,
or more commonly today, Pascal. It would be perverse to deny that there is some
weight in the argument. Nevertheless, structure is not an absolute but rather a
question of degree - it is possible to write programs of reasonable structure in
BASIC. Also the degree of 'structure', despite its importance, is only one of several
criteria on which the suitability of a programming language is to be judged. The
attributes of BASIC (wide availability, ease oflearning and advanced facilities to
aid the testing and modification of programs) will take some defeating and, collec-
tively, are arguably superior to those possessed by other languages.
We have attempted to achieve a reasonable degree of 'structure' in the design
of the subroutines, that is, as far as we believe is reasonable within the constraints
imposed by today's commonly available versions of BASIC. For example, we have
tried to keep the length of individual subroutines well within a page and have
restricted the use of GOTO as much as possible. Where this statement is employed,
the direction is forward in the program whenever practical. Only one RETURN
statement is present in each subroutine.
The style of presentation is largely after that given in the book The Little Book
of BASIC Style (Nevison, 1978) and we can recommend this work to those who
write a significant number of programs in BASIC. In writing the subroutines we
have generally given clarity priority over the demands of speed and memory. It was
necessary to reproduce the program listings in this book at a size which would
facilitate the task of entering them manually into a computer. To satisfy this
requirement the number of characters per line has been restricted to 57.
At first glance the printed code may appear to be somewhat over 'REMed'
and spaced. The reader will no doubt feel free to compact the programs, indeed
software is available for several machines specifically to accomplish this task. The
reverse process however, is not so readily achieved. It is, nonetheless, probably
best to leave this exercise until the programmer is satisfied that correct operation
has been established.
On occasions, it will be necessary to increase the speed at which a program runs.
For example, if a subroutine has to be called many times by the main program, as
could happen in a simulation exercise, increases in speed could be beneficial. Pro-
gramming method, presentation, the machine and its employment of BASIC all
combine to determine the speed at which a program runs. Handbooks supplied
with computers generally contain hints on how speed may be increased, such as by
the removal of lines containing REM statements, general compaction of the pro-
gram and the introduction of multiple-statement lines. Increases in speed are often
gained at the expense of clarity and therefore they need to be justified.
Introduction 3
The great worth of subroutines is found in their flexibility. They impose no restric-
tions on input and output data format and they may be tested independently of
the main program. A common subroutine may be used in several programs. Sub-
routines form the building blocks from which large programs are constructed.
At the heart of many subroutines is an algorithm which performs the mathe-
matical task allotted. It takes the information required from the host program and
returns the information that the host requires in its turn. There are several ways of
writing an algorithm to generate the required results, and perhaps by the exercise
of greater ingenuity and wisdom the reader may well be able to improve on our
efforts. Alterations which merely improve speed at the expense of clarity should
be closely examined for their value.
A few words of explanation on the various headings under which the subroutines
are described may prove helpful here:
Description - Provides a brief outline of the function of the subroutine and men-
tions any other subroutines required.
Subroutine - In BASIC, subroutines are called by their line number. As line number
references are more difficult for humans to relate to than are descriptive names,
each subroutine is given a six letter name which is 'called' just prior to the GOSUB
statement in the main program (a technique adapted from FORTRAN).
Method - Under this heading is given a brief description of the mathematical
method employed and a guide to the operation of the subroutine. The subroutines
have been written to be used essentially as 'black boxes'. The brief description of
the method of operation is included, not so much as a teaching aid in itself, but
rather to remove ambiguity that may exist over the use of certain mathematical
terms. It also serves to facilitate further study of the subject should this be desired.
References are supplied in support of more unusual procedures, or where infor-
mation on the mathematical method may not be found readily.
Subroutine listing - The listing of the subroutine usually (though not always) starts
with the line number 2000 and each line is incremented by 10. In many applications
it will be desirable to change the line numbers employed for the subroutine, such as
when more than one subroutine is used within the same program. The subroutine
itself contains introductory REM statements which further indicate its application
and define input and output variables, together with instructions on the minimum
sizes required by arrays.
Sample program - Each subroutine is accompanied by at least one sample program
which it is intended primarily to be of assistance in constructing the tests that the
user will wish to conduct. These examples may not appear to be directly relevant
to the user's intended application, but the number of potential uses for many of
the subroutines is legion and a large number of examples would be required to
reflect these adequately.
4 Advanced BASIC Scientific Subroutines
Syntax
Upper-case letters have been used throughout. Output has been restricted to what
can be achieved with simple PRINT statements. As graphical output tends to be
very machine specific and subject to personal preference, we did not feel it
appropriate to include this in the sample programs. Subroutines to generate
graphical output were felt to be outside the scope of this book. Those requiring
Introduction 5
access to subroutines on this subject are referred to books by Angell and Jones
on graphics (Angell and Jones, 1983a, 1983b; Angell, 1985).
Multiple·statement lines and multiple assignment statements have both the
capacity to simplify and confuse programs: however, because of their restricted
availability, these facilities have not been exploited and each line of program
contains one instruction only.
Variables
Descriptive names have been employed where this is felt to aid understanding.
The maximum number of letters used in any variable name is six. Some earlier
versions of BASIC require that the variable name be defined by the first two
characters and users of these will have to accommodate this requirement by
selecting their own variable names. Also, some machines will not permit reserved
BASIC words to be included at the beginning of variable names; this restriction
has been accepted and may superficially give the impression of some idiosyncrasy
in the choice of names for several variables.
Integer variables are not used in this work and string variables only on a few
occasions. String variables are terminated with the '$' character. Array variables
are given single letter names.
The subroutines contain a list of global and local variables. Global variables
are used to communicate input and output values between the main program (and
sometimes other subroutines) and the subroutine. A local variable has a function
purely within a subroutine; it may be used within the main program, but caution
should be exercised as execution of the subroutine is likely to affect its value.
Statements
DIM - It is assumed that the size of the array must be declared before it is used
and that a variable may not be employed for this task; that is, DIM B(78) is
acceptable, but DIM B(NUMOBS) is not. Indications on the minimum array
sizes to be specified are contained within the subroutines and employed in the
sample programs. Except in the case of programs in which space is likely to
impose constraints (for example, those involving regression techniques and analysis
of variance), it is satisfactory to continue the generally accepted practice of safely
over-specifying the size of array required.
END - is necessary to denote the end of a program. Subroutines come below END
in the sample programs. STOP is not used, though it may be substituted for END
where the END statement is not available. END is also used within some sub-
routines to terminate the program if a major error is discovered.
FOR-NEXT - The word STEP is omitted if its value is unity. P, Q, R and S are
used as control variables in the subroutines (and are included under the heading
6 Advanced BASIC Scientific Subroutines
of Local variables). This leaves the usual control variables I, J, K, L, M and N for
use in the sample program and the user's main program without overmuch
thought.
Functions
RND(-l) - is used to reseed the uniform random number generator. This is useful
if the same set of random numbers is required each time a program is run - for
example, in diagnostic work. A programmer will have to consider whether a
constant or new set of random numbers is required each time a program is run and
then select the desired function from the machine's library.
Software errors can be conveniently divided into three categories: those which are
identified during the interpretation of the program; those which occur during the
running of the program; and logical errors which produce erroneous results.
The BASIC language interpreter makes identification of syntax and run-time
errors reasonably straightforward. Errors identified may be patently errors in code
entry or perhaps an incompatible form of BASIC. Run-time errors give a line
number at which the error was spotted. If this is found to be in the section of the
program written by the reader, then a customary procedure for debugging should
Introduction 7
be enacted. If it occurs in the subroutine then the input data should be checked
to ensure that it is sensible. If this is found to be satisfactory then the code
entered for the subroutine should be double-checked.
The most difficult errors are those which produce wrong results and, as when
writing their own software, readers should test that their programs give sensible
output. The degree of testing that can be justified must, of necessity, be left to
the programmer's discretion.
The most common causes of inaccuracy having their origins inside the sub-
routine include:
Bugs in the subroutines - although these subroutines have been checked under a
wide variety of conditions, they clearly have not been tested with all machines,
nor with multitudinous driver programs, nor with all possible input data. They
were written by humans and it would be arrogant to presume that all of them are
totally free of error.
The computer printouts presented in this book have been reproduced photo-
graphically and therefore the copying process itself should not be responsible for
the introduction of mistakes.
Many of the subroutines do contain some rudimentary mechanisms to facilitate
error identification which serve to warn the user of possible failure or where
failure has occurred. However, notWithstanding other difficulties, to include the
extensive error detection necessary to cover every contingency would occupy
much space and add considerably to complexity. Error checks have been mini-
mised or omitted altogether where their use is likely to cause real increases in
run time (for example, in subroutines likely to be used in simulation exercises).
Readers must decide for themselves the degree of checking and testing that is
necessary according to their habit and requirements.
8 Advanced BASIC Scientific Subroutines
The effort applied and the method adopted when writing a program will depend on
its intended application and purpose. The approach selected for a one-off program
will clearly be different from that chosen for work which is going to form part of
some software for a laboratory or which is likely to be modified later by others.
Work on programs being developed with the aid of this book may proceed along
the following lines:
Subroutine: RNDBIN
Description
Method
where n is the number of trials and p the probability of a success on a single trial.
B; are independent random variables which take the value 1 with probability p
and 0 with the probability 1 - p.
Subroutine Listing
9
10 Advanced BASIC Scientific Subroutines
Sample Program
If five dice are thrown 10000 times, estimate by simulation the number of times
three or more sixes will occur.
>RUN
THE NUMBER OF SUCCESSES IS 345
The Subroutines 11
The expected number of times three or more sixes would be thrown in 10000
throws is 354.9 (see sample program on binomial probability and distribution
function).
Note
As with other simulation exercises, the value obtained by running the sample
program will depend on the machine and the initial value of the uniform random
number generator.
12 Advanced BASIC Scientific Subroutines
Subroutine: RNDPSN
Description
Method
Tn = -(I/L)ln (ii
1=1
Ui)
In(ii1=1
U1' <-L
')
n
IT Uj < EXP(-L)
1=1
The smallest value of n for which this condition is satisfied has a Poisson dis·
tribution of parameter L.
A further deSCription of this technique is given by Morgan (Morgan, 1984)
The Subroutines 13
Subrouting Listing
Sample Program
The telephone operators at a large switch board have to deal with telephone calls
at an average rate of2 per minute. Assuming the process can be represented by a
Poisson distribution, estimate, by simulating 10 000 one-minute intervals, the
probability of 1, 2, 3, 4 or 5 calls arriving within a one-minute interval.
1150 LET Ll = 2
1160 LET Nl = 1
1170 LET N2 = 5
1180 LET NUMSIM = 10000
1190 LET TEVENT = 0
1200 LET VEXPLI = EXP(-LI)
1210 LET X = RND(-l)
1220 REM
1230 REM COUNT NUMBER OF TIMES NI <= XPSN <= N2
1240 REM CALL SUBROUTINE RNDPSN NUMSIM TIMES
1250 FOR J = 1 TO NUMSIM
1260 GOSUB 2000
1270 IF XPSN < HI OR XPSN > N2 THEN GOTO 1290
1280 LET TEVENT = TEVENT + 1
1290 REM
1300 NEXT J
1310 PRINT" PROBABILITY OF BETWEEN "; Nl; " AND "; N2
1320 PRINT" CALLS = "; TEVENT/NUMSIM
1330 END
>RUN
PROBABILITY OF BETWEEN 1 AND 5
CALLS = 0.8491
Subroutine: RNDNRM
Description
Generates pairs of random numbers which are normally distributed with mean
and variance 1,N(O, 1)
°
Method
°
If U 1 and U2 are two independent random variables uniformly distributed
between and 1, U(O, 1), and
Vi =2U1 -1, V2 =2U2 -1 and
R2 = V~ + VLR 2 < 1 (R2 rejected otherwise)
then
Nl = V2((-2InR2)/R2)t and
N2 = Vl((-2InR2)/R2)t
where Nl and N2 are independent variables with a N(O, 1) distribution.
Subroutine Listing
Sample Program
1360 NEXT I
1370 END
>RUN
T AREA
-2 2.12E-2
-1.5 6.31E-2
-1 0.1556
-0.5 0.3146
o 0.5008
0.5 0.6931
1 0.8448
1.5 0.93
2 0.9762
These results are to be compared with those published in tables on the standard
normal curve. These are: 0.02275,0.06681,0.1587,0.3085,0.5000,0.6915,
0.8413,0.9332 and 0.9773 respectively.
18 Advanced BASIC Scientific Subroutines
Subroutine: RNDEXP
Description
Method
In general, random variables may be transformed with the aid of the relationship
fx(x) =fu(u) I du/dx I
If X = -(l/L)ln(U) where U is a uniformly-distributed random variable with a
U(O, 1) distribution, andfu(u) = 1 for 0 < u < 1 then
fx(x) = 1. I-L.EXp( -Lx) I
=L.EXP(-Lx)
which is an exponentially-distributed random variable.
Subroutine Listing
Somple Program
The mean time to failure of a certain device is two years (or an average rate of
0.5 failures per year). By conducting 10 000 simulations, estimate the probability
The Subroutines 19
that at least one failure will occur in four years. The failure process has an expo-
nential distribution.
>RUN
PROBABILITY FAILURE OCCURS IN FIRST 4
TIME UNITS IS 0.8618
This answer of 0.8618 should be compared with the expected value of 0.8647
which is obtained by direct calculation.
20 Advanced BASIC Scientific Subroutines
Subroutine: BINOPD
Description
Method
Subroutine Listing
2170 REM
2180 REM CHECK INPUT DATA
2190 IF PB < 0 OR PB > 1 OR NB < 1 THEN GOTO 2310
2200 IF NUMSUC > NB OR NUMSUC < 0 THEN GOTO 2310
2210 LET QB 1 - PB
2220 LET PX = QB~NB
2230 LET FX = PX
2240 IF NUMSUC = 0 THEN GOTO 2290
2250 FOR R = 1 TO NUMSUC
2260 LET PX (NB + 1 - R)*PB*PX/(R*QB)
2270 LET FX = FX + PX
2280 NEXT R
2290 REM
2300 RETURN
2310 REM
2320 PRINT " PB, NB OR NUMSUC INVALID"
2330 PRINT" PB = "; PB; ", NB = "; NB;
2340 PRINT ", NUMSUC = "; NUMSUC
2350 END
Sample Program
If five dice are thrown, determine (a) the probability that exactly three sixes are
thrown and (b) the probability of throwing three or more sixes.
This problem may be tackled conveniently by considering the probability that
(a) exactly two numbers other than six are thrown and (b) that zero, one or two
numbers which are not sixes are thrown. The probability of not throwing a six is
5/6.
>RUN
P(X) = 3.215E-2 F(X) = 3.5494E-2
Thus (a) the probability of throwing three sixes is 0.032150 and (b) the
probability of throwing three or more sixes is 0.035494.
22 Advanced BASIC Scientific Subroutines
Subroutine: POISPD
Description
Method
°
k=O
=1 t =
Subroutine Listing
Sample Program
Telephone calls arrive at a switch board on average at a rate of two per minute.
Assuming that the process can be modelled as a Poisson distribution, determine the
probability of (a) exactly t, (b) at least t and (c) t or fewer calls arriving in a one
minute interval for t = 0, 1,2, 3, 4 and 5 calls.
>RUN
T P(X = T) P(X <= T) P(X >= T)
o 0.13534 0.13534 1
1 0.27067 0.40601 0.86466
2 0.27067 0.67668 0.59399
3 0.18045 0.85712 0.32332
4 9.0224E-2 0.94735 0.14288
5 3.6089E-2 0.98344 5.2653E-2
is 0.8481. The discrepancy is well within the expected precision of the process
of simulation.
The Subroutines 25
Subroutine: NORMDT
Description
Computes the area under the upper and lower tails of the standard normal curve.
Method
The integrals
Subroutine Listing
Sample Program
Determine the area under the lower and upper tails of the standard normal dis-
tribution for values of z in the range - 6 to + 6 atintervals of 0.5
>RUN
VARIATE LOWER UPPER
Z AREA AREA
-6 9.86588E-10 1
-5.5 1.89896E-8 1
-5 2.86652E-7 1
-4.5 3.39767E-6 0.999997
-4 3.16712E-5 0.999968
-3.5 2.32629E-4 0.999767
-3 1.3499E-3 0.99865
-2.5 6.20967E-3 0.99379
-2 2.27501E-2 0.97725
-1. 5 6.68072E-2 0.933193
-1 0.158655 0.841345
-0.5 0.308538 0.69l462
0 0.5 0.5
0.5 0.691462 0.308538
1 0.841345 0.158655
1.5 0.933193 6.68072E-2
2 0.97725 2.27501E-2
2.5 0.99379 6.20967E-3
3 0.99865 1.3499E-3
3.5 0.999767 2.32629E-4
4 0.999968 3.16712E-5
4.5 0.999997 3.39767E-6
5 1 2.86652E-7
5.5 1 1.89896E-8
6 1 9.86588E-10
The results agree with those published in five-figure tables - much higher
accuracies are claimed for this method.
Notes
1. The test AZ > 12 may be adjusted to take account of precision of the working
and the magnitude of the smallest number the machine can hold. This facility
28 Advanced BASIC Scientific Subroutines
will prove useful if unusually large values of z are likely to occur by design or in
error and interruption of the program in run time proves undesirable.
2. For full accuracy it is important that the tail area selected for study is com-
puted directly; that is, if z > 0, use UAREA to compute the small area and not
1 - LAREA. Similarly, if z < 0 use LAREA in preference to 1 - UAREA.
The Subroutines 29
Subroutine:~lVDD
Description
Method
Density function
Subroutine Listing
Somple Program
The mean life of a gas discharge tube under certain conditions is 92 hours
(IlL = 92). Use the exponential distribution to determine the density at L = 1/92
and the probability that the component will fail during the fIrst 50 hours of
operation.
>RUN
TIME = 50. MEAN = 1.087E-2
DENSITY = 6.312E-3
AREA UNDER CURVE = 0.4193
The probability that the tube will fail in less than 50 hours is 0.4193; the
density of the probability function at this time is 0.006312.
The Subroutines 31
Subroutine: LlVGAAfAf
Description
Evaluates the natural logarithm of the complete gamma function rea) for a > O.
Afethod
rea) LOOtO:-1exp(-t)dt
Integration by parts yields
rea + 1) = area) a> 0
In the computation use is made of the relationship:
rea) = rea + 5)
a(a + 1)(a + 2)(a + 3)(a + 4)
Subroutine Listing
Sample Program
>RUN
ALPHA LN(T(ALPHA) )
0.1 2.2S27
0.3 1.0958
1 o
1. 32 -0.11133
2 1.8626E-9
2.5 0.28468
The Subroutines 33
3 0.69315
10 12.802
300.62 1412.7
Notes
1. The result will be accurate to at least 9 decimal digits given that the computer
is capable of such accuracy.
2. High values of ALPHA have the potential to cause overflow. The program is
interrupted if ALPHA is greater than lE7. This limiting value may be adjusted
to suit the capacity of the reader's machine.
34 Advanced BASIC Scientific Subroutines
Subroutine: GAMMFN
Description
Evaluates the ratio of the incomplete gamma function G (p, y) to the complete
function r(p) for p > 0, y > 0.
Requires subroutine LNGAMM.
Method
f:
The ratio is defined by
The algorithm used to evaluate G(y,p) has been published by Lau (Griffiths
and Hill, I985b) and exploits the relationship
where
Subroutine Listing
Sample Program
Determine the value for G(y,p) for the following values ofp andy:
p 0.5 0.5 5.5 13 26 35 35
y 7.85E-5 5.4135 3.4945 14.623 32.711 22.721 56.1585
>RUN
P Y G(Y,Pl
0.5 7.S5E-5 9.9972E-3
0.5 5.4135 0.999
5.5 3.4945 0.20003
13 14.623 0.69999
26 32.711 0.S9999
35 22.721 1. 0001E-2
35 56.159 0.999
These results may be checked against the tables for X2 by substituting degrees
of freedom = p /2 and X2 = Y/2 or directly against tables for the incomplete gamma
function (Pearson, 1956).
Notes
Subroutine: BETAFN
Description
Evaluates the ratio of the incomplete beta function Ix(P, q) to the complete func-
tion B(p, q) for p > 0, q > 0, 0 < x < 1. The natural logarithm of the complete
beta function, In B(p, q), is also determined.
Requires subroutine LNGAMM.
Method
where
B(p, q) = (r(p)r(q»/r(p + q)
The subroutine described in this section is adapted from that published in
FORTRAN by Majumder and Bhattacharjee (Griffiths and Hill, 1985c).
Ix(P, q) in (1) is integrated by parts. Ifp ~ (p + q)x, the resulting series
Subroutine Listing
Sample Program
Determine the incomplete beta ratio I X(p, q) for the values of p, q and x given
in the table overleaf. Also evaluate the complete beta function, B(p, q), for each
pair of values of p and q.
40 Advanced BASIC Scientific Subroutines
p q x
>RUN
P Q X IX(B(P,Q» B(P,Q)
0.5 0.5 6.158E-3 5.001E-2 3.142
0.5 500 1.579E-5 9.997E-2 7.929E-2
1 0.5 0.3597 0.1998 2
1 500 4.462E-4 0.2 2E-3
The Subroutines 41
Notes
cm-SQUARED DISTRIBUTION
Subroutine: CmSQD
Description
Computes the area under the X2 curve from zero to a positive argument as a
function of the number of degrees of freedom.
Requires subroutines LNGAMM and GAMMFN.
Method
Subroutine Listing
Sample Program
Evaluate the major and tail areas under the X2 curve for the following values of
argument,x and degrees of freedom, m: 3.93 x 10-3 , 1; 2.706,1; 0.872,6; 5.348,
6; 15.352, 19; 49.513, 38; 46.244, 68; 94.037,68.
>RUN
D.F. XCHI CHIX2 1-CHIX2
1 3.93E-3 5E-2 0.95
1 2.71 0.9 0.1
6 0.872 1E-2 0.99
6 5.35 0.5 0.5
19 15.4 0.3 0.7
38 49 _,5 0.9 0.1
68 46.2 2E-2 0.98
68 94 0.98 2E-2
44 Advanced BASIC Scientific Subroutines
Subroutine: FDISTR
Description
Computes the area under the upper tail of the F-distribution for (m, n) degrees
of freedom.
Requires subroutines BETAFN and LNGAMM.
Method
The integral of the upper area of the F-distribution, 1 - F(z), is solved with the
aid of the subroutine for the incomplete beta function BETAFN. 1 - F(z) is equal
to I x(P, q) if n/2 is substituted for p, m/2 for q, and n/(n + mz) for x.
Subroutine Listing
Sample Program
Use the F-distribution to determine the probability of obtaining values for the
F-ratio, si /s~, greater than those shown in the table. m and n are the number of
degrees of freedom corresponding to s1 and s~ respectively.
>RUN
DF1 DF2 XF FAREA
1 1 39.9 0.1
5 3 5.31 0.1
4 30 2.69 5E-2
24 6 3.84 5E-2
24 30 2.47 9.97E-3
8 1 5.98E3 1E-2
8 4 49 1E-3
8 4 14.8 1E-2
The results agree with those published in tables of the upper percentage points
of the F-distribution.
The Subroutines 47
Subroutine: TDISTR
Description
Computes the area under the upper tail of Student's central t distribution for n
degrees of freedom.
Requires subroutines BETAFN and LNGAMM.
Method
Use is made of the relationship (t0l./2,n)2 = FOI.,l, n where tOl./2,n denotes the value
of a variable with a t distribution and n degrees of freedom at the point a12. al2 is the
probability that the variable exceeds ta/2 ,no Fa, l,n is similarly defined for the
F-distribution for 1 and n degrees of freedom.
The upper tail probability for t is determined directly from the subroutine
BETAFN rather than via the subroutine FDISTN and is set equal tolx (P,q)/2
(see notes on BETAFN). Ix(P, q) is evaluated by substituting nl2 for p, 0.5 for q,
and nj(n + (t0l.,2)2/2) for X.
Subroutine Listing
Sample Program
Use the subroutine TDISTR to determine the upper tail area of the t distribution
at the following points:
t o 12.706 0.7 2.947
n 1 1 1 10 15
t 0.854 2.704 0.677 1.658
n 30 40 120 120
>RUN
OF XT TAREA
1 0 0.5
1 1 0.25
1 12.706 2.5E-2
10 0.7 0.24994
15 2.947 4.9971E-3
30 0.854 0.19994
40 2.704 5.0058E-3
The Subroutines 49
Note
For large values ofn (say exceeding 1000) computation time could be considered
too long. It may be helpful to use the normal approximation for large n or set n
= 1000 for n > 1000 with some small loss of accuracy.
50 Advanced BASIC Scientific Subroutines
Subroutine: MNVRNC
Description
Computes mean, variance, standard deviation, l:x and l;x2 for a set of data
values. The cases of known and estimated mean values are considered.
Method
The following defInitions are used in the calculations performed by this subroutine:
n = number of data elements in the sample
xi = value of the ith element
x = estimate of population mean
IJ =true population mean.
Subroutine Listing
Sample Program
Use the subroutine MNVRNC to fmd the mean, variance and other summary
statistical data for the sample values 0.9, 1.3, 1.4, 1.2,0.8, 1.
1120 NEXT J
1130 REM
1140 REM COMPUTE SUMMARY STATISTICS
1150 REM CALL SUBROUTINE MNVRNC
1160 GOSUB 2000
1170 PRINT " SUM OF DATA VALUES " ,. SUMl
1180 PRINT " SUM OF SQUARES OF DATA VALUES 11 ; SUM2
1190 PRINT " MEAN "; MEAN
1200 PRINT " VARIANCE, MEAN ESTIMATED " ,. VRME
1210 PRINT " VARIANCE, MEAN KNOWN " ,. VRMK
1220 PRINT" STANDARD DEVIATION, MEAN EST. " ,. SOME
1230 PRINT" STANDARD DEVIATION, MEAN KNOWN " ,. SDMK
1240 END
>RUN
SUM OF DATA VALUES 6.6
SUM OF SQUARES OF DATA VALUES 7.54
MEAN 1.1
VARIANCE, MEAN ESTIMATED 5.6E-2
VARIANCE, MEAN KNOWN 4.6667E-2
STANDARD DEVIATION, MEAN EST. 0.23664
STANDARD DEVIATION, MEAN KNOWN 0.21602
Subroutine: AlAJrAlIlV
Description
Sorts data and determines their maximum, minimum, median and range. Computes
percentiles and cumulative frequency distribution for use in descriptive statistics.
Alethod
The given data are sorted in order of increasing magnitude by using the Shell Sort
method. This method is a well-known computer sorting technique and is covered
in many computing books (Lee and Lee, 1982). The maximum and minimum
values are obtained by selecting the first and last items of the sorted array respec-
tively. The range of the data is dermed as the difference between the maximum
and minimum values. The kth percentile of the data is the number t such that at
least k per cent of the data values are smaller or equal to t and also at least
(100 - k) per cent are equal to or larger than t. If t is found to lie at the centre
of the interval of two given data points, then the mean of the two data points is
selected. If t lies elsewhere in the interval, the nearest data point is chosen. The
median is dermed as the 50th percentile. The cumulative frequency is the total
frequency up to and including a particular item or class of data.
Input array A( ) is used for storing both input information and ordered output
data.
Subroutine Listing
2000 REM MAXIMUM AND MINIMUM
2010 REM
2020 REM SUBROUTINE: MAXMIN
2030 REM
2040 REM COMPUTES MAXIMUM, MINIMUM, RANGE, MEDIAN,
2050 REM PERCENTILES AND CUMULATIVE FREQUENCY DIST.
2060 REM
2070 REM VARIABLES:
2080 REM INPUT:
2090 REM A() •..•• INPUT DATA ARRAY
2100 REM NUMDAT .• NUMBER OF DATA
2110 REM PRCNT ••• REQUIRED PERCENTILE (\)
2120 REM OUTPUT:
2130 REM A() .•••. SORTED ARRAY
2140 REM F() ••••• ARRAY OF CUMULATIVE FREQUENCY
2150 REM MAX •.••• MAXIMUM VALUE
2160 REM MEDIAN .• MEDIAN VALUE
2170 REM MIN ••.•• MINIMUM VALUE
2180 REM NITM •••• NUMBER OF DIFFERENT ITEMS OF DATA
54 Advanced BASIC Scientific Subroutines
Sample Program
The following list gives the marks obtained in a test by a class of 60 students.
Arrange the list in increasing order of marks obtained and thus
(a) find maximum and minimum marks obtained,
(b) range of marks obtained,
(c) the median and the 80th percentile,
(d) tabulate cumulative frequency distribution.
If the pass mark was 30, find how many students failed the test.
40,26,60,70,90,40,40,20, 100,20,40, 10,40,5,40,30,20,40,30,40,
90,70,40,30,25,20,10,5,60,50,40,40,20,50, 70,80,5,10,40,60,
10,30,40,60,5,20,5,25,40,80,80,5, 70,40,30,50,20,50,60,50.
1000 REM SAMPLE PROGRAM: PMAXMIN
1010 REM FINDS MAXIMUM, MINIMUM, RANGE, MEDIAN,
1020 REM PERCENTILES AND CUMULATIVE FREQUENCY DIST.
1030 REM
1040 DIM A( 61)
1050 DIM F(60)
1060 DIM V( 60)
1070 REM
1080 REM SET INITIAL VALUES
1090 LET NUMOAT = 60
1100 LET PRCNT = 80
1110 REM
1120 REM READ DATA
1130 PRINT" INITIAL LIST"
1140 PRINT
1150 FOR l I T O NUMDAT
1160 READ A(I)
1170 PRINT A(I);
1180 IF INT(I/10) = 1/10 THEN PRINT
1190 NEXT I
1200 DATA 40, 26, 60, 70, 90, 40, 40, 20, 100, 20
1210 DATA 40, 10, 40, 5, 40, 30, 20, 40, 30, 40
122.0 DATA 90, 70, 40, 30, 25, 20, 10, 5, 60, 50
1230 DATA 40, 40, 20, 50, 70, 80, 5, 10, 40, 60
1240 DATA 10, 30, 40, 60, 5, 20, 5, 25, 40, 80
1250 DATA 80, 5, 70, 40, 30, 50, 20, 50, 60, 50
1260 REM
1270 REM SORT DATA AND PRINT RESULTS
1280 REM CALL SUBROUTINE MAXMIN
1290 GOSUB 2000
1300 PRINT
1310 PRINT" SORTED LIST"
56 Advanced BASIC Scientific Subroutines
1320 PRINT
1330 FOR I = 1 TO NUMDAT
1340 PRINT A(I);
1350 IF INT(I/10) = 1/10 THEN PRINT
1360 NEXT I
1370 PRINT
1380 PRINT" MINIMUM "; MIN
1390 PRINT" MAXIMUM "; MAX
1400 PRINT" MEDIAN = "; MEDIAN
1410 PRINT" RANGE "; RANGE
1420 PRINT PRCNT; "TH PERCENTILE = "; PVAL
1430 PRINT
1440 PRINT" CUMULATIVE FREQUENCY DISTRIBUTION"
1450 PRINT
1460 PRINT" MARK " , " CUMULATIVE FREQUENCY"
1470 FOR l I T O NITM
1480 PRINT V(I), " ", F(I)
1490 NEXT I
1500 END
>RUN
INITIAL LIST
40 26 60 70 90 40 40 20 100 20
40 10 40 5 40 30 20 40 30 40
90 70 40 30 25 20 10 5 60 50
40 40 20 50 70 80 5 10 40 60
10 30 40 60 5 20 5 25 40 80
80 5 70 40 30 50 20 50 60 50
SORTED LIST
5 5 5 5 5 5 10 10 10 10
20 20 20 20 20 20 20 25 25 26
30 30 30 30 30 40 40 40 40 40
40 40 40 40 40 40 40 40 40 40
50 50 50 50 50 60 60 60 60 60
70 70 70 70 80 80 80 90 90 100
MINIMUM 5
MAXIMUM 100
MEDIAN 40
RANGE 95
80TH PERCENTILE 60
CUMULATIVE FREQUENCY DISTRIBUTION
MARK CUMULATIVE FREQUENCY
5 6
10 10
20 17
25 19
26 20
The Subroutines 57
30 25
40 40
50 45
60 50
70 54
80 57
90 59
100 60
From the cumulative frequency table the total for marks less than 30 is 20,
and so 20 students fail the test.
58 Advanced BASIC Scientific Subroutines
Subroutine: COMMNS
Description
Computes basic statistical data for two samples and determines the value of
Student's t statistic with its associated degrees of freedom. It is assumed that the
two samples are taken from populations of equal variance. Paired and unpaired
data may be analysed.
Method
Let the subscripts 1 and 2 distinguish the parameters of two samples. For the
first sample of size nl the mean is given by
n1
Xl = ~ Xli
i=1
and the subscripts 1 and 2 are used to denote the first and second values of the
pair.
The Subroutines 59
Subroutine Listing
Sample Programs
>RUN
MEAN OF A = 106
VARIANCE OF A = 264.4
MEAN OF B 108.78
VARIANCE OF B = 215.19
DIFFERENCE BETWEEN MEANS 2.7778
SE OF DIFF. BETWEEN MEANS = 6.9997
VALUE OF T = 0.39684
DEGREES OF FREEDOM 18
The difference between the mean values of the two samples is small in com·
parison with the standard error and this is reflected in the value of the t statistic
of 0.397. Statistical tables show that a value of 2.1 with 18 degrees of freedom
would have been significant at the 5 per cent level. On the basis of this evidence
there is no reason to believe that the machines are producing different results.
Sample program for (b)
The analysis of this problem may be achieved by minor amendments to the sample
program used to solve (a).
>RUN
MEAN OF A 106
VARIANCE OF A 264.4
MEAN OF B 109.82
VARIANCE OF B 213.56
DIFFERENCE BETWEEN MEANS 3.8182
SE OF DIFF. BETWEEN MEANS 1.2779
VALUE OF T 2.9878
DEGREES OF FREEDOM 10
This value of 2.99 for t should be compared with 2.23 which corresponds to
the 5 per cent probability level for 10 degrees of freedom. This result is significant
and the conclusion is that there is likely to be a real difference in the performance
of the two machines. This difference was not revealed in the first analysis as the
variance in the capacitor values swamped that attributable to the machines. Pairing
the samples has made the check on the machines' performances much more
sensitive.
Note
CONTINGENCY TABLE
Subroutine: CONTIN
Description
Method
ei; =Xi,X'jjt
X2 for each cell = (Xi; - eij)2 jeil
mn
Total X2 = ~ ~ (Xi; - eij)2 jei;
I J
Degrees of freedom = (m - 1) (n - 1)
where m and n are the number of row and column effects respectively.
Subroutine Listing
2700 NEXT Q
2710 NEXT P
2720 LET DF = (NUMA - l)*(NUMB - 1)
2730 RETURN
2740 REM
2750 PRINT" EXPECTATION < 1 AT ROW"; P; " COL. "; Q
2760 END
Sample Program
Batches of ceramic capacitors are fired in one of four kilns and at the end of
their processing are subjected to severe environmental testing. The number of
batches that passed and failed the tests over the period of a year were recorded
and this information is presented in the table below.
Use a contingency table in conjunction with the x: test to check whether
there is evidence that the quality of output from the kilns is significantly different.
Quality Assurance
Kiln pass fail
1 22 16
2 24 8
3 25 9
4 18 20
1220 NEXT J
1230 NEXT I
1240 REM
1250 REM COMPUTE CONTINGENCY TABLE AND PRINT RESULTS
1260 REM CALL SUBROUTINE CONTIN
1270 GOSUB 2000
1280 PRINT " EFFECT B AND TOTAL"
1290 PRINT " EFFECT A"
1300 FOR l I T O NUMA1
1310 IF I = NUMA1 THEN PRINT " TOTAL"
1320 FOR K = 1 TO 4
1330 PRINT P$(K);
1340 FOR J = 1 TO NUMB1
1350 IF J = NUMB1 THEN PRINT " ",.
1360 PRINT F(I,J,K);
1370 NEXT J
1380 PRINT
1390 NEXT K
1400 PRINT
1410 NEXT I
1420 PRINT " DEGREES OF FREEDOM "; DF
1430 END
>RUN
EFFECT B AND TOTAL
EFFECT A
OBSERVED 22 16 38
EXPECTED 23.8169 14.1831 38
DIFFERENCE -1. 8169 1.8169 0
CHI-SQUARED 0.138605 0.232751 0.371356
OBSERVED 24 8 32
EXPECTED 20.0563 11. 9437 32
DIFFERENCE 3.94366 -3.94366 0
CHI-SQUARED 0.775439 1.30215 2.07759
OBSERVED 25 9 34
EXPECTED 21. 3099 12.6901 34
DIFFERENCE 3.69014 -3.69014 0
CHI-SQUARED 0.639007 1. 07305 1.71206
OBSERVED 18 20 38
EXPECTED 23.8169 14.1831 38
DIFFERENCE -5.8169 5.8169 0
CHI-SQUARED 1. 42069 2.38568 3.80637
TOTAL
OBSERVED 89 53 142
EXPECTED 89 53 142
DIFFERENCE 0 0 0
CHI-SQUARED 2.97374 4.99363 7.96737
DEGREES OF FREEDOM = 3
68 Advanced BASIC Scientific Subroutines
It will be found by reference to tables that the 0.05 level of,c for 3 degrees
of freedom is 7.815. The analysis gives a value of 7 .97; this result may therefore
be regarded as statistically significant. Kiln 4 contributes the largest part of the
value for X2 and a further investigation would probably start with an examination
of the quality of output from this apparatus.
Notes
1. The significance of this result may be tested directly with the aid of subroutine
CHISQD.
2. Data for use in contingency tables should be organised so that low expected
values are avoided. An error message is produced if the magnitude of the expected
value is less than 1 in any cell.
The Subroutines 69
Subroutine: PERCOM
Description
Method
n! = n(n - 1) (n - 2) ... I
0!=1 n=0,1,2 ...
n!
P(n,r)= - - r=0,1,2 ... r";'n
(n - r)!
n!
C(n,r)= - - - r=0,1,2 ...
(n - r)!r!
The factorials are computed with the aid of the gamma function:
a! = rea + 1)
Subroutine Listing
Sample Program
>RUN
LN( NUMBER OF WAYS OF ARRANGING) 52 CARDS 156.36084
NUMBER OF WAYS TO DEAL 13 CARDS
WITH REGARD TO ORDER 3.9542424E21
WITHOUT REGARD TO ORDER = 6.3501353E11
The Subroutines 71
Subroutine: OWAOVA
Description
Method
Data on the samples to be tested are stored in array F ( ). Let k be the number of
samples to be tested and n the number of observations in each sample. The
information on the samples is contained in columns 1 to k of F( ) and that on
the observations in rows 1 to n. The values of the observations on the ith sample
are thusxli,x2j, ... ,Xni.
The grand mean is given by
k n
X = ~ ~xi;/nk
i=1 ;=1
Subroutine Listing
Sample Program
Five similar machines are employed to cut tube to lengths of 20 mm. Eight samples
of tube were taken from each machine and the measurements displayed in a table
(see opposite). (a) Determine the mean lengths of the tubes cut by each machine and
(b) produce an analysis ofvariance table to enable the hypothesis that all five
machines produce tube of the same average length to be tested.
The Subroutines 75
Machine
Observation
1 2 3 4 5
number
1 17.5 16.9 21.4 23.2 23.4
2 17.3 15.2 19.1 19.6 15.4
3 19.4 20.5 23.5 21.6 24.6
4 17.8 17.8 21.8 19.5 16.9
5 21.9 20.9 21.9 18.1 19.6
6 17.9 23.5 18.7 18.1 21.1
7 17.8 24.8 21.6 19.2 16.9
8 17.4 24.4 18.3 21.5 22.8
1350 NEXT I
1360 PRINT " GRAND MEAN = " ,. GRNDMN
1370 PRINT
1380 PRINT " ANOVA TABLE"
1390 PRINT
1400 PRINT " SOURCE D.F. SUM SO MEAN SQ";
1410 PRINT " F-RATIO"
1420 PRINT
1430 PRINT " BETWEEN"; C(l,l), C(1,2), C(1,3), C(1,4)
1440
1450
PRINT ..
PRINT "
SAMPLES"
WITHIN ...
, C(2,l), C(2,2), C(2,3)
1460 PRINT " SAMPLES"
1470 PRINT " TOTAL II; C(3,l), C(3,2)
1480 END
>RUN
SAMPLE MEANS AND VARIANCES
SAMPLE MEAN VARIANCE
1 18.375 2.462143
2 20.5 13.02857
3 20.7875 3.435536
4 20.1 3.32
5 20.0875 11. 74982
GRAND MEAN = 19.97
ANOVA TABLE
For 4 and 35 degrees of freedom the 0.05 value ofF is 2.5. The computed
ratio is less than this and consequently, on the basis of this trial there is no reason
to reject the hypothesis.
Notes
1. For this analysis the number of observations in each sample must be equal.
2. This subroutine includes a check for a low value of residual. Its action is
similar to that described in the notes section of the two-way analysis.
3. Scheffe (1959), Chatfield (1970), Davis and Goldsmith (1972) and Wonnacott
and Wonnacott (1981) are suggested for further reading.
The Subroutines 77
Subroutine: TWAOVA
Description
Method
The ANOVA tables below indicate the method of computation. Running the
subroutine causes the results of these calculations to be stored in array C(). The
special case of where there is only one observation per cell is treated separately
and the row containing the interaction effect is set to zero.
The dot notation is used to identify a row, column or cell mean in order. In
the tables, A and B are the number of effects to be analysed and R the number
of replicates.
Prior to calling subroutine TWAOVA it is necessary to store the input in the
three-dimensional array F( ). The subroutine holds the mean values of each cell,
together with the row and column means and the grand (or corner) mean, in
array M().
Subroutine Listing
Sample Programs
1. Without Replication
The average hourly outputs of three workers when operating one of five machines
over a period of time is shown in the able overleaf. Construct an ANOVA table to
assess whether it is likely that a Significant difference exists between the perform-
ances of the operators and machines.
82 Advanced BASIC Scientific Subroutines
Machine
Operator (effect B)
(effect A)
>RUN
TABLE OF MEANS OF INPUT DATA
ANOVA TABLE
From tables F O•05 ,4,8 = 3.84 and FO.OS,2,S = 4.46. These values are to be com-
pared with the F-ratios of 1.41 and 8.59 respectively. Thus the effect due to the
operators (the B effect) is significant at the 5 per cent level and consequently
there is evidence of a real difference in their performances. The low value ofF
achieved for the machines (the A effect) provides little evidence that any differences
in performance can be attributed to them.
2. With Replication
Two lots of four brands of paint were examined in an accelerated life test. The
performance of the paints under three environmental conditions was examined
and the table overleaf constructed. The table shows the number of days the paint
samples survived the test. Construct an ANOVA table and use this to comment
on the performance of paints under various conditions.
84 Advanced BASIC SCientific Subroutines
Paint
Environment (effect B)
(effect A)
1340 NEXT J
1350 PRINT"" M(I,NUMB1)
1360 IF I = NUMA THEN PRINT
1370 NEXT I
1380 PRINT
1390 PRINT " ANOVA TABLE"
1400 PRINT
1410 PRINT "SOURCE D.F. SUM SO MEAN SO";
1420 PRINT " F-RATIO"
1430 PRINT
1440 PRINT " EFF. A "; C(l,l), C(1,2), C(1,3), C(1,4)
1450 PRINT " EFF. B "; C(2,1), C(2,2), C(2,3), C(2,4)
1460 PRINT " INTACT. "; C(3,1), C(3,2), C(3,3), C(3,4)
1470 PRINT " RESIO. "; C(4,1), C(4,2), C(4,3)
1480 PRINT "TOTAL "; C(5,1), C(5,2)
1490 END
>RUN
TABLE OF MEANS OF INPUT DATA
ANOVA TABLE
From tables F O•05 ,3,12 =3.49, F O•05 ,2,12 =3.88 andFo.05 ,6,12 =3.00. The
values of F for the interaction and paint effects are 0.52 and 0.53, consequently
there is no evidence to suggest that there is any real difference between the
general performance of the paints under the various environmental conditions.
The effect of the environment on paint life is likely to be real as the value for
F of 4.91 is significant at the 5 per cent level.
Notes
1. With some experimental data the residual (or unexplained variation) can
approach zero. To avoid interruption of the program under these conditions a
check for a low residual value is made. If the residual sum of squares is found to
86 Advanced BASIC Scientific Subroutines
be less than a factor of 105 smaller than the total sum of squares, the residual is
increased and a warning issued.
2. For this analysis the number of observations in each cell must be equal.
3. Scheffel (1959), Chatfield (1970), Davis and Goldsmith (1972) and Wonnacott
and Wonnacott (1981) are suggested for further reading.
The Subroutines 87
Description
This set of four principal subroutines may be used to fit a sample of data to a
curve of the form y = B 1 + B2X2 + ... + BkXk' The values of the coefficients B
are estimated by the method of least squares. In addition to determining the
regression coefficients, supporting information is computed, inclUding: corre-
lation coefficients, ANOYA table, standard error of the coefficients and residual
analysis.
Requires subroutines SOLUTN and MATDET for full analysis.
Method
A model of the formy =B1Xl +B2X2 + ... + BkXk + eis employed, where
are the regression coefficients; Xl is set to unity in all obser-
Bl ,B 2 , . . . ,B k
vations and B 1 is the constant term; X2 , X3, ... ,Xk are the independent
variables and y the dependent variable. The error term, e, is equal to the dif-
ference between the observed value of y and its predicted value. The system
of equations may be represented in matrix notation by
Y=XB+E
which is equivalent to
Xn 2 X n 3'" Xnk
Subroutine: MLNRGI
Description
Computes mean, variance, standard error and correlation matrix for each set of
variables. Also evaluates X T X.
Method
Array F( ) is used to store the input data. The first column of this array is gener-
ated by the subroutine, the other columns being filled from the driver program so
that information is contained in the following form:
The driver program sets NUMOBS equal to the number of sets of observations
and NUMINV equal to the number of independent variables (n and k - 1 respec-
tively in the preceding notation).
The transpose of F( ) is multiplied by F( ) and the result placed in array D( ).
D() contains X TX and XTy, and this information facilitates the calculation of
the summary statistics: mean
n
Xi= ~ xmdn
m=l
estimate ~f variance
n
~
m=l
+)
xm;/n •
The Subroutines 89
Subroutine: MLNRG2
Description
Finds the inverse of X T X and estimates the values of the regression coefficients.
Method
xTx and XTYare copied from array D() into A() and the normal equations
XTXB = XTYare solved with the aid of subroutine SOLUTN (which in turn
calls subroutine MATDET). A() is expanded beyond the usual requirements of
SOLUTN by inserting an identity matrix between XTX and XTy so that (XTX)-l
may be extracted from A after execution and this is contained in rows and columns
1 to k. The values of the estimates of the coefficients are held in the first column
of array B( ).
Subroutine MLNRG3
Description
Computes the analysis of variance table, the standard error of estimate, the
standard error of the estimated coefficients and the multiple regression coefficient
R2.
Method
n n
Syy = ~ Y~ - ~ Ym/n
m=l m=l
The standard error of estimate a = VC(2, 3) and the multiple regression coef-
ficient is given by Rl = C(1, 2)/C(3, 2).
The standard errors of the estimated coefficients are calculated from
SE(B) = «(XTX)-l)al )1-
and placed in column 2 of array B( ).
Subroutine MLNRG4
Description
Performs residual analysis, computes predicted value of the dependent variable, the
residual and the standardised residual.
Method
The results of the residual analysis are stored in array R( ). The first column of R
contains the value of the dependent variable predicted from
y=Bl +BlXl + . .. +BkXk
for the values of x provided in the input data and the values of B estimated by
MLNRG2. Predicted and observed values are compared and their difference stored
in column 2 of R( ). The third column contains the standardised residual which is
the difference between observed and predicted values of Y divided by the standard
error of estimate, a.
Subroutine Listings
3660 NEXT P
3670 REM
3680 REM CALCULATE MEAN, VARIANCE AND STANDARD ERROR
3690 FOR P = 1 TO NUMIN2
3700 LET H(l,P) D(l,P)/NUMOBS
3710 LET H(4,P) D(P,P) - D(l,P)*H(l,P)
3720 LET H(5,P) SQR(H(4,P))
3730 LET H(3,P) H(4,P)/(NUMOBS- 1)
3740 LET H(2,P) SQR(H(3,P))
3750 NEXT P
3760 REM
3770 REM COMPUTE CORRELATION MATRIX
3780 FOR P = 2 TO NUMIN2
3790 FOR Q = 2 TO NUMIN2
3800 IF H(5,Q) = 0 THEN GOTO 3910
3810 LET V1 = D(P,Q) - H(l,P)*D(l,Q)
3820 LET V(P-1,Q-1) = V1/(H(5,P)*H(5,Q))
3830 NEXT Q
3840 NEXT P
3850 RETURN
3860 REM
3870 PRINT " NUMBER OF OBSERVATIONS AND/OR VARIABLES";
3880 PRINT " UNSUITABLE FOR REGRESSION ANALYSIS."
3890 PRINT " NUMOBS = "; NUMOBS; " NUMINV = "; NUMINV
3900 END
3910 REM
3920 PRINT" TOO LITTLE INFO ON SE OF VARIABLE "; Q
3930 END
4000 REM SUBROUTINE: MLNRG2
4010 REM
4020 REM COMPUTES B VALUES BY SOLVING NORMAL EQUS AND
4030 REM FINDS INVERSE OF X'X (SEE TEXT) WITH THE AID
4040 REM OF SUBROUTINE SOLUTN. REQUIRES THE INPUT AND
4050 REM OUTPUT OF SUBROUTINE MLNRG1.
4060 REM
4070 REM VARIABLES:
4080 REM OUTPUT:
4090 REM A() ..... CONTAINS INV. OF X'X IN ROWS
4100 REM AND COLS (1,NUMINV+1)
4110 REM B() ..... COL. 1 CONTAINS B COEFFICIENTS
4120 REM LOCAL: ... MCOL, MDET, ODR, P, Q, R, W()
4130 REM ARRAY DIMENSIONS:
4140 REM A() ..... (NUMINV + 1,2*NUMINV + 3)
4150 REM B() ..... (NUMINV + 1,2)
4160 REM W() ..... (NUMINV + 2 )
4170 REM
4180 REM COPY X'X, IDENTITY MATRIX AND X'Y INTO A()
4190 FOR P = 1 TO NUMIN1
4200 FOR Q = 1 TO NUMIN1
4210 LET A(P,Q) = D(P,Q)
4220 NEXT Q
4230 FOR Q = NUMIN2 TO 2*NUMIN1
4240 LET A(P,Q) = 0
4250 NEXT Q
The Subroutines 93
Sample Program
Fit the equationy = Bl + B2X2 + B3X3 + B4X4 to the data presented in the table
below. Generate an ANOVA table and comment on the goodness of fit.
Y X2 X3 X4
ANALYSIS OF RESIDUALS
The equation
y = 12.74 + 37lxz - 2.l8lx3 - 4.92x4
has been determined by least squares regression.
Examination of the standard errors shows that the coefficients B z and B4 lie
within two standard errors of zero and consequently Xz and X4 are important in
the determination of y. The value of x 3 however is less clear and further analysis
may be appropriate to judge whether or not this parameter should be retained.
Overall the model provides a very close fit to the data:
(a) The residual mean square is low.
(b) The multiple regression coefficient R Z indicates a fit of 99.6 per cent.
(c) Observed and predicted values are close.
The Subroutines 99
Notes
1. Most practical regression problems produce normal equations that are well
behaved, however certain properties of the input data could cause execution of
the program to be disrupted and some error detection is included within the sub-
routines to assist with diagnosis. Interruption will occur if the input data contain
insufficient information to permit the solution of the normal equations or esti-
mation of the variance of the data. Rounding errors may cause disruption in the
case of ill-conditioned equations. If ill-conditioning is detected a warning is printed
by subroutine MATDET though interruption of the program will only occur if
gross inaccuracy causes subsequent failure (such as square-root error). Ill-
conditioning may cause values of the coefficients B to be determined which fit
the data well and yet which may be widely different from true values.
2. The computed value of residual may be effectively zero under some circum-
stances. In such cases a small but finite value for error variance is substituted, a
warning message is issued and computation continued.
3. Scheffe (1959), Chatfield (1970), Davis and Goldsmith (1972), Miller (1981)
and Wonnacott and Wonnacott, (1981) are suggested for further reading.
100 Advanced BASIC Scientific Subroutines
POLYNOMIAL REGRESSION
Subroutine: POLYRG
Description
Method
Fitting the polynomial relationship is exactly the same as fitting multiple regression
with Z, Zl , Z3, ... ,zk-l replacing the values of the independent variables Xl,
X3, X4, •.. ,xk-l for a polynomial of degree k - 1
The subroutine POLYREG transforms the input data so that they are in a form
suitable for MLNRG 1. The value for z is placed in the first column of F( ) and the
value for y in the second. The degree of the polynomial is selected and POLYRG
generates the higher orders of z for each observation.
Subroutine Listing
Sample Program
>RUN
NUMBER OF OBSERVATIONS = 9
DEGREE 3
PREDICTED VALUES
6 3 6 6.866
7 4 26 25
8 5 60 61. 21
9 6 122 121. 5
The polynomial
y = 0.996 + 1.83z - 2.96z 2 + Z3
is found to fit the data. The coefficients of Z, Z2 and Z3 are all significant. The
value of R 2 indicates a very close fit overall though for values of y predicted near
zero the fit may be considered inadequate. Methods of improving the fit in this
region could include the fitting of a higher-order polynomial or increasing the
number of data points in this area.
Notes
Description
Method
1. Addition. If A and B are two matrices of the same order with elements of
atj and b ij respectively, then their sum A + B is given by the resultant matrix C
with elements Cji =ajj + b j/ . C is of the same order asA and B.
2. Subtraction. Similar to addition but with C =A - B where cli =ajj - b ij .
3. Multiplication by a constant. If a matrix A with element ail is multiplied by
a constant k, the resultant matrix is Cwith element Cti = k.aii'
4. Transpose of a matrix. This is a matrix with rows and columns interchanged.
If C = A T then element aij in A becomes equal to element cii in C.
5. Multiplication of two matrices. Two matrices can be multiplied if they are
compatible; that is, if the number of columns of the first matrix is equal to the
number of rows of the second. If A is of order m x nand B is of order n x p,
then the product C = A *B is of order m x p with elements
n
cii = 1: aik·bkj
k=l
In the subroutines MATADD and MATSBT the matrices A andB are stored in
two-dimensional arrays A() and B() respectively. The resultant matrix Cis
stored in the array A( ) and over-writes the previous matrix A. This facilitates
further mathematical operations. Likewise in the subroutines MATCNT and
MATTRN the input matrix A and the resultant matrix C are stored in the array
A(). However, in the subroutine MATMUL the two matrices to be multiplied
are stored in the arrays A( ) and B( ) and the resultant matrix is stored in the
array C(). Care must be taken in dimensioning these arrays correctly. The
minimum allowable dimensions depend on the operations carried out. If p is
equal to the maximum row or column size of any array acted upon by the
subroutine, then the choice of dimension (p, p) for arrays A(), B() and C()
will prove satisfactory.
The Subroutines 105
The subroutine MATRED is written to read input matrices A and B via the
DATA statement from the main program. The selection is implemented by
setting the input variable RED$ equal to 'A' to read matrix A or 'B' to read
matrixB.
The subroutine MATWRT is written to print matricesA,B or C. The input
variable WRT$ is set to either' A' to write matrix A, 'B' to write matrix B or
'C' to write matrix C.
Subroutine Listing
6340 END
7000 REM READ IN TWO MATRICES
7010 REM
7020 REM SUBROUTINE: MATRED
7030 REM
7040 REM READS MATRICES A AND B FROM A DATA STATEMENT
7050 REM
7060 REM VARIABLES:
7070 REM INPUT:
7080 REM A() •.... INPUT MATRIX A
7090 REM ACOL .... NUMBER OF COLUMNS IN A()
7100 REM AROW .... NUMBER OF ROWS IN A()
7110 REM B(j ..... INPUT MATRIX B()
7120 REM BCOL .•.. NUMBER OF COLUMNS IN B()
7130 REM BROW .... NUMBER OF ROWS IN B()
7140 REM RED$ .... "A" TO READ AI), "B" TO READ B
7150 REM LOCAL .... P,O
7160 REM ARRAY DIMENSIONS:
7170 REM A() ..... (AROW, ACOL)
7180 REM B() ..... (BROW, BCOL)
7190 REM
7200 IF RED$ = "B" THEN GOTO 7300
7210 IF REDS <> "A" THEN GOTO 7390
7220 REM
7230 REM READ MATRIX A
7240 FOR P = 1 TO AROW
7250 FOR 0 = 1 TO ACOL
7260 READ AIP,O)
7270 NEXT 0
7280 NEXT P
7290 GOTO 7370
7300 REM
7310 REM READ MATRIX B
7320 FOR P = 1 TO BROW
7330 FOR 0 = 1 TO BCOL
7340 READ B(P,O)
7350 NEXT 0
7360 NEXT P
7370 REM
7380 RETURN
7390 REM
7400 PRINT" INVALID REDS, RED$ "; REDS
7410 END
8000 REM WRITE OUTPUT MATRICES
8010 REM
8020 REM SUBROUTINE: MATWRT
8030 REM
8040 REM PRINTS MATRICES A, BAND c.
8050 REM
8060 REM VARIABLES:
8070 REM INPUT:
8080 REM A() ....• INPUT MATRIX A
8090 REM ACOL .... NUMBER OF COLUMNS IN A()
8100 REM AROW .... NUMBER OF ROWS IN A()
The Subroutines 109
Sample Programs
>RUN
INPUT MATRIX A:
1 2 3 4
5 6 7 8
9 10 11 12
INPUT MATRIX B:
1 4 7 10
2 5 8 11
3 6 9 12
TRANSPOSE OF (2.5*A - B)
A= ( ; : D
n=C: _; ~)
112 Advanced BASIC Scientific Subroutines
>RUN
INPUT MATRIX A:
2 1 2
3 5 7
1 0 1
INPUT MATRIX B:
-3 1 0
6 2 1
1 -1 2
2 2 5
28 6 19
-2 0 2
-3 2 1
19 16 27
1 -4 -3
The products of A.B and B.A are not equal. This example illustrates the non-
commutative law of matrix multiplication.
Notes
Subroutine: MATEGN
Description
Finds the eigenvectors and eigenvalues of a real symmetric matrix by the Jacobi
diagonalisation method.
Method
Subroutine Listing
Sample Program
Escape
>RUN
INPUT MATRIX A:
11 8 5 4.5
8 6 5.3 4
5 5.3 9 7
4.5 4 7 8
EIGENVALUES
25.594332
=0.21026969
6.9957887
1. 6201487
EIGENVECTORS
The column of eigenvalues printed above are the principal diagonal elements
of the output array A( ). The remaining elements are either zero or very small.
The first column of eigenvector matrix (output array B( )) corresponds to the
first eigenvalues and so forth. Thus
25.594332 corresponds to 0.56739933
0.46192228
0.50952013
0.45285211
etc.
Notes
Description
Method
The subroutines MATDET and MATINY use an array A() to store the input
matrix A and A I J respectively. Therefore the array A( ) will have different number
of columns depending on the subroutine used. For example, if A is an n x n
120 Advanced BASIC Scientific Subroutines
matrix, then the maximum number of columns (variable MeOL) for array A()
will be n for subroutine MATDET and 2n for MATINY.
The array A() is also used for storing the results of the computation in sub·
routine MATINY, consequently the required inverse of matrix A is stored in the
first n x n rows and columns of the array A().
Subroutine Listings
2440 NEXT Q
2450 FOR Q = 1 TO ODR
2460 LET A(Q,P) = W(Q)
2470 NEXT Q
2480 NEXT P
2490 FOR P = 1 TO ODR
2500 FOR Q = 1 TO ODR
2510 LET A(P,Q) = A(P,ODR + Q)
2520 NEXT Q
2530 NEXT P
2540 RETURN
2550 REM
2560 PRINT " MATRIX A IS SINGULAR AND HAS NO INVERSE"
2570 END
3000 REM DETERMINANT OF A MATRIX
3010 REM
3020 REM SUBROUTINE: MATDET
3030 REM
3040 REM EVALUATION OF THE DETERMINANT OF A MATRIX
3050 REM BY GAUSS ELIMINATION WITH PIVOTING
3060 REM
3070 REM VARIABLES:
3080 REM INPUT:
3090 REM A() ..... INPUT MATRIX
3100 REM MCOL .... MAXIMUM NUMBER OF COLUMNS IN A()
3110 REM ODR ..... ORDER OF MATRIX
3120 REM OUTPUT:
3130 REM MDET ..... DETERMINANT
3140 REM LOCAL: ...• LMNT, MLTPLR, NDET, PVOT, ROWM,
3150 REM SIGMA, SIGN, rLRNC
3160 REM ARRAY DIMENSIONS:
3170 REM A() ...... (ODR,ODR)
3180 REM
3190 LET SIGN = 1
3200 LET TLRNC = 1E-3
3210 REM
3220 REM EVALUATE SUM OF SQUARES OF ELEMENTS
3230 GOSUB 3740
3240 REM
3250 REM PICK UP PIVOT ELEMENT
3260 FOR P = 1 TO ODR - 1
3270 LET ROWM = P
3280 LET PVOT = ABS(A(P,P»
3290 FOR Q = P + 1 TO ODR
3300 LET LMNT = ABS(A(Q,P»
3310 IF LMNT <= PVOT THEN GOTO 3340
3320 LET ROWM Q
3330 LET PVOT = LMNT
3340 REM
3350 NEXT Q
3360 REM
3370 REM ROW INTERCHANGE
3380 IF ROWM = P THEN GO TO 3460
3390 FOR R = P TO MeOL
122 Advanced BASIC Scientific Subroutines
Sample Program
>RUN
INPUT MATRIX A:
0.15 0.88 1. 33 0.25 0.5
0.34 1.5 5.45 0.64 1.7
0.55 2.5 4.84 0.93 1.87
0.67 3.4 6.78 0.11 3.54
0.7 7;8 0.99 1. 88 1
DETERMINANT -0.28126
INVERSE MATRIX
Notes
detA
-----~1
n n
V(L LAn
;=1 ;=1 '
If this condition is satisfied then a warning is issued without the interruption of the
main program. This test is carried out in subroutine MATDET. Note that the
critical ratio, NDET, triggers the warning when it is';;;; TLRNC. This value may
be adjusted to suit a particular application. Caution should be exercised when ill-
conditioning is detected as the accuracy of the results may be affected.
2. Conte (1965), Bajpai et al. (1974) and Mason (1984) are suggested for further
reading.
The Subroutines 125
2. 7 Interpolation
Subroutine: INTPLN
Description
Method
where
n
Lt(x) = IT (x - Xj)/(Xt - Xj)
;=1
j,pj
Subroutine Listing
2000 REM INTERPOLATION
2010 REM
2020 REM SUBROUTINE: INTPLN
2030 REM
2040 REM EVALUATES A FUNCTION AT A GIVEN POINT BY
2050 REM APPROXIMATING THE FUNCTION FROM A TABLE
2060 REM OF FUNCTION VALUES. USES LAGRANGE'S FORMULA
2070 REM
2080 REM VARIABLES:
2090 REM INPUT:
2100 REM A() •...• ARRAY OF X COORDINATE VALUES
2110 REM B() ••••• ARRAY OF Y COORDINATE VALUES
126 Advanced BASIC Scientific Subroutines
Sample Program
From the following table of function values y = [(x), find the value of y at x =
1.65 by use of the Lagrange interpolating polynomial.
x 0.16 0.25 0.66 1.00 1.44 1.88 2.00 2.30 2.74 3.14
[(x) -0.68 -0.51 0.23 0.68 0.98 0.91 0.82 0.49 -0.22 -1.00
>RUN
Y(1.65) 0.99837168
This example illustrates one of the main applications of the Lagrangian inter-
polating polynomial; that is, evaluating a function at some unknown point when
values of the functions are known at a set of tabular points.
Notes
1. This method fails to give meaningful results if, over the range of the input data,
the function to be interpolated has more than one value of y for any value of x. A
sketch of the data points can be helpful in indicating the nature of the function.
2. It is difficult to estimate errors in interpolation without a prior knowledge of the
nature of the function to be interpolated.
3. Conte (1965), Fox and Mayers (1968) and Conte and De Boor (1972) are sug-
gested for further reading.
128 Advanced BASIC Scientific Subroutines
Subroutine: CHBSHV
Description
Method
Bn = 2 1- k (n +kk)/2)
Subroutine Listing
Somple Program
>RUN
COEFFICIENTS OF T( 1} :
1 0
COEFFICIENTS OF X-1
1 0
COEFFICIENTS OF T( 2} :
2 0 -1
COEFFICIENTS OF X-2
1 0 1
COEFFICIENTS OF T( 3) :
4 0 -3 0
COEFFICIENTS OF X-3
1 0 3 0
COEFFICIENTS OF T( 4) :
8 0 -8 0 1
COEFFICIENTS OF X-4
1 0 4 0 3
COEFFICIENTS OF T( 5) :
16 0 -20 0 5 0
COEFFICIENTS OF X-5
1 0 5 0 10 0
COEFFICIENTS OF T( 6} :
32 0 -48 0 18 0 -1
COEFFICIENTS OF X-6
1 0 6 0 15 0 10
COEFFICIENTS OF T( 7) :
64 o -112 0 56 0 -7 0
COEFFICIENTS OF X-7
1 0 7 0 21 0 35 0
COEFFICIENTS OF T( 8) :
128 o -256 0 160 0 -32 0 1
132 Advanced BASIC Scientific Subroutines
COEFFICIENTS OF r8
1 0 8 0 28 0 56 0 35
COEFFICIENTS OF T( 9) :
256 o -576 0 432 0 -120 0 9 0
COEFFICIENTS OF r9
1 0 9 0 36 0 84 0 126 0
Note
Hamming (1962) Ralston and Wilf (1'962), Conte and De Boor (1972) and Bajpai
et al. (1974) are suggested for further reading.
The Subroutines 133
FOURIER ANALYSIS
Subroutine: FURIER
Description
,=1
where n is the number of equally-spaced data points; (n - 1) is the period of the
function; r is the set of harmonic indices; and k = 2rrx/(n - 1).
Method
To fit the data points Y(Xl)' y(xz) ... ,y(xn) to the Fourier series, the harmonic
coefficients a, and b, need to be computed. The method used in the computation
is indicated in the following formulae.
n-l
ao =(l/(n - 1»(y(xl) + ~ Y(Xj» and b o =0
;=2
To improve the general level of accuracy, the average value, ao, is subtracted
from the data in the following calculations:
n-l
a, =(2/(n - 1» (y(Xl) + ~ «y(x/) - ao)Cj» and
j=2
n-l
b, =(2/(n - 1» ~ «y(Xj) - ao)S/) where
/=2
Subroutine Listing
2580 REM
2590 REM COMPUTE FOURIER COEFFICIENTS
2600 LET SIGMAA = D(l) - A(l)
2610 LET SIGMAB = 0
2620 FOR 0 = 2 TO V1
2630 SIGMAA SIGMAA + (D(O) - A(l»*C(Q)
2640 SIGMAB = SIGMAB + (0(0) - A(l»*S(Q)
2650 NEXT 0
2660 LET A(P + 1) 2*SIGMAA/V1
2610 LET B(P + 1) 2*SIGMAB/V1
2680 REM
2690 REM COMPUTE DATA POINTS FROM FOURIER APPROX.
2100 F(l) = F(l) + A(P + 1)
2110 FOR 0 = 2 '1'0 NUMDA'I'
2120 F(Q) = F(Q) + A(P + l)*C(Q) + B(P + l)*S(Q)
2130 NEXT 0
2140 NEXT P
2150 LET F(NUMDAT) F(l)
2160 REM
2110 RETURN
2180 REM
2190 PRINT " NO. HARMONICS TOO HIGH OR NUMDA'r INVALID"
2800 PRINT" NHRMC = "; NHRMC; ", NUMDAT = "; NUMOAT
2810 END
2820 REM
2830 PRINT" FIRS'r AND LAST DATA POINTS NOT EQUAL,"
2840 PRINT" FIRST AND LAST DATA: "; D(l), D(NUMDAT)
2850 END
Sample Program
time 0 1 2 3 4 5 6 7 8
sig. 15.5 20.5 4.69 9.09 16.5 5.4 9.31 11.8 -2.02
time 9 10 11 12 13 14 15 16 17
sig. 4.61 10.6 -3.54 1.48 10.9 5.16 15.5 20.5 4.69
Approximate the signal by a Fourier series. Use the first sixteen observations
to determine the Fourier coefficients as far as the sixth harmonic.
136 Advanced BASIC Scientific Subroutines
HARMONIC AR BR
o 7.999 o
1 2.994 3.99
2 2.006 -7.65E-3
3 2.488 5.96E-9
4 -5.744E-3 -1.008E-2
5 -6.667E-4 6.999
6 1. 338E-2 2.409E-8
FOURIER APPROXIMATION
The Subroutines 137
Notes
1. The subroutine performs some checks on the input data and the program will
be interrupted and a warning issued:
(a) If the number of harmonics to be computed is too high for the available data;
that is, ifNHMRMC > (NUMDAT - 1)/2.
(b) If the first and last data points are not equal.
(c) If fewer than three items of data are available.
2. A value for NHRMC of zero or less will cause the mean value of the function
to be computed and stored in A(1).
3. Bajpai et al. (1974) and Hamming (1962) are suggested for further reading.
138 Advanced BASIC Scientific Subroutines
2.9 Calculus
Description
Method
K1 =H.f(xn,Yn)
Kz =H.f(xn +H/2,Yn +K 1/2)
K3 =H.f(xn + H/2,Yn + Kz/2)
K4 =H.f(xn +H,Yn +K3)
and then using the recursion formula
Kl =H.y~
Ll =Hg(xn,Yn, zn)
K2 = H.(y~ + Ld2)
L2 =H.g(xn + H/2,Yn + K 1/2, zn + Ld2)
K3 = H(y~ + L2/2)
L3 = Hg(x n + H/2,Yn + K 2/2, zn + L2/2)
K4 = H.(y~ + L 3)
L4 =H.g(xn +H,Yn +K3,Zn +L3)
and Y n +1 = Yn + (Kl + 2K2 + 2K3 + K 4)/6
Y~+1 = y~ + (Ll + 2L2 + 2L3 + L 4)/6
Subroutine Listings
DIFEQ1
DIFEQ2
Sample Programs
1. Solve y' =(6x 2 - 4xy)/(2x 2 + 1) wheny(O) =0 with step size = 1/32 and
number of steps = 13.
Also evaluate v = 2x 3 /( 1 + 2X2) for the same number of steps. Compare these
two results.
>RUN
X Y' Y(X) vex)
0 0 0 0
3.125E-2 5.8403535E-3 6.0916187E-5 6.0916179E-5
6.25E-2 2.3135629E-2 4.8449624E-4 4.8449612E-4
9.375E-2 5.1226602E-2 1.6194822E-3 1. 6194818E-3
0.125 8.9072543E-2 3.7878798E-3 3.7878788E-3
0.15625 0.13533008 7.2742105E-3 7.2742086E-3
0.1875 0.18844904 1.2317521E-2 1. 2317518E-2
0.21875 0.24677412 1.910651lE-2 1.9106506E-2
0.25 0.30864197 2.7777784E-2 2.7777778E-2
0.28125 0.37246515 3.8416956E-2 3.8416948E-2
0.3125 0.4367978 5.1062102E-2 5.1062092E-2
0.34375 0.50038058 6.5708938E-2 6.5708926E-2
0.375 0.56216536 8.2317087E-2 8.2317073E-2
From the computer printout it can be seen thaty(x) is equal to vex) for six signi-
ficant figures. In fact, vex) is the exact solution of the given differential equation
y'(x).
2. Solve the second-order equationy" = 2y 3 wheny(1) = 1 andy'(l) = 1 with
step size = 1/32 and 33 steps. Also evaluate v = 1/x for the same step values and
compare the results.
1070 REM
1080 REM DEFINE DIFFERENTIAL EQUATION TO BE SOLVED
1090 DEF FNF(X,Y,Z) = 2*Y 3 A
1100 REM
1110 REM DEFINE FUNCTION TO BE EVALUATED
1120 DEF FNV(X) = l/X
1130 REM
1140 REM ARRAY DIMENSIONS:
1150 DIM A( 34)
1160 DIM B(34)
1170 DIM C(34)
1180 REM
1190 REM INITIALISE VARIABLES
1200 LET XO = 1
1210 LET YO = 1
1220 LET ZO = -1
1230 LET H = 1/32
1240 LET NUMSTP = 33
1250 REM
1260 REM EVALUATE AND PRINT RESULTS
1270 REM CALL SUBROUTINE DIFEQ2
1280 GOSUB 2000
1290 PRINT" X", " yll', " YIX)";
1300 PRINT" V(X)"
1310 FOR I = 1 TO NUMSTP
1320 LET X = A(I)
1330 PRINT A(I), C(I), B(I), FNVIX)
1340 NEXT I
1350 END
>RUN
X Y' Y(X) V(X)
1 -1 1 1
1.03125 -0.9403122 0.96969698 0.96969697
1.0625 -0.88581312 0.94117649 0.94117647
1.09375 -0.83591833 0.91428575 0.91428571
1.125 -0.7901234 0.88888893 0.88888889
1.15625 -0.74799117 0.86486491 0.86486486
1.1875 -0.7091412 0.84210532 0.84210526
1. 21875 -0.6732412 0.82051288 0.82051282
1. 25 -0.6399999 0.80000007 0.8
1. 28125 -0.6091611 0.78048788 0.7804878
1.3125 -0.58049874 0.76190484 0.76190476
1.34375 -0.55381274 0.74418613 0.74418605
1. 375 -0.52892547 0.72727282 0.72727273
1.40625 -0.50567886 0.71111121 0.71111111
1. 4375 -0.48393178 0.69565228 0.6956'5217
1.46875 -0.46355799 0.68085118 0.68085106
1.5 -0.44444426 0.66666679 0.66666667
1. 53125 -0.42648876 0.65306135 0.65306122
1. 5625 -0.40959979 0.64000013 0.64
1.59375 -0.39369451 0.62745112 0.62745098
1. 625 -0.37869799 0.61538477 0.61538462
1.65625 -0.3645423 0.60377374 0.60377358
144 Advanced BASIC Scientific Subroutines
Again it can be seen by comparing values of y(x) and v(x) that y(x) is equal to
v(x) to six significant figures and v(x) is the exact solution ofy"(x).
Notes
Description
Method
1. Trapezium rule. This method divides the area bounded by the limits A and B
into a number of trapezia each of width H. Summing the areas of trapezia gives
I A
B
F(x)dx ~ H/2 [{F(A) + F(B)} +
2{F(A +9) +F(A + 2H) + ... +F(A +(N - 2)H)}]
where
H =(B - A )/(N - I) and N = number of ordinates
A =lower limit and B = upper limit.
2. Simpson's rule. This method divides the area bounded by the limits into an
even number of parallel strips of width H, and approximates the area of pairs of
strips using parabolas. Thus
fA
B
F(x)dx ~ H/3 [{F(A) + F(B)} +
4{F(A + H) + F(A + 3H) + ... + F(A + (N - 2)H)} +
2{F(A + 2H) + F(A + 4H) + ... +F(A + (N - 3)H)}]
where
H= (B -A)/(N - 1) and
N = number of ordinates which should be an odd integer.
3. Discrete data set. If the function F(x) is defmed by a set of discrete data
Yt = Y(Xi) at a set of ordinates xi (i = 1, 2, ... ,N) spaced at distance H, then by
Simpson's rule
f B=XN
A-Xl
_ F(x)dx ~H/3 [(yt + YN) + 4(yz + Y4 + ... +YN -1)
+2(Y3+YS + ... +YN-Z)]
where N = number of data points which should be an odd integer.
Subroutines Listings
146 Advanced BASIC Scientific Subroutines
/NTDAT
Sample Programs
f:sinx~
(b) Repeat the exercise by using Simpson's rule with 19 ordinates.
>RUN
INTEGRAL BY TRAPEZIUM METHOD 1. 9998322
The exact value of the integral is 2. It can be seen from this example that
Simpson's rule provides a better approximation than does the trapezium rule, and
with fewer subdivisions. A disadvantage of Simpson's rule is the requirement for an
even number of steps; this is not a condition for the use of the trapezium rule.
A major limitation of both methods is the need to specify uniform intervals.
Caution should be exercised when integrating functions which exhibit widely
different rates of change over the range of interest.
2. A continuous functionf(x) is defmed by the table below:
x 0 0.30 0.60 0.90 1.20 1.50 1.80
f(x) 2.72 3.00 3.32 3.69 4.06 4.48 4.95
Use Simpson's rule to estimate
f:· S
f(x) dx
1160 NEXT I
1170 REM
1180 REM EVALUATE INTEGRAL
1190 REM CALL SUBROUTINE INTDAT
1200 GOSUB 2000
1210 PRINT " RESULT OF INTEGRATION "; SIGMA
1220 END
>RUN
RESULT OF INTEGRATION = 6.711
The value of the integral is 6.71 to two places of decimals. The above example shows
a useful method of integrating in cases where we only know the ordinates, and not
the function that describes the relation.
Notes
1. A check for input data is made in the subroutines and the main program is
terminated if
(a) the range is incorrectly stated - that is, if the lower limit of integration is
greater than the upper limit,
(b) the number of ordinates is not an odd integer for Simpson's method.
2. The error of the trapezium rule approximation is
- (B _A).H2 f"(c)/12 A<c<B
and for Simpson's method is
- (B -A).H4 f'"'(c)/180 A<c<B
The subroutines do not calculate these error terms. In practice the rule of thumb
applied for determining the accuracy of the result is to re-run the program with
approximately double the number of ordinates than before and then compare the
results. However, note that if the width H gets too small, then the error tends to
increase because of rounding errors.
3. Conte (1965) and Mason (1983) are suggested for further reading.
The Subroutines 151
Subroutine: SOLUTN
Description
Method
Subroutine Listing
2000 REM SOLVES N LINEAR EQUATIONS WITH N UNKNOWNS
2010 REM
2020 REM SUBROUTINE: SOLUTN
2030 REM
2040 REM SOLVES SYSTEMS OF LINEAR EQUATIONS OF FORM
2050 REM A*X = B BY GAUSS ELIMINATION WITH PIVOTING
2060 REM REQUIRES SUBROUTINE MATDET
2070 REM VARIABLES:
2080 REM INPUT:
2090 REM A() ..... LOCATION MATRIX FOR AIB .•. COEFF.
2100 REM MATRIX- ADJOINED WITH CONST. MATRIX
2110 REM MCOL .... MAXIMUM NUMBER OF COLUMNS IN A
2120 REM (ODR + NO. OF SYSTEMS TO SOLVE)
2130 REM ODR ..... ORDER OF COEFFICIENTS MA'l'RIX A
2140 REM OUTPUT:
2150 REM A() ..... THE ORIGINAL MATRIX IS OVERWRITTEN
2160 REM BY THE SOLUTION MATRIX
2170 REM LOCAL .... MDET, P,Q,R,W()
2180 REM ARRAY DIMENSIONS:
152 Advanced BASIC Scientific Subroutines
Sample Program
>RUN
INPUT MATRIX A:
SOLUTION MATRIX
1
2
3
4
Hence from the computer printout, Xl =1, X2 =2, X3 =3 and X4 =4. This is an
exact solution and generally this method gives an exact solution if there are no
round-off and other errors. Most personal computers are accurate to eight or nine
significant figures.
Notes
Subroutine: QADEQN
Description
Method
The roots of a quadratic equation of the form Ax2 +Bx + C = 0 are given by the
formulae
Xl = -BI2A + y(D)I2A and X2 = -BI2A - Y(D)I2A
where D is the discriminant B2 -4A C. However. in the presence of significant
error the use of above formula may adversely affect the results. When AC is small
compared with B2 then better results can be obtained by making use of root-
product relation, that is
X2 == C/(A. X1)
The root Xl is calculated using the standard formula but in order to avoid the
terms (-B ± Y(D) )/2A becoming zero the sign of yD is chosen to be + if B is
negative and - if B is positive.
The types of roots are determined by the nature of the discriminant, that is
(i) if B2 - 4AC> 0 then Xl and X2 are real roots,
(il) if B2 - 4AC= 0 then Xl =X2,
(iii) if B2 - 4AC < 0 then Xl and X2 are complex roots.
These roots are stored in the output array R( ). Thus
Xl =R(l) + iR(2) and
X2 = R(3) + iR(4)
If the two roots are real then the imaginary parts R(2) and R( 4) are made zero.
Subroutine Listing
Sample Program
1060 REM
1070 REM SET INITIAL VALUES
1080 LET A 10
1090 LET B 7
1100 LET C -12
1110 REM
1120 REM COMPUTE ROO'rS AND PRINT RESULTS
1130 REM CALL SUBROUTINE QADEQN
1140 GOSUB 2000
1150 PRINT " REAL PARTS IMAGINARY PARTS"
1160 PRINT
1170 PRINT R (1), R(2)
1180 PRINT
1190 PRINT R( 3), R(4)
1200 END
>RUN
REAL PARTS IMAGINARY PARTS
-1. 5 o
0.8 o
Note
The value of coefficient A is checked for magnitude as small values may cause
overflow when the reciprocal is calculated. B2 and A. C are also computed by the
subroutine and place an upper limit on the magnitudes of A, Band C.
The Subroutines 157
Subroutine: CUBEQN
Description
Method
Yl =VCOS(J
Y2 = VCOS((J + 21f/3) and
Y3 = Vcos((J + 41f/3)
Finally, the roots of the original cubic equation are given by
Xl = Yl - z/3
X2 = Y2 - z/3 and
X3 = Y3 - z/3
The input array A() stores the coefficients of descending powers of X, while
the output array R( ) stores the roots of the cubic equation. Thus
Xl = R(I) + iR(2)
X2 = R(3) + iR(4) and
X3 = R(5) + iR(6)
If all the roots are real, then the imaginary parts of the roots iR(2), iRe 4) and
iR(6) are zero.
Subroutine Listing
2810 REM
2820 PRINT" THE COEFF. OF X 3 IS SMALL. SOLUTION"
A
Somple Program
Solve x 3 + 3x2 + 6x - 3 = O.
>RUN
REAL PARTS IMAGINARY PARTS
0.40628758 0
-1.7031438 2.1173648
-1.7031438 -2.1173648
Notes
1. The variable TLRNC may be adjusted to suit the numerical range of the machine
in use.
2. Inverse cosine is not available on some versions of BASIC, though inverse
tangent generally is. ATN is employed to generate ACS when a trigonometrical
solution is required.
3. Stephenson (1969) and Lee and Lee (1982) are suggested for further reading.
162 Advanced BASIC Scientific Subroutines
Description
Finds the solution of an equation of the form I(x) = 0 by Newton's method and
the method of bisection.
Method
Subroutine Listing
Sample Program
Find two real roots of the equation 4X4 - 2.5x 2 - X + 0.5 =0 by using first the
bisection method and then Newton's approximation. Use (0, 0.5) and (0.5, 1) as
the initial bounds and 0.25 and 0.75 as the starting value for the roots.
1170 PRINT
1180 REM
1190 REM FIND ROOT BY NEWTON'S METHOD, INPUT INITIAL
1200 REM ROOT. CALL SUBROUTINE NEWITR
1210 INPUT " GUESSED ROOT "i GRT
1220 PRINT " GUESSED ROOT = " , GRT .
1230 GOSUB 2000
1240 PRINT " ROOT BY NEWTON'S METHOD " , RT .
1250 PRINT
1260 END
>RUN
LOWER BOUND 70
LOWER BOUND = 0
UPPER BOUND 1.5
UPPER BOUND = 0.5
ROOT BY BISECTION METHOD 0.303576
>RUN
LOWER BOUND 1.5
LOWER BOUND = 0.5
UPPER BOUND 11
UPPER BOUND = 1
ROOT BY BISECTION METHOD 0.864243
The required roots are 0.303576 and 0.864243. The accuracy of these solutions
may be checked by substituting back in the original equation.
Notes
3. BISECT is simple to use and can prove helpful in indicating the location of roots.
Its disadvantage is that it converges more slowly than Newton's method and gener-
ally a greater time is required to achieve the desired accuracy.
4. Conte and De Boor (1972), Lee and Lee (1982), Miller (1981) and Mason
(1983) are suggested for further reading.
The Subroutines 167
Subroutine: COMPLX
Description
Method
a b quadrant
+ve +ve 1st
+ve -ve 4th
168 Advanced BASIC Scientific Subroutines
Subroutine Listing
2290 LET AI = AI - BI
2300 GOTO 3090
2310 REM
2320 REM MULTIPLICATION A = A*B
2330 REM
2340 LET V1 = AR
2350 LET AR = AR*BR - AI*BI
2360 LET AI = V1*BI + AI*BR
2370 GOTO 3090
2380 REM
2390 REM DIVISION A = A/B
2400 REM
2410 LET V1 = AR
2420 LET V2 = BR*BR + BI*BI
2430 IF V2 = 0 THEN GOTO 3110
2440 LET AR = (AR*BR + AI*BI)/V2
2450 LET AI = (AI*BR - V1*BI)/V2
2460 GOTO 3090
2470 REM
2480 REM RECIPROCAL A = l/A
2490 REM
2500 LET V2 = AR*AR + AI*AI
2510 IF V2 = 0 THEN GOTO 3140
2520 LET AR = AR/V2
2530 LET AI = -AI/V2
2540 GOTO 3090
2550 REM
2560 REM SQUARE A = A*A
2570 REM
2580 LET V1 = AR
2590 LET AR = AR*AR - AI*AI
2600 LET AI = 2*V1*AI
2610 GOTO 3090
2620 REM
2630 REM POLAR FORM OF A
2640 REM
2650 LET RPI = 3.1415926536
2660 LET AMOD = SQR(AR*AR + AI*AI)
2670 IF AR = 0 THEN GOTO 2740
2680 LET AARG = ATN(AI/AR)
2690 REM
2700 REM DETERMINE QUADRANT FOR AARG
2710 IF AR < 0 AND AI < 0 THEN LET AARG AARG - RPI
2720 IF AR < 0 AND AI >= 0 THEN LET AARG = AARG + RPI
2730 GOTO 3090
2740 REM AR = 0
2750 IF AI = 0 THEN GOTO 3170
2760 IF AI < 0 THEN LET AARG = -RPI/2
2770 IF AI > 0 THEN LET AARG = RPI/2
2780 GOTO 3090
2790 REM
2800 REM INVERSE POLAR FORM OF A
2810 REM
2820 LET RPI = 3.1415926536
170 Advanced BASIC Scientific Subroutines
2830 IF AARG < -RPI OR AARG > RPI THEN GOTO 3210
2840 IF AMOD < 0 THEN GOTO 3210
2850 LET AR = AMOD*COS(AARG)
2860 LET AI = AMOD*SIN(AARG)
2870 GOTO 3090
2880 REM
2890 REM COpy B INTO A, A =B
2900 REM
2910 LET AR = BR
2920 LET AI = BI
2930 GOTO 3090
2940 REM
2950 REM COPY A INTO B, B A
2960 REM
2970 LET BR = AR
2980 LET BI = AI
2990 GOTO 3090
3000 REM
3010 REM EXCHANGE A AND B, A = B, B = A
3020 REM
3030 LET V1 = AR
3040 LET AR = BR
3050 LET BR V1
3060 LET V1 AI
3070 LET AI BI
3080 LET BI = V1
3090 REM
3100 RETURN
3110 REM
3120 PRINT" MODULUS OF B = 0 AT DIVISION"
3130 END
3140 REM
3150 PRINT" MODULUS A = 0 AT RECIPROCAL"
3160 END
3170 REM
3180 PRINT" AI = 0, AR = 0, AARG INDETERMINATE"
3190 PRINT" AT POLAR FORM"
3200 END
3210 REM
3220 PRINT" AMOD NEGATIVE OR AARG OUT OF RANGE AT ";
3230 PRINT "INVERSE POLAR"
3240 PRINT" AMOD = "; AMOD; " AARG = "; AARG
3250 END
Somple Program 1
Ifa = -2 + 3; andb = 1 + 2i, fmd the values ofa + b,a - b,ab and a/b.
>RUN
REAL PARTS IMAGINARY PAR'fS
A + B -1 5
A - B -3 1
A :I< B -8 -1
A / B 0.8 1.4
Hence
a + b = -1 + 5i
a-b=-3+Ii
ab = -8-Ii
alb = 0.8 + l.4i
These results are readily verified by direct calculation.
172 Advanced BASIC Scientific Subroutines
Sample Program 1
~n=zl+lKl~2+1~3+1~J
Determine the input impedance and input admittance (l/ziJ in complex and
polar form whenzl = 2 + 3j, Z2 = 5 + Ij, Z3 = 0 + 2j, Z4 = 3 - 4j.
>RUN
The Subroutines 173
Again the results displayed in the computer printout may be verified by direct
calculation.
References
Adams, A. G. (1969).'Areas under the normal curve', Algorithm 39, Computer J.,
12.
American National Standards Institute (1978). American National Standard for
Minimal BASIC, ANSI X3.60.
Angell, I. O. (1985). Advanced Graphics with the IBM Personal Computer,
Macmillan.
Angell, I. O. and Jones, B. J. (1983a). Advanced Graphics with the BBC Model B
Microcomputer, Macmillan.
Angell, I. O. and Jones, B. J. (1983b). Advanced Graphics with the Sinclair ZX
Spectrum, Macmillan.
Bajpai, A. C. et 01. (1974). Engineering Mathematics, Wiley.
Chatfield, C. (1970). Statistics for Technology, Penguin.
Conte, S. D. (1965) Elementary Numerical Analysis, McGraw-Hill.
Conte, S. D. and De Boor, C. (1972). Elementary Numerical Analysis - An
Algorithmic Approach, 2nd edition, McGraw-Hill.
Davis, O. L. and Goldsmith, P. L. (1972). Statistical Methods in Research and
Production, 4th edition, Oliver and Boyd.
Fox, L. and Mayers, D. F. (1968). Computing Methods for Scientists and
Engineers, Oxford University Press.
Froberg, C. E. (1970). Introduction to Numerical Analysis, 2nd edition, Addison-
Wesley.
Gosling, P. (1982). Practical BASIC programming, Macmillan.
Griffiths, P. and Hill, I. D. (editors) (1985a). 'Algorithm AS66 The normal integral'
by I. D. Hill, in Applied Statistics Algorithms, Ellis Horwood, p. 126.
Griffiths, P. and Hill, I. D. (editors) (1985b). 'Algorithm AS 147 A simple series for
the incomplete gamma integral', by Chi-Leung Lau, in Applied Statistics
Algorithms, Ellis Horwood, p. 203.
Griffiths, P. and Hill, I. D. (editors) (1985c). 'Algorithm AS63 The incomplete
beta integral', by K. L. Majumler and G. P. Bhattacharjee, in Applied Statistics
AlgOrithms, Ellis Horwood, p. 117.
Hamming, R. W. (1962). Numerical Methods for Scientists and Engineers, McGraw-
Hill.
Iyanaya, S. and Kawadu, Y. (editors) (1980). Encyclopedic Dictionary of Mathe-
matics, Mathematical Society of Japan, MIT Press.
Kreyszig, E. (1983). Advanced Engineering Mathematics, 5th edition, Wiley.
Lee, J. D. and Lee, T. D. (1982). Statistics and Computer Methods in BASIC,
Van Nostrand Reinhold.
Mason, J. C. (1983). BASIC Numerical Methods, Butterworths.
Mason, J. C. (1984). BASIC Matrix Methods, Butterworths.
Miller, A. R. (1981). BASIC Programs for Scientists and Engineers, Sybex.
174
References 175
176
Index 177