You are on page 1of 32

Detailed Solutions A-07

Q1.

JUNE 2003

I = f (0), where f ( x) = cos x. I = = 3.14.

a.

b.

c.

d.

e.

Use divided difference interpolation.

f.

If Ax = x, then A 1 x = (1 / ) x.

It is a property of Gauss formulas.

k = 4 + (4 > 1) = 4 + 1 = 5.

n +1 = C n2 . Order = 2.

PART I
Q2

lim x n +1 = x = lim x n . The error is defined by x n = n .


x

x
a
(i) x = ( 1 + 2 ) gives 2 x 2 = x 2 + a, or x = a .
2
x
x
x2
x2
) gives 2 = 3
, or x = a .
2
a
a
Substituting x n = + n in the first formula, we get

(ii) x = ( 3

2
1
( + n ) 1 + 1 + n
2


1
= ( + n ) 2 2 n + 3 n
2

+ n +1 =

1
[ 2 + n n2 + L]

2
2

=
Hence, n +1 =

n2 n3

+L
2 2 2

n +1

or

2
3


4 n + L

(1)

n2
.
2

(2)

Substituting x n = + n in the second formula, we get

+ n +1 =

3 2 3
1
( + n ) 3 12 ( + n )2 = 1 2 n n2

Hence, n +1 =
or

3 n2 n3

2 2 2

n +1

(3)

3 n2
2

(4)

Error in the second formula given by ( 4 ) is 3 times the error in the first formula given by ( 2 ). If, we
multiply the first formula by 3 and add to the second formula, then from ( 1 ) and (3 )
2 3
n +1 = 2n + L

Then, the order of the new formula is 3. The new formula is


2
x2
1
3a
1
3a x
4 x n +1 = x n 3 + 2 + 3 n or x n +1 = x n 6 + 2 n .
2
a
8
a
xn
xn

Q 3a

3 2 2 u11
A = 2 4 4 = 0
2 4 5 0

u12
u 22
0

u13 u11
u 23 u12
u 33 u13

0
0
u 33

0
u 22
u 23

Comparing the elements, we get


2
u 33
= 5, u 33 = 5 ;
2
u 22

2
+ u 23

= 4, u 22 = 2

Hence, U = 0
0

Q 3b

u13 u 33 = 2, u13 = 2

1
2

5;

5
5
0

2
4

5;

u 23 u 33 = 4 , u 23 = 4

u12 u 22 + u13 u 23 = 2 , u12 = 1

5;

5
5

#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
clrscr();
float a[10][10], b[10], x[10], oldx[10], sum, big, c;
float eps;
int
n, niter, i, j, ii, jj, k, l;
printf("Input the order of matrix : n\n");
printf("Input the number of iterations : niter\n");
printf("Input error tolerance : eps\n");
scanf("%d %d %e", &n, &niter, &eps);
printf("n = %d, niter = %d, eps = %e\n", n, niter, eps);
printf("Input augmented matrix row-wise\n");
printf("Elements of the augmented matrix\n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
scanf("%f", &a[i][j]);
printf("%f ", a[i][j]);
}
scanf("%f", &b[i]);
printf("
%f\n", b[i]);
}
printf("Input initial approx. to the solution vector\n");
for (i = 1; i <= n; i++)
{
scanf("%f", &oldx[i]);
printf("%f ", oldx[i]);
}
printf("\n");
for (i = 1; i <= n; i++)

2
u11

5;

2
2
+ u12
+ u13
= 3, u11 = 2 .

l10:

x[i] = oldx[i];
for (ii = 1; ii <= niter; ii++)
{
for (i = 1; i <= n; i++)
{
sum = 0.0;
for (j = 1; j <= n; j++)
{
if((i - j) != 0)
sum = sum + a[i][j] * oldx[j];
}
x[i] = (b[i] - sum) / a[i][i];
}
big = fabs(x[1] - oldx[1]);
for (k = 2; k <= n; k++)
{
c = fabs(x[k] - oldx[k]);
if(c > big)
big = c;
}
if(big <= eps)
goto l10;
for (l = 1; l <= n; l++)
oldx[l] = x[l];
}
printf("ITERATIONS NOT SUFFICIENT\n");
printf("Solution vector at this stage\n");
for (i = 1; i <= n; i++)
printf(" %f ", x[i]);
printf("\n");
goto l20;
printf("Number of iterations = %d\n", ii);
printf("Solution vector\n");
for (i = 1; i <= n; i++)
printf(" %f ", x[i]);
printf("\n");

l20:
}
Q 4a

Let the uniform mesh be defined as x 0 , x1 , K , x n , x n +1 , K where x i = x 0 + ih , i = 1, 2, K Integrate the


given differential equation y = f ( x, y ) in interval [x n , x n +1 ] to get
xn +1

xn +1
dy
dx =
f ( x, y ) dx
xn
dx

or

xn +1

y ( x n +1 ) = y ( x n ) +
xn

f ( x, y ) dx

We note that f (x, y) is the slope of the solution curve and it changes continuously. Approximate the
changing slope in [x n , x n +1 ] by the fixed slope f ( x n , y n ) at x = x n . Then, we get the
approximation
y n +1 = y n + f ( x n , y n )

x n +1

dx

or

y n +1 = y n + h f ( x n , y n )

where x n +1 x n = h . This method is called the Euler method.


We have, x 0 = 0, y 0 = 1 and y n +1 = y n + 0.1( x n + y n ) ,

n = 0, 1, 2, 3.

For n = 0 , we get y ( 0.1 ) y1 = y 0 + 0.1 ( 0 + 1 ) = 1.1 .


For n = 1 , we get y ( 0.2 ) y 2 = y1 + 0.1 ( x1 + y1 ) = 1.1 + 0.1 (0.1 + 1.1) = 1.22 .
For n = 2 , we get y ( 0.3 ) y 3 = y 2 + 0.1 ( x 2 + y 2 ) = 1.22 + 0.1 (0.2 + 1.22) = 1.362 .
For n = 3 , we get y ( 0.4 ) y 4 = y 3 + 0.1 ( x3 + y 3 ) = 1.362 + 0.1 (0.3 + 1.362) = 1.5282 .

Q 4b

Gauss-Jordan method gives [ A I ] [ I A 1 ] .


1 1 2 1 0 0

1 5 8 0 1 0 , R 2 R1 , R3 2 R1 ,
2 8 14 0 0 1

1 1 2 1 0 0

0 4 6 1 1 0 , R 2 4 ,
0 6 10 2 0 1

1 1 2
1 0 1 2 5 4 1 4 0
1
0 0

0
1
3
2
1
4
1
4
0
,
R
R
,
R
6
R
,
1 4 0 ,
1
2
3
2 0 1 3 2 1 4

0 6 10 2
0 0 1 1 2 3 2 1
0 1

1 0 0 3 2
1 2 1 2
3R3
R3

R1
, R2
, 0 1 0 1 2
5 2 3 2 .
2
2
0 0 1 1 2 3 2
1
Q 4c

1 2 1 2
32
A 1 = 1 2
5 2 3 2 .
1 2 3 2
1

P ( x) = c + c x . We have xi = 2, xi2 = 6, .
1
0 1
f ( xi ) = 13, xi f ( xi ) = 13 . Normal equations for fitting the required linear polynomial are

Let the linear polynomial be

(with w(x)=1):
3

f (x ) c c
0

i=0
3

i =0

f (x ) x c
i

i=0

This

gives

xi = 0

i=0

xi

i =0

xi2 = 0

i =0

13 4 c0 + 2 c1 = 0 and - 13 + 2 c 0 6 c1 = 0 .

Hence

we

get

13
c0 = 13 10 , c1 = 13 5 . Hence the required linear polynomial is P1 ( x) = (2 x 1) .
10
Q5

Power method : Let

1 , 2 , K , n

be the distinct eigen values such 1 > 2 > L > n and

v 1 , v 2 , K , v n be the corresponding eigenvectors. Then, any vector v in this vector space of


eigenvectors can be written as

v = c1 v 1 + c 2 v 2 + K + c n v n .
Then, Av = A (c1 v 1 + c 2 v 2 + K + c n v n ) = c1 1 v 1 + c 2 2 v 2 + K + c n n v n

= 1 c1 v 1 + c 2 2

v 2 + K + c n n


v n

Pre-multiplying by A, k1 times and k times, we get


k
k

2
n
k
k
A v = 1 c1 v 1 + c 2 v 2 + K + c n v n

1
1

k +1
k +1



A k +1 v = k1 +1 c1 v 1 + c 2 2 v 2 + K + c n n v n

1
1

(1)
(2)

