Detailed Solutions A-07 JUNE 2003: I X X F F I
Detailed Solutions A-07 JUNE 2003: I X X F F I
Q1.
JUNE 2003
a.
b.
c.
d.
e.
f.
If Ax = x, then A 1 x = (1 / ) x.
k = 4 + (4 > 1) = 4 + 1 = 5.
n +1 = C n2 . Order = 2.
PART I
Q2
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)
+ 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
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
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
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
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 )
n = 0, 1, 2, 3.
Q 4b
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
(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
1 , 2 , K , n
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
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
Q 6a
Since the data is equispaced, assume without any loss of generality that x 0 = h, x1 = 0, x 2 = h . Then,
x x2 h2
)=
Therefore, Error
h h 2
2h 3
h 2 =
.
3 3
3 3
h3
9 3
M3 .
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));
}
}
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=
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
1
3
a f ( x) dx
is transformed to
1 g (t ) dt
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
qa
+ n +1 = p ( + n ) + 2 1 + n
2 n
n2
= p ( + n ) + q 1
+ 3 2 + ....
= ( p + q ) + ( p 2q ) n +
3q n2
....
n +1
3q 2 1 2
n = n .
( 1 ) = ( 1 a1 3 ). .
x (k +1) = H x (k ) + c
Gauss-Seidel method:
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
1
< 1. Hence, the method converges.
2
DECEMBER 2003
a.
g.
h.
i.
n e ax = e ah 1 e ax .
j.
k.
g.
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
Q 2b
Set e k = x k . Substitute in the Newton-Raphson method and expand the terms in Taylor series
obtain
ek +1 = ek
Q f ( ) = 0
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
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
4.6 x
4.43
=
2 y
0.14
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
+ (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
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 .
= minimum .
[
[
[
]
]
]
10c +
30b
30a
31
+ 100a
98
12
fk
= 31,
xk f k
= 98,
x k2 f k
= 346 .
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
, 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
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
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
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
| Error |
[ x0 , x 1 ]
[ 0, 1 ]
We require
Q 9b
h
e 5 10 4 , or
8
40
h 10 4
e
12
= 0.03836 .
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 :
0 f ( x) dx = 3 2 f 4 f 2 + 2 f 4 .
Both the methods are exact for
f ( x) = x 3 .
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
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
(24 2 + 2) = 0.
Hence, = 0 ,
1 191 i
, and = 0.2887 .
48
16
Q 11a
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,
x1 = 1.1, y1 = 2.3207 .
k1 = 0.1 f ( 1.1, 2.3207 ) = 0.3421,
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,
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.
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
fk
7 x 3 + 8x 2 + 8x k + 1
= xk k 2 k
.
f k
21x k + 16 x k + 8
#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.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
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 .
[
[
[
[
[
Q 5a
]
[
[
[
]
]
]
]
]
]
]
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 .
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
Q 6a
y k +1 = A 1 v k ,
v k +1 = y k +1 m k +1 ,
4 1 1
= 2 1 0 .
5 2 1
= Lim
k
(y k +1 )r
(v k ) r
r = 1, 2, K , n
= 1/ .
1 ]T ,
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
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
9 3
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,
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
( 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 .
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 )
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.
25
y (0.2 ) = 1.253.
y (0.4 ) = 1.6960.
a.
s.
t.
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.
w.
x.
A
C
y.
[ f ( x k ) 5 x k ] 2 = 4.
PART I
Q 2a
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
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
k = c2
Here,
1 2 k
0
0 < 1 and
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 .
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
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
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
PART II
Q 7a
third d.d
1.50
1.50
1.50
fourth d.d
0.0
0.0
Q 7b
h3
9 3
E
M 3 where
[ 0, 1]
(0.1) 3 2
e 0.00047 .
9 3
Q 8a
Na + b cos t i = f (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 ) =
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
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 =
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
3
3
1
1
1
= 1.1172 .
I = 21 cos
f ( x) = (1 x 2 ) cos x ;
31
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
u (0.2) u1 = u 0 + hu 0 +
32