0% found this document useful (0 votes)
183 views

Appendix and Index

This document provides an overview of matrices and their properties, including: 1. Matrices can be square, identity, row vectors, column vectors, transposed, zero, or equal. 2. The basic matrix algebra operations are addition, subtraction, and multiplication. 3. The trace of a matrix is the sum of its diagonal elements. The determinant of a matrix represents its size and can be used to solve systems of equations. 4. Minors and cofactors are used to calculate the determinant by expansion, and the adjoint matrix is related to the cofactors. The inverse of a matrix allows solving systems of equations.

Uploaded by

kankirajesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

Appendix and Index

This document provides an overview of matrices and their properties, including: 1. Matrices can be square, identity, row vectors, column vectors, transposed, zero, or equal. 2. The basic matrix algebra operations are addition, subtraction, and multiplication. 3. The trace of a matrix is the sum of its diagonal elements. The determinant of a matrix represents its size and can be used to solve systems of equations. 4. Minors and cofactors are used to calculate the determinant by expansion, and the adjoint matrix is related to the cofactors. The inverse of a matrix allows solving systems of equations.

Uploaded by

kankirajesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 104

H

Solution of Linear
Systems by
Matrix Methods
-__--- -

OVERVIEW OF MATRICES
A matrix is a rectangular array of elements arranged in rows and col-
umns. If the matrix contains in rows and n columns, the matrix is said
1.0 be of size in x a. The element in the ith row and jtii column of the
matrix A is denoted by 07. For example,

all a12 a13


072 023
(1 31 a 32 a33
L a 41 04 a43]

is a 4 x 3 matrix.

Types of Matrices
Matrices may belong to one of the many types discussed here.
1.Square Matrix A matrix in which rows in is equal o columns a.
2. identity Matrix A square matrix in which all the diagonal elements
are one and other elements are zero. That is
a1 for i=j
a ,, = 0 for ij
Numerical Methods

Identity matrices are denoted by I. For example, a 3 x 3 identity is


written as
100
1= 0 1 0
0 0 lJ

3. Pow Vector A matrix with one row and n columns.


4. Column Vector A matrix with in rows and one column.
5. Transpose Matrix The matrix A 7' is called the transpose of A if the
element a0 in A is equal to element aj, in AT for all i and j. For example,
if

[1 2
A=13 "
[5 6
then,
AT 11 3 5
2 4 6
It is clear that AT is obtained by interchanging the rows and the columns
of A.
6. Zero Matrix A matrix in which every element is zero.
7. Equal Matrix A matrix is said to be equal to another matrix if and
only if they have the same order and the corresponding elements are
equal. That is,
matrix A = matrix B
if = b i, for all i audi,

Matrix Algebra
We can perform only three operations, namely, addition, subtraction and
multiplication on the matrices. The division, although not defined, is
replaced by the concept of inversion discussed later.
Two matrices A and B can be added together (or subtracted from each
other) if they are of the same order. Then
sum C = A + B
can be obtained by adding the corresponding elements. That is,
c 1— a0 +b v for all i and
Similarly,
difference E A - B
can be obtained by subtracting the corresponding elements. That is,
= a0 - b v for all i and
Solution at Linear Systems by Matrix Methods

Two matrices A and B can be multiplied in the order AB if and only if


the number of columns of A is equal to the number of'rows of B. That is,
if A is of order in x r, then B should be of order r x n where rn and it are
arbitrary values. In such cases, we may obtain
P - AR
which is of order in x n. Elements of the matrix P is given by

J) =ap b A for all i and

The following general properties apply to rnatr3x algebra.


1. A±B=B±A
2. A±(B±C)=(A±B)±C
3, (A ± B) T = A T ± B'
4. 1A = Al, where I is identity matrix
5. (AB)C=A(BC)
6. C(A + B) CA + CB
7. (A+B)C=AC+BC
8. a(AB) = (aA)B = ACaR), where a is a scalar

Traces and Determinants


The trace of a matrix is the number obtained by adding its diagonal
elements (from upper left corner to the lower right corner). For example,
the trace of the matrix

[Uii 012 013


A=a 21 a22 a23 is a, + a 22 + a33
a 31 (133 (133

The determinant of a 2 x 2 matrix, sa y A, is written in the form


a 11 a12
CL 22

and the determinant is computed as


a 11 U 93 - a12
Similarly, for a 3 x 3 matrix the determinant is given by

a ll a 12 a13
Al a 31 a 22 1(23
=
1 a 32 a33

23' a21 a 23 a21 a22


-a
=all -l2 +013
a 32 a 33 a31 (133 a31 a 32
Numerical Methods

= a 11 (a 22cz - aa) - a(a21a - a31a23)


+ a 13 (a 21a 32 — 172a31)
= a 11a 22a + a1 ' . 13a21a32 - a11a32a
- a 21 a 12a 53 - a31aa13
Note that there are 6 product terms added together, For larger matrices,
the determinant is much more difficult to deflne and compute manually.
In general, for an n x matrix, the determinant will contain a sum of n
signed product terms, each having n elements.
Some of the important properties of determinants that would be help-
ful in computing their values are:
1. Interchanging two rows (or two columns) of a matrix changes the
sign of the determinant but not the value.
2. If two rows (or columns) of a matrix are identical then its determi-
nant is zero.
3. If a matrix contains a row (or column) of all zeros, then its determi-
nant is zero.
4. Value of the determinant of a matrix does not change when a
scalar multiple of one row (or column) is added to another row (or
column).
6. If every element of a row (or column) is multiplied by a scalar u,
the value of the determinant is multiplied by u.
6. If A and B are square matrices of same size, then J AB I A I IBI.
7. For a triangular matrix (in which all the elements below (or above)
the diagonal are zero), the determinant is the product of the diago-
nal elements.

Minors and Cofactors


The minor M j of the element u j of the determinant J A I is obtained by
striking out the ith row and jth column. That is,

C' 22 a23 , = a ll (213


M• 1W22
a 32 a 33 a31 a33

and so on. That is, the minor of a particular element is the determinant
that remains after the row and the column that contain the element
have been deleted.
The cofactor of an element is its minor with a sign attached. The
cofactor d, of an element a0 is given by
d0 = ( _ 1)t "
The value of the determinant of a matrix can be obtained by expanding
the determinant by cofactors. This is done by choosing any column or
row and determining the sum of the product of eac i element in the
chosen row or column and its cofactor.
Solutn of Urear Systems b y Matrix Methods 509

Ad joint Matrix
If d, is the cofactor of the element o, of the square matrix A, then, by
definition, the adjoint matrix of A is given by
ac(A)
Where

[111 C!10 dL1 -

H l 22

[d d2

Inverse of a Matrix
If 3 and C are two n x n square matrices such that
BC CB = I (Identity matrix
then, B is called the inverse of C and C the inverse of A. The common
notation for inverses is B ' and C 1 . That is.
B B =I
C -1 C = I
The concept of matrix inversion is useful iii solving linear s ystems of
equations.

SOLUTION OF LINEAR SYSTEMS BY


-- DETERMINANTS
We can solve a system of linear equations by determinants using a
method called Cramer's Rule. For the sake of simplicity, we consider a
2 x 2 system such as
ax1 -- hx 9 c
dxr ± ex 2 = f
We can solve for the variable x 1 by eliminating the variable x2.
Thus,
ce - hf
A1
Ui? -

Similarly,

af - cd
cxc - bd
IQ NumercoI Methods

Alternatively, we can express x and x 2 using determinants. That is,

c a c
fe
XL = and x2=
czb a
Id e Id e

This is known as Cramer's rule.

Solve the following system of equations using Cramer's rule:


2x + 3X2 = 12
4x 1 - = 10

12
10 -i] -12-30 423
X' - 3 -2-12 14
4
12 -1

2 121
4 101 20-48 28
X2 -==2
2 3I -14 14
4

SOLUTION OF LINEAR SYSTEMS BY


MATRIX INVERSION
A linear system of n equations in r unknowns can be represented in
matrix form as
AK = B
where A, X and B are matrices and are given by

U a12
a 21 a22
A
a, 1 0n2
Solution of Unear Systems by Matrix Methods 5.11

5,
X= x :2 B=

XrJ

A is called coefficient matrix and B is known as contan.t vector. X is


the required solution arid, therefore, it is called the solution vector. If we
multiply the matrix equation
AX = B
By A' on both sides, we get
A'AX=A'B
A' is the inverse matrix of A. We know that A- ' A = I is the identity
matrix and is given by
[i 0 0 ... 0
H 1 0 ... 0
1=001 ...0

0 0 0 ... ii

Therefore,
A-'AX=IXX
is the solution of the system of equations and is obtained from
= GB
If we know the inverse of the matrix A, we can obtain the solution vector
X by past-multiplying it by B.
The inverse A' 1 of a square matrix A exists, if and only if, A is
nonsingular (i.e. det A 0). A' 1 is the matrix obtained from A by replac-
ing each element a j, by its cofactor d and then transposing the resulting
matrix and dividing it by the determinant of A.
adj(A)
C-A
det A
where adj(A) is the adjoint of matrix A and is given by the transpose of
the cofactor matrix of A.
Then
adj(A) = DT
where
d1, d, 2 ... di,,
d2, d 22 ... d2

d, 42 ... d
J.2 Numerical Methods

d1i is the cofactor of the element a and is given by


d, = (-1'
M is called the minor of cz and is taken as the determinant
after deleting itli mw and jth column. of matrix A

Solve the idlowing system using matrix


inversion method
+ x2 + x 3 = 7
-X2 +X 3 =
4x 1 -* 2x2 - 3x3 = 4

21 1
Given, A 1 -1 1 and B=O
[7j
42 -3 4

M
" -- I- 1 d11 = 1
-3

M12=1 _13j=_7
=7

j3 = -1^M =6 =6

M2 = =-5 d21 = 5

M = .H_io = -10

21
Mn4 2 0

I19
M31= =2

2J4
1 ifl1 32

(/33 -3

So'ution o' Unear Systems by Matrix Methods

17 6
D 5 -10 0
2 -1 -3

15 2
AdjA_DT = 7 -10 -1
6 0 -3

det A a l 1d 11 + a 12d 12 + a 13c1 13 15

1 5 2
15 15 15
A'=C=--
15 15 15
6
15 15

[7
B0
[4
We know that X = CB and therefore

1 =-L + o + _ 1
15 15

X2
15 15

+ 0 -- =2
15 15

GAUSS-JORDAN MATRIX INVERSION


The Gauss-Jordan elimination technique (discussed in Chapter 7) can be
used to iuvei-t a matrix effectively. The square matrix A which is to he
inverted is augmented by a unit matrix of the same order as follows.

a 11 (112 11n 1 1 0 0
0 22 a2fl 0 1 0

a, 0 0 1
If we carry out Gauss-Jordan elimination using the first row as a pivot
o-' we get

.I4 Numerical Methods

[1 C12 ... afl 0 ... 0


0 a 21 •.. 1 2n a281 1 0.

L° 0n2
an,, a n, n I

When we repeat the process using the second row as the pivot row, the
result is

1 0 a 13 ... a18 a 1. n t 1 (I],2 0 0


1
() 1 a 23 - 0 a 2 ,4i
2n 02n-2 0 ... 0
o o 3 CZJ Us,, (Z,, f I a 3fl , 2 1 0
o o a fl 3 ... a 8 ann.,1 0n,n42 0 1

This elimination process, if continued for all the it rows, yields the final
result as follows:

Fi 0 0 ... 0
o 1 0 .. 0 8 I a2,l
o o 1 - oa
a,,. 1 n?i41 .fl+rL
O 0 0 ...

The matrix a0 for i = 1 to n andj n + ito 2n is the inverse matrix ofA.


i1.... . fl
C=A(a
=n+ 1,...,2n
where the element
c ) = for i = 1.....a and j 1, ..., a.

Find the inverse of the coefficient matrix of the system given in Example
A2 using Gauss-,Jordan elimination technique.

21 1100
Augmented A = 1 -1 1 0 1 0
4 2 -3 0 0 1

Pivot row-1

1 112 112 112 0 0


0 -3/2 1/2 -112 1 0
0 0 -5 -2 0 1

Solution of Linear Systems by Matrix Methods jl

Pivot row2

1 0 2/3 113 113 0


0 1 -113 1/3 -2/3 0
L° 0 -5 -2 0 1
Pivot row-3

-.0 O I L' l S 113 2/15


o 1 0 7/15 -2/3 -1/15
00 1t2/5 0 -115
The last three columns represent the inverse of the matrix
2 1 1
1 -1 1
4 2 -3
Compare this with the result obtained in the previous section.

Once the inverse of A is known, the solution vector X can be obtained by


simple matrix multiplication. That is
X=A'B = CB
= c 11b 1 + c 1 ), 2 + +
+ c22 2 + + c2,b
and so on.
In general,

= 1cjb1 tr],...,n
i-I
Note that ci, = of augmented A in the final step.

Key Terms

Adjoint matrix Inverse matrix

Coefficient matrix Minor

Co factor Nonsingular matrix

Column vector Row vector

Cramer's rule Square matrix

Determinant Trace of a matrix

Equal matrix Transpose matrix

Identity matrix Zero matrix
APKNOIX

Solution of
Polynomials by
Graeffe's Root
Squaring Method
-

Gracife's rout squaring method is a direct method of finding roots of a


polynomial with real coefficients. This method deserves attention both
for it.s historical interest and a novel idea involved.
Graeffes method transforms a pol y nomial p,(x) into another polyno-
mial of the same degree but whose roots are the squares of the roots of
the original polynomial. Because of the squaring property, the roots of
the new polynomial will he spread apart. more widely than in the origi-
nal one, when the roots are greater than 1 in abolute value. Repeating
this process until the roots are reall y far apa we can compute the
roots directly from the coefficients.
We consider here a simple example to ih1L.,rate the root squaring
technique.
Let.
pox) = Cr - I )(x - 2Yx - 3) tB.1
Then, we consider another function p 1 (y) such that
10P -11 0(x) p(—i)
= ..) - 1.fx - 2)(x -- 3-x - 1)(-x - 2)(-.c 3)
Li -- 1l(x -- 2))x - 3(x + 1)(x + 2)x + 3)
12 - I )C - 4)(x 2 - 9)

=(), 1(y-4)ty-9) B.2)


Solution of Polynomials by Groeffe's Root Squaring Method J.Z


where
Y = x2
We know that the roots of p 0 (x) = 0 are x,= 1, x 2 = 2, and x = 3. And
fre" 'o. (B.2) the roots of P1 ( Y) = 0 are y j = 1,y 2 = 4, and v 3 =9. It shows
that roots of PiY) = 0 are the squares of the roots of PoY = 0. This
implies that if we compute the roots of p 1 (y), then we can obtain the
roots of p 0 (x) from

x1 =

x2 =

Xj =

Now, let us repeat the procedure for finding the roots of p 1 y ). Consider
a third polynomial
P2(z) -p i (y) p1(-y)
= (5 - 1)i.z 16Xz - 81) (B.3)
The roots of Eq. (8.3) are
1 (= y1) -• = x) x1

= 16 (= V)2
Y2 x) --------
z=8l(=y) - - =x) ---. y3(

Iteration 2 Iteration I
That is, after the second iteration, we can estimate the roots of original
equation p 3 x) from the relation
Z1 = (X) 2 =x, i=1,2,3

1-
Suppose we have done the squaring process k times and the roots of the
final equation are r 1 , then