Now, i 1 < 1 , i = 2, K , n . Hence, as k , the right hand sides of (1) and (2) tend to

1k c1 v 1 and 1k +1c1 v 1 . Therefore, all the ratios of the components of the left hand sides of (1)
and (2) tend to 1 , the largest eigen value in magnitude

A k +1 v r
, r = 1, 2, L , n .
k A k v

1 = lim

( )

The iteration is stopped when the magnitudes of the differences of the ratios are given error tolerance.
The algorithm is given by
y k +1 = Av k ,

v k +1

mk +1 = max (y k +1 )r

v k +1 = y k +1 mk +1 ,

(y )
1 = lim k +1 r , r = 1, 2, K , n .
k (v k )r
is the corresponding eigen vector. We have the following results.

v 0 = [ 1, 1, 1] ,
T

y 1 = Av 0 = [ 28, 4, 2] ,
T

v 1 = [1, 0.14286, 0.07143] ,


T

y 2 = Av 1 = [25, 1.42858, 2.28572] , v 2 = [1, 0.05714, 0.09143] T ,


T

y 3 = Av 2 = [25.24, 1.17142, 1.63428] , v 3 = [1, 0.04641, 0.06475] T ,


T

y 4 = Av 3 = [25.17591, 1.13923, 1.741] , v 4 = [ 1, 0.04525, 0.06915] T ,


T

y 5 = Av 4 = [25.5908, 1.13575, 1.7234] , v 5 = [ 1, 0.04438, 0.06734] T .


The ratios of the components of y 5 and v 4 are [25.5908, 25.0994, 24.9226]T. The three ratios tend to
the same eigen value 25 which gives 1 . The corresponding eigen vector is v 5 .
T

Q 6a

The bound for the error in quadratic interpolation is given by


1
Error max (x x 0 )(x x1 )(x x 2 ) M 3
6
where M 3 = max f ( x ) .
x0 x x2

Since the data is equispaced, assume without any loss of generality that x 0 = h, x1 = 0, x 2 = h . Then,

max (x x 0 )(x x1 )(x x 2 ) max x x 2 h 2 .


Let g ( x) = x( x 2 h 2 ) . Setting g ( x) = 0 = 3 x 2 h 2 , we get the stationary points as x = h / 3 . The
required maximum is

x x2 h2

)=

Therefore, Error

h h 2
2h 3
h 2 =
.

3 3
3 3

h3
9 3

M3 .

We have f ( x) = e x , f ( x) = e x , f ( x) = e x , f ( x) = e x , and M 3 = max e x = 1 .


0 x 1

Choose h such that

< 5 10 4 , or h 3 < 45 3 10 4 , or h < 0.1983 .

9 3

Q 6b

#include <stdio.h>
# include<conio.h>
float power (float m, int n);
long int fact (int m);
void main ( ) {
clrscr();
int i, a;
float val, temp, x;
printf ("Input the value of x ");
scanf("%f", &x);
fflush(stdin);

temp = power(x,2);
val = 1- (temp/2 );
a = 2;
for (i=3; i<=25; i++) {
temp = (float) fact(a*(i-1));
val += power (x, (a*(i-1))) / temp;
}
printf ("The sum of series is %f ", val );
}
float power (float base, int n) {
int i;
float p;
p = 1;
for (i=1; i<=n; i++) {
p = p*base;
}
return p;
}
long int fact (int n) {
int i;
long int p = 1;
if (n > 1)
for (i=2; i<=n; ++i)
p = p*i;
return p ;
}

Q 7a

Q 7b

PART II
#include <stdio.h>
#include <conio.h>
float T(int,float);
void main() {
clrscr();
int n;
float x,Tn1;
printf("n = ");
scanf("%d", &n);
printf("x = ");
scanf("%f", &x);
Tn1 = T(n,x);
printf("The value of Chebyshev Polynomial = %f\n", Tn1);
}
float T(int a, float x1) {
int m, k;
float Tn;
if (a == 0) {
return( 1.0);
}
else if (a == 1) {
return(x1);
}
else {
m = a - 1;
k = a - 2;
return( 2.0 * x1 * T(m, x1) - T(k, x1));
}
}

We have the following divided difference table.

f (x) first d.d second d.d third d.d

4
5

48
100

52

294

97

15

10 900
202
21
1
Newtons divided difference interpolation:

f ( x) = f ( x0 ) + ( x x0 ) f [ x 0 , x1 ] + ( x x0 ) ( x x1 ) f [ x0 , x1 , x 2 ]
+ ( x x0 ) ( x x1 ) ( x x 2 ) f [ x 0 , x1 , x 2 , x3 ]
= 48 + ( x 4)(52) + ( x 4)( x 5)(15) + ( x 4)( x 5)( x 7)(1) = x 3 x 2 .
Hence, f (2) = 4, f (8) = 448 .
Q 8a

Bairstows formula
R p = c n 2 , R q = c n 3 ,

S p = bn 1 c n 1 pc n 2 , S q = ( c n 2 + pc n 3 ), ,

R = bn 1 , S = bn + pbn 1 ,
p1 = p 0 + p,

q1 = q 0 + q .

p = 3
q= 5

1
p = 3
q= 5

p=

RS q SR q
R p S q Rq S p

q =

RpS R S p
R p S q Rq S p

p 0 = 3, q 0 = 5.

5 3 5 9
3 6 6 3
5 10 10

4 = b4

3 3 30
5 5
_____________________
1 1 10 36 = c 3
_____________________

We have R p = 10, R q = 1, S p = 5, S q = 7, R = 1, S = 1 .
6
5
= 0.0923, q =
= 0.0769 .
65
65
p1 = 3 0.0923 = 2.9077, q1 = 5 + 0.0769 = 4.9231 .

p=

The factor is x 2 + 2.9077 x 4.9231.


Q 8b

Classical Runge-Kutta fourth order method.


1
[ k 1 + 2k 2 + 2k 3 + k 4 ]
6
k

h
k1 = h f ( x n , y n ) , k 2 = h f x n + , y n + 1 , k 3 = h
2
2

k 4 = h f ( xn + h , yn + k3 )
y n +1 = y n +

h
f x n + , y n + 2
2
2

We have f ( x, y ) = x 2 + y 2 , x 0 = 1, y 0 = 2, h = 0.2 .
k1 = 0.2 ( 1 + 4) = 1.0 , k 2 = 0.2 f ( 1.1, 2.5 ) = 1.492,
k 3 = 0.2 f ( 1.1 , 2.746 ) = 1.7501, k 4 = 0.2 f ( 1.2, 3.7501 ) = 3.1007.
1
y (1.2) y1 = y 0 + ( k1 + 2k 2 + 2k 3 + k 4 ) = 3.7642.
6

Q 9a

Gauss-Legendre two point formula


1
1
1
+ f
.
f ( x) dx = f

1
3

a f ( x) dx

is transformed to

1 g (t ) dt

by the transformation x = [(b a) t + (b + a)] 2 .

Transform the interval [5, 12] to [1, 1]. Use the transformation x = [ 7t + 17] 2 .
We have dx = 7 dt 2 and
12

Q 9b

Q 10a

dx
=
x

7dt
1
= 7
+
7t + 17

7
3 + 17 7

= 0.8729.
3 + 17
1

#include <stdio.h>
#include <conio.h>
void main () {
clrscr();
FILE * fp;
char c;
int nw=0,ns=0;
fp = fopen ("sample.txt", "r+" );
if (fp == NULL)
printf("Cannot open file.\n");
else {
while (( c=fgetc(fp)) != EOF) {
if ( c == ' ' || c == '\n' || c == '\t' )
nw++ ;
if ( c == '.' )
ns++;
}
printf ("The total number of words and sentences" );
printf (" in the file are % d and % d respectively", nw, ns );
}
fclose( fp );
}
f ( x 0 , x1 ) =

f 1 f 0 (1 x1 ) (1 x 0 )
1
=
=
x1 x 0
x1 x 0
x 0 x1

f ( x1 , x 2 ) f ( x 0 , x1 ) [ 1 ( x1 x 2 )] + [ 1 ( x 0 x1 )]
(1) 2
=
=
.
x 2 x0
x 2 x0
x 0 x1 x 2
Let the result be true for n = k , that is
f ( x 0 , x1 , x 2 ) =

f [ x 0 , x1 , L , x k ] =
Then,

( 1) k
.
x 0 x1 L x k

f [ x 0 , x1 , L , x k +1 ] =

f [ x1 , L , x k +1 ] f [ x 0 , x1 , L , x k ]
x k +1 x 0

[(1) k /( x1 x 2 L x k +1 )] [(1) k /( x0 x1 L x k )]
x k +1 x0

