You are on page 1of 10

PH 305: Computational Physics

MidSem: 5 x 6 = 30 marks, 2 hours


1 2
= (1 0
0 1

1. Consider a matrix

0
1)
1

Perform a QR decomposition of this matrix A. Then use this


decomposition to solve = where,
1
= (2)
1
Ans.
= , = = , =
But = 1 Hence = . [2 marks]
For the above matrix,

2
1

3
1

3
1
3

2 2

6
1

and =

6
2

1
2

3
2)

[1+1 marks]

Hence
3
=

2
0
3

( 2)

1
= (0) [1 mark]
1
2. Correct this piece of pseudo C-code that is meant to implement the
Gram Schmidt orthonormalization procedure (Dot[a,b] stands for dot
product of vectors a and b).

for (int i = 0; i < n; i + +)


{
v = a[i];
for (int j = 0; j < i; j + +)
{
v = v Dot[q[j], v] a[i];
}
v
q[i] =
;
[
]
Sqrt[Dot v, v ]
}

Ans.

v = v Dot[q[j], v] q[j]; .[2 marks]

Corrected line

If n = 3, and a[0] = (1,1,0), a[1] = (-1,0,2), a[2] = (1,1,1) what are


the output vectors q[0],q[1] and q[2] a) before correcting the code
b) after correcting the code ?

Ans.
Before: q[0] = (

2
1

,
2

[1] = (

After: q[0] = (

,
2

[1] = ( 3

, 0)

, 0,
5

) ; [ 2] = (
5

,
3

,
3

) .[2 marks]

, 0)
1

,
2 3

,
2

22
);
3

2 1

[2] = (3 , 3 , 3) [2 marks]

3. The Hilbert matrix of size is the symmetric matrix


1
= [ ] where = +1. As n increases, the Hilbert
matrix becomes more and more ill-conditioned (determinant
becomes closer to zero). Use Gaussian elimination with partial
pivoting to solve the system of linear equations shown below,
rounding to two significant digits after each intermediate
calculation. Compare this solution with the exact solution
(1 = 3, 2 = 24, 3 = 30).

1
1
1 + 2 + 3 = 1
2
3
1
1
1
+ 3 2 + 4 3 = 1
2 1
1
1
1
1 + 2 + 3 = 1
3
4
5
Ans.
Augmented matrices (round off eg. 0.155 is replaced by 0.16)
1.00 0.50 0.33 1.00
[A|b] = (0.50 0.33 0.25 1.00)
0.33 0.25 0.20 1.00
1.00 0.50 0.33 1.00
[|]1 = ( 0.0 0.08 0.09 0.50) [2 marks]
0.0 0.09 0.09 0.67
1.00 0.50 0.33 1.00
[|]2 = ( 0.0 1.00 1.12 6.25)
0.0 0.09 0.09 0.67
1.00 0.50 0.33 1.00
[|]3 = ( 0.0 1.00 1.12 6.25 )
0.0 0.00 0.01 0.11
1.00
[|]4 = ( 0.0
0.0

0.50
0.33 1.00
1.00
1.12 6.25 ) .. [2 marks]
0.00 1.00 11.00

This leads to the following solution for the linear system


3 = -11.00, 2 = 18.57, 1 = -4.66

.[ 2 marks ]

Which is totally different from the exact solution.


Note: If a different rounding scheme such as 0.155 0.15 is used then a
different set of augmented matrices are obtained. Also some may choose
not to make the running pivot equal to unity each time. This will lead to a
minor penalty of one mark only.

4.

Use the QR algorithm to generate a sequence of matrices


0 , 1 , 2 , 3 taking care to round off to two places after the
decimal. It is given that
1 1
= 0 = (
)
1 0
If you think of 3 as an approximately diagonal matrix, what
are the eigenvalues of 3 ? How do they compare with
the actual eigenvalues of the original matrix ?

Ans.

= 1
1 1 .....[1 mark]


1 = (

1.5 0.5
) ..[1 mark]
0.5 0.5

1.6 0.2
2 = (
).......[1 mark]
0.2 0.6

3 = (

1.62 0.08
) .[1 mark]
0.08 0.62

The approximate eigenvalues of 3 are {1.62,-0.62}..[1 mark]


The exact eigenvalues of the original matrix A are
1
1
{2 (1 + 5), 2 (1 5)}
{1.618033988749895, 0.6180339887498949} ..[1 mark]
We can see that this algorithm converges rapidly for this matrix.