r -x =-(x)' (8.4)
Remember that we never have p 0 (x) in factored form as given in
Eq. (8.1), but the result is the same.
Now, let us consider a third degree polynomial in standard form as
P OW = ax3 + a2x 2 + a 1 x + a 0 (B.5)
Then,
p1(y) = -p 0(-x) p(x)
= ((7 3x 3 + u2x 2 + a 1 x + o,) (a 3 x - a 2 x2 + a 1 x - a0)
= a32
X - (a - 2a 1a3)x4 + (a - 2a0a 2)x - a02

by3 + b2Y + b 1 y 1 + 6 0 (B.6)


Numerical Methods

where
Y x2
and
b3=+a

b2 .- - 2a 1 (1 3 )

= + (a 2 2aa) (B.7)

L bo TL_____
We can thus show that for a general polynomial of degree n,
p 0 (xj = ax + a, - n 1 + + a0
after first squaring process,

r
b,z - -( a 2a /7,, -

ja,:i±2a,,u,,_4

This process can be repeated replacing 'a' values by 'b' values in Eq.
(13.9) each time. Let, us suppose that our final equation after k iterations
(i.e. squaring k times) is
+ B 0 = (J
4 B- (B. 10)
Assuming that the roots of Eq. (BIll) are now more widely separated,
we have
1y11>>Iy2I>>Iy3 ... >>yfl
Then,

Yi
B.
B,, 2
Y2
1fl-I

B0
Y,

That is.
B1
yi ----.--,i=1,2,...,n
i+1

(R.11)
Solution of Polynomials by Graeffes Root Squaring Method

Thus,

E
x = 2 k th root of y = 2t)1_ (B.12)
vi B
The m -'vantage of Graeffe's root squaring method over other meth-
ods is th it does not require any initial guessing about roots. The
method is also capable of giving all the roots but the limitation is that
the polynomial should have only real coefficients.

Apply root squaring technique to estimate the roots of


6x + 8 = 0
Table below shows the coefficients of successive polynomials (using Eq.
(B.7))as well as the roots estimated (using Eq. (B.12)).
Coefficients Roots estimated
a ______ x2 x

0 1 —3 —6 8
1 1 —21 84 —64 4.5826 2.0 0.8729
21 1 -273 4368 —4096 4.0648 2.0 0.9841
3' 1 —65793 16843008 —16777216 1 4.0020 2.0 0.9995
The exact values are 1, —2, and 4. Signs must be determined by substi-
tuting the estimates in the original polynomial. When we substitute an
estimated root, if the value of the pol3momial is zero, then the root is
positive; otherwise negative.
APPENDIX

Difference Operators
and Central Difference
Interpolation
Formulae
—--— --------

INTRODUCTION
In Chapter 9 we have already discussed briefly the application of finite
differences for interpolating the function values. Here we consider again
the finite differences of functions and discuss in detail various operators
used on them. We also discuss here some of the central difference formulae
used for interpolation.

-- MM_FINITE DIFFERENCES
Suppose we have a function, f(x), whose values are known (or tabulated
at a set of points x 0, i i , x9,.., x. Let us denote the function values f(x0),
fx,) by 10.11...../. The difference between any two consecutive
function values is called the finite difference. The difference in function
values
fix1 - fL = + ( Cl)
is k.nown as the first forward difference at x = x. We may denote this
first diflrence at .v = x1 as

Li1
where A is an operator called the forward thffererwe operator.
Difference Operators and Central Dffefence Interpolation Formulae 5M

By applying the proces repeatedly we generate the second forward


difference, third forward difference, and so on. Thus the kth forward
difference of Ax) at x =; is given by
(C.3)

Find expression for and


A(Af,)
= + - I;)
= Af. * - 'VI.
12fIiifVfi
— f 2 -2f1 +j
=

= [14 a- 3f 2 + /+ -- t

The difference in ft nction values


(C.4)
is known as the first backward difference at x =;. This is denoted by

F vf=_1j
where V is an operator called the backward diffrenee operator.
The kth backward difference of fix) at x = x is defined by
V fV ( Vf)VfV h f I (C,6)
Forward and backward differences introduce asymmetry. Sometimes we
may need formulae which are symmetrical about the points of interest.
Such formulae are based on central differences.
The difference in function values
(C.7)
is known as the first central difference of at x x1 . This is denoted by
(C.8)
where a is called the central dtffere;we operator.
The kth central difference at x x is defined as

Note that if the function values are only known at x 1 , x2....., x,, then
f(x 112) is indeterminate and therefore 5f(xi ) is not computable. However,
we can evaluate 5 2f(x) as follows:
S L_ O ,in — T1 •1P2
Numerical Methods
= + - - + t;. 1
(CdO)
2
In general, we can compute 3 kf, for all positive integers h,

DIFFERENCE OPERATORS
We have seen three difference operators, namely, forward operator A,
backward operator V, and central operator 6. We consider here some
more operators that are often used in the manipulation of interpolation
formulae.
Shift Operator
We have an operator known as ,slu/i or thsphicernent or translation
operator denoted by E. The displacement or shift operator is defined as
LE t 1 (CII)
E kf=/ C.12)
If the values of x1 are equally spaced such that
* - X = h
then
=Xi +h
Eq. (C.12) may he written as
1? fl x ) =Pxi+ kh) C.13)

Inverse Operator
An operator opposite of E is known as inverse operator and is defined as
E'f(x) = g(x) (C.14)
Note that
Eg(x) = EE-'f(x) = f(x)
Eg(x) = g(x + It)
Then
g(x -f h) = f(x)
Therefore,
g(x) f(x - It)
That is,
(C. 15)
Similarly.
Ef(x)=J(x —kIt) (C. 16)
Difference Operators and Central Difference interpofation Formulae

Averaging Operator
The averaging operator p is defined as

(C.17)
That is,

/if(x)=[f(x +.k)+f(x
)]
RELATIONS BETWEEN THE OPERATORS
The difference operators are related to one another in a number of ways.
We consider here a few of them.

Relation between A and E


We know that
Mx)=f(x +h) (f(x)
Ef(x) - Lf(x)
(E- 1)f(x)
Therefore,
LA E -1 orE= (C.18)
Relation between v and E
Vftx) f(x) -f(x - Ii)
1.1(x) - Ef(x)
(1 E-1 ) Ax)
Therefore
C19)
or
E = (1 - VY1
(since (E 1 ) = E)

Relation between A, v and E


We have
EV E(1 - E1)
= E ---1

Therefore
Lii] (C.20)
Similarly, we can show that
E 1 =V

524 NumercaI Mebods

Relation between E, Sand ji


We. have

.( /'
ö f( x = / X + - f X -

=Ef(x)
Therefore,
5= E" E E 112 A E 1 ' 2 V (C.21
Similarly, we can show that

(C.22)

From Eqs (C.21) and

E- E*
\Ve know
. + V (E U
Th en,

+V

Example C.2.

Prove that :\ - :\V.

- V =E- 1) -(1-E1)
R 2 +
Av=(E-1)(1-E:l
= E--2 + E
Therefore
-

Example C.3

Show that S2 = E2 -- 2E + I
= (E - 1) (E --1)
- 2E + 1
Difference Operators and Central Difference Interpolation Formulae

Prove 82 V
- E1°12
82 = EE 1 '
= E + E' 2
- V r'(E-1)--(1—E1)

Hence,

From Example C.2, we know


A-V
and, therefore,
52 = AV
From Example C.3, we can prove that
= E 2 - 2E + 1
= E(E - 2 + E')
E (A— V) = EAV
Similarly, the readers may attempt to prove the following relations

1. p2 =1+_ or

2.
VA

3.

CENTRAL DIFFERENCE INTERPOLATION

FORMULAE

We have already discussed in Chapter 9 the forward and backward


difference formulae. They are useful when the value required is at the
beginning or at the end of the table. However, if the point of interest is
located at the inidd]e of the table, then we may use the formulae based
on central differences.
Let x 0 be the middle point and f the corresponding function value.
Consider the values of x on either side x 0 such that
= f(x 0 + f = f(x 0 - h)

= f(x + 2h), f_2 = f( 0 - 2h)


and so on.
Numerical Methods

We can now form a difference table with the values f(x) on either side of
as shown in Table C.!.
Table C.l Central difference table
x f First Second Third Fourth
L (Jiffer( . m ilif/i.'ren.re diff'renn diffiir.nce
2/? 12
of-312
- h / AL2 = h

I Al I = f2 Af26 f- Il)
A1, 2
To - = Sf
I A = f=
2

Af 1 =
L*2h 12

The entries in the table are related using the relation between A and ö
Operators. We know that
S
and therefore we can show that
= (
i;2 = 2
Ef =
Similarl y , we can prove for all the entries.
We present here the following central diflrence interpolation formulae
which use differences close to the centre of the table.
1. Gauss forward formula
2. Gauss backward formula
3. Stirling formula
4. Bessel formula
5. Lap]ace- Everett formula

Gauss Forward Interpolation Formula


We have used the Newton-Gregory forward interpolation formula in
Chapter 9. This is given by

f(x)=f0 +i12f +
3!f0 +... (C.23)
where

a=x0+ph or

We can ShOW that


= 2
(1 + = 2f +

Difference Operators and Central Difference Interpolation Formulae 52Z

= Ef 1 (1 + z)f = Alf- +
= i 1f 1 + ' f-.1 and so on.
Substituting for Afo, if0........e above equivalents in Eq. (C.23) and
after simplification, we obtain

f(X)=fL .
+ (P) 2 11+ ( ) 3f +( P " ) A4f +...

(C.24)
where
m(m—l)(m-2) ... (rn—n+1)

Equation (C.24) is known as Gauss forward formula. Note that this


formula involves 'odd' differences below the centre line and 'even' differ-
ences on the central line.

Gauss Backward Interpolation Formula


Gauss backward formula is obtained using the odd differences above the
centre line and even differences on the central line. This is obtained by
using the following substitutions in Eq. (C.23).
Afo = f I+
= Af 1 + A3f.1
fo = f-1 +
A3f 1 = f.-2 +
=
+
Thus, we obtain the Gauss backward interpolation formula as

f(x)=fo + ) j +'Jfi +(P+1)3f2 +2J4f2


(C.25)
Equation (C.25) is popularly known as Gauss backward formula.

Stirling Formula
Stirling formula is obtained by taking the average of the two Gauss
formulae. Therefore, adding Eqs (C.24) and (C.25) and dividing by 2, we
obtain

0 f-i L2
f(x)=fo + P

1) 2 —_14
f-i f-2
1-2 +--- (C.26)
+
M Numerical Methods

Equation (C.26) is known as Stirling formula, Note that Eq. C.26 in-
volves the means of the odd' differences just above and just below the
central line and even' differences on the line. To use this formula, p
must satisfy the condition

2 <p 2

Bessel Formula
Bessel formula is a modified form of Gauss forward formula, which is
given below.

f(x)=fo Po }22fi +(p31 i -... (C27)

We know
O
Af = f1 - f0 and, therefore, f) f1 (C.28'
= 'ff0 - then, = - (C.2)
Similarly,
= - E5f_2 (C.30)
Now, we rewrite Eq. (C27) as
p(p—l)21

+Al + (C.31)

Now, substituting Eqs (C.28), (C.29), and (C.30) in (C.31), we get


+1 p
+pAf

p(p- 1 (2f A3f1).-'---J?-3f1 +...

= fo f + p( j — 1) (A2 f0 + 2 f )

p — A) P (p - 1)
(A3f1)+... (C.32)
3!
Equation (C.32) is called Beacl formula. Note that the Bosse] formula
involves odd differences below the centre line and averages of the even
differences on and below the central line.
Difference Operators and Central Difference Interpolation Formulae ¶

Observe that when p = - 1all odd order differences vanish and we get

1 fO' Mf.2+A4f_1
2 f(x) k(fo+f1)_ iI
8 ) 128 2

5 LVf_3+AJf_2
14 2 C.33)

Equation C.33) is known as formula for interpolating to haves,

Laplace-Everett Formula
Again consider the Gauss forward forrnua
p(p- 1) (p L1)p(p_1)
f(x) - fçj + + A"! + , - A 3 f-i '... ( C.34)

W: elifluhlaLe die add diiThreticei rou Eq. (C34) tue result vill give
us the Laplace-Everett form i1a. Vve inow
= f1 -

= Au0 - Af
A 5f A4f1 --
and so on.
Substitutin g these in Eq. (C.34) and rearranging the terms, we get

f(x)=J- p)f(, i) f1 (ç) A 2 f (P+l)A2f