(1) k +1
.
x 0 x1 L x k +1

( 1) n
.
x 0 x1 L x n
Q 10 b Unions contain members whose individual data types may differ from one another. However, the
members that compose a union all share the same storage area within the computers memory, whereas
Hence,

f [ x 0 , x1 , L , x n ] =

each member within a structure is assigned its own unique storage area. Thus, unions are used to
conserve memory. They are useful for applications involving multiple members, where values need not
be assigned to all of the members at any one time.
union id {
char color[12]
int size;
} shirt, blouse;
Here we have two union variables, shirt and blouse, of type id. Each variable can represent either a 12character string (color) or an integer quantity (size) at any one time.
The 12-character string will require more storage area within the computers memory than the integer
quantity. Therefore, a block of memory large enough for the 12-character string will be allocated to
each union variable. The compiler will automatically distinguish between the 12-character array and
the integer quantity within the given block of memory, as required.
A structure is a collection of one or more variables, possibly of different types, grouped together under
a single name for convenient handling. Structures help to organize complicated data, particularly in
large programs, because they permit a group of related variables to be treated as a unit instead of as
separate entities. Examples:
(i) The payroll record: an employee is described by a set of attributes such as name, address, social
security number, salary etc.
(ii) A point is a pair of co-ordinates, a rectangle is a pair of points and so on.

Q 11a

We have the exact solution as = a 1 / 3 or 3 = a. Set the error as x n = n . Substituting in the


given equation, we get

qa
+ n +1 = p ( + n ) + 2 1 + n


2 n

n2
= p ( + n ) + q 1
+ 3 2 + ....

= ( p + q ) + ( p 2q ) n +

3q n2

....

We have two unknowns p and q. Setting p + q = 1, p 2q = 0, we get p = 2 3 , q = 1 3 . Hence, for


p = 2 3 , q = 1 3 , the method is of order 2, since

n +1

3q 2 1 2
n = n .

The error constant is given by


Q 11b

( 1 ) = ( 1 a1 3 ). .

x (k +1) = H x (k ) + c

Gauss-Seidel method:

where H = ( D + L ) 1U is the iteration matrix and A = L + D + U . The method converges if the


spectral radius of H is less than 1. We have
1

0
0 1 0
4 0 0 0 1 0
0 4
0 0 1 = 1 2 4 0 0 0 1 = 1 0 2 4

8
8
0 0
1 2 4 0 0 0
0 1 2
0
Eigen values of H : H I = 0 .
2 0
H = 1 2
0 1

12

(1 4)

18

0
0
2
0

2
1
1
1
1

= 0 gives = 0 , or = 0, = ; or = 0, 0, 1 2.
16
4
4
4

(1 4)

12

We have spectral radius of H =

1
< 1. Hence, the method converges.
2

Detailed Solutions A-07


Q1.
.

DECEMBER 2003

a.

0/0 form. Use L Hospitals rule three times.

g.

It is a property of Lagrange fundamental polynomials.

h.

Error equation of Regulafalsi method is k +1 = c k .

i.

n e ax = e ah 1 e ax .

j.

k.

g.

h.

( ) (

It is the GaussLegendre 3 point formula.

( ).

Expand by Taylor series. The first nonvanishing term is O h

PART I

Q 2a

2
3

2 5 . We get L = 1

5 15
3/ 2

4
A = LL = 2
3

Ax = LLT x = b .

0
1
7/2

0 .

1/ 2

Let LT x = z . Solve Lz = b . Then, solve LT x = z .

By forward substitution of Lz = b, we get z = 5 / 2, 3 / 2, 1 / 2 .


By backward substitution of LT x = z, we get x = [ 1, 2, 1]T .

Q 2b

Set e k = x k . Substitute in the Newton-Raphson method and expand the terms in Taylor series
obtain

ek +1 = ek

[ek f ( ) + (1 / 2)ek2 f ( ) + ...]


f ( ) + ek f ( ) + ...

Q f ( ) = 0

= ek [ek + cek2 + ...][1 + 2cek + ...]1


= e k [e k + cek2 + ...][ 1 2ce k + ...] = cek2 + L
where c = 1

Q 3a

f ( )
Hence, e k +1 = ce k2 . The order of the method is s = 2.
2 f ( )

We shall use Gauss elimination method and reduce the augmented matrix [A | b] to [U | z ] where
U is an upper triangular matrix.
2
1
2 6

1 2
1
0

2
2
0

3
11
7
3
5
0

a
b ; R 2 2 R1 , R3 R1 .
c

2
1
0 2

0 4

b 2a
c + 2b 5a

10

3
5
10

b 2a , R3 + 2 R 2
c a

to

The system has a solution if c + 2b 5a = 0. Then, the given system has a one parameter family of
solutions.
Q 3b

Let f (x, y ) = 3x 2 + y 2 + 2 xy 11 = 0, g ( x, y ) = x 2 + 2 y 2 5 xy + 1 = 0 . New tons method :


f / x
g / x

f / y x
f
=

g / y k y
g k

Next approximation is x k +1 = x k + x,
6x + 2 y
We have,
2x 5 y

2 y + 2 x
4 y 5 x k

y k +1 = y k + y .

x
f
y = g .

k

We are given that x 0 = 0.8, y 0 = 1.5. We obtain


7.8
5.9

4.6 x
4.43
=

2 y
0.14

The solution is x = 0.2224, y = 0.5859 . Hence,


Q 4a

x1 = 1.0224, y1 = 2.0859 .

(i) Value assigned to &a is 1130. Value assigned to &b is 1134. Value assigned to &c is 1138.
(ii) Value of *pa = 0.002. Value of &(*pa) is 1130.

Q 4b

Use New tons divided difference interpolation. Rearrange the data in ascending order of x i .
x
0
1
3/2
2

f(x)
3
3
13/4
5/3

first d.d

second d.d

third d.d

0
1/2
19/6

1/3
11/3

New tons divided difference formula


f (x ) = f (x 0 ) + (x x 0 ) f [x 0 , x1 ] + (x x 0 )(x x1 ) f [x 0 , x1 , x 2 ]

+ (x x 0 )(x x1 )(x x 2 ) f [x 0 , x1 , x 2 , x 3 ]

3
1
1

= 3 + (x )( 0 ) + (x )(x 1) + (x )(x 1) x ( 2) = 6 x 3 + 16 x 2 10 x + 9 .
2
3
3

Q 5a

a = 100, b = 200
count = 1
c = 20 * (1 1) = 0
d=4*1*1=4
funct1(a, c) = 100
funct1(b, d) = 196
count = 2
c = 20 * (2 1) = 20
d = 4 * 2 * 2 = 16
funct1(a, c) = 80
funct1(b, d) = 184
count = 3
c = 20 * (3 1) = 40
d = 4 * 3 * 3 = 36
funct1(a, c) = 60
funct1(b, d) = 164

11

count = 4
c = 20 * (4 1) = 60
d = 4 * 4 * 4 = 64
funct1(a, c) = 40
funct1(b, d) = 136
count = 5
c = 20 * (5 1) = 80
d = 4 * 5 * 5 = 100
funct1(a, c) = 20
funct1(b, d) = 100
Q 5b

Substitute x = x1 t. Then, the given formula becomes


h
h
2
h f (t )dt = 3 [a f (h ) + b f ( 0 ) + a f ( h )] + ph [ f (h ) f ( h)].

Make the formula exact for f (t ) = t i ,

i = 1, 2, L , 5.

h
[2a + b] , or 2a + b = 6 .
3
0 = 0 , satisfied.

f (t ) = 1 :

2h =

f (t ) = t :

[ ]

2 3 h
h = 2ah 2 + 4 ph 3 , or a + 6 p = 1 .
3
3

f (t ) = t 2 :
f (t ) = t 3 :

0 = 0 , satisfied.

[ ]

2 5 h
3
h = 2ah 4 + 8 ph 5 , or a + 12 p = .
5
3
5

f (t ) = t 4 :

Solving , we get a = 7 / 5, b = 16 / 5, p = 1 / 15 .
For f (t ) = t 5 , the equation is satisfied. For f (t ) = t 6 , we get
16 7
2 2

c = a 12 p h 7 =
h .
7
3
105

Error term =

Q 6a

c (6 )
16h 7
h7
f ( ) =
f (6 ) ( ) =
f (6 ) ( ),
6!
4725
(105)(6 ! )

x0 < < x2 .

We generate the data as


x
0 1 2 3 4
f ( x) 1 2 4 8 16

Least squares approximation : J = f ( x k ) (c + bx k + ax k2 )

= minimum .

Conditions of extremum gives


J
= 0 = f ( x k ) (c + bx k + ax k2 ) ,
or N c + b x k + a x k2 = f k
c
J
= 0 = f ( x k ) (c + bx k + ax k2 ) x k , or c x k + b x k2 + a x k3 = x k f k
b
J
= 0 = f ( x k ) (c + bx k + ax k2 ) x k2 , or c x k2 + b x k3 + a x k4 = x k2 f k .
a

[
[
[

]
]
]

These are the normal equations. We have N =5,


x k = 10, x k2 = 30, x k3 = 100, x k4 = 354,
Normal equations are
5c + 10b +

10c +

30b

30a

31

+ 100a

98

30c + 100b + 354a = 346 .

12

fk

= 31,

xk f k

= 98,

x k2 f k

= 346 .

The solution is c = 9 / 7, b = 34 / 35, a = 8 / 7 . The least squares approximation is


f ( x) = (45 34 x + 40 x 2 ) 35 .

Q 6b

#include <stdio.h>
#include <math.h>
#include <conio.h>
#define d b * b 4 * a * c
#define root if (d > 0) {
printf("The two real roots are ");
printf("%f %f", (b+sqrt(d))/(2.0*a), (bsqrt(d))/(2.0*a));
}
else if (d == 0) {
printf("The repeated roots are ");
printf("%f %f", b/(2.0*a), b/(2.0*a));
}
else {
printf("The complex pair is ");
printf("%.2f+%.2fi ", b/(2.0*a), sqrt(abs(d))/(2.0*a));
printf("and %.2f%.2fi", b/(2.0*a), sqrt(abs(d))/(2.0*a));
}
void main() {
clrscr();
int a, b, c;
printf("Enter the value of a, b, c : ");
scanf("%d %d %d", &a, &b, &c);
root;
}

