You are on page 1of 7

PGA-1-Report-Paawan Dubal-16577

Question.2.1.A.1 Solving the tridiagonal system of equations via LU decomposition.

• The program generates a random tridiagonal matrix as per the definition provided in the
question & solves the system of equations.
• First step is decomposing the co-efficient matrix in lower & upper triangular matrix.
• Second step is solving the system with upper triangular matrix & constant vector.
• Result of second step is then utilised to calculate the solution with lower triangular matrices.

A=

88 55 0 0
2 26 78 0
0 46 66 58
0 0 77 26

L=

1 0 0 0
0.022727 1 0 0
0 1.858586 1 0
0 0 -0.9750575 1

U=

88 55 0 0
0 24.75 78 0
0 0 -78.969696 58
0 0 77 26

b=

13
99
43
50
y=

13
98.70454545
-140.450872
-86.9476848

Final solution of the system of equations

x=

0.14772727
3.98806244
1.77854136
-86.947684

Question.2.1.A.2 Flop counts in the solution to system of equations:

• Flop counts for tridiagonal system is of order of 3n, where n is the number of equations.
• Flop counts for general system is of order of (2/3)n^3, where n is the number of equations.

Question.2.1.B.1 LU decomposition with partial pivoting:

A=

2 1 1 0
4 3 3 1
8 7 9 5
6 7 9 8

U=

8 7 9 5
0 1.75 2.25 4.25
- -
0 0 0.857142857 0.285714286
0 0 0 0.666666667
L=

1 0 0 0
0.75 1 0 0
0.5 -0.2857 1 0
0.25 -0.4285 0.33333333 1

P=

0 0 1 0
0 0 0 1
0 1 0 0
1 0 0 0
Question.2.2.A. Classical GS

• Here we observe that results of Classical & modified GS is same. However, error is less in
Modified GS as compared to Classical GS

A=

22 60 70 89 61
55 44 55 51 70
47 12 68 6 53
42 22 3 15 17
92 85 67 71 80

Q=

0.17421952 0.80641852 0.40491151 0.21420139 -0.3309096


0.43554879 -0.0192855 0.11941188 0.56232538 0.69242782
0.37219624 -0.5080322 0.71933489 -0.1441774 -0.2552321
0.33260089 -0.2374615 -0.4376076 0.54726647 -0.5847970
0.72855434 0.18663474 -0.3359231 -0.5635780 0.06254203

R=

126.2774723 103.3280107 111.2708367 96.66807374 124.7807682


0 52.0799598 32.63454506 77.42863592 31.80976819
0 0 60.00656097 16.02848464 36.87000487
0 0 0 15.07240986 9.00494537
0 0 0 0 9.81897269

Modified GS

A=

22 60 70 89 61
55 44 55 51 70
47 12 68 6 53
42 22 3 15 17
92 85 67 71 80

Q=

0.17421952 0.80641852 0.40491151 0.21420139 -0.3309096


0.43554879 -0.0192855 0.11941188 0.56232538 0.69242782
0.37219624 -0.5080322 0.71933489 -0.1441774 -0.2552321
0.33260089 -0.2374615 -0.4376076 0.54726647 -0.5847970
0.72855434 0.18663474 -0.3359231 -0.5635780 0.06254203
R=

126.2774723 103.3280107 111.2708367 96.66807374 124.7807682


0 52.0799598 32.63454506 77.42863592 31.80976819
0 0 60.00656097 16.02848464 36.87000487
0 0 0 15.07240986 9.00494537
0 0 0 0 9.81897269

Question.2.2.B. Errors for given combination for identity & Hilbert matrix

Aeye=

1.00E-05 0.00E+00 0.00E+00 0.00E+00 0.00E+00


0.00E+00 1.00E-05 0.00E+00 0.00E+00 0.00E+00
0.00E+00 0.00E+00 1.00E-05 0.00E+00 0.00E+00
0.00E+00 0.00E+00 0.00E+00 1.00E-05 0.00E+00
0.00E+00 0.00E+00 0.00E+00 0.00E+00 1.00E-05

Hilb=

1 0.5 0.33333333 0.25 0.2


0.5 0.33333333 0.25 0.2 0.16666667
0.33333333 0.25 0.2 0.16666667 0.14285714
0.25 0.2 0.16666667 0.14285714 0.125
0.2 0.16666667 0.14285714 0.125 0.11111111

A=

1.00001 0.5 0.33333333 0.25 0.2


0.5 0.33334333 0.25 0.2 0.16666667
0.33333333 0.25 0.20001 0.16666667 0.14285714
0.25 0.2 0.16666667 0.14286714 0.125
0.2 0.16666667 0.14285714 0.125 0.11112111
Classical GS

Q=