_(P +i \4f, P \ij' •. (C.35)

1tIiiii4
P or 1-p=q
and simplifying, Eq. (C.35) becomes

fC)[fo (4 1 Yf+..]+[fi J 1 21 1 (C.36)

Equation (C.36) is known as Laplace-Everett formula. This formula in-


volves only even differences on and below the central line. This can be
used when 0 <p < 1.
Q Numerical Methods

Key Terms
Averaging operator Forward difference operator
Backward difference Gauss backward formula
Backward difference operator Gauss forward formula
Bessel formula Inverse operator
Central difference Laplace-Fverett formula
Central difference operator Shift operator
Displacement operator Stirling formula
Forward difference Translation operator
M0 7 APPE"Ix.

C Programs

—T.
INTRODUCTION
; programs are basically made of functions. As we know, a function is a
unit of a program that performs a particular task. A C function is similar
to a subroutine in FORTRAN. A function begins running when its name
is used in the program.
All C programs need a main function which is named as
niainU
Therefore, the programs in this appendix begin with the main function.
Since the main function does not use any arguments, its name is followed
by a set of empty parentheses.
Ever ything inside a C function is enclosed between two curly brackets.
like C..). The left curly bracket signals the beginning of the function and
the right one signals the end of the function.
Some features of C that are dist-inctIy dif1irent from FOPTR.\N aie
A Cee-form language and tlt-isfiur vc nay follow any torn
of statements that may please us.
• A comment or remark can he inserted anywhere that a space can
appear in a C program provided it is preceded by /@ and followed by

• As a convention (and not as a rule), everything in C is written


using lower-case letters. Thus, names of all variables and functions
are written in lower-case.
• All C statements must end with a semicolon.
• C does not support statement numbers. However, we can assign a
label to a statement as follows:
begin : sum =

We may direct the control to this statement by using the goto


statement as
goto begin;
Numerical Methods

• C language does not have STOP and END statements. While the
closing bracket } represents the "END" of a function, STOP may be
replaced by invoking the exit() function available in C.
• Unlike FORTRAN. all variables and functions that return values
must explicitly be declared for their types.
jut ,,d,l); /* deciarinq integer variables .
tijrt X, y, JO1 / *declori ng r:ai varabs.. /
• C supports what are known as preprocessor directives #include
and #define. The #include directive is used to include in the
program library functions and other files. We may use the #deflne
directive to define constants and functions that are used in the
program.
• C does not support any operator for exponentiation. Instead, it uses
a function pow(x,y) to compute x.
• C uses square brackets to represent arrays variables, like, a[ij.
b[i]j], etc.
• Unlike FORTRAN, C array elements are numbered from ZERO,
not ONE. That is, the array u{3] will be represenled in the memory
as alOI, al 1], and el2].
• C uses an operator & known as address operator to read the values
from the keyboard. We may use this operator to obtain the address
of a variable in the memory. For example, & x gives the address of
the location of x.
• C defines as the modules operator. This operator divides the first
operand by the second and gives the remainder, (not the quotient)
as the result.
• C defines another operator known as "star operator to define a
pointer. The statements
:I. S

i or. 'p .' p a dec/cr /;r:r.:r *:


p=&o; /k ess Lu p ,
make p point to a Now, the statements p+5 and a+5 both would
give, the same result. That is, p means the value stored at the
address pointed to by p.
C uses the following relational and logical operators:
= = is equal to
< is less than
> is greater than
<= is less l,han or equal to
>= is greater than or equal to
H is not equal to
II logical OR
&& logical AND
C ProgorT •3

• C has two more control statements continue and break In addino


to the conventional goto statement. These two are used inside a
loop. While the break transfers the control to the first statement
outside the loop, the continue statement skips the remaining part
of the loop.

FORTRAN TO C CONVERSION
rJ FORTRAN programs in the text have been translated almost line
by line using C equivalents given in Table D.l
Table D.1 C equivalents
FORTRAN Statements C Equuaients
INTEGER int
REAL float, double
I >ARAME'I'ERS (iVI 100 /tdefine M 100
I NTRINS1C inclod(, cmath,h>
IIEAD( ') statement scanf{ j statement
WRITE ( ,) statemei1 printfl) statement
lu iiction subprograms Preprocessor macro definition
Statement number Label name
(IOTO <number> goto <label>
COTO inside a loop break or continue
STOP inside a program exit( function
IF( ... )THEN...
IF...) TI LEN ... ELSE, if (...) ... else
1)0 CONTINUE
.. for (i
EN I)

The preprocessor directives #define and #include are always placed


before the mainO function. An y constants and variables declared hefor,
the 111 *I) itnctinn are considered to be global and are available te C

funcCoco, defined after that point 1.n he file.


It should b noted that the programs have been Lranslatod tine by line
SO as to enable the readers to understand the logic easily. It is quite
possible to simplify or improve the efficiency of C programs in this
appendix using some of the unique features of C. This requires a complete
understanding of the language.
Readers new to C language must read an introductory book on C such
as Programming in ANSI C by E Balagurusamy before attempting to
analyse and apply the C programs given in this appendix.
4 Numerical Methods

Table Di List of programs



Program No. Name Description
1 POLY Program POLY evaluates a polynomial of degree
n at any point x using Homer's rule.
2 BISECT This program finds a root of a nonlinear equa-
tion using the bisection method.
FALSE This program finds a root of a nonlinear ecuation
by false position method.
4 NEWTON This program finds a root of a nonlinear equation
by Newton-Raphson method.
5 SECANT This program finds a root of a nonlinear equation
by secant method.
6 FIXEI)P This program finds a root of a function using the
flxedp point iteration method.
7 MIJLTIR The program finds -Al the real roots of a polyno-
mial.
8 COMPR This program locates all the roots, both real and
complex, using the Bairstow method.
ii M1JLLER This program evaluates rout of a polynomial us-
ing Muller's method.
10 LEGI This program solves a syateni of linear equations
using simple Gaussian elimination method.
11 LEG2 This program solves a system of linear equations
using Gaussian elimination with partial pivoting.
12 DOLT This program solves a system of linear equations
using Dohttle LU decomposition-
13 JACIT This program uses the subprogram JACOBf to
solve a,y-,tern of equations by Jacobi iteration
method.
14 GASIT This program uses the subprogram GASEII) to
solve a system of equatious by Gauss-Seidel
iteration method.
15 LAGRAN This program computes the interpolation value
at it specified point, given a set of data points,
using the Lagrange interpolation representation.
16 NEWINT This program constructs the Newton interpolation
polynomial tor a given set, of data points and
then computes interpolation value at a specified
value.
17 SPLINE This program computes the interpolation value
at a specified value, given a set of table points,
using the natural cubic spline interpolation.
18 LINREG This program fits a line Y = A + HX to a given
sot of data points by the method of least squares.
19 POLREG This program fits a polynomial curve to a given
set of data points by the method of least squares.
20 NUDIF5 This program computes the derivative of a tabu-
lated function at a specified value using the New-
toil interpolation approach.
(Contc/.)

C Programs

Table 132'Contd.)
Pruiare \Nu rrie
TRAPE1 This program integral-es a given function using
the rapeodal rule,
22 SIMS1 Tins prugruol iritegraLes a given function using
the Sin- ore 'H rule.
1; .:rut Rb inthgration by
bisecting the imervals N times.
24 TRAPE2 This plugram 0: ''r'tc: t. ubu) aeud function us-
ing the trapez :1
23 8MS2 C rf3iis program integrate tabiiiated function u-
ing the Simuons 1/3 rule. If the number of seg-
mcnls is odi, the trapezoidal ruic is used for the
lest siieflt.
23 EVILERThis program estimates the solution of the first
order differep ti.ut equation y ftx, y) at ihe
given pOifl usa- Eulort; method.
1TEUN )rograaiThis solveS LbO first Q!ier differential
equation /L vi .15110 the Hiuns method.
PtLYCL- This oeu5rum eoe.'es 1 ii' ;hfI'ereiia! cquatoa of
type v = fix. ') hy pnlon method.
11JNGF4 This program computes the ohithri of ' first order
difThrential equation of t ype y' - fix, y) using
the / th order RunyeKi'tta method.
'30 MILSIM ThHs program ( ,Ives the first order diftereni i1
equation y fix, yi using the Milne-Smmpac;n
met hod.
ot'Jr;-U:S in C :Itd Lirc no! avriaIea in F'O'.
v!uts fthe. -
tiir "t i1ua'.r:Y tr y tod.:vr lop It t'iieA\ i'

Program 1 POLY
- '--.- -------------------. *
* Main p: ocioam
Pc:graTo HOLY eval.laLe:e e ç:C tnoni1 of degree n
* .it any po.rit X -. r q Ice ia: :5 LUiC

-- -------- *
* ----- - ------ ---
* SuLrouL1::3 cuec
* horrier *
* -- - - - - - - - - - - - - - - - -- - - - -------- - - ---
*
* Variables used *
* r - qceC jt
a - 2\ecny o or ,'ii-.----. :o-: t _ceCnLS
* x - P: ut of ova iat inn
p - Vale of p(lyIiOrnCc.5 a x*
*
* Constants used *
* NIL
--- ---- ---- .* /
AM Numerical Methods

main(

mt fl,i; / Declaration of variables


float x,p,a[lOJ;
float horner(irxt n, float all, float x);
p rintf('Inpit degree of polynomial, n\n);
scanf("%d", &n);
printfVlriput polynomial coefficients a(0) W a(n) \n');
for(i=O; 1<fl; i-f-+)
scanf"%f", &a[i]);
printf("Input value of x (point of evaluation) \n");
scanf("%f" &x);

/*pya2ua1flg polynomial at x using homer's rule


p horner(n,a,x); /* Calling the function burner k/
/ Writing the result

printf("f(x) %f at x = %f \rj', p, x);


printf("\n")

/ End of main program POLY *7


-----------------------------------------------
1* Defining the function homer *1

float homner(jrit n, float all, float x)


/
homer computes the value of a oo1ynornl of ordei
at any given point x. *7

t; 7* Local variables */
float p;