PART II
Q 7a

Partition method :
B C
X
1
A=
, A = Z
E
D

Y
V

where V = ( D E B 1C ) 1 , Y = B 1C V , Z = V E B 1 , X = B 1 ( I C Z ) .
Let the partition of the given matrix be
B =

1 1 , C = 1 , E = [3 5 ] , D = [ 3 ] .
4 3
1

Then, we obtain the following results :


B 1 =

, E B 1C =[ 13 ] , D E B 1C =[ 10 ] , V =[1 10 ]

Y = B 1C V = [ 2 5

Q 7b

X
Z

1 2 ]T , Z = V E B 1 = [11 10

14 10
Y
= 15 10
V
11 10

15
0
1 5

Power method :
y k +1 = Av k ,
v k +1 = y k +1 m k +1 ,
(y )
= lim k +1 r
k (v k )
r

1 5 ] , X = B 1 ( I C Z ) =

2 5
12

1 10
m k +1 = max (y k +1 )r
r

r = 1, 2, K , n .

13

14 10

15 10

1 5
0

All n ratios tend to the largest eigen value in magnitude.


v 0 = [ 1, 1, 1]T ,

y 1 = Av 0 = [ 8, 4, 18]T ,

y 2 = Av 1 = [ 95 9, 10 9, 70 9]T .

v 1 = [ 4 9, 2 9, 1] T ,

After two iterations, the ratios for are 95/4, 5, 70/9. The ratios have not yet converged.
Q 8a

Jacobi method : Let a ik be the largest off-diagonal element in magnitude. Choose such that
tan 2 =

2a i k
ai i ak k

or

2a i k
1
tan 1
ai i ak k
2

If a i i = a k k , then = 4 , if a i k > 0 ; and 4 , if a i k < 0 . Then, the elements a i i , a i k , a k i , a k k


form the 22 rotation sub-matrix. Repeat the procedure until A is reduced to a diagonal matrix. Then,
the eigen values are on the diagonal of this matrix. The product of the rotation matrices S = S1 S 2 K S r
gives the matrix of eigenvectors. The first column of S is the eigenvector corresponding to the eigen
value in the first (11) location of the diagonal matrix, etc.
First rotation : a12 = a 21 = 3 is the largest off-diagonal element.

1
6
tan 1
= .
2
22 4

1 2 1 2 0

S1 = 1 2 1 2 0.
0
0
1

A1 = S

1
1

A S1 =

S1T

5
0
3 2

A S1 = 0
1 1 2
3 2 1 2
1

Second rotation : a13 = a 31 = 3 / 2 is the largest off-diagonal element.

3 2
1
, or = 0.40741346 radians, sin = 0.396236, cos = 0.918149.
tan 1
5 1
2

0.918149 0 0.396236

S2 =
0
1
0
.
0.396236 0 0.918149

0.0
5.915479 0.280181
A2 = S 21 A1 S 2 = S 2T A1 S 2 = 0.280181
1
0.649229
0.0
0.649229 0.084525
0.64923 0.70711 0.280181
S = S1S 2 = 0.64923
0.70711 0.280181.
0
0.918149
0.396236
Iterations have not converged since A is not reduced as yet as a diagonal matrix. The eigen values may
be near 5.9, 1, 0.08. The columns of S are the corresponding eigenvectors.
Q 8b

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
char** swap(int, char *p1[]);
void main() {
clrscr();
char *p[10];

14

int i=0,n,j;
printf("Enter no of strings : ");
scanf("%d", &n);
for (i=0; i<n; i++) {
p[i] = (char *) malloc(2*n);
printf("Enter string : ");
scanf("%s",p[i]);
fflush(stdin);
}
char **q = swap (n, p);
printf("The ascending order of strings is :\n");
for (i=0; i<n; i++)
printf("%d : %s\n",i+1, *(q+i));
}
char** swap(int n1, char *p1[]) {
char *temp;
int i,j;
for (i=0; i<n1; i++) {
for (j=i+1; j<n1; j++) {
if (strcmp(*(p1+i), *(p1+j)) > 0) {
temp = *(p1+i);
*(p1+i) = *(p1+j);
*(p1+j) = temp;
}
}
}
return p1;
}
Q 9a

The bound on the error in linear interpolation is given by


1
1
Errror = ( x x 0 )( x x1 ) f ( ) max ( x x 0 )( x x1 ) max f ( x) .
2
2 [ x0 , x 1 ]
[ x0 , x 1]
Now, the stationary point of ( x x 0 )( x x1 ) is x = ( x 0 + x1 ) / 2. Hence,
2
1
(x1 x 0 )2 M 2 = h M 2 ,
8
8
where h = x1 x 0 and M 2 = max f ( x) .

| Error |

[ x0 , x 1 ]

We have f ( x) = e , f ( x) = e x , f ( x) = e x and M 2 = max [e x ] = e .


x

[ 0, 1 ]

We require

Q 9b

h
e 5 10 4 , or
8

40

h 10 4
e

12

= 0.03836 .

(i) Make the formula exact for f ( x ) = 1, x, x 2 .


f ( x ) = 1:
1= a +b+c
1 b
f ( x) = x :
= +c
2 2
1 b
f ( x) = x 2 :
= + c.
3 4
The solution of this system is a = 1 / 6, b = 2 / 3, c = 1 / 6 . The formula is given by
1

0 f ( x) dx = 6 f (0) + 4 f 2 + f (1).
(ii) Make the formula exact for f ( x ) = 1, x, x 2 .

15

1= + +

f ( x ) = 1:

1 3
= + +
2 4 2 4
1 9
=
+ +
.
3 16 4 16

f ( x) = x :
f ( x) = x 2 :

The solution of this system is = 2 / 3, = 1 / 3, = 2 / 3. The formula is given by


1

0 f ( x) dx = 3 2 f 4 f 2 + 2 f 4 .
Both the methods are exact for

f ( x) = x 3 .

For f ( x ) = x , the error constant for the first method is


4

1 120 and for the second method is

7 960 . Hence the second method is better since it has a smaller error constant.
Q 10a

(i)
#include <stdio.h>
void main() {
int i, sum=0;
for (i=2; i<100; i+=3)
if (i%5 == 0)
if ((i/5)%2 ==0)
sum += i;
printf("The sum is %d", sum);
}

Q 10a (ii)
#include <stdio.h>
void main() {
int i, sum=0;
for (i=2; i<100; i+=3)
sum += (i%5 == 0) ? (((i/5)%2 == 0) ? i : 0) : 0;
printf("The sum is %d", sum);
}

Q 10b

Given system is A x = b and Gauss-Seidel method is x ( k +1) = H x ( k ) + c, k = 0, 1, K


where, iteration matrix = H = ( D + L ) 1 U and c = ( D + L ) 1 b .
1

0 0
2 0 0 0 1 0
48
1