0.82658692 -0.5333633 0.17532893 -0.0390476 0.00356132


0.41328933 0.37411458 -0.7178829 0.40697886 -0.0907879
0.27552622 0.46292428 -0.0563148 -0.7012835 0.46348291
0.20664466 0.44329783 0.35235189 -0.1697427 -0.7796284
0.16531573 0.40589406 0.57147229 0.55877746 0.41122728

R=

[[1.20980623e+00, 6.88823808e-01, 4.92016612e-01, 3.85412829e-01, 3.17760476e-01]

[0.00000000e+00, 1.30066588e-01, 1.40198195e-01, 1.32705585e-01, 1.22327434e-01]

[0.00000000e+00, 0.00000000e+00, 8.07290637e-03, 1.26433673e-02, 1.49202619e-02]

[0.00000000e+00, 0.00000000e+00, 0.0000000e+00, 3.49787587e-04, 7.11043615e-04]

[0.00000000e+00, 0.00000000e+00, 0.0000000e+00, 0.00000000e+00, 3.52486934e-05]]

Q*Q^T=

[[ 1.00000000e+00, -8.19019690e-11, 3.44496643e-10, -4.99421243e-10, 2.33456779e-10]

[-8.19019690e-11, 1.00000000e+00, -4.45858473e-09, 5.31488016e-09, -2.00511389e-09]

[ 3.44496643e-10, -4.45858473e-09, 1.00000001e+00, -8.58723262e-09, 4.34871208e-10]

[-4.99421243e-10, 5.31488016e-09, -8.58723262e-09, 9.99999995e-01, 9.29627941e-09]

[ 2.33456779e-10, -2.00511389e-09, 4.34871208e-10, 9.29627941e-09, 9.99999992e-01]]

Error=

[[ 4.27613500e-12, -8.19019690e-11, 3.44496643e-10, -4.99421243e-10, 2.33456779e-10]

[-8.19019690e-11, 1.28088296e-09, -4.45858473e-09 , 5.31488016e-09, -2.00511389e-09]

[ 3.44496643e-10, -4.45858473e-09, 1.18338821e-08, -8.58723262e-09, 4.34871208e-10]

[-4.99421243e-10, 5.31488016e-09, -8.58723262e-09, -4.62015437e-09, 9.29627941e-09]

[ 2.33456779e-10, -2.00511389e-09, 4.34871208e-10, 9.29627941e-09, - 8.49888693e-09]]


Modified GS

Q=

[[ 0.82658692 -0.53336332 0.17532893 -0.03904766 0.00356132]

[ 0.41328933 0.37411458 -0.71788298 0.40697886 -0.09078799]

[ 0.27552622 0.46292428 -0.05631489 -0.70128357 0.46348291]

[ 0.20664466 0.44329783 0.35235189 -0.16974271 -0.77962848]

[ 0.16531573 0.40589406 0.57147229 0.55877746 0.41122728]]

R=

[[1.20980623e+00 6.88823808e-01 4.92016612e-01 3.85412829e-01 3.17760476e-01]

[0.00000000e+00 1.30066588e-01 1.40198195e-01 1.32705585e-01 1.22327434e-01]

[0.00000000e+00 0.00000000e+00 8.07290637e-03 1.26433673e-02 1.49202619e-02]

[0.00000000e+00 0.00000000e+00 0.00000000e+00 3.49787587e-04 7.11043615e-04]

[0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 3.52486934e-05]]

Q*Q^T=

[[ 1.00000000e+00 -8.19019690e-11 3.44496643e-10 -4.99421243e-10 2.33456779e-10]

[-8.19019690e-11 1.00000000e+00 -4.45858473e-09 5.31488016e-09 -2.00511389e-09]

[ 3.44496643e-10 -4.45858473e-09 1.00000001e+00 -8.58723262e-09 4.34871208e-10]

[-4.99421243e-10 5.31488016e-09 -8.58723262e-09 9.99999995e-01 9.29627941e-09]

[ 2.33456779e-10 -2.00511389e-09 4.34871208e-10 9.29627941e-09 9.99999992e-01]]

Error=

[[ 4.27613500e-12 -8.19019690e-11 3.44496643e-10 -4.99421243e-10 2.33456779e-10]

[-8.19019690e-11 1.28088296e-09 -4.45858473e-09 5.31488016e-09 -2.00511389e-09]

[ 3.44496643e-10 -4.45858473e-09 1.18338821e-08 -8.58723262e-09 4.34871208e-10]

[-4.99421243e-10 5.31488016e-09 -8.58723262e-09 -4.62015437e-09 9.29627941e-09]

[ 2.33456779e-10 -2.00511389e-09 4.34871208e-10 9.29627941e-09 -8.49888693e-09]]

You might also like