5.

A square metal plate has a constant temperature on each of its

four boundaries, as shown in Figure 1. Use a grid to


approximate the temperature distribution in the interior of the
plate. Assume that the temperature at each interior point is the
average of the temperatures at the four closest neighbouring
points. Recast this problem as a solution to a linear system.
Implement the Gauss Seidel method using the starting guess as
(1 = 2 = 4 = 1000 , 6 = 8 = 9 = 00 ,
3 = 5 = 7 = 500 ).
What do these temperatures become after two iterations?
1000

1000

00

00
Ans.
1

1 = 4 (100 + 100 + 2 + 4 )
1

2 = 4 (100 + 1 + 3 + 5 )
1

3 = 4 (100 + 0 + 2 + 6 )
1

4 = 4 (100 + 1 + 5 + 7 )
1

5 = 4 ( 2 + 4 + 6 + 8 )

6 =

1
4

(0 + 3 + 5 + 9 )

7 = 4 (100 + 0 + 4 + 8 )
1

8 = 4 (0 + 5 + 7 + 9 )
1

9 = 4 (0 + 0 + 6 + 8 )
1
1/4
0
1/4
0
0
0
0
0
1
50
1/4
1
1/4
0
1/4
0
0
0
0
2
25
0
1/4
1
0
0
1/4
0
0
0
3
25
1/4
0
0
1
1/4
0
1/4
0
0
4
25

0
1/4
0
1/4
1
1/4
0
1/4
0
=
0
5
6
0
0
1/4
0
1/4
1
0
0
1/4
0

25
7
1/4
0
0
1
1/4
0
0
0
0
8
0
0
1/4
0
1/4
1
1/4
0
0
0
(
0)
0
0
1/4
0
1/4
1 ) (9 )
( 0
0
0

Gauss-Seidel Iteration .. [3 marks]


1

1, = 4 (100 + 100 + 2,1 + 4,1 )


1

2, = 4 (100 + 1, + 3,1 + 5,1 )


1

3, = 4 (100 + 0 + 2, + 6,1 )
4, =

1
4

(100 + 1, + 5,1 + 7,1 )

5, = 4 ( 2, + 4, + 6.1 + 8,1 )
1

6, = 4 (0 + 3, + 5, + 9,1 )

7, =

(100 + 0 + 4, + 8,1 )

4
1

8, = 4 (0 + 5, + 7, + 9,1 )
1

9, = 4 (0 + 0 + 6, + 8, )
This means after one iteration ..[2 marks],
1

1,1 = 4 (100 + 100 + 100 + 100) = 100


1

2,1 = 4 (100 + 1,1 + 50 + 50)


1

3,1 = 4 (100 + 0 + 2,1 + 0)


1

4,1 = 4 (100 + 1,1 + 50 + 50)


1

5,1 = 4 ( 2,1 + 4,1 + 0 + 0)


1

6,1 = 4 (0 + 3,1 + 5,1 + 0)


1

7,1 = 4 (100 + 0 + 4,1 + 0)


1

8,1 = 4 (0 + 5,1 + 7,1 + 0)


1

9,1 = 4 (0 + 0 + 6,1 + 8,1 )

= 75
= 43.75
= 75
= 37.5
= 20.31
= 43.75
=

20.31

10.16

This means after two iterations .[1 mark]

1,2 =

1
4

(100 + 100 + 75 + 75)

87.5

2,2 = 4 (100 + 1,2 + 3,1 + 5,1 ) =


1

3,2 = 4 (100 + 0 + 2,2 + 6,1 )

67.19

46.88

4,2 = 4 (100 + 1,2 + 5,1 + 7,1 ) =

67.19

5,2 = 4 ( 2,2 + 4,2 + 6.1 + 8,1 ) =


1

6,2 = 4 (0 + 3,2 + 5,2 + 9,1 )


1

7,2 = 4 (100 + 0 + 4,2 + 8,1 )


1

8,2 = 4 (0 + 5,2 + 7,2 + 9,1 )


1

9,2 = 4 (0 + 0 + 6,2 + 8,2 )

43.75
=

25.2

46.88

25.2

12.6

The exact answers are,

t1 85.71428571428571, t2 71.42857142857143, t3 50.0


t4 71.42857142857143, t5 50.0
t6 28.571428571428573, t7 50.0, t8 28.571428571428573
t9 14.285714285714286

You might also like