8
16
0
H = 1 6 0 0 0 2 =
96
0
4 3 8 0 0
27 6 12
0
0 48
1
=
0
8

32
96
0 27 12

0 1 0
0 0 2

0
0 0

Eigen values of H : H I = 0 gives the characteristic equation as

(24 2 + 2) = 0.
Hence, = 0 ,

1 191 i
, and = 0.2887 .
48

Spectral radius of H = ( H ) = 0.2887 < 1.


Hence, the iteration converges.

16

Q 11a

Runge-Kutta classical fourth order method

1
( k 1 + 2 k 2 + 2k 3 + k 4 )
6
k
h

k1 = h f ( x n , y n ) , k 2 = h f x n + , y n + 1 , k 3 = h
2
2

k 4 = h f ( x n + h, y n + k 3 ) .
y n +1 = y n +

k
h

f x n + , y n + 2 ,
2
2

We have f ( x, y ) = x + y, x 0 = 1, y 0 = 2, h = 0.1 .
n = 0 : k1 = 0.1 f (1, 2) = 0.3,

k 2 = 0.1 f ( 1.05, 2.15 ) = 0.32,

k 3 = 0.1 f (1.05, 2.16 ) = 0.321, k 4 = 0.1 f ( 1.1, 2.321 ) = 0.3421,


y ( 1.1 ) y1 = 2.3207.
n = 1:

x1 = 1.1, y1 = 2.3207 .
k1 = 0.1 f ( 1.1, 2.3207 ) = 0.3421,

k 2 = 0.1 f ( 1.15, 2.4918 ) = 0.3642,

k 3 = 0.1 f ( 1.15, 2.5028 ) = 0.3653, k 4 = 0.1 f ( 1.2, 2.686 ) = 0.3886 .


y ( 1.2 ) y 2 = 2.6857 .
Q 11b

The initial value problem ( I V P ) is y = f ( x, y ), y ( x 0 ) = y 0 .


Existence theorem : Let f ( x, y ) be continuous and bounded at all points in some closed rectangular
region about ( x 0 , y 0 ) , that is, in x x 0 a, y y 0 b . Then, the I V P has at least one
solution.
Now, f ( x, y ) = ( x + sin y ) 2 is continuous in every rectangle about x 0 = 0, y 0 = 3 .
2

Also, x + sin y 4 for 1 x 1 and all y. Hence, the given I V P has at least one solution.
Uniqueness theorem: Let the I V P satisfy the existence theorem and let f (x, y ) satisfy the Lipschitz
condition
f ( x, u ) f ( x, ) L u

Then, the solution of the I V P is unique. A sufficient condition is f y should be bounded, that
is,

f y M in the considered domain.

Now,

f
= 2( x + sin y ) cos y , and
y

f
4 for x [1, 1 ] and for all y . Hence, the solution is
y

unique.

17

Detailed Solution
Q1.

A-07

1
1 4
1 + 3 = .
2
27 9

a.

Set f ( x) = x 3 . Then, C =

l.

Lim x k +1 = x = Lim x k . This gives x 3 = q, or x = q 1 / 3 .

m.

n.

o.

p.

q.

r.

dx

June 2004

Romberg formula: I = {h22 I (h1 ) h12 I (h2 )} /(h22 h12 ), with h2 = 1 / 4, h1 = 1 / 3. We obtain
the result as 0.5867.
Error( x) 0.5 ( x 0.1)( x 0.2) M 2 . Error(0.15) 0.00125 M 2
N = 4. Normal equations are 4a + 10b = 50, 10a + 30b = 150. The solution is a = 0,
b = 5. y = 5x.
0 4
Iteration matrix = H =
. Spectral radius of H = 4 > 1. Diverges.
4 0

PART I
Q 2a

f (0) = 1, f (1) = 6.
x k +1 = x k

Root lies in (-1, 0 )

fk
7 x 3 + 8x 2 + 8x k + 1
= xk k 2 k
.
f k
21x k + 16 x k + 8

We get x 0 = 0.5, x1 = 0.14286, x 2 = 0.14286. Hence, x 0.143.


Q 2b

#include <stdio.h>
#include <math.h>
main()
{
float xinitial, eps, fx, dfx, xnew;
int i, n;
float f(float s);
float df(float s);
printf("Input value initial approximation xinitial\n");
printf("n: number of iterations\n");
printf("eps: error tolerance\n");
scanf("%f %d %e", &xinitial, &n, &eps);
printf("xinitial = %f n = %d eps = %e\n\n", xinitial, n, eps);
/* Calculate f and its first derivative at xinitial */
for(i = 1; i <= n; i++)
{
fx = f(xinitial);
dfx = df(xinitial);
xnew = xinitial fx / dfx;
fx = f(xnew);
if(fabs(fx) <= eps) goto l10;
/* Iteration is stopped when abs(f(x)) is less than or equal to eps.
Alternate conditions can also be used.
*/
xinitial = xnew;
}
printf("\nITERATIONS ARE NOT SUFFICIENT");
goto l20;
l10:
printf("Iterations = %d", i);
printf(" Root = %10.7f, f(x) = %e\n", xnew, fx);

18

l20:
return 0;
}
float f(float x)
{
float fun;
fun = 7.0*x*x*x+8*x*x+8.0*x+1;
return(fun);
}
float df(float x)
{
float dfun;
dfun = 21.0*x*x+16.0*x+8.0;
return(dfun);
}

Q 3a

Bairstows formula
R p = c n 2 , R q = c n 3 ,

S p = bn 1 c n 1 pc n 2 , S q = ( c n 2 + pc n 3 ), ,

R = bn 1 , S = bn + pbn 1 ,
p1 = p 0 + p,

p=

R p S q Rq S p

q =

RpS R S p
R p S q Rq S p

q1 = q 0 + q . p 0 = 0.4, q 0 = 1.1.
1

4.5
0.4

3
1.64

4
0.104

4.1
0.4

1.1
0.26
1.48

4.51
0.614

p = 0.4
q = 1.1

p = 0.4
q = 1.1

RS q SR q

1.1
1
3.7
2.32
_______________________________

p = 0.0969,

Q 3b

Q 4a

T 1

= (U U )

= (U

x1(k +1) =

1 T

) U