p - aln];
for(i=n-l;i>=o;j-

p = px + a[iJ;

return(p);

/ End of Function homer


7* --------------------------------------------------*7
C Progrtm l

Program 2 BISECT
---------- .--*
Main program
* A
This program finds a root of a nonlinear
equation using the bisection method -

*
Functions invoked
Macro F(x) a
* ---------------------------------- ------------------ *
*
* SuhroutneS used

* - ------------------ ------------------------------------ *
*
* variables used
* *
a - Left endpoint of interval
*
b - Right endpoint of interval
* *
S - Status
* *
root - Final Solution
*
Lourit -- Murnber of :teaions done
* -------------------------------------*
*
* Constants used
*
* EPS - Error bound
-*
-------------
#include <math.h>
#define BPS 0.000001
#defioe F(x) (x)*(X)4(X)_2

main(

j Ot s, count;
float a.broOt;
printf("\n")
printf('SOLUTION BY BISECTION METHOD \n");
printf(\n*)
prntf('Input starLing values \n";
scanf("%f %f" ,&a,&b)
/*Ca ll i r g the subroutine bin() !

bim(&a, &b, &root, &s, &count);

if (s0

printf('\fl")
printH"StartirLg points do not bracket any root \n);
prinf(" (Check whether they bracket EVEN roots \oA);
printf('\n)

Numerical Methods

else

print-.f("\nRoot = %t \n, root);


print f("F(root) %f \n, F(root));
prinLf("\n)
pr.inLf('Iteratjons %d \n', count);
printf ("\n)

End of main program

1* ------------------- ----------------------

/* Defining the subroutine bim)) /

bim)float *a, float *h float *root lot I s, lot *count)

7* This subroutine finds a root of nonlinear eauation


in the or-val [-ib] using the bisection method *7

hoar xl.x2,xO, tO, fi, f2;


/* F'unction values at iniLia points */
x1
x2 =
- F'(xl);
f2 - F'x2);
/ * 'rest If nitlai values bracket a SINGLE cnot * /
if(fl*t2 > 0)

(J;
return; /* Progiam terminated *7

else
Bisect the interval and locate the root iteratively

count = 0;

begin: Iteration begins /


xO = (XI +
f F(xO);
11 (fO-=O)

= 1;
'root = xO;
ret-u un;

j f(i*fO < 0)
C Programs

x2 = xO;

else

xl xO;
fl

/ Test for accuracy irid repeat the process, if necessary *1


jf(fabs( (x2--xl)/x2) EPS)
- 1

*root = (xl+x2)/2.0;
return; /* Iteration ends *1

else

*count = A co t ut 1:
goto begin;

End of subroutine bim() */


1* - __------ -

Program 3 FALSE
*
A
* Main progiam
* This program find-, a root of a nonlinear equation *
* by false position method *
* -- ----- ----- -------------------------------- - -------*
* Funcl:ions. invoked *
* Macro F(x)*
* --------------------------- --- ----------. ------------*
* Subroutines used *
* fal() *
* --- ------ --------------------------------- ----------- *
* Variables used *
* a - Left endpoint of inteai *
b - Right endpoint of intervoL *
* - Status *
* root - Final solution *
* count - Number of iterations completed *
* - --------------------------- ------------ -- -------*
* Constants used *
* EPS - Error bound *
* - - - - - - - - - - - - - - - - - - - - - - - - - ------------ - A /
4Q Numerical Methods

#include <math.h>
#define EPS 0.000001
#define F(X)
main(

mt S, count;
float a,b,root;

printf ("\n)
prinrf('SDLTTTON flY FALSE POSTTTON 1 7T1[OD \r"J; ,1
printf ('\n'
t
printf("Input s arting values \n°)
ccanf('%f %f, &a, &b);
P Calling the function fal() */

fal(&a,&b,&s,&root,&count);

if (s==0)

printf("\n)
print f('Starring points do not bracket
any root \n)
printf ("\n)

else

prnLfY'\n')
pr.intf("Root = %f \n', root);
printt('F(root) = %f ri', F(root));
printf('\n NO. OF ITERATTONS = %d \n, count-.);

End of main)) program /

1 --------------------------- ------- -----------------------* /

/4 Defining the o]brout1ne fal() /

fal(float 4 a, float 4 b, mt float *root mt *count)

/ fal finds a root of A nonlinear equation I

float xl,x2x0, fO, fl, £2;


xl =
x2 =
£1 = F(xl);
f2 = F(x2);

/* Test if a and b bracket a root */


C Programs 541

if(fl*f2 > 0)

= 0;
return; /I Program terminated

else

print f ('S n xl x2 sn')

*count = 1;
begin: /4 Iteration begins */

xO = xlflk(x2xl)/(f2fI)
f = F(xO);
if(ff2 < 0)

x2 = xO;
= fO;

else

xl = xO;
fl = fO;

printf("%5d %156f %15.6f \n", *count x, x2);


/ Test whether the desired accuracy has been achieved
if(Eabs((x2-xi)/x2) < EPS)

= 1;
*root = (xl+x2)*0.5;
return; / Iteration ends *1

else

*CCUflt = * count 1;
goto begin;

/* End of subroutine fal() */


7 k ------------------------------------------------- ---- * /

Program 4 NEWTON
/ ---- ---------------------------------------------**
* Main program
* This program finds a root of a nonlinear equation *
*
* by Newton-Raphson method
Numerical Methods
* ---
- - - - - - - - *
* Functions invoked *
* Micros F(x), FD(x), Library function fibs() *
* --------------------------------------------------*
*Subroutines used *
* NTL
* --------------------------------------------- *
*Variablec. used
• xO - Initial vale of x *
• xn - New value of x *
• lx - Function value at x *
• fEdx - Value of function derivative at x
• count - Number of iterations done *
* ---- --------------- --------------------------------------- *
* Constants used *
* EPS - Error bound
* MAXIT - Maxiurn nufterof iterations permitt.ei
* ---------------------------------------------- - - ---*

include <rnath.h
#defino EPS 0.000001
#define MAXIT 20
#define F(x) (x)*(x)+().2
#define P0(x) 211 (x)+l
main(

lilt count;
fiot xO, xn, rx, tdx;
prm:t ("\n")
printf("Input initial value of x \n")
suariLV%f, &xO)
prntf ('S \*)
printf (" SOLUTION BY NEWTON RAPHSON METHOD \n");
printf(''n");
count 1;
begin: /* Iteration begins */
Lx = F(xO);
fdx = FD(xO);
xn = xO fx/fdx;
if(tahs((xn-xO)/xn) < EPS) 1* Iteration ends */

printf("Root = %f \n, xn);


pririt("FuncLion value = %f \n, F(xri)(;
printf'Nurnber of iterations %d \n", count);
printfV\n")
C Programs 54

else

xO = Xr1;
count = count + 1;
if (count < MAXIT)

goto begin;

else

printf("\fl SOLUTION DOES NOT CONVERGE \n');


printf('1N %d ITERATIONS \n, MAXIT);

f* End of main() program


/

-------------------------------
Program 5 SECANT
1* -------------
*
* Main program *
* This program finds a root of a nonlinear *
* equation by secant method *
* -- - -- - - - - - - - - -- -- - - - - - *
* Functions invoked *
* Macro F(x) *
^
*
* Subroutines used *
* sec() *
A ------------------------
------------------------
------------
*
*Variables used *
* a - Left endpoint of interval A
* b- Right endpoint of interval *
* xi - New lett point A
* x2 - New right point *
• root - Final solution *
• count - Number of iterations
- completed *
--------------------------------------------
*------ A
* Constants used *
* EPS - Error bound
* MAXIT - Maximum number of iterations permitted
/
* --------------------------A

#include <math.h>
*define EPS 0.000001
44 Numerical Methods
*define MAX1T 50
define F(x)

float a,b, root,xl,x2;


mt count, status;
printf('\n)
printf(" SOLUTION BY SECANT METHOD \n'°);
print
printf("Input two starting points \n);
scanf(%f %f, &a, &b);

sec(&a, &b, &xl, &x2, &root, &count. &status);


if (status 1)

rintf(\")
PLilitf (" DIVISION BY ZERO \fl);
prifltf("\flLast xl. = %t \n", xl);
prntf('\nLast x2 - %f \n", x2);
prfltt("\nNQ OF ITERATIONS = %d \n", count);
printf('\ii)

eisa if(status == 2)

prrntt ("\n')
prirtf("NO CONVERGENCE IN %d ITERATIONS \n", MAXIT);
prntt ("\n")
else

printf("\n")
printf("Ro - %f \n', root);
ntf value at roar = %f \n, F(root));
printf ("\n);
printf("NQ. OF ITERATIONS %d \n", count-);
printf (\n")

I
End of main() program */

* /
/' Defining subroutine sec(

sec(float *a, float *h float- *xl float *x2, float


*root mt *count, mt *status)
C Programs
/k
This subroutine computes a root of an equation us-ng
the secant method. */

float x3,fl, t2,erroL;

Function values at initial points '


*xl *0;
=
fi =
f2 = F*b);

Compute the root iteratively *,'


kCOUflL = 1;
begin: /* iteration process begins *1
if(fahs(fl-{2) i.E-la)

status - 1;
return; / * Prograrr. trninauiod */

xi -_ - f* (*x2 *Xi) / ( 12 Ii);


error fobs> (x3_*x2 !x3)

/* Test- far: accuracy


if (error > [PS)

/* Vest f- (,, r c-onvergence */


j I ir"nt =MAXI-T)

*tatus S 2
return; '* Program terminated */

*xl x2;

= x3;
fI = f2;
F(x3);
*count *count 4 1;
gc)to begin; /* Compute next approximation

else

*root x3;
*staLus - 3;
etufl1; /* Iteration ends /
Numerical Methods

I
/* End of subroutine sec()
1*

Program 6 FIXEDP
1* ----------------- -------------*
* Main program*
This program finds a root of a function using **
* the fixedp point iteration method
* - ------------ ------ *
* FunCtiOnS invoked *
* Library function fabs() and macro G(x)
* ---------------------**
* Subroutines used
* NIL--.----- *
* -------------------------------------------- *
* variables used *
* xO - Initial guess *
* x - Estimated root
* error - Relative error *
* -- - - - - - - - - - - - - - - - - A

-constants used *
* EPS - Error bound
* MAXTT - Maximum iterations allowed
* -------------------- ------
# include math.h>
* define EPS 0.000001
* define G(x) 2.0_(x)*(X)

main(

mt MAXIT, i;
float xO, x, error;
SOLUTION BY FIXED-POINT METHOD \n");
printf("\fl
printf("\fl)
printf(iflPUt initial estimate of a root \n);
scanf(%f, &xO);
printf('MaXimUIfl iterations allowed \n*);
scanf ("%d', &MAXIT);
i1-'-, 7hT.TTR OF X
--
ERROR \n);
priOttV\fl
/*IteratiUfl process begifls*/
for(ii;i<=MAXIT 4 I

x = G(xO);

C Programs MZ

,error - fabs( (-xO)/x);


printf("%lOd %10.7f %10.7f \n, I, x, error);
if (error < EPS)
goto end; /*Iteration process ends*/
else
xO =

printf("\nProcess does not converge to a root. \n");


printf("Exit from iteration loop\n");
end:

/* End of main() prograia*/


/* --------------------------------------------------* /
Program 7 MULTIR
---------- --
* Main program
• The program finds a1 tne real roots of a polynomial *
* ----------------- -. ----------------*
* Functions 1ovoked *
* NIL *
*--------- ----*
* Subroutines used *
* newton() *
* dflat()
* ------------------------------------------------------*
• Variables used *
• n Liegree of polyriomiol *
• a - Polynomial coefficients A(N+l) *
• xO - Initial guess *
• xc - Root obtained by Newton method *
• root - Root Vector *
• status - Solution status *
* --------------------------------------------- . *
* ConsLants used *
*FPS - Error bound *
* 4A)(I rr - Maximum iterations permitted *
* --------------------------------------------------*

#include <math. h>


#define EPS 0.000001
#define M/.XIT 50

void main)

.LnL n, status, i, j;
Numeca1 Methods

float a[llJ, rootiO j , xO, xc;

void dflat(int n, float a[llJ, float xr)


void newton(int n, float aLl I float xO, mt *stf.s
float *xr);

printf("\n")
printf('\n EVALUATION OF MULTIPLE ROOTS \n);
prir1tf(\n*)
printf(*Input degree of polynomial, n.
scanf('%d, &n);

prin:f("\nlnput poly coefficients, a(l) to a(n+l). \ri');


fori = 1; 1 < 11+1; If4)
scanf("%f", &a[i]);
printf('\nInput initial guess of x \n;
scant ("%f'. &xD);
printf (\n*)

/* Process of root searching hegir *7


for =n; i >r2; - -)
/ Find ith root by Newton Method *7

newton(n,a,xO&status,&xr);

if (status == 2)

for(n; j>ri+l;j- --)


rintf("root %d - %f \n"j, rootf:]);

printf("\nNext root does not converge in \n");


printf('%d iterations \ri". MAXTT);
printf I
goto end; 7* Processing ends *7

root[i] = xx;

/* Deflate the polynomial by division (x-xr) */


dflat(n,a,xr);
xO = xr;
/* Proceed to next root
/* End of for loop *1

/* Compute the last root */


root[l] -a[lJ/a[21;
7* Write results */
printf("\n ROOTS OF POLYNOMI.L ARE: \n");
printf(-\n)
for (i=l;i<=n;i++)
printf('ROOT %d = %t \n, i, root[i]);
C Programs 549

printf ("\n')
end:
printf ('ENIY);

J End of main() program *7

7* --------------------------------------------------*

1* Defining the subroutine riewton() *1

void newton(nt n, float aill], float xO, mt *status,


float *xr)
/ This subroutine finds a root of the polynomial using
the Newton-Raphson method

mt 1, count;
float ix; / Value of polynomial at xO */
float fdx; 7* Value of oulynornial derivative at xO

Count = 1;
/* Compute the value of function at xO
begin:
fx =
for (i=n; i>=l ; 1--)
ix = fx * xO L1;
J Coruptc the value of derivative at xO *7
fdx = [n+1] *
for(inri>2;i- -)
dx - fdx * xO + n[iJ * (i-l)•

/ I Compute a root xr
= xO-fx/fdx;

7* Test for accuracy /


if(fabsN*xr_xO)/(*xr)) <= EPS)

4 sLamm_s = I;
returr:;

/ Test for convergence */


if (count<MAXIT)

xO *Xr;
count = count + 1;
goto begin;

else
Q Numeiical Methods

*status -- 2;
return;

/ nd of subroutine newton() */
1* ----------------- -------- * /
/* Defining the subrou t ine dtlat() */

void dflat(int n, float u[ 1 l], float xr)


/ Ibis subroutine reduces the degree of polynomial by
one using synthetic division

float h[1]J;
mt
A
Evaluate the coefficients of the reduced polyriunilal
b1n]] C);
for(i=n;i>l;i- -)
biJ = ali+lj + xr, * h[i+1 ]
/* Chdrge coefficients from b array to a array */
fox (i-l;i<-i+i;i++)
au]
/* Ind of subroutine dflat()

* /

Program 8 COMPR
* --- ----------------------- - ---------------------- *
* Main program
* This program locatc,.s all the roots, both real *
* and complex, using thf, Birstow method *
* ----------------------------------------------------*
* Functions invoked *
* NIL *
* --- - . --- - --------------- --------------------------- *
* Subroutines used
* input, bstow,q-uad,output *
* ---------------------------------------------------------*
* Variables useu *
* fl - Degree of polynomial
* *
a - Array of coefficients of polynomial
* *
uO,vO - TniLial values of coefficients of the
* quadratic factor *
C Programs
* u,v - Computed( values of coefficients of the *
* quadratic factor *
* b - Coefficients of the reduced polynomial *
* xl,x2 - Roots of the quadratic factor
* type - Type of roots (real,imaginary or equal) *
* ---- ---- ---- ---- ---------------------------- ----.------- *
* Constants used *
* EPS - Error bound
* ----------------------------------------------------* /

#include cmath.h>
lfdefine EPS O.00)OQl
#define image 1
*detine equal 2
#det Inc unequal 3

main

mt fl, ±;
float a[llJ, b(ll), uO, vU, u, v, xl, x2, dO, dl,
d2, root, type, status;

printf ("\n')
printf" EVALUATION OF COMPLEX ROOTS \n">;
prinrf ("\n")

/ Get input data


prntL(°Input degree of polynomial, n
scanf("%d",&n);
printf('\r Input coeIficints an+1) to a(l) \n);
for(i=n+i; i>l;i--)
scanfY'%f".&a[i]};
printf(-\n Give initial values uO and vO \n");
scanf("%f %f-',&uU,&vO);

begin:
if(ri > 2)

-' Chtain a quadratic factor *,

bstcw(n,a[1l] ,b[ll],uO,vO&u,&v,&status);
if (status 1)

d2 = 1;
dl = - U;
dO = -v;

else
52 Numerical Methods

printf("\n No Convergence in 100 iterationS \n");


goto end;

7* Find roots of the quadratic factor


quad(d2..dl,dO,&xi,&x2,&E),-Pe);

7* Print the roots *7


outpuL (n, type,xl,x2)
7* Set the coefficients of the factor polynomial */
n-2;
for(i=l;iznil; .+F)
all) - b[i±2];
/* Set initial values for next, quadratic factor */
U = U;
vO v;
goto begin;
} / endif */
it (n 2
. ) 7* polynomial is quadratic

quadlo3aL2,aI1J,&xl,&x2,&LYPe);
output ( ri type , x 1. , x2)

i
else / last root of an odd order polynomiai

rmot = -a[.j/e12];
printf("\n")
ptiriLf("Firial root = %f \n", root);
pririLf("\r");

end:
printt ("End");

/ 1, End of memo program


7* -----------------------------------------------------

7* Defining the subroutine bstow() /

bstow(int n,float s[llJ, float b[llJ,float uO,tloat vU,


float *uf10 *vfloat *status)

I" This subroutine finds the quadratic factor using


multivariable Newton's method and also finds the
reduced polynomial *7
C Programs

(
float. d,deiu,de1vc111j;
mt count,

count S
begin:
b[n1] - a[n+l];
bin) - afn] - u0h(nl]
Lor(ln-i;j>-1;i)
b[i] - [ i] 4 uO * h[il + vU * bi.-2J;
c[ni1] = 0;
c E n ] - b[n+l1;
for(i=n-1;j>1;j_ -)
C[i] b1i-1] + u 0 * c[i-lJ t vU *
cl = c2] * c[2] - c[1 * c[3;
delu -(b121 * c[2] - b[l] *
deiv = -. (oti) * c 1 2J b[2] * c"] ) /d;
uC -i- deLi;
vU do2v;

if(fabs(delu/*u) <- EPU && tabs(de!v/*v) EPS)

*sta t us =
ret U 0;

if (count < 100)

UI)
vU =
couo count + 1;
got() beqin;

- else

2;
recuLL;

/* End of 3Ubrou tir:e be tow () * /


1* -- --------------------------------------------- -*

Define the subroutine quad() */

quad)flost a,flot: bfloat c,foat *xl,fjo C t x2 float


"type)
554 Numerical Methods

/ Tin o-1/ruire 1ve: a rr ri1C eati.Ofl o


a(xx) - bx - c

float 0;

= -
< raws w er

x2 =

e : : --- i f (q - -. / roots are real and

x1
*2 - xi;

ce2. -,
&I 1 f U:iLft'i
k/
/ roul

xl = - :it (:) /
- q ) S

roc\irT;

lod of '.ioC'./: Td) ./


/

/k Defining output ) roiiL joe.

outpuL(iflt n, inL type, floa t. xi, fjuaL x2


/* This subroutine disMays t he rcs Of Lhe cidro:iC
equation

pr.: otf \fl"


f'Rccts of adraLi at n - %d \
fao.or n)
p riri ("\n')
-= image)

- %f--%fj \n" l, x2
print0nooW = -j \n' xl. x2)

el/r2 iH t T o FCl11/il)

print.f('Rootl = %f \n", xl);


prirtf)Root2 %f \n, x2)

else 1* Type == unequal /


C Programs SS

fl
printf("Root.1 =%f \n, xi);
printf("Root2 = %t \n, x2);

return;

I End of subroutine output() *1


1* --------------------------------------------------- /

Program 9 MULLER
/* --------------------------------------------------*
* Main program *
This program evaluates root of a polyncial using *
Muller's method *
* ----------------------------------------------------*
* Functions invoked *
* NIL *
*-------------------------- --- ------- --------------------------- *
* Subroutines used
* F(x) *
* ------------------------------------------------ - ------ *
* Variables used *
* xi,x.2,x3 - initial values *
fl,f2,f3 -- function values at xi,x2.x3 *
* aO,al,a2 - coefficients of quadratic polynomial *
hi - xi-x3
* di function difference fi-f3 *
* --------------------------------------------------- *
* Constants used *
* EPS - Error bound *

#incl.ude <math.h>
Ildefine BPS 0.000001

msin(

float F(float x);


float xl,x2x3x4,fl,f2,f3,f4hl,h2,dl,d2,a0,al.a2,h;
printf("\nlnnut three initial po i nts \n");
scant'%f If %f' &xl..&x2,&x3);

f = F(xl);
f2 F(x2);
f3 = Fx3):

begin:
hi = xi-x3;
Numerical Methods

h2 x2-x3;

di = f1-t3;
d2 = f2-L3;
/ Compute pa urtetors aOal,a2
aU f3;
al = (d2*hl*hldi*h2*h2) / (hl*h2* )hl-h2));
a2 (dith2d2h1)/(hk}12*h1_h2));

I Compute h */
f(ol>0 .0)
h=(-2 .C*aO)/ (al+sqrt (al*al4*a2aO)
else
h=(.2.0*aO)/(a1_Scrt(al*a4*a2*aO))
J* Compute x4 and f4
X4 = x3-1h;
fi F(x4)

/ lest for accuracy


f(i4<=iiPS) root obtaired

pr .!nt f ( \n\riHOOT BY MULLERS OI)\r\fl" /


prrt tf("Rc/ot=%f\fl, x4
pr±xlLf

else

= x2;

- f2:

t?
/4;
gote hegic;

/ End of main)) program


* ----------------------------------------------------- /
.' t)etininq the subroutine F(x) k/
float Nfloat x)

float f;
f - x*XAx+2*x*X10X_20:
return (f);

/* End of subroutine ,)
------------------------------------------------* /
0
C Programs 537

Program 10 LEG
-- *
* Main program *
This program solves a system of linear equations *
* using simple Gaussian elimination method *

* Functions invoked *
NIL *
* ---------------------------------------------------*
* Subroutines used *
* GAUSS1 *
* ------------------------- -.------ ----. *
* Variables used *
* n - Number of equations in the system *
* - Matr:x of coefficients *
* b - Right side vector *
* x - Solution vector
------------------ ----- ----- ----- - -
* status - Solution status *

main(

mt statusn.i,j;
float a[lO] [10], bib, x[10]
printf('\n SOLUTION SY STMPLE GAUSS METHOD \n");

printf("What is the size of the system (n)? \n');


scanf('%d", &n);

Driritf"Inout coefficients a(i,j), row-wise, \n);


printf("one row on each line. \n");
tor]i*l;L<=n;i^•+)
for(jl; j<n; ++[
scanf'%f", &a[i] [j
prntf ("\nInput vector h \fl")
Ear (il;i<rri; i+)
scanf("%f, &b[i]);

/* obtari solution by simple Gauss elimination method *J


/* call the subroutine gaussl() /

gaussl(rLa,b,x,&statug);

if(status 1= 0)

print f(\nSOLul'IQN VECTOR X \n");


5 Numpricai Methods

fCL (i1;ifl;j++)
printf("%106f", xLiJ)
Pr" ntf ('S

e se

PXint'SjrIgu1ar rntrix, reorder equatiorAb.

/ End of main)) program


1* - ---
- * /
/ * Defining Suoroutirie gau (
ga . 2ss1(rA t n, float aflO] )l0j, float b[].Oi flea, x{10J,
ins *Status)
This q ubroutine SQ1VCS
a set of n Il000r eia5jon
by cau ss eilminatLon r::e:hod i

inti k;
float- p vo, Eactt, 50111;

-El Lrnn:tinr ) heq±nr---------- ----


for(k 'ri ; k<=n-1

pivot = alE) [kJ


if(plo < 0.000001)

As:atus 0;
rocurn;

*SOatu S -
• - r;

factor off) Lk] /oivoL;

afi [jJ = a [ i ] ] - factor * a[k] Li];

b[i] r b[i] - factor * b[k]

Back SUbStjtUtjO begins - ------ - *1

x[n] = b[nJ / a [ rl) LnJ


f or(k = n-1;k>=1;k. -)
C Programs 552

sum = 0.0;
for(j=k+l;j<n;j+i)
Sum suxr. + a[kJ [j] * x[jJ
x[k] (b[k 1 - sum) / aCk]

return;
/* End of subroutine gussl () /
/ * ---------------------------------------------------- * /

Program 11 I..EG2
/ * ---------------------------------------------------*
* Main program
* This program solves a system of linear equations *
* using CuSsisn Elimination with part:ai. pivoting *
- - -------------- ------- -
--------------------------- -----------
* ----------------------------
*
Functions invoked
* NIL *
* --------------------------------------------------- *
* Subroutines used *
^ Gauss2 *
* --------------- --------------------------------------- *
Variables used
* - Number of equations *
* a Coefficients matrix *
* b - Right side vector
* x - Solution vector *
* ---------------------------------------- -- -------
* Constar:s used *
* *
NIL
* -------.--- I
main(

int i,j,n.
floar a 1] [10) hl0] x[l0J

printf("\n GAUSS METHOD WITH PARTIAL PIVOTING \n);


prinrf('\nwhar is the size r. of the system? \n);
scanf("%d", &n);
printf("\nlnput coefficients a(i,j), rowwise \n);
printf("one row on ea ,:-!h line \n");
for(i=l; i<=n; i+4-)
for(j=1; j<n; j ++)
scanf("%f,&a[i}[j]);
Numerical Methods

print t('\nFnter vector b \n");


tor(i = 1; jz=fl; i++)

scarif(%f, &b[i));
gauss2 (n,a.bx);

printf("\n SOLUTION VECTOR X \n);


printf ("\n)
for( i-i; j<rfl; I ++)
printf("\t %f, x[i));
prinLf("\r")
/ End of main() program k/
7* - -- - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - -- - --- - - k /
7* Defining subroutine gauss2() /

aauss2(int n, float a[13] O],1oat b[lL)], float x[1O)

This s'jbroutino solves a Sys ,- all of linear equicr


ci imirjaLicn
-;a-- rrtriod .: at t i)

7' Wi -1.Lminat ci

/ * Solu:i on by hack .ubatiLuLion * /


bsuh In, a , b, xl

) / EriAof routine gii t2 () /


7* ---------------------------------------- ---------------- *

/ A tin j Ti' L) h/ ui,' ii tire 'j 1_j ( ) /

c"a"cE1,iE' ) crr.a tI:. JU :1.3tOfl


ncorperati up partial pivoL op t:echnique

f1ot fac:or;
for)k : l;k<=nl:Ji: )

pivot(n,a,b,k)
[or (i=k+1 i<=n; j++)

factor = a[i] [k] / a[k]


for(j=k+l ; j<=n; j++)
C Programs 6J

a[] [j] - a[] fj]-factor alk] [j];

bEt] b[j_fctor*hIkj;

return;
!* End o' elimo rouLinc*7
7* - ---------------------------------------- - - - - - - - - -*
/* L)efntng subrotine pivoto)

it include ziniLh. ri>


p ivotEiric n, float a[lDJ [1OJ , float. h [ I 0] lot. k)
/ This subroutine p erforms the task of partial pivoting
(reordering of e(uations) -/

i!L p,i,j;
float large, temp;
7* Find pivot. p */
P=
lerge = fhs(a[k] [k]
for (ik+l; i=-=ri; i++)

iI(fahs(a{i 1 [kl)>targe)

large fabsi[iJ[k!
p = 1;

/ Exchange rows p and k '1


if (p! -k)

tar (j=k; j<=n i++)

temp = a[ p ] Ml
afp?[j] a[kl[j];
a[k)[jJ. temp;

temp = bip);
b[p
b[k) = temp;

return;

/ End of subroutine pivot)) *7


1* -------------------------------------------------- * /
62 Numerical Methods
I
1* Defining subroutine bsub()
bsub(int n, float a[10]t101, float b[101, float x[lO])
/* This subroutine obtains the solution vector x by back
substitution *1

mt i,j,k;
float sum;
x[n] - b[n j / a[n]tnl;
for(k=n-1;k>-l;k-- )

5fl = 0.0;
tor( j =.k+l;j<rl; j++)
sum = sum - a[k][j] *
x[ k J = (b[k] -sum) / a(k}[k];

return;

/* End of subroutine bsub() I


- ----------- - ------ --------- *1

Program 12 DOLIT
/ * -------------------------------------------------- *
Main program
* This program solves a system of linear equaLiorLs *
using L)olittlC LU decomposition
* --------------------------------- -- -- *
*
* Functions invoked
* *
NIL
* --------------------------------------------------*
*
* Subroutines used
* *
bUD, SOLVE
* ---------- ---- ------------- - ---------------*
* Variables used *
* *
n - System size
a - Coefficient matrix of the system *
* b - Right side vector *
* 1 - Lower triangular matrix *
* u - Upper triangular matrix
* fact - Factorization status *
* ---------------------------------------------------*
*
* Constants used
* *
YESNO
* ----------------------------------------------------* /
C Programs

* define YES 1
* define NO 0

main(

mt n, fact, ij;
1110) 110) bIb], x[lO];
float a,1 1011101, u[10] t1OJ
SOLTJTTON BY DOL1'IPLE NETHOL) \n\n");
printf("\n
/* Reed input data *1
print.f("\nWhet is size of A? \n');
scnf("%d", &n):
prmnt.fV'TyPe coefficients a(i, j ), row by row
foL (i=i; i< = n; i++)
for ( =1; j<-n; j ++)
scanf("%f", &a[iJ11);
priritf("\nTYPe vector U on one line \n);
for( =1; i<=i'l; i+)
scenf('%f", &b[i))
/ LU factoriZetiOfl *1

bud(ne,u,l,&fact)
,* p rint LU matrices
if (tact == YES)

/* Print. 13 matrix J
pr j il t f("\rINA TRTX U \n");
for(i1; j<fl;++)

for(j1; j<zrn;j++)

pntf("%15.6f u[iI

printf("\n")

/ Print L matrix
print f("\BMATRIX L \n");
for(i1; i<=rr; i+)

for(j1;j<fl;i)

printf("%15.6f 1[i)[j)) -

printf ( \n)
54 Numerical Methods
/* Solve for x /
soivo(ru,l.b,x);
print f("\nSOLUTIOW VECTOR X \n\n);
for(il; i<-n;j++)
printf (%l5.6f \n, x[i)
prinrt (" \n)

else

printf("\n FACTORIZATION NOT POSSIBLE \n);

/* End of rnan() program


* /

/ Definina the subroutine lud() */


lud(int n, float al101 tlOj float u[10][10", float

1(101 [101, i.nt 'fact)
/A This subroutine decomposes the matrix A into L and U
matrices using DOLIT'rLE algorithm *1

mt ijk;
float sum;
/* Initialize U and L motrices
for ( ini; i<=n; j ++)

ulil H] = 0.0;
1[i](jJ = 0.0;

1* Compute the elements 01 U and L k1


for (1 1; j <=n; j +
u[l] = a[l} [1];
for(i-l; i<n;j++)
lii] [ii = 1.0;
for(i=i;i<=n;i-)
i [iJ l au] [1] / ufi] [1];
for (j-2; j<n;j++)

for(i2;i<j;il.i

sum = a[i] Ii];


tor(k=l;k<=j-j;k±
Sum = sum - li] 1k] * u[k] [j]
C Programs

uIil 111 su;

if (u [j I Ii] <i
*
reLuLfl;

for(i;ri4)

sum =
[or (k k= 1-1; k
sum - t [1.] lkJ u[kI ci)
[II [11 = sun' / u]j] {j

*tart S

coLumn;
/ Enu of nubLouLLfle d]

/
/* I3efnflg the subroutine solve(
] [10], tiodL
solve(int n, float u [ 10 1 110), float 11 10
b]l0], floaL x[iU1)
Lh€sOiut.Ofl vector x using the
/* Th 4 5 subroutine obt,itris
coefficients of L and 0 uaLriues

mt i,J;
Citoat simu, z 10]
/* Forward substitutiOn */
z]11 = bill;
for]i_2;i<sfl11

sum =
for (jl;j-i
sum '- sum Uii * z[]
zft] = b]i]

/* Back suhst i luti on


x[r) -. z I n ) /iitri] ]ri)
fr(lfl-1

sum = 0.0;
for(j=i*l;J<=fl;J
*
sum - su1 ui[j
Numerical Methods

x[iJ (z[iJ -sum) /u[iJ [1]

return;

End of subroutine solve()


/*
*/

Program 13JACIT
/* ------------------------------------
* Main program *
*
* This program uses the subprogram JACOBI to solve
a system of equations by Jacobi iteration meLhoJ
* -------------------------------------------------**
* F unctions invoked
*
* NIL
* -------------.- ---. - -
---------*
* Subroutines used *
JACOBI *
* --------------------------------------------------*
* Variables used *
*
a - Coefficient matirx *
*
b - Right side vector *
n - System size *
*
x - Solution vector *
*
count - Number of iterations completed *
*
status - Convergence status *
*
Constants used *
* EPS - Error bound *
MAXIT - Maxjnun iterations p ermiLted *
* --------------------------------------------------

#include zmathh>
#def j ne EPS 0.000001
#define MAXIT 100
main)

mt i,jflcOUfltStatus;
float a(lO) [10] bflOJ x{l0]
printf("\n SOLUTION BY JACOBI
ITERATION \n");
prjntf(\nat is the size n of the system? \n);
scanf('%d" &n);
prin Lf(\nInput coefficients a(i,j, row by row \n");
for(jrl; 1<=fl i++)
for (j=l;j<rn;j+4)
C Pogroms 56Z

scant("' &a[i)tiH
prir("\flIflPUt vector
foriii<+)
scanI(""'
&C000t, &statUS)

it atUS'""2)
iterations", MAXIT);
prirti("\° convergence in %d
printf ("\n\fl)

else
SOTJTION VECTOR X
printfV\°
for(11 i<n;)
printf(i5.6f" xifl d", co't);
rintf(1\nhta ofl5 = %

k/
J. End of main() program
* /
/* Defining the routine jacnhi()
n, float 5101103, Eloat blO), tlOat xllO].
jacobi(iflt
*cOUflL,
mt *status)
atiOflS us
S y"tern of a lineal
ÜS
subroutine solves a
the 3aCabi iteration method

mt j,j,key;
float sum, xOlO);

1* Initial values of
for{i- = l ; j<=n; 1+ F)
xO[fl = b[i]
7* jacobi iteration begins *7
*COUflt = 1;
begin:
key 0;

/ Computing values of xi')


for(il j<n-i)

b[i1;
for(j=l j<n;j+)
Nurnecicat Methods

f ( L=j)
COflLjflue;
= stLm -- aIijijj * xOTj];

xEi sum / oti.J [ii;


if key 0)

1* Testii i g for ducUracy */


if(fabs((xij XC].])
EP)
key = 1;

/* Jesting for Con vergence */


i f(key -= 1)

if( tcoupt- :MAJ(J'f)


*sLcUS -
2;
Le 1--urn;

CiSC

*StdhS

tCr-_1jerj.j+)

*c(1Jrft = *CoUrlt 1;
q 0^-(D begin-

C Urn;

/ * End ur SuL:ejt no
jrCObt ( /
1* --- - ----
- -
/
Program 14 GAS IT
1*
-. ----.-.----
* Main --------- ------ +
proqrd:II
* *
flas
Program uses the subprogr GASE:iD to sov d
'st
of cj-
* by Guss-g ci iteral orz meubod
-------------------------- --- *
* *
FUnct;or1 invQkcj

* NIL *
*. *
---- .---
----------- *

I

c Programs 1
A

* Subroutines used *
* ;ASETD - -.------ *
* - - --------
* Variables used
a - Coefficient matrix *
h - Right side ve:LOr *
n Systen size *
* x - Solution vector
count - Number of iteratioflS completed *
* * status Convergence
--------.--
- status *
A

consLanLs used *
* EPS - Error bound *
MAXIT - MaximUm iteratiollS peflittCd
* ------------* /
# define MXIT 50
defic- FPS O.Q000
main)

float a[10) )01 b[ 10 1 , <110];


mt j,j,nCOuritStatus
ITERItiiON \n");
printf(°\fl SOtYPlON BY GAUSSSEL
printf("\flat is the size n at the system? \n);
scant ("%d" &n) row

printf("\nIflPut coefficient s a(iJ), r
printf("Ofle row on each line \n");
for(i=l; j<=n;i++)
for(il; j<r1; ++)
scanf ("%", &[i-) [ji);
printf(1\nuhiPUt vector b\n);
for(i l ; j<fl; j4-+)
scant ("%f', &b[il);
gaseid(fl,a.b'x &couflt, &status);

if (statUs2)
printf("11N0 convergence in %d iterations; \n MAXIT)
printt(\fl\fl*)

else
SOLUTION VECTOR X
printf("\fl
for(il; i<=n;i++)
printf("%15.6 x[ifl;
print f\fl\tatbons = %d', count)
7Q Nu rn eocci l Methods

*
End of main() program.
- - - -
k
/
/*
Defining the routine gaseid */
gaseid(int n, float lOj Fbi, flct. hlnj, float x[bDh mt
ounL, mt *status)
/ This SUbXOLttjne solves a
of inear Lja jQr using
the c-auss-sejdel itorajcr, alquriLbjfl

mt key;
fboaL sum, x0[1OJ;
/* Ini ti a l values of x
for (il; i=n;i+ +)
xO[i) b[i] / [] [jj
/* Gaseid i teration begins */
*count 1;
begin:
key - 0;
/*
ComPutin q values of x'
fonHf I<=fl;i^)

Saui -:
fo! ( j l;j<n j^.)
if (i==j)
Continue;
sum = sum - * XOIji;
a(ij [jI
X[I] sum / a[i}[i];
if (key0)

/* Testing
for nccurç-v */
if (fabs ( x (ii -xO 11 /x[.j ) >Pi)
key 1;

Testing for convegencc */


if (key 1)

J.f(*Count=._MAX1.,r)

C Programs

*ct-at1S = 2;
/* Program terminated */
return;

else

for(i=l;1ru j+)
xOi]

k cOUflt = *COUILt+?;
gate begin;

return;

* End of routine gaseid() *f


--- -* /

Program 15 LAGRAN *
1* -------------------------- -----.
*
--mair, program 0 *
This progrdm cotpUtes the interlx)latiOl1 valor' at
specified points qiven a set of data x,intS, using **
* the Lagraflgc interpolation representation
* --------------------- *
* Functions invoked *
* NIL
* ------ .-- **
* Subroutines used *
* NIL
* --------------------------**
* Variables used *
* n - Number of data sets *
* x(i) - Data points
* f(i) - Function values at data points
*- Point at which interpolat ion is taquired **
* fp Interpolated value at XP *
* - Lagraflgiafl factor
* ----------------------- ------------ -- **
* Constants used
MX - Maximum rlumbur of data points permitted *
* ---------------------*
*define MAX 10
main(
Z2 Numerical Methods
irit n, i,j;
fio.3t X[MAXJ,f[F1AX)fp,lfsumxp;
-
Pr- ntf("\nlnput number of data points, n \n);
scanfl"%d, &n);

printf("\nTnpit- data points x(i) and values f(i)


p rintf("(one set in each line) \n')
for(i=l; i<fl;j++)
scanf("%f %f', &x[i], &ffjfl;
p rintf("\nlnput x at which interpolation
is required. \n");
scanf("%f', &rp);

sum 0.0;

If 1.0;
f.or(j=l;j<r.;ji-)

j =j)
If

suir. = sum + if A
flu;

fp
printf ('\ :AGRANGIAN I NTERPOLATION \n\r)
• print 'IrLeLuuIaLed function valuc \n")
p rintf('at x=%f is %f \n", P, fp);
X
1* End of main() program
------------------------- --------------------------------

Program 16 NEWINT
/ **
* Main program *
*
This program constructs the Newton interpolation *
* I yriini ai for a given set of data points and then *
computes interpolation val ue at a specified value *
*
A
Functions invoked *
* NIL *
* Su
broutines used *
* NIL *
* ---------------------------------------
C Programs
*
* Variables used *
* Number of data points *

x - Array of independent data points A
* f - Array of funct i on values
*
xp - Desired point for interpolation
*
fp - Interpolation value at XP
*f Difference table
* coefficients of interpolation *
a - Array of *
* polynomial
* -----------------------**
* Constants used A
* NIL
* ------. .--- * /

main(

irLt j, r.;
i, xL li) ] mo] aFlOL d[1O1 [10]
float xp EP, sum
printfi (' \nlriput number of data points \ri*)
scant ( ,, %d", &n)
x and € (x). \n");
print t( II \r.lnpUt values of
printt("Dfle set on each line \n*);

for(l;1<fl
scanfV% f %f &x[i] &tiiI); (
7* Con struCt difference table *7
for(i1;1<=fli)
d'i] [l = E[l]; -

for (j2;j<-n)
for(irl; i<n-j+l; i++)
d[i]N] = (d[i+ll li-li -d[i] [j-1)) / (x[i+-l)

/* Set the coefficients of inLerpolatiOfl polynomial


tor(j=l; j<=n;i+)
eLi] d[l] [i];
Compute interpolatio n value
d \ri);
printf ("\n1n.it xp where interpolation is require
scanf("%f &xp);
sum =
for(ir2; i<=n;r-+)

p1 = 1.0;
for(j=l;i<il;)
Pi = p1 (XP-x[)1);
sum = sum + atil * pi;
74 Numerical Methods

f = sum;
I' Write results */
printf('\n)
printf(' NEWTON I NTERPOLATION \n);
printf("\n)
print f('Interpo1ated value \n);
printf(t x = %f is %f \n, xp, fp);

/* End of main() program *1


/* ------------------------------------------------------ *1

Program 17 SPLINE
/* ------------- --------- -----------------------------
*
* Main program *
*
This program coniputes the interpolation value at
*
a specified value, given a set of table points, *
*
usixig the natural cubic spline interpolation *

Functions invoked *
* NIL *
--------------------------------------------------*
* Subroutines used *
* GAUSS
* ----------------------------------- ---------- -.---
* Vxiables used
* n Number of data points. *
*
x -- N by 1 array of data points. *
*
f - N by 1. array of function values
*
xp - Point at which interpolation is reiiirod *
*
fp - Interpolation value at xp
*
a - Array of second derivatives (N-2 by 1) *
*
d - Array representing (N-2 by 1)
C - Matrix (N-2 by N-2) representing the *
*
coefficients of second derivatives *
h - Array of distances between data points *
*
( h(i) = x(i) - x(i-l) ) *
*
df - Array of differences of functions *
* ---------------------*
* Constants used *
*
MAX - Maximum number of table points permitted *
*
- -.----- -------* /
#define 5 10
main(
C Programs 575

mt i.j,n,m;
float xfS1,f[S],a[S],dCS,C[S)[S],h1S,df[S],U[S),
xp, fp, qi ,q2, q3;

1* Reading input data *7

printf('\nlnput ::umber of data points, n \n°)


scanf("%d, &n);
printf("\nlnput data points X(I) and function \n);
printt("voiues f(i), one set on each line \n);
for(i=l; i<=n; j+f)
scanf("% f %f, &x[],&t[iJ);

printf('\nlnput point of Interpolation \n");


scanf(%f", &xp);
7* Compute distances between data points and function
differences *7

h[i] x(i)
=
df[ i ] = fCi] -

7* Initialize C matrix
tor(i2; i<n-l; i++)
tor(j=2; j<=n-l; j++)
ciii [JJ = 0.0;

7* Compute diagonal elements of C


for(i=2;i<fl-l; i++)
c [ i ] [I] = 2.0 * (hiti

Compute off-diagonal elements of c


for(i3; i<.n-l;i++)

c[i-l] (ii = h[i]


c[i] [i-li = h[i]

/ Compute eeinents of d array


for(i=2; ic=n-l; 1+4-)
d(i) = (df[ilJ/hil) - df[i]/h[i]) 6.0;

/* Compute elements of a using Gaussian elimination.


Change array subscripts from 2 to n-i to 1 to n-2
betore calling gauss() subroutine.

in = n-2;
for(irl; j<=m; i++)
Numerical Methods

d[i] d[i+l);
for(j-l; j<=m;j++)
c(i)1
j
] = C[i+l) {j+1]

guss(m,c,d,a);
/k Compute the coefficients of natura' cubic spline
for(i=n-l;i>2;i- -)
a[i] au-11;
a[lJ = 0.0;
a[n] = 0.0;

/4 Locate the domain of xp


for(i=2; j<=n;i++)

if(xp <= x[i])


break;

Jb Compute interpolation value at xp */


u[ i - l ] = xp - x(i-l];
u[i] xp - x[i];
qi h[j]*h[i] * u[i] u[i]*u[iJ*u[i];
Q2 u[ilI*u(il)*ufi_lJ - hlii*h[i] * uti-11;
q3 = f1iu[3.-l] - Eli l]u[i];
fp = (ai-1 i*gl + a[i.*(12)/(6.0 * h(i]) + 3/h(i]
/ Write result /
printf("\n SPLINE INTERPOLATION \n \n");
printf ("Interpolation value = %f \ri" fp)

/* End of man() program *1


1* ------------------------------------------------ --

/* Defining gauss() subroutine *1

gaus(int n, float a[l0]tl01, float b[l0], float x[101)

/* This subroutine solves a set of a linear equations using


gauss elimination method

ml ijk;
float pivot, factor, sum;
1* - Elimination begins ------------
for(k=l;k<=n-l;k+ I-)

pivot a [k] (kJ


for(i=k4 1; i<=n; i++)

C Programs fZl

factor = api] [k] / pivOL;


forj=k 1 1; ]<=n;4 +)
a[ij [ii a[i] U] - factor * aikI W;
b [ i jI = b[iJ factor

/ Back substitution begins


xnJ b[nJ/a[nUn};
for(k-n-];k>_L;k—)

sum 0.0;
for(j=k+l;j<=n; j±)
sum sum + aik] 1i] * xh]
x[k] = (h[k]-sumU/a1k McI;

ret urn;

/ I Ind of subroutine gauss( */


1* ------------- ---- -- ---- ----------------------------

Program 18 LINREG
1 *
* Main prugiam
* This program firs a line Y A + BX to a given *
* sot of data points b y the method least squares *
*___ ----------------------------------------
* FucL.ions invoked *
* Library function fabsM *
* ----------------------------------------------- ---------*
* Subroutincis used *
* NIL *
* *
Variables used *
* xy - Data arrays *
* n - Number of data sets *
* sumx - Sum of x values *
* sumy - Sum of y values *
* sumxx -- Sum of squares of x values
* su1ny - Sum of products of x and y *
* xmean - Mean of x values
* yniean - Mean of y values *
* *
a - y intnrcept of Lhe line
b - Slope of the line *
* --------------------------------------------------*
Numericni Methods

Constants used
*
* MAX -- Limit for number of daLe points
*
EPS - Error limit
* - - ------ *

#inclucle <rnath.h>
define MAX 10
ttdefine EPS 0.000001

ma in

tot in;
float x[101, yllO);
float sumx, surny, sunux, sumxy, xmean, vmeorl,
denom, a, b;

printfY'\n LINEAR REGRESSION \n \n");

/ Reading data values k/


orintfV\nlnput number of data poinLs, r. \rl')
scanf("%d", &n);
printf("\nlnput x and y values \n;
print.f ("One set or. each I inc \n')
for (i = 1; i<'n;i+4-)
ccant("%f %f", &x[i3, &y{i]);
/* Computing constants a and b of the linear equation *1
sumx = 0.0;
surny 0.0;
SUlflXX 0.0;
suinxy 0.0;
for(i1; i<n;i++)

silrnx = sumx t
suiny = suniy + yti);
SUTflXX SUThXX + x[iI *
suraxy = sumxy - x[i]

enean = sumX/n;
ymean = surey/n;
cienom = n*sumxx - surex * sumx;
if(fabs(denom) > FPS)

b = (n*sumxy - sumx * si.miy) /derLorl;


a ymean - b * xmean;
printf("\n LINEAR REGRESSION LINE y - a+hx \rt');
printf\nThe coefficients are:
C Programs 572

printf("a = if \n, a);


printf("b = %f \n', b);

else

printf('\n NO SOLUTION \n");

/ End of main() program *1

----------------------------------------------------*1

Program 19 POLREG
/ * ----------------------- ------ - -------..------------*
Main program *
*
This program fits a polynomial curve to a given *
set of data points by the method of
* least squares *
* ---------------------------------------------------*
* Functions invoked *
* NIL *
----------------------------------------------------

* Subroutines used *
* normal, gauss *
* ----------------------------------------------------*
* Variables used *
* x,y - Arrays of data values *
* n - Number of data points *
ir - Order of the polynomial under construction *
* in -. Number of polynomial coefficients *
* *
c - Coefficient matrix of normal equations
* b - Right side vector of normal equations *
* *
a - Array of coefficients of the polynomial
* ------------------------------------------------------*
* Constants used *
* MAX Mamimumn number of data points *
* ---------------------------------------------------
/
#include <maLh.h
#define MAX 10
main(

mt fl,ITlp,m,i;
float
printf("\n POLYNOMIAL REGRESSION \n\n");
5M Numerical Methods

7* Reading values *7
pxintf("Input number of data points n
scanf("%d,&fl);
printf("Input order of polyn(Amial, mp L eqLiired \n);
scant ('%d" . &mp)
printf( , lnpUt data values, x and y \ri");
printf("orie set on each line \r.);
for(i=l; i 'z=n; j++)
scanf("%f %f &x[iJ.

/ Testing the order */


if(ri <= MP)

printt("\rl REGRESSION IS NOT POSSIBLE \n");


goto stop;

/ Number of polynomial coefficients */


in = mp - 1;

7* Computation of elements of c and b */


normal (x,y,c,b,fl,rn);

/ Computation of coefficients a(l) to a(m)


gauss (in, c, b, a)

1* Printing of coefficients a(i) */


printf("\n POLYNOMIAL COEFFICIENTS \n\n");
for(i=l; i<=mi4+)
prinLf("%15.6f a[iJ);
printf (' \n)
sLop:
printf ('END's);

7* End of main() program


7* -----------------------------------------------------

/ Defining the subroutine ,normal() /


normal(float X[MAX ), float y tMAX], floaE c[MAX][MAX),
float b[MAXJ, j Ot n, mt in)
/* This subroutine computes the coefficients of normal
equations

lot l,j,k,ll,12;

for(j=lj<=m;i++)

for(k=l;k<'Th;k-+)
CPrograrns k.1

ctjj [k] 0.0;


11 = k+j-2;

C[i]1k] = [ 1)[k] pow Ix[i7

b[j] 0.0;
12 = i-i;
tor(i=1;i<n;j++)
[
b j l - bj1 iy[i] * pow(X[i]12);

return;

nd of subroutine norma] () *1
---------------------------..--.. -------------- *1
/* Defining giuss() subroutine */
gauss(inc n, float- aLM?X j [MAXL float b[MAX], float x[MAX]

* This subroutine solves a set of n linear equations by Gauss


EljminaJon inathod /

tnt
t.Ioat rivot, factor, Suit;
/ Elimination begifis */
for (k'l ; k .n=n-l; k+ )

pivct ak [k
for i - k * 1; <=ri; j +,)

factor = a[i Iki/pivot;


Lor(j=kl;<n;j4#)
a1i I j J = au] j] - factor * o[kj [1];
b[i] =b[l] - factor * b[k];

/* Back substitution begins *1


xn] = bnj lain] Lii];
for(k=n-1;k>,1;k_ -)

sum - 0.0;
for (jki ; j <=fl; J4 f)
2 Numerical Methods
sun + a[ k ] [ j] *
xk] (b[k]_sum)/a[k] [kh

return;

/ End of subroutine gauss(


Al
1* ----------- -

program 20 NUDIF
/ * -------------------
Main program
* This program cciTpUteS the derivative of a tal3ilated
* function at a specified value using the Newton**
* interpolation approach
* ------------------------- -------**
* Functions invoked *
* NIL
* ------------------------------ *
* Subroutines used *
* NIL
* -----------------**
* Variabl es used A

* n - Number of function values given *
* x - Array of values *
* f - Array of function values *
* a - ray of coefficients of Newton polynomial *
* d - Difference table *
* xp - Desired point of differentiation *
* dii - Derivative of the function at XP
* ------------------ *
* COflStantB used *
* NIL
• -------------------------------------------A /

main(

mt
float x[lo),flOI,a[10),d[b0]t101,xthm;

/* Reading input data A/


printf( , \fllflPut number of data points \n);
scanf(%d*, &n);
printf('\flInPut values of x and f(x), \n);
printf(*one set on each 1in \ri);
for (i 1; 1< =n; I +
scanf("%[ %f,
C Programs 83
7* Constructing difference table d I
for(i=1; i<=n;i+ft)
d(i)F11 = fIji
for(j=2; j <rn. j++)
for(=l; i<nj+l; j +)
dli] [jJ = (d{i+1j [ j -1J - d [ i ] [j-1] )/(x[i-j-lJ
x(iJ );

/* Set the coefficients of Newton interpolating jlynja1 *1


for(j=l; i<n;j++)
a[j] = d[l] [j]
/* Compute derivative at a given x = xp *1
printf('\nInput xp where derivative is required \n");
scanf("%f, &xp);
dif = a123;
for(k=3; k<=n;k.#+)

sum = 0.0;
tor(i1; i<=k-l; i++)

p = 1.0;
for(14 ; j<k_l; j+±)

if(i. == j)
continue;
P = p * (>cp -

sum = sum + p;

dif = dif + alk] Sum;

/* Write results
print f("\niJNFRlcAr DTFFTJENTTATTON USING
printf('rq w'roN POLYNOMIAL \n\n);
p rintf("DERIVATIVE at x %f is %f \n., xp,dit);

/* End of main() program *


1* --------------------------------------------------------- *7

Program 21 TRAPE1
/ * ----------------------------------------------------*
* Main program k
* This program in tegrates a given function
* using the trap ezoidal rule *
**
A Numerical Methods
*
* Functions invoked *
NIL - *
* *
* Subroutines used *
* F
* ----------------**
Variables used *
* a - Lower limit of integration *
* b - Upper limit of integration *
* h - Segment width *
* n - Number of segments *
Ict - Value of integral
----- -------. A
* - ---- - --------

* Constants used
* NTT,*
* -------------------- --------

#include <math.h)

rtain( I

nt n,;
float a,b,h,SUXtt,1ct
float F(float x):
printf("\flGive initial value of x
scanf('%f&a);
printf('\flGiVC final value of x
scant ("%t", &b);
printf ("\nWhat is the segment width? \n")
scanf("%f", &h);

n (b-a)/h;

sum (F'(a) + F(b))/2.0;


tor(il;i<=fll)
{
sum = sum + F(a+ith);

ict suxr *

printt ("\n")
tegtm0n between %f and %f \n, ab);
print f(I fl
printf(,Whefl h = %t is %f \n, h, itt);
prirtf ("\n)

/* End of main() program


/* ----------------------------------*7
C Programs
float F(float x)

float f;
f =
return (t);

1* End of subroutine F(x) *1

Program 22SIMS1
/ **
* Main program *
This program integrates a given function *
*
using the Simpsons 1/3 rule *
**
* FU11CLions invoked
*
* Macro F(x) *
--------------------------------- ---------------------- *
* Subroutines used *
* NIL A
*
*

* Variables used
* a - Lower unit of integration *
*
b - Upper limit of integration *
*
h - Segment width *
n - Number of segments *
* ics - Value at the integral *
*
*
* Constants used *
NIL *
** /
#nc]ude <nathh
#defnp P(x) 1 - exp(-(x)/20)
main(

mt n,m,j;
float a,b,h,smjcsx fi, f2, f3;

p rintf("\nlnjtj5i value of x \n'fl;


scanf("%t, &a);
pr j nLf(\nFina1 value ot x \n);
scarif("%f", &b);
print f (\rumber of segments (EVEN number) \n);
scanf('%d", &n);

NumedCal Methods

(b-a)/rt;
M -- r2
sun =
= a
fi -
for(i'L; j<rn;1--)

f2 = F(x+h);
- F(x+2')
.S um= sum + f + 4t2 +
ti f3;
= x 4- 2h;

ics sum * h13.0; ab);


pjtf(\11It1ter5l from %f o %t \n
printfVen h = %f is %t \n", Ii, ics);

End of mainJ) program


Ik ----------- ----------------------

rogram 23 ROMBRG
p

/ * ---------**
* Mai program *
This program perfo5 Romberg flLegrat1Orl *

g the intervals N times
----------------------
----------*
- byectifl
*---- ----------------------- *
*Functions invoked *
Library function tabs( *
* Macro F(X))
* ------------ *
Subroutines used *
* NIL
* ------------**
* Variables used
* a - Starting point of the interval *
b - End point of the inteal *
*
* h - Width of the interval
*
* n - Number of times bisection is done
*
* m - Number of trapezoids
r - Matrix of Romberg Integral values
* -------------*
* Constants used *
* EPS - Error bound
* -------------* /
C Programs MZ

#include <math.h> I

#define EPS 0.000001


#detine F(x) 1.0/(x)
main(

mt i,j,k,tTI,n;
float a,b,h,sunix,rrlQ] [10;

printt("\nlnput end points of the interval \n");


scanf('%f %f', &a&b);
printt('\nlnput maximum number of times');
printf("\nthe subintervals are bisected \n');
scanf("%d', &n);
/ Compute area using entire interval as one trapezoidal
h = b - a;
r[1JL1J = I•i *
intf('\n%l5.6f \n', r[l) [l});
pr

/* Process of Romberg integration begins "I


for(i=2; 1<=fl+l;i4---)

in = pc2,(i-2)); / trapezo dal for ith refinnemL *1


h h/2; / bisect step-size /

/* Use recursive trapezoidal rule for in strips *1


sum = 00;
for(k=l; k<=m; k++)

x a + (2*k_l)*h;
sum +

r[iJ [iJ = r{ilJ {1}/20 + h*Sunl;


i Compute Richardson's improvements *,
for(j=2;j<=i ; j++)

r(iJ f ] r[i] N-1J+(r


j = j ] [ j-l]-r[j-lJ li-i]) /((4,j-l) -1):

/ Write results of improvements for ith refinement *1


for(j=l; j "i; j++)
<

t
prin
%15.6f', r[i] [jJ );
f ( 1

prir.tf('\n)
/* Test for accuracy *1
if(fabs(r[j-1] [i-i) - r(i]{i)) < EPS)
/ Stop further refinement *,
NumehCal Methods

printf ('S \ri)


INTFGRATION %f \n, r{i1iI);
printfL'ROMBEPG
pi-int' ('
j)Li Stop;

eI Se

continue;

Write final result


IFn'3}ATION %[ \n", [r-1) ri+l3
printf("\flROMBFJ
printf("(NOrttlal exil fron ioop) \n")

stop:
printf ("End")

i nd of !flulfl() prograit

Program 24 TRAPE2
*
Ma).n program *

This progrnff, integrates a tabulate d function *
* using the trapezoidal rule
---------------
*
* Functions invoked *
* Library function fabs()
* -------- ------ *
* Subroutines used *
* NIL
* -----------------------------**
* Variables used *
* n Number of table point *
x - Array of independent daLa points
*
* y - Array of function values
*
- Lower lirniL of integration

* b - Upper limit of integration *
* h- Distance between points *
* nl - Position of A in the table *
* n2 position of 0 in the table *
* let - Value of integral
-----------*
*
Constants used
N11.*
* ------------------------ * /
C Programs

#include <math.h>
define MAX 15

main(

mt n, nl, n2, i;
float ab,h,suIn,ict,xiMAXJy[NAxJ;

/ Reading table values /


pLintf("Nulnber of data points \n);
scarif("%d", &n);
print f("\nlnput table values, set by set \n");
for(i=1;i<=n; i-+)
soanF("%f %f", &xb],&y[i]);

/* Reading the limits of integration I


printf("Initial value of x \n");
scanf("%f",&a)
priritf ('Fina]. value of x
scanf('%f", &b);
print- f y'\n'ihat is segment width? \n');
scanf("%f", &h);

/* Computing the position of initial and final values


nl = (inn)(fabs(a-xI1J)/h-+-1.5);
n2 (int)(fabsb-x[1])/h+2..5);
Evaluating the integral
sum - 0.0;
for(i=nl;i<=n2.--1;!.4+)
smi = sum + y [ i ] +
= sum h/2.0;
printf("\nlntegral from %f to %f is %f\n", a,b,ict);

/ End of main() program


*

Program 25 SIMS2
1* - ----------------------------------------.------- -- *
* Main program *
* This program integrates a tabulated function
using the Simpson's 1/3 rule.If the number of
* segments is odd, the trapezoidal rule is used *
for the last segment. *
* *
Functions invoked *
* Library function fabs() *
* ---------------------------------------------------*
Numerical Methods
*
* Subroutines used *
NIL
A

* Variables used *
* - Number of table points
*
* x - Array of independent values
*
* y- Array of function values
*
* a - Lower limit of integration
*
* h - Upper limit of integration
*
h - Distance between independent values
*
* ni - Position of A in the table
*
* n2 - Position of B in the table
*
* .l - Area computed using Simpson's rule
* 12 - Area of the last segrrcrit (by trapezoidal rule) *
*
ics - Value of integral
-------------------------------------------*
*
* Constants used *
Nib
* -- - ---- --------------------------- * /

tiinclude <math.h>
main(

mt i,n.nl,n2,'n,l;
float x[l51,yE15],a,b,h,5Ufl,iCS,1,i2
/* Reading table values *7
printf("Input number of data points \n);
scanf("\%d", &n);
printf("\nlflPut table values, set by set \n");
for(i=l; i<n;i++)
scant(%f %f, &x[iJ,&y[i]);
1* Reading the limits of integration
printf('Input initial value of x \n);
scanf("%f, &a);
printf("Input final value of x \n);
scanf("%f", &b);
printf(What is segment width? \n);
scenf(*%f, &h);
7* Computing the position of initial and final values
ni (int)(Labs(a-xtlJ}/h+l-.S);
n2 = (int)(fabs(b-x[lfl/h+l.5).
7* Testing for even intervals */
m = n2 - ml;
if (m%2 == 0) / m is even *1
C Programs 521

i2 = 0.0;
1 = n2 - 2;

else / in is odd */
7* Use trapezoidal rule for the last strip *1
i2 = (y[n2_]1+y(n2))*h/2.0;
1 = n2 - 3;

7* Use Simpson's rule for 1 strips


sum = 0.0;
for(i=nl;i<1; jH.+2)
sum = sum + + 4*y[i+l) + y(i+2);
ii - suni*h/30

7* Integral is sum of ii and i2 *1


cs = ii + i2;
7* Writing the results *7
priiitf("\iilnte gral from %f to %f is %f \n, i,b,ics);

7* End of main) program


7* ----------------------------------------------------
- ----------- * /

Program 26 EULER
----------------------------------------
* Main program *
* This program estimates the solution of the first *
* order differential oguation y' f (x, y) at a given *
* *
point using Ruler's method
*
*
*
* FuncLions invoked *
NIL
* *
*
* Subroutines used
* *
func()
* --------------------------------------------*
*
* Variables used
*
* x - Initial value of independent variable
* *
Y- Initial value of dependent variable
* *
xp - Point of solution
* h- Incrementa' step-size
* n - Number of computational steps required *
* *
dy -Incremental I in each step
-----------------------------*
5fl Numerical Methods

Constants used
* *
NIL
* ------------------------------------------------- --.-- * /

main(

mt 1,0;
float x,y,xp,h,dy;
float £unc(float, float);

printf("\n SOLUTION LW EULER'S METHOD \n \n);

/* Reading initial data


prnLt("Input initial values of x and y \i)");
scanf("%f %f, &x,&y);
printf("Input x at which y is required \n");
scanf("%f", &xp)
printf("lnput step-size, h \n");
scanf('%f", &h);

/* Cornputo number of steps required


n = (lot) ( (xp-x) !hfO5)

7* Compute y recursively at each step f

for(il,-i.=n;i+l-)

dy = h * func(x,y);
X = X 4 h;
y y + dy;
printf("%5d %I0.6f %10.6f \n", a,x,y);

/* Write the final resulL J


printf(\nVa1ue of y at x = %f is %f \n, x,y);

/* End of main() program


7 * ---------------------------------- ----------------- * /

/ Defining subroutine func() */

float tunc(float x, float y)

float f;
f 2.0 y/x;
return(f);

/ End of subroutine func()


7* --------------------------------------------------* /
C Pragrqms

Program 27 HELJN
/ * -- - -- - - - - - - - - - -- - - -- ---- -- - - --- - - - --- - - - - - - - - - - - - - - - - - - - - - *
ma-in pxDgram
* This program solves the first order differential *
* equation y' = f(x,y) using the Heun's method *
* -----------------------------------------------------*
* _its invoked *
* NIL *
* ------ ---------------------------------------------------*
* Subroutines used *
* func() *
- -------------- - --------------------------- *
* Variables used *
* x - Initial value of independent variable *
* y - Initial value of dependent variable *
X I ) - Point of solution *
* h - Step-size *
* r Number of stops *
* - ---------------------------------------*
Constants used *
* NIL *
--------------------------.------------------------- * /

main(

mt 1,0;
float x,v,xp, h,ml,m2;
float func(float, float);

printt("\n SOLUTION BY HEUN'S METHOD \n \n');


/* Reading initial data /
p rintf (.'Iriput initial values of x and y \n);
scanf("%f %f", &x.&y);
print.f('Input x at which y is required \n);
scanf(%f, &xp);
printf("Input step- size, h \n");
scanf("%f, &h);

/ I Compute number of steps required *1


n = ( int)((xp-x)/h-i-O.5);

/* Compute y recursively at each step


for(i = l; i<=n;i-*+)

ml = func(x,y);
m2 = func(x+h,y+mlh);
X = X + Ii;
y y + 0.5*h*(xol+rn2)
594 Numerical Methods
printf('%5d %1-0. 6f 10 .6f \rV, i,x,y)

/ Write the final resulL


princf("\nValue of y at x = %f is %f \n, X, Y)

/* End of rtain() program


1* -----------------------------------.------ -- ---- ------* /
/* Defining subroutine func() *1

float furic(float x, float y

float f;
f - 2,0
*
return f

/* End of subrouLiflo func() */


/ ------------------ ------* /
Program 28 POLYGN
*
Muiri prOcJiaTi
T his program solves the differentia) equat.ion *
* of type y' = flx,y by polygon mothod

unct.IOr'S njoked *
NIL
*
S.ibrouLe5 used *
* t]C(
ft----------- ------,-- *
*
* Variables used
x - Initial value nf the independent variable
*
y - initial value of the dependent variable *
* - Point of solution
* h - incremental nep-size
* stops required
a -- Number of computational
A- -----_ ------------- *
*
* constariLs:sed *
* NIL
* - --------- ---------- -------
main(

mt j,n;
float xyxp,h,rfll, m2

C Pogrorns

float func(float, float);


prir. tf ( \n SOLUTION U'' PD[GON flET1IOD \n \n"
i Reading initial data k/
printf" input initial values of and y \ri")
scanf("%f if", x&y)
priritf("Input x at. which y is required \n"):
an
sc f("%f", &xp)
printf "Inpuu step-size, h
suanf("%f", &h)
f Compute nurabcr of steps required /
n = (int) ((xp-x)/h0.5);

..' Compute y recrs.iveiy at each step *1

for ( i=l; i<•fl; i++)

ni = furic (x, v)
.3' h,y0.*hrnfl;
x = x -
y = y ' m2 -h;
p rintt':"%5d %l0.0 %10.6t \ri", i,x,);

/* Write the fir.a. result 'I


printf('\nValue of y at x = %f is if \n', x,y);

/ End of niai.n> program


* I,

/A Defining subroutine func()


float func(float x, float y)

float f;
f = 2.0 * y/x;
return(f)

J* End of subroutine func()


7* ------------------------------------------------------

Program 29 RUNGE4
/ * ------------------------------------------------------*
* Main program *
*
+ This program computes the solution of first order
* f(x,y) using *
differential equation of type y'
* *
the 4th order Runge-Kutta method
* -----------------------------------------------------*
Numerical Metfloas

* Functions invoked *
*
* Nil
* - *
*
* Subroutines used
func()
*---------------------------------------------------
*
* Variables used
*
x - Initial value of independent variable
y - Initial value of dependent variable *
* *
xp - Point of solution
*
h - Step-size
* *
n - Number of steps

* Constants used *
* *
NIL
* - ------------------------------------- -- ----------------* /

rnain(

nt i,fl;
float xy,xp,h,rni ,rn2,rn3m4;
float fiLnc(f Loa I:, float);

printfV\n SOLUTION BY 4th ORDER R( METHOD\n\n*);

7* input £nicial data */.


priritf("Input initial values of x and y \n°;
scaotVf f", &x&y);
printf("Tnput x at wh:ch y in required \*);
scait("%f", &xp);
pririt.f("Input step-s7e,
scanf("%f", &L);

1* Compute number of steps required


n = (in.) (xo-x)/hi-O.5)
7* Compute y at each step *7
printf('\n")
printf (" ----------------\
printfV STEP X Y \n";
printf(" --------
for i=l i<=n; i +)

ml = func(x,y)
m2= func(xO . 5*h , y+O5*rnl*h);
m3= func(x+O.Yh, y+O.5*m2*h);
m4 = func(x- y+rn3*h)
CPograms 591

x x1-h;
y - y *- (ml+20 m n2 4 2 . 0 k m3 + .4) * h/6.0;
printfY'%5d %15.6f f15.6f \n", ixy);

printf( --------------------------------------\n4
/k WriLe the final value of y /
printf("\nValue of y at x %f is %f \n", x,y);

/k End of miin() program


/ -. -------------------------/
/ Defining subroutine func()
float func(float x, flea: y)

float f;
f 2.0 * y/x;
ret urrf)

/ End of subroutine func() */


* -- --- --- --- ------- *

Program 30 MILSIM
------*
/ k -- ------------------- --
k
k main program
* This program SOIVOS the first order differential *
* equation y ' = f(x,y) using Mime-Simpson method *
* - ---------------------------------------------------- ---
* Functions invoked *
* NIL
*
* Subroutines used
* *
func()
* --------- ------. .- -.- ---*
*
* Variables used
* x(l) - Initial value of independent variable *
* *
y(l) - Initial value of dependent variabTe
* *
xp - Point of solution
*
n- Number of steps
* h- Step size
* x- Array of independent variable
*
y - Array of dependent variable
-----------------------------------------------*
* Constants used
*
NIL
* --------------------------------------------------*
Numerical Methods

main(

mt i,fl;
float h,x[l5Jy[l5]xp,ml,m2,m3,m4,f2f3,f4,f5;
float funcfloet, float);
1* Reading initial values */
printf("Input initial values of x and y \n");
scanf("%t %f, &x[U,&y[l]);
printf("Iriput value of x at which y is required \n);
s can f("%f", &xp);
printf("Input step-size, h \n");
scanf("%f", &h);

/ Compute number of computation required


a = (int.) ((xp-x[i])/h+O.5)

/* We require four starting points for Mime-Simpson


method.
Initial
values form the first point. Remaining three points are
obtained
using 4th order RX method *7

print f(\nTNITIAL VALUES ARE %10L6t %10.6f", x[lJ,y[l]);

/ I Computing three more points by RK method */


pinLf("\n\nTHREE VALUES BY RE METHOD \n);
for(i=l l<3; j+±)

ml = func(x[i].y[i));
m2 - tunc(x[i]--0.3'h, yci+O.5*ml*i1);
m3 = func(x[i]+O.5*h, y{i]+0.5*m2*h);
m4 = func(x[i]+h, yIiJ+m3*h);
x[i-.-l] xi +
yi-1-11 y[i] i (ml+.2.0*m2 2.0m3 f. m4)*h/6.0;
printf("\n%Sd %iOJf %l06f", i x{i+l]y[i-t-l]);

Computing values by Milne-Simpsen method *7


printf ( \n\nVALUES OETAINED BY NE-SflPSON METHOD \n");
for]i=4; i<r;i+)

f2 = f i inc(x[i-2J, y[i-2]);
f3 = fun c(x[ i - lJ, y[i-lfl;
f4 func(x)ij, yli]);

/ p redicted value of y (by Mime's formula)*/


y[i+l] = y[i 31 1 4,0*h/3.0 * (2.0*f2_f3F2,0*f4);
x[i.'lJ = x[i) i-
f5 = tunc(x[i+l], y[i'-l]);

C Programs 599

/ Corrected value of y (by Simpson's formula) I


v[-lj y[il]+/3.O (f3±4.0*f44-f5);
print f("\n%5d %10.6f 10.6f", i, x[ii , y[i+l]

printf("\n\nValue of y at x %f is f", x[n+l], y[n+1J);

/ End of main() program


------------------------------------------------------* /

/* Defining subroutine funcO*/

float func(float x, float y)

float
= 2.0 * y/x;
* return (f)

/ End of subroutine func)


/* - ----------------* /
- APPENDIX
K_J
Bibliography

!.NUMERICAL COMPUTING
1 . Antia, 11 2v1, Auinei-c'cil Methods br Scicu(cs t.s and fr;igineers, Tata
McGraw-Hill Publishing Company, New Delhi, .1991.
2. Atkinson, L \', P J Harley and J D Hudson, Numerical Mrt!,ods
with PORTRAi\7 77. Addisori-Wc1cv Publishin g Comnaicv. 1989.
3. Buchanan, J L and P H Turner, Numerical Methods atul..4n.rztvscs,
McGraw-Hill Book Company, 1992.
4. Chapra. S C and It P Canale, Numerical. Methods tar Enguwers,
2nd Edition, McGraw-Hill Book Company. 1989.
5. Coristantinides, A, Applied Numerical Methods ad/i Personal
Computers, McGraw-Hill Book Company. 1987.
6. Conte, S I) and Carl do Boor. K/muon fur y Numerical Anal ysis, 3rd
Edition, McGraw-THU Book Company, 1981.
7. Gerald, C F and P 0 Wheativ. Applied Numerical Analysis. 5th
Edition. Addison-Wesley Publishing Company, 1991.
8. Griffith ,, D V and I M Smith, Numerical Methods /r Engineers.
OxThrd University Press. 1991.
9. Ledevrnann, W (Chief Editor), .Handbook of Applied Mathematics
(Volume lii) John Wiley &. Sons, 1981.
10. Mathews, J II, Numerical Methods /ir Mathc'mu/ics. &ienc'c and
Engineering, 2nd Edition, Prentice-Hall at India, 1994.
11. Scheid, F, Numerical Anal ysis i Schauin Series), McGraw-hill
Publishing Company, 1990.
12. Yakowit.z, S and F Szidrirovszkv, An. hrItroiuJinri. to Numerical
Computation, 2nd Edit ion, Macmidan I 'abashing Company, 1090.
Bibliography 6U1

PROGRAMMING

1. Baliigurusamv. E, FVR'I hAN for Bginncrs. 'fats McGraw-Hill Pub-


lishing Company, New Delhi, 1985.
2. Balagurusamy, E. Programming in Aj'JSI C, 2nd Edition, Tata
McGraw-Hill Publishing Company, New Delhi, 1989.
3. Chamberland, L. FOR THAN 90-A Reference Guide, Prentice-Hall,
1995.
4. Etter, D M. Structured FORTRAN 77 for Engineers and Scientists,
4th Edition, Benjamin/Cummings Publishing Compan y . 199.
5, Kochan, S G, Programming in C, Hayden Book Company, 1983.
6. McCracken, D D and W I Salman, Computing for Engineers and
Scientists with FORTRAN 77, 2nd Edition. ,John Wiley & Sons,
1988.
7. Nyhoff, L and S Lecstma, FORTRAN 77 and Numerical Methods
fbi Engineers and Scientists, Prentice-Hall, 1995.
Index

Abacus 14 Power method 479


Ahanlute error 66, 70 Secant 153
Accuracy 8, 63 Shooting mithod 469
Adams -Bashfort}i predictor 450 Analog computer 2. 17
Adams-Moulton corrector 450 Analytical method 123
Adjoint matrix 509 Application programs 26
Algebraic equation 122 Approximating functions 276
Algebraic expression 102 Arguments 109, 110
Algorithm 7, 30, 80 Arithmetic logic unit 22
Bairstow 186 Arithmetic operators 102
Basic Gauss elimination 213 Array 99
Bisection 133 Assembler 28
Cholesky 241 Assembly language 27
Crout 240 Assignment statement 102
Dolittle 231, 233 Associative law 57
False position 139 Asymptotic convergence factor 86
Fixed-point 169
Gaussian integration 401 Back substitution 212
Gauss-Jordan 228 Backward difference derivative 361
Gauss-Seidel 261 Backward difference quotient 348
Homer's rule 128 Backward difference table 298
Incremented search 167 Backward difference 298
Iterative refinement 243 Backward error analysis 87
Jacobi 254 Backward jump 35, 103
Linear regression 327 Bairstow's method 183
Muller 196 Base 41
Multiple roots 178 Basic Gauss elimination 212
Natural cubic spline 307 Bender-Schmidt equation 494
Newton-Raphson 146, 171 Binary chopping method 131
Partial pivoting 220 Binary code 27
Polynomial fit 336 Binary digits 40
Pol ynomial method 477 Binary numbers 40
Index

Binary system 12 Computer-aided learning 13


Bisection algorithm 133 Computer-aided manufacture 13
Bisection method 131 Computer-managed learning 13
Bits 49 Condition number 81, 246, 247
Blunder 69 Conditional execution 103
Book's rule 387 Conditioning 80
Boundary value problem 412, 464 Constants 97
Bracketing method 124 Continuous data 2
Branching structure 33 Control statement 96
Hugs 113 Control unit 22
Built-in-functions 112 Control variable 106
Convergence 86
C9 Bisection method 134
C++ 9 False position method 140
Calling program 109, 110 Fixed-point method 163
Calling statement 109, 110 Gauss-Seidel 267
Central difference 512 ,Jacobi method 26
Central difference derivative 361 Ncwton-Raphson 147
Central difference operator 521 Secant method 153
Central difference quotient 349 Conversion error 64
Central processing unit 22 Corrector 427
Character constants 98 Counter 943
Character type 98 Cramer's rule 509
Characteristic equation 472 Crank-Nicholson formula 496
Characteristic matrix 472 Crose average 489
Characteristic polynomial 472 Crout algorithm 240
Characteristic values 472 Croci LU decomposition 231
Chebyshev basis polynomial 315 Cubic spline 302
Chebyshee interpolation 314 Curve fitting 275, 323
Chebyshev points 314
Chebyshev polynomial 315 Data 20, 40
Cholesky's factorisation. 241 Data error 64
Chulesky's algorithm 241 DATA statement 101
Chopping 65 Debugging 26, 113
Closed form 371 Decimal numbers 41
Coefficient matrix 244, 246, 511 Decimal system 41
Cofactor 508 Decomposition 231
Column vector 506 Deflation 175
Comment line 95 Degree of equations 410
Compiler 26, 28 Dependent equations 209
Complete pivoting 220 Dependent variable 323, 410
Complex constants 98 Descartes rule 174
Complex number Determinant 507
Complex root 173, 176, 183, 199 Diagonal average 489
Complex type 97 Diagonally dominant system 268
Composite approach 374 Difference equation 484
Composite Simpson's 1/3 rule 382 Difference tables 360
Composite trapezoidal rule 374 Differential equations 408
Computer memory 40 Digital computer 3, 17
Computer program 20, 24, 27 Dimension 100
Computer-aided design 13 Direct method 207
4 Index
Direct substitution method 161 Fixed loop 34
Dirirhict boundary conditior 488 Fixed point arithmetic 52
Discrete data 2 Fixed point equation 161
Discretisation error 67 Fixed point method 160, 168
Display screen 20 Floating point arithmetic 53
Distributive low 57 Hooting point form 50, 98
Divided difference table 29 Floating point number 51
Divided differences 288 Floppy disk 23
DO loop 106 Flowchart 32, 103, 107
D(-)..WHILE structure 106 FORMAT statement 101
Documentation 114 Fori tat-directed VU statement 100
Dolittle algorithm 231 FORTRAN 9
Do] ittle LU decomposition 231 FORTRAN expression 102
Double precision 99 Forward difference 295
Drag coefficient 69 Forward difference derivative 360
Driver program 109 Forward difference quotient. 348
Dummy variables 109, 110 Forward difference table 296
Forward difference 295
Efficiency 9 Forward elimination 211. 212
Eigcnvalue problem 465 Forward error analysis 87
Eigeriva]ues 472, 475 Forward jump 34, 103
Eigenvector 472, 476 Fourth generation 16
Elimination approach 207 Functions 109
Elliptic equation 4.84, 486
Empirical error 64 Gauss elimination 212, 219, 228
ENIAC 15 Gaussian integration 394
Equal matrix 507 Gaussian quadrature 395
Error propagution 73 Gauss-Jordan method 228
Euler's method 419 Gauss-Legendre formula 396
Euler-Maclaurin formula 388 Gauss-Legendre rules 371
Executable statement 96 Gauss-Seidel iteration 259, 489
Experimental error analysis 88 General purpose computer 3, 18
Expert s ystems 16 General solution 411
Explicit method 495 Global truncation error 421
Exponent 51 Gracife's method 516
Exponential form 98 Graphical method 123
Expressions 102
Extrapolation method 124 Hall interval method 131
Extrapolation 362, 388 Hard disk 24
Hardcopy 20
Factorisation 230 Hardware 21
Fudeev-Leverrier meth 1 474 [feat equation 493
False position algorithm 139 Heun's method 425
False position formula 138 Hexadecimal numbers 40, 42
False position method 138 Hexadecimal system 42
Fifth generation 16 High-level language 28
Finite ditidrence method 464, 469, Homogeneous equations 209
484 Horner'sj rule 129
Finite-element method 484 Human error 69
First generation 16 Hybrid computer 17
Five-point formula 350 Hyperbolic equation 484, 497
Index

IC chips 16 Laplace's equation 486


Identity matrix 246, 472, r 5O5 Laplacian operator 486
IF..ELSE structure 103 Large-scale integration(L81) 16
111-conditioned problem 9, 81 Law of cooling 408
Ill-conditioned system 209, 244 Law of motion 408
111-conditioning 342 Lest-squares polynomials 276
Implicit method 496 Leat-squares regression 276, 324,
Inconsistent equations 208 325
Incremental search 167 I.iehmann's method 489
Independent variable 323, 410 Linear equation 206. 411
Induced errors 80 Linear Fitting 324
Induced instability 85 Linear function 121
Infinite solutions 208 Linear interpolation 138, 279
Information 20 Linear interpolation for-mula 280,
Inherent error 64 282
Inherently unstable 81 Linear system 168
Initialisation 96 Linearly convergent 134, 140, 164
liii Li a] -value problein 412, 464 List-directed I/O LuLoiriiiL 100
Inner loop 108 Local truncation error 421
Input devices 21 Logarithm 14
Input error 64 Logic errors 114
Input statement 100 Logical conatunLs 98
Integer arithmetic 52 Logical expression 105
Integer constants 98 Logical operators 105
Integer form 50 Logical type 98
Integer type 91 Looping structure 31 106
Integration nodes 370 Low level language 27
Interactive computing 30 Lower triangular matrix 231
Interpolation 276 LU decomposition 231, 240
Interpolation function 281
Interpolation method 124 Machine code 27
Interpolation polynomial 276 Machine epsilon 71
Interpreter 26 Machine language 26, 27
Interval arithmetic 52 Main program 109
Intrinsic functions 112 Mainframe computer 18
Inverse matrix 509 Mantissa 51
Iterative method 123, 124 Mark il-I
Iterative process 8 Mathematical model 3
Iterative refinement 242 Matrix inversion 245
Matrix norm 247
Jacobi iteration 253 Mean-value theorem 79
Memory unit 22
KmrchholTs law 409 Method of square roots 241
Knots :WO, 312 Microcomputer 18
Knowledge-based systems 16 Microprocessor 18
Midpoint method 433
Lagrange basis polynomial 282 MJlne's formula 445
Lagrange interpolation 281 Milne-Simpon method 445, 451
Lagrange interpolation polynomial Minicomputer 1
282, 371 Minor 508
Longuage processors 26 Mixed-mode expression 102
Ql Index

Modelling 13 Octal numbers 40, 44


Modelling error 69 Octal system 44
Modifiers 452 One-dimensional array 99
Modular programming 31, 109 One-step methods 412
Modular structure 222 Open end method 124
Modules 109 01100 form 371
Monolonc convergence 1:3 Operation system 24
Monotone divergence 163 Operators 102, 104, 105
Muller's method 195 Order of conve rg'ner' 61
Multidimensional array 99 Order of cqoation 410
Multiple roots 174, 178, 199 Ordinary differential equationa 410
Multisegment approach 374 Outer loop 106
Multistep methods 412, 444 Output devices 22
Output statement Pit)
Named constant 90 Over determined 209
Natural cubic spline 806 Overflow 55
Nesting 107
NCW tori form 278, 267 Parabolic equaLiori 464, 492
Newton interpolation polynomial Pa a ii hi Oil in pu tcr 9, 20
26, 371 iranieer statement. 99
Newtons interpolation 286 Partial ilinvatives 483
Newtons three-eighths rule 385 Partial ditterential equation 410,
Newton-Cotes formula 371 183
Newton-Cafes rules 371, 388 Partial pivoting 220
Newton-Gregory formula 296. 298 Particular solution 412
Newton-C z-egorv interpolation 296, PCAT 19
296 PCX'l' 19
Newton-Raphson algorithm 146 Pentium 19
Newlon-Raphson formula 145 Personal computer 19
Newton-Raplison method 145, 170, Perturbations 80
178 Picard's method 417
Nodes 300 Piecewise polynomial 300
Non-linear equation 206, 411 Pivot element 219
Non-linear fitting 329 Pivot, equation 214
Non-linear function 121 Pivoting 219
Non-linear system 168 Poisson's equation 490
Non-singular matrix .511 Polygon method 432
Normal equations 326 Pol y nomial equation 122
NorinalicaLion 52, 214. Polynein'iisl fitting 333
Normalised numbers 52 Polynomial method 473
Numerical computing I Positional form 98
Numerical differentiation 347 Power form 277
Numerical error 65 Power method 477
Numerical instability 80 Precedence rule 102
Numerical integration 370 Precision 63
Numerical method 3 Predictor 426
Numerical quadrature 370 Predictor-corrector method 426
Numerical stability 8 'rinter 20
Numerically unstable 80 Procedural error 65
Processing block 90
Object program 26, 28 Program statement 95
Index 607

Program unit header 95 Shooting method 464, 465


Purification 177 Sign hit 50
Significant digits 62
Quadratic convergence 148 Simple difference 294
Quadratic equation 123, 195 Simple harmonic motion 409
Quadruplets 43 Simpson's 113 rule 379
Simpson's 318 rule 385
Radioactive decay 409 Simpson's formula 445
Radix point 42 Simulation 13
Rate of convergence 8,96 Simultaneous equations 207
Real constants 98 Singular syslenis 209
Real numbers 51 Size 99
Real root 173 Slide rule 14
Real type 97 Softcopy 20
Recursive trapezoidal rule 391 Software 24
Regression analysis 323 Source program 28
Regression line :126 Special purpose computer 18
Regression plane 342 Spiral convergence 163
Regula folsi 138 Spiral divergence 163
Relational expression 104 Spline function 300
Relational operators 104 Spline interpolation 299
Relative error 70 Spline interpolation polynomial 801
Relaxation parameter 266 Splines 300, 302
Representation error 64 Square matrix 505
Residual vector 243 Stability 80
Richardson ext rrpulation 362, 389 Starting values 444, 499
Romberg integration formula 390 Statement functions 112
Romberg integration 371, 388 Statement label 96
Root squaring method 516 Statement number 96
Roots 121 Stopping criterion 127
Rounding 65 might-line logic 33
Roundoff error 8. 62. (F cturcd programming 33
Row vector rea, nrain 109
Row-sum norm 247 Sut uLinc- 109 10
RungeKutta method 136 Suliscrip d vari e 99
Run-time erron- 114 Suhscrip a 9
Subtractiv tion 56. 76
Sampling points 370 Successive rumations 161
Saturation growth rate 331 Successivci u laxation 266
Scaling factor 478 Successive r xtiori method 266
Scatter diagram 323 Supercomput r 19
Scientific form 98 Superlinear convergence 157
Search bracket 126 Symbolic computation 9
Secant algorithm 153 Symbolic constant 96
Secant formula 152 Symmetric rounding 65, 66
Secant method 151 Synthetic division 175
Second generation 16
Semi-numeric method Tabulated function 347
Sensitivity analysis 80 Taylor expansion 278
Sequence structure 33 Taylor series method 413
Shifted power form 277 Testing 113
Index

Third generation 16 Underfiow 55


Three-point formula 349 Unique suhttim 208
Top-down design 31 TJNIVAC 15
Trace of a matrix 474, 507 (Jqer triaigii1ar-tnatrjx 231
Transcendental equation 122 Usernonual 114
Transibtor 16, 40 Utility programs 25
Translators 26, 28
Transpose matrix 506 VaCULLHT tube 16

Trapezoidal rule 372 Validation 3


Triangle inequality 73 Variable dec1artion 99
Triangularisal,ion 213 Variable loop 34
'I'rithagonal systern 307 Variable-order approach 388
Tripleta 45 49 Variables 98
Truncating 65 \'pctor computers 9
Truncation error 8, 67
Two-dimensional array 100 Wave equation 497
Two-point forxnala 348 Weighting coelficicnce 370
Type declaration 95 WlflI'hectk'r disk 24
Workstation 19
Under determined 209 Zero trix 506

You might also like