[
[

q = 0.0984 ,

= (U

1 T

) U

3/ 2

U =
0

3 / 2 1 / 2
1 1 ;

0
2

q1 = 1.0016.

2
1
0
=
6
0

3
6
0

3/ 2

3 / 2

4 6 4

1
= 6 15 9 .
6

4 9 7

1
9 3 x 2( k ) x 3( k ) ,
6
1
x 3(k +1) = 4 3 x1( k +1) 2 x 2( k +1)
8

x ( 0) = [1

p1 = 0.4969 ,

x 2(k +1) =

].

1 1]T , x (1) = [1.1667

1.0667

1
5 + 2 x1( k +1) + 2 x 3( k ) ,
5

1.2042] ,

19

x ( 2) = [1.1674

0.9853

1.1841].

0 120 40

1
Iteration matrix = H = ( D + L ) U =
80 .
0 48
240
57 5
0
Characteristic equation of H : (2402 53 18) = 0.
1

53 141.7357

Eigen values of H : = 0,

= 0.4057, 0.1849 .

480
Spectral radiusof H : ( H ) = 0.4057.
Rate of convergence = log 10 ( H ) = 0.3918 or as = ln ( H ) = 0.902.
Q 4b

The Power method is given as the following


y k +1 = A v k ,

v k +1 = y k +1 m k +1 ,

m k +1 = max (y k +1 )r ,
r

= (y k +1 )r (v k )r .

v 0 is given as [1, 1, 1]T .


T
T
T
y 1 = 1, 17, 1 , v1 = 0.05882, 1, 0.05882 , y 2 = 0.88236, 20.05882, 2.05882 ;
T
T
v 2 = 0.04399, 1, 0.10264 ,
y 3 = 1.08798, 20.24927, 2.10264 ,
T
T
v 3 = 0.05373, 1, 0.10384 ,
y 4 = 1.1075, 20.26141, 2.10384 ,
T
T
v 4 = 0.05466, 1, 0.10384 ,
y 5 = 1.10932, 20.26233, 2.10384 ,
T
v 5 = 0.05474, 1, 0.10383 .
Ratios of : 20.295, 20.262, 20.261 ,
20.3 and the corresponding eigen vector is v5.

[
[
[
[
[

Q 5a

]
[
[
[

]
]
]
]

]
]
]

Substitute x k = + k in the secant method to obtain


( k k 1 ) f ( + k )
f ( + k ) f ( + k 1 )

k +1 = k
=k

( k k 1 )[ k f ( ) + ( k2 / 2) f ( ) + L ]
( k k 1 ) f ( ) + (1 / 2)( k2 k21 ) f ( ) + L

= k [ k + c k2 + L][1 + ( k 1 + k )c + L] 1
= k [ k + c k2 + L][1 ( k 1 + k )c + L]
= k [ k c k k 1 ] + L = c k k 1 + L
1 f ( )
where c =
.
2 f ( )
Hence, we have

k +1 =

A kp

k +1 = c k k 1 .

gives k = A kp1 , or k 1 = k(1 / p ) A (1 / p ) . Hence,

k +1 = A kp = cA (1 / p ) 1k + (1 / p ) . Comparing the powers of k , we get


p = 1+

Q 5b

1
, or
p

p 2 p 1 = 0 ,

p=

1
1 5 . Since, p > 0 , we get p = 1.618 = 1.62.
2

# include <stdio.h>
void main ( )
{
int years,method,i;
float depreciation,value,original;
printf ( "Method used : ( 1 ) Straight line.. ( 2 ) Sum.." );
scanf ("%d", &method );

20

printf ( "Original value: " );


scanf ( " %f ", &original );
printf ( "No. of years : " );
scanf ( " %d " , &years );
switch (method)
{
case 1 :
printf ( " \ n Straight line method \ n " );
depreciation = original / years;
for ( i =1; i <= years; ++i )
{
original -= depreciation ;
printf ( "End of year % 2d ", i );
printf ( " Depreciation : % f ", depreciation );
printf ( " Current value : % f \ n ", original );
}
break ;
case 2 :
printf ( " \ n Sum of year's digits method \ n " );
value = original ;
for ( i = 1 ; i <= years; ++i )
{
depreciation = ( years - i + 1 ) * original / ( years*(years+1)/2);
value -=depreciation;
printf ( " end of year % 2d ", i );
printf ( "depreciation : % f ", depreciation );
printf ( " current value : % f \ n ", value );
}
break ;
}
}

Q 6a

Inverse power method:

y k +1 = A 1 v k ,

v k +1 = y k +1 m k +1 ,

v k +1 is the required eigen vector .

4 1 1

= 2 1 0 .
5 2 1

= Lim
k

(y k +1 )r
(v k ) r

r = 1, 2, K , n

= 1/ .

v 0 = [0.8 0.3 1.0]T

y 1 = [ 3.9 1.3 4.4 ]T , v 1 = [ 0.8864 0.2955 1 ]T , y 2 = [ 4.2501 1.4773 4.841 ]T ,


v 2 = [ 0.8779 0.3052

1 ]T , y 3 = [ 4.2064 1.4506 4.7791 ]T , v 3 = [ 0.8802 0.3035

1 ]T ,

y 4 = [ 4.2173 1.4569 4.794 ]T , v 4 = [ 0.8797 0.3039 1 ]T , y 5 = [ 4.2149 1.4555 4.7907 ]T .


Ratios: 4.791, 4.789, 4.791 .

Q 6b

a
tan = 13 = 1 ,
a12

= 4.79,

0
0
1

= , S = 0 1 2 1 2 .
4

0 1 2 1 2

21

1
4.79

0.2088


1 4 2 0

B = S 1 A S = S T AS = 4 2
0
0 .

0
0
2

Sturm sequence: Define f n = I B . Then


f 0 = 1, f 1 = b1 , f r = ( br ) f r 1 c r21 f r 2 , r = 2, L , n . .
f 0 = 1, f 1 = 1, f 2 = f 1 8 f 0 , f 3 = ( 2) f 2 .
Form the Sturm table

f0
f1
f2
f3
V( )
3
+

3
2
+

+
2
1
+

+
2
0
+

+
2
1
+
+

+
2
2
+
+

0
eigenvalue
3
+
+

1
4
+
+
+
+
0
From the Sturm table, we find that there are eigen values in ( 3, 2 ), ( 3, 4 ) and 2 is an eigen
value.
Largest eigen value lies in ( 3, 4 ).
PART II
Q 7a

h3

error

Error in quadratic interpolation is bounded by

9 3

We have f = 192( 3 + 2 x ) and M 3


h3

960 < 10 6

gives

= 960 for

M 3 , M 3 = max f ( x )
( a, b)

x [0, 1] .

h < 0.00253.

9 3

Q 7b

f (x)

2 f

3 f

1
0
1
2
3
4

1.2
1.0
3.8
9.6
18.4
30.2

0.2
2.8
5.8
8.8
11.8

3.0
3.0
3.0
3.0

0
0
0

We have h = 1.0.
f 0 ( x x 0 )( x x1 ) 2
+
f0
1! h
2 !h 2
2
= 1.2 0.2( x + 1) + ( x + 1) x (1.5) = 1.5 x + 1.3 x + 1

f ( x) = f ( x 0 ) + ( x x 0 )

Q 8a

I=

f (0.5) = 2.025 .

h
[ f 0 + 4( f1 + f 3 + L + f 2 N 2 ) + 2( f 2 + f 4 + L + f 2 N 1 ) + f 2 N ].
3

We have f ( x) = 1 /( x 2 + 2 x + 10).

22

1
h = 1.0 ; I = [ f (0) + 4 f (1) + f (2)] = 0.15442 .
3
1
h = 0.5 ; I = [ f (0) + 4{ f (0.5) + f (1.5)} + 2 f (1) + f (2)] = 0.15454.
6
Romberg value =

Q 8b

16 I (0.5) I (1.0)
= 0.15455.
15

#include <stdio.h>
#include <math.h>
float f();
main()
{
float a, b, h, sum, x, trap;
int n, i, m;
printf("Input limits a & b and no. of subintervals n\n");
scanf("%f %f %d", &a, &b, &n);
printf("Limits are a = %f, b = %f\n", a, b);
printf("Number of subintervals = %d\n", n);
h = (b a) / n;
sum = 0.0;
m = n 1;
for (i = 1; i <= m; i++)
{
x = a + i * h;
sum = sum + f(x);
}
trap = h * (f(a) + 2.0 * sum + f(b)) / 2.0;
printf("Value of integral with %d ", n);
printf("Subintervals = %14.6e\n", trap);
return 0;
}
float f(float x)
{
float fun;
fun = 1.0 / (10.0 + 2.0 * x + x * x);
return(fun);
}
2

Q 9a

b
= minimum .
I = y k a +
x k

1
Normal equations : a N + b
= yk ,
xk
We have N = 6,

y
1
1
+ b 2 = k
xk
x
xk
k

(1 / x k ) = 21, (1 / x k2 ) = 136.5, y k

= 51,

Normal equations are 6a + 21b = 51 ,


21a + 136.5b = 295.5.
Solution is a = 2, b = 1.8571.
p ( x) = 2 + (1.8571 / x).

Q 9b

i =0

i =0

P( x) = Ai ( x) f ( x i ) + Bi ( x) f ( x i ).
Ai ( x) = [1 2( x x i ) l i ( x i )] l i2 ( x) ,

Bi ( x) = ( x x i ) l i2 ( x)

23

( y k / x k ) = 295.5.

l 0 ( x ) = ( x 2), l 0 = 1, l1 ( x ) = x 1, l1 ( x ) = 1
2
2
A0 ( x ) = 1 + 2( x 1) ( x 2) , A1 ( x ) = 1 2( x 2 ) ( x 1)
2
2
B0 ( x ) = ( x 1)( x 2) , B1 ( x ) = ( x 2)( x 1)
.
2
2
2
2
P ( x ) = ( 2 x 1)( x 2) (9) + (5 2 x )( x 1) (87 ) + ( x 1)( x 2) ( 23) + ( x 2)( x 1) (163)

3
2
= 30 x 65 x + 63 x 19 .
P(1.5) = 30.5

Q 10a

Choose three points as x 0 = 0, x1 , x 2 = 1.


2
Define ( x ) = ( x + 5 x + 3) ( a + bx).
We have (0) + ( x1 ) = 0,

( x1 ) + (1) = 0,

( x1 ) = 0. Hence, we get

2
(3 a ) + x1 + 5 x1 + 3 ( a + bx1 ) = 0 .
2
x1 + 5 x1 + 3 ( a + bx1 ) + 9 ( a + b ) = 0 , and

2 x1 + 5 b = 0 .

The solution of this system is b = 6, x1 = 1 / 2, a = 23 / 8 . Hence,

Q 10b

# include <stdio.h>
long fibonacci ( int count );
main ( )
{
int count, n;
printf( " Number of fibonacci numbers : " );
scanf(" %d ", &n);
printf ( " \n" );
for ( count = 1 ; count <= n ; ++count )
printf ( " \n i = %2d , F = %1d", count , fibonacci(count) );
}
long fibonacci ( int count )
/* F = 1 for i < 3 , and F = F1 + F2 for i > = 3 */
{
static long int f1 = 1, f2 =1 ;
long int f ;
f = ( count < 3 ) ? 1 : f1 + f2 ;
f2 = f1 ;
f1 = f ;
return f;
}

Q 11a y = 2 x 2 + 3 y 2 ;
x 0 = 1, y 0 = 1 ,
h = 0.1 ,

f ( x, y ) = 2 x 2 + 3 y 2
y ( x n + h) = y ( x n ) + h y ( x n ) +

y (1.1) = y ( 1 ) + 0.1 y ( 1 ) +

h = 0.1 ,

h2
y ( x n ) ,
2

y = 4 x + 6 yy .

0.01
y ( 1 ) = 1 + 0.1(5) + 0.005(34 ) = 1.67.
2

x1 = 1.1, y1 = 1.67.
y( 1.2 ) = y ( 1.1) + 0.1 y ( 1.1) + 0.005 y ( 1.1 )

= 1.67 + 0.1( 10.7867 ) + 0.005( 112.4827 ) = 3.3111.

Q 11b

p ( x) = (23 / 8) + 6 x .

y = x 2 + y 2 , y( 0 ) = 1

24

f ( x, y ) = x

2
+ y , x 0 = 0,

y0 = 1

h
k1 = h f ( x n , y n ), k 2 = h f x n + , y n + 1 ,
2
2

k 3 = h f x n +

y n +1 = y n +

1
6

k
, yn + 2
2
2

, k 4 = h f ( x n + h , y n + k 3 ),

( k1 + 2k 2 + 2 k 3 + k 4 ).

.h = 0.2 , x 0 = 0, y 0 = 1.
k1 = 0.2, k 2 = 0.244, k 3 = 0.2538, k 4 = 0.3224,
x1 = 0.2,

y1 = 1.253.

k1 = 0.3220, k 2 = 0.4179, k 3 = 0.4455, k 4 = 0.6090,

25

y (0.2 ) = 1.253.
y (0.4 ) = 1.6960.

Detailed Solutions A-07 December 2004


Q1.

a.

Relative error = exact value numerical value / exact value = 0.0016.

s.

t.

Number of iterations required [ log(b a) log ]/ log2 = log /log2.


0 p
Iteration matrix = H =
. Spectral radius of H = p 2 . Convergence if p < 1.
2

p
0

u.

f [ x1 , x 2 ] = x12 + x1 x 2 + x 22 , f [ x 2 , x3 ] = x 22 + x 2 x3 + x32 , f [ x1 , x 2 , x 3 ] = x1 + x 2 + x3 .

v.

Least squares error =

w.
x.

A
C

Use Taylor series expansions to obtain error as h 4 f ( 4) ( ) / 12.


I = {[ f (0) + 4 f (1 / 2) + f (1)] / 6} = 7 / 20.

y.

Upper case of g is taken as case G.

[ f ( x k ) 5 x k ] 2 = 4.

PART I

Q 2a

Perform the operations R 2 + 2 R1 , R3 ( R1 / 2), R 4 ( R1 / 2).

2
1
4
1

0
5

3
0

0 3 2 3 3 2

0 5 2 1 3 2

Q 2b

0
0

0
0

2
. Now, perform the operations R3 + (3R 2 / 10), R 4 ( R2 / 2).
0

5 3
0
2
. Perform R 4 (5 R3 / 21).
0 21 10 3 2 3 5

0 12
3 2 2

5 3
0
2
.
0 21 10 3 2 3 5

0
0
39 21 13 7

A = LL .
T

x 4 = 1, x 3 = 1, x 2 = 1, x1 = 1.

We get L = 3 8
0

368 55

55 8
3 8 55

Ax = LLT x = b. Set LT x = Z . Solve LZ = b, then solve LT x = Z .

LZ = b gives Z = [ 0.35355

LT x = Z gives x = [0.0625

Q 3a

1.02497
0.5

0.25]T

0.64667]T

Set k = x k . Substitute in the Newton-Raphson method and expand the terms in Taylor series to
obtain
[ f ( ) + (1 / 2) k2 f ( ) + ...]
k +1 = k k
f ( ) + k f ( ) + ...
= k [ k + c k2 + ...][1 + 2c k + ...] 1
= k [ k + c k2 + ...][ 1 2c k + ...] = c k2 + L

26

where c = f ( ) /[ 2 f ( )]. Hence, k +1 = c k2 . The order of the method is p = 2.

Q 3b k +1 = c k2 , where c = f ( ) /[ 2 f ( )]. Substituting k = 0, 1, 2, . . ., we get

k = c2
Here,

1 2 k
0

0 < 1 and

Find k such that

Q 4a

k = c

and

c =

2 k 1

2k

f ( )
1

.
2 f ( ) 20

k (0.05) 2

Root lies in ( 2, 1) .

x k +1 =

5 10 7 . We get k = 3.

x k 1 f ( x k ) x k f ( x k 1 )
.
f ( x k ) f ( x k 1 )

x 0 = 2, x1 = 1 .

We get x 2 = 1.05263, x 3 = 1.16024, x 4 = 1.14096, x 5 = 1.14282, x 6 = 1.14286.

Q 4b

l0:

# include <stdio.h>
# include <math.h>
float f(float);
main ( )
{
float a, b, x, eps, fa, fb, fx;
int i, n;
printf ("Input two approximations to the root \ n");
scanf ("%f %f ",&a, &b);
printf ("input m: number of iterations \ n");
scanf ("% d", &n);
printf ("eps: error tolerance \ n");
scanf ("%E", &eps);
for (i = 1; i <= n; i++ )
{
fa = f(a);
fb = f(b);
x = (a* fb - b*fa)/(fb - fa);
fx = f(x);
if (fabs (fx) <= eps)
goto l0;
a = b;
b = x;
}
printf (" \ n Number of iterations given are not sufficient");
goto l5;
printf ("Number of iterations = % d \ n", i);
printf ("Root =% 10.7f, f(x) = % e \ n", x, fx);

l5:

return 0;
}
float f(float x)
{
float fun;
fun = x*x;
return (fun);
}

Q 5a

( k +1)

x1

1
1
(k )
( k +1)
(k )
(k )
( 2.5 + x 2 ); x 2
= (2.75 + x1 + x3 );
4
4

27

( k +1)

x3

( 0)

x1

1
1
(k )
(k )
( k +1)
(k )
(1.75 + x 2 + x 4 ); x 4
= (1.25 + x 3 ).
4
4
(0 )

= 0.4, x 2

( 0)

= 0.6, x 3

( 0)

= 0.3, x 4

= 0.3. We get

x1(1) = 0.475, x 2(1) = 0.5125, x3(1) = 0.2125, x 4(1) = 0.2375;


x1( 2) = 0.4969, x 2( 2) = 0.5156, x3( 2) = 0.25, x 4( 2) = 0.2594;
x1(3) = 0.4961, x 2(3) = 0.5008, x3(3) = 0.2438, x 4(3) = 0.25.

Q 5b

0
0
0 1 / 4
1 \ 4 0 1 \ 4

Iteration matrix = H = D 1 ( L + U ) =
0 1 \ 4
0 1 \ 4

0 1 \ 4
0
0
Eigen vaules : H I = 0 gives 256 4 48 2 + 1 = 0.
Hence, 2 = 0.163627, 0.02387 or = 0.4045, 0.1545 .
Spectral radius of H = ( H ) = 0.4045.
Rate of convergence = log10 ( ( H )) = 0.3931.

Q 6a

f ( x, y, z ) = x 2 + y 2 4.82 = 0, g ( x, y, z ) = xy + yz + zx 0.59 = 0,
h( x, y, z ) = yz 2 + y 2 z + 1.33 = 0. Newtons method:
f / x f / y f / z x
f
g / x g / y g / z y = g .



h / x h / y h / z z
h
k
k

Next approximation is x k +1 = x k + x; y k +1 = y k + y; z k +1 = z k + z.

2 x

y + z

x
f


z+x
x+ y
y = g

h
z 2 + 2 yz
y 2 + 2 yz k z
k
Using the given initial approximation, x 0 = 1, y 0 = 2, z 0 = 0.5, we get
2
1.5

2y

4
0.5
1.75

0 x
0.18
3 y = 0.09
0.17
2 z
k

The solution of the system is x = 0.39, y = 0.24, z = 0.125 .


Hence, x1 = 1.39, y1 = 1.76, z1 = 0.625 .

Q 6b

# include <stdio.h>
#define SIZE 100
main ( )
{
int i, n, f [SIZE];
void reordering (int n, int f [ ] );
printf (" \ n Total number of numbers to be entered");
scanf (" % d", & n);
printf (" \n");
for ( i = 0; i < n ; ++i )
{
printf ( " i = % d, f = ", i +1);
scanf (" % d", & f [ i ] );
}
reordering (n, f );

28

printf ( " \ n \ n Numbers in ascending order : \ n \ n" );


for ( i = 0; i < n; ++i )
printf ( " i = % d, f = % d \n ", i +1, f[ i ] );
}
void reordering (int n, int f [ ] )
{
int i , item, temp;
for (item = 0; item < n - 1; ++item)
for ( i = item +1; i < n; ++i )
if ( f [ i ] < f [ item ] )
{
temp = f [ item ];
f [ item ] = f [ i ];
f [ i ] = temp;
}
return;
}

PART II
Q 7a

Data is not equispaced . Use the divided difference formula.


f ( x) = f ( x 0 ) + ( x x 0 ) f [ x 0 , x1 ] + ( x x 0 ) ( x x1 ) f [ x 0 , x1 , x 2 ]
+ ( x x 0 ) ( x x1 ) ( x x 2 ) f [ x 0 , x1 , x 2 , x 3 ] .
Form the divided difference table.
x
f(x)
first d.d
second d.d
0
2.5
1
0.5
2.0
10.5
11.0
4.5
2
5
187.5
59.0
12.0
7
515.5
164.0
21.0
10
1502.5
329.0
33.0

third d.d

1.50
1.50
1.50

fourth d.d

0.0
0.0

f ( x) = 2.5 + ( x 0) 2 + ( x)( x 1)4.5 + ( x)( x 1)( x 2)(1.5) = 1.5 x 3 + 0.5 x 2.5


f (8) = 769.5 .

Q 7b

h3
9 3
E

M 3 where

M 3 = max f ( x) . h = 0.1, M 3 = max (e x + 1 ) = e 2 .


[ 0, 1]

[ 0, 1]

(0.1) 3 2
e 0.00047 .
9 3

Q 8a

J = [ f (t i ) (a + b cos t i )]2 = minimum


i =1

For minimum, we have the necessary conditions


N
N
J
J
= 0 = [ f (t i ) (a + b cos t i )] ,
= 0 = [ f (t i ) (a + b cos t i )]cos t i .
a
b
i =1
i =1
Normal equations are

Na + b cos t i = f (t i ) ,

a cos t i + b cos 2 t i = f (t i ) cos t i .

2
We get cos t i = 0.2713, cos t i = 1.8821, f (t i ) = 1.4535, f (t i ) cos t i = 1.4794.
Normal equations are 5a + 0.2713b = 1.4535 , 0.2713a + 1.8821b = 1.4794 .
Solution is a = 0.25, b = 0.75. Hence, f (t ) = 0.25 + 0.75 cos t .

29

Q 8b

# include <stdio.h>
# include <math.h>
main ( )
{
float x[10], y[10], xin, yout, sum;
int n, i, j;
printf ("Input number of points: n \ n");
scanf ( "%d" , & n);
printf ( "Input the abscissas \ n");
for ( i = 1; i <= n; i++)
scanf ( "% f ", & x[ i ] );
printf ( "Input the ordinates \ n");
for ( i = 1; i <= n; i++)
scanf ( "%f ", & y[ i ] );
printf ( "Input the value x for which interpolation is required \ n" );
scanf ( "% f ", & xin );
yout = 0.0 ;
for (i = 1; i <= n; i++ )
{
sum = y[ i ];
for (j = 1; j <= n; j++ )
{
if ( i != j )
sum = sum * ( xin - x [ j ] ) / ( x [ i ] - x [ j ] ) ;
}
yout = yout + sum;
}
printf ( " At x = % 5.3 f , y = % 8.5 f \ n" , xin, yout ) ;
return 0;
}

Q 9a

h f ( x 2 ) = a f ( x 2 2h) + b f ( x 2 h) + c f ( x 2 )

( 2h ) 2
( 2 h) 3
h2
h3
= a f 2 2h f 2 +
f 2
f 2+ .... + b f 2 h f 2 +
f 2
f 2 + .... + c f 2
2!
6
2!
6

h2
h3
f 2 (4a + b)
f 2 (8a + b) + ....
2
6
( i ) Comparing, we get a + b + c = 0, 2a + b = 1, 4a + b = 0.
The solution is a = 1/2, b = 2, c = 3/2.

= (a + b + c) f 2 h f 2 (2a + b) +

( ii ) Error term =

h3
h3
(8a + b) f 2 ( ) =
f 2 ( )
6
3

f ( x 2 ) =

( iii ) Formula is given by

1
[ f ( x 0 ) 4 f ( x1 ) + 3 f ( x 2 )].
2h

1
[ 0 4 1 + 3 2 ]
2h
1
4
.
0 + 4 1 + 3 2
RE
2h
h

Round off error

RE =

Q 9b

1
[ f (0.2) 2 f (0.6) + f (1.0)] = 4.64 .
0.16
1
h = 0.2 : f (0.6) =
[ f (0.4) 2 f (0.6) + f (0.8)] = 4.4 .
0.04
h = 0.4 : f (0.6) =

30

Error : O (h 2 ) .

Q 10a

1
[ 4 f (h / 2) f (h)]
3
1
= [ 4 f (h = 0.2) f (h = 0.4)] = 4.32 .
3

Richardsons estimate =

Make the formula exact for f ( x) = x i , i = 0, 1, 2.


f ( x) = 1 : 2 = a + b; f ( x) = x : 0 = a + bc; f ( x) = x 2 : (2 / 3) = a + bc 2 .
Solution is a = 1 / 2, b = 3 / 2, c = 1 / 3.
Error term: Set f ( x) = x 3 : C =

dx [a + bc 3 ] =

4
.
9

C
2
Error =
f ( ) =
f ( ) .
3!
27

Q 10b

Q 11a

# include <stdio.h>
# include <math.h>
float f(float,float);
main ( )
{
float x0,y0,h,xf,x,y;
int i, iter ;
FILE *fp ;
fp = fopen ( "result", "w" );
printf ( "Input initial point initial value , \ n");
printf ( "Step size h and final value xf \ n");
scanf ( "%f %f %f %f ", &x0, &y0, &h, &xf );
fprintf ( fp , "x0 = %f ", x0 );
fprintf ( fp , "y0 = %f, h = %f ", y0, h );
fprintf ( fp, "Final value = % f \ n", xf );
iter = (xf-x0)/h+1;
for ( i = 1; i <= iter ; i++ );
{
y=y0+h*f(x0, y0);
x = x0 + h ;
if(x<xf)
{
x0 = x ;
y0 = y ;
}
}
fprintf ( fp , " At x = % 6.4 f, y =% 12.6 e \ n", x, y );
printf ( " \ n See FILE `result' for results \ n \ n" );
fclose ( fp ) ;
return 0;
}
float f (float x, float y)
{
float fun ;
fun = x * x + y * y ;
return ( fun ) ;
}
1
1
1
+ f

( i ) Gauss-Legendre 2 point formula : f ( x)dx = f

3
3
1
1
1
= 1.1172 .
I = 21 cos
f ( x) = (1 x 2 ) cos x ;

31

( ii ) Gauss-Chebyshev 2 point formula :


1
f ( x)
1
+
dx = f

2
2
2
1 1 x

f ( x) = (1 x 2 ) 3 / 2 cos x;

1
I = ( 2)1
2
2

3/2

1
1

=
= 0.8444 .
cos
cos

2 2 2
2

Q 11b ( i ) Euler method : u n +1 = u n + h f (t n , u n ) = u n + h (u n2 + t n2 )


t 0 = 0, u 0 = 1, h = 0.2 :

u (0.2) = u (0) + 0.2 f (0, 1) = 1 + 0.2 = 1.2 .

( ii ) Taylor series method of order four :


h2
h3
h 4 iv
u n +
u n +
un
2
6
24
u 0 = 1 , u 0 = 1, u = 2uu + 2t , u 0 = 2, u = 2(u u + u 2 ) + 2,
u n +1 = u n + h u n +

u 0 = 8, u iv = 2(u u + 3u u ); u 0iv = 28.


h2
h3
h 4 iv
u 0 +
u 0 +
u0
2
6
24
0.004
0.0004
= 1 + 0.2 + 0.02(2) +
(8) +
(28) = 1.2525.
3
6

u (0.2) u1 = u 0 + hu 0 +

32