Docsity

Gaussian Elimination: Numerical Computations Homework Solutions, Assignments of Mathematics

Toggle sidebar
bg1
CSE/MATH 451.002: Numerical Computations, spring
2005
Answers to home work 6
Wen Shen
1 Gaussian elimination
All the computation here are done with 5 digits. If you did it with more digits, your results
would be slightly different from mine.
Gaussian elimination without pivoting:
Following the algorithm in the text book or in class, we get
m21 =a21
a11
= 0.66667, m31 =a31
a11
=−0.46838
so that the linear system after one step of elimination becomes:
3.3330 x1+ 15920 x2−10.333 x3= 7973.6
−10596 x2+ 16.501 x3=−5314.8
7461.8x2−6.5253 x3=−3737.4
Second elimination step, with m32 =a32/a22 =−0.70421 gives
3.3330 x1+ 15920 x2−10.333 x3= 7973.6
−10596 x2+ 16.501 x3=−5314.8
−5.0947 x3=−5.3
The solution becomes:
x1= 1.0354, x2= 0.49996, x3=−1.0403.
Gaussian elimination with scaled partial pivoting:
We get the following scaling factors:
s1= 15920, s2= 16.710, s3= 5.1792
and |a11|
s1
= 0.000209,|a21|
s2
= 0.13297,|a31|
s3
= 0.30142
so that the 3rd equation is used as the first pivot row (l1= 3). One step of elimination gives:
15931 x2−13.932 x3= 7979.4
24.082 x2+ 7.2129 x3= 4.8281
−1.5611 x1+ 5.1792 x2−1.6855 x3= 2.7140
1
pf3
pf4
pf5

Partial preview of the text

Download Gaussian Elimination: Numerical Computations Homework Solutions and more Assignments Mathematics in PDF only on Docsity!

CSE/MATH 451.002: Numerical Computations, spring

Answers to home work 6

Wen Shen

1 Gaussian elimination

All the computation here are done with 5 digits. If you did it with more digits, your results would be slightly different from mine.

Gaussian elimination without pivoting: Following the algorithm in the text book or in class, we get

m 21 =

a 21 a 11

= 0. 66667 , m 31 =

a 31 a 11

so that the linear system after one step of elimination becomes:

  1. 3330 x 1 + 15920 x 2 − 10. 333 x 3 = 7973. 6 − 10596 x 2 + 16. 501 x 3 = − 5314. 8
  2. 8 x 2 − 6. 5253 x 3 = − 3737. 4

Second elimination step, with m 32 = a 32 /a 22 = − 0 .70421 gives

  1. 3330 x 1 + 15920 x 2 − 10. 333 x 3 = 7973. 6 − 10596 x 2 + 16. 501 x 3 = − 5314. 8 − 5. 0947 x 3 = − 5. 3

The solution becomes:

x 1 = 1. 0354 , x 2 = 0. 49996 , x 3 = − 1. 0403.

Gaussian elimination with scaled partial pivoting: We get the following scaling factors:

s 1 = 15920, s 2 = 16. 710 , s 3 = 5. 1792

and |a 11 | s 1

|a 21 | s 2

|a 31 | s 3

so that the 3rd equation is used as the first pivot row (l 1 = 3). One step of elimination gives:

15931 x 2 − 13. 932 x 3 = 7979. 4

  1. 082 x 2 + 7. 2129 x 3 = 4. 8281 − 1. 5611 x 1 + 5. 1792 x 2 − 1. 6855 x 3 = 2. 7140

We now have: |a 12 | s 1

|a 22 | s 2

so that the 2nd equation becomes the 2nd pivot row (l 2 = 2), and the system after even another step of elimination becomes

− 4785. 4 x 3 = 4785. 5

  1. 082 x 2 + 7. 2129 x 3 = 4. 8281 − 1. 5611 x 1 + 5. 1792 x 2 − 1. 6855 x 3 = 2. 7140

with the solution: x 1 = 1. 0000 , x 2 = 0. 50000 , x 3 = − 1. 0000.

Comparing our answers we see clearly the effect of pivoting.

2 Gaussian Elimination in Matlab

i) c = [0.2:0.2:1]; x = ones(5,1); A = vander(c); b = A*x; x1 = naiv_gauss(A,b); % Gauss-elimination without pivoting x2 = A\b; % Gauss-elimination with pivoting error1 = (x-x1)’ error2 = (x-x2)’ And the errors are:

error1 = 1.0e-11 * -0.0722 0.1998 -0.1795 0.0604 -0.

error2 = 1.0e-12 * -0.0551 0.1361 -0.1164 0.0400 -0.

We see with pivoting the errors are smaller. ii) Change the first 2 lines with

c = [0.1:0.1:1]; x = ones(10,1);

And the errors are:

error1 = 0.0012 -0.0059 0.0119 -0.0136 0.0094 -0. 0.0011 -0.0002 0.0000 -0.

error2 = 1.0e-10 * 0.0022 0.1087 -0.4844 0.8731 -0.8466 0. -0.1618 0.0311 -0.0031 0.

3 LU factorization in Matlab

The correct system of linear equations should be:

JP 2

−αf 1 + f 4 + αf 5 = 0 −αf 1 − f 3 − αf 5 = 0

JP 3

−f 2 + f 6 = 0 f 3 − F 1 = 0

JP 4

−f 4 + f 8 = 0 −f 7 = 0

JP 5

−αf 5 − f 6 + αf 9 + f 10 = 0 αf 5 + f 7 + αf 9 − F 2 = 0

JP 6

−f 8 − αf 9 + f 12 + αf 13 = 0 −αf 9 − f 11 − αf 13 = 0

JP 7

−f 10 + f 14 = 0 f 11 − F 3 = 0

JP 8

−f 12 + αf 16 = 0 −f 15 − αf 16 = 0

JP 9

−αf 13 − f 14 + f 17 = 0 αf 13 + f 15 − F 4 = 0

JP 10

−αf 16 − f 17 = 0

We see that we have 17 unknowns and 17 linear equations, and there will be a unique solution if the system is “good” (meaning A is invertible). Also note that the coefficient matrix A here is sparse, i.e., many entries are zero. Therefore it might be advantageous to use the sparse matrix in Matlab. In order to solve the problem, my script file looks like this: (If you don’t use the sparse matrix, your codes would look different.)

% Set up the matrix, use sparse structure for A, where only non-zero % elemets will be stored. A = sparse(17,17); alpha = cos(pi/4); A(1,1) = -alpha; A(1,4) = 1; A(1,5) = alpha; A(2,1) = -alpha; A(2,3) = -1; A(2,5) = -alpha; A(3,2) = -1; A(3,6) = 1; A(4,3) = 1; A(5,4) = -1; A(5,8) = 1; A(6,7) = -1; A(7,5) = -alpha; A(7,6) = -1; A(7,9) = alpha; A(7,10)= 1; A(8,5) = alpha; A(8,7) = 1; A(8,9) = alpha; A(9,8) = -1; A(9,9) = -alpha; A(9,12) = 1; A(9,13) = alpha; A(10,9) = -alpha; A(10,11) = -1; A(10,13) = -alpha; A(11,10) = -1; A(11,14) = 1; A(12,11) = 1; A(13,12) = -1; A(13,16) = alpha; A(14,15) = -1; A(14,16) = -alpha;

A(15,13) = -alpha; A(15,14) = -1; A(15,17) = 1; A(16,13) = alpha; A(16,15) = 1; A(17,16) = -alpha; A(17,17) = -1;

% we do LU factorization for A [L,U] = lu(A);

% set up the 4 different right-hand-sides, with % b(4) = F1, b(8) = F2, b(12) = F3, b(16) = F4. b1= sparse(17,1); b1(4) = 10; b1(8) = 15; b1(12) = 0; b1(16) = 10; b2= sparse(17,1); b2(4) = 15; b2(8) = 0; b2(12) = 0; b2(16) = 10; b3= sparse(17,1); b3(4) = 10; b3(8) = 0; b3(12) = 20; b3(16) = 0; b4= sparse(17,1); b4(4) = 0; b4(8) = 10; b4(12) = 10; b4(16) = 0;

% at the end we solve the system v = L\b1; f1 = full(U\v) % make a full vector from a sparse one

v = L\b2; f2 = full(U\v)

v = L\b3; f3 = full(U\v)

v = L\b4; f4 = full(U\v)

The results for a), b), c) and d) become:

a) b) c) d) -26.8701 -19.7990 -22.6274 -14. 19.0000 14.0000 16.0000 10. 10.0000 15.0000 10.0000 0 -28.0000 -13.0000 -22.0000 -20. 12.7279 -1.4142 8.4853 14. 19.0000 14.0000 16.0000 10. 0 0 0 0 -28.0000 -13.0000 -22.0000 -20. 8.4853 1.4142 -8.4853 0. 22.0000 12.0000 28.0000 20. 0 0 20.0000 10. -16.0000 -11.0000 -14.0000 -10. -8.4853 -1.4142 -19.7990 -14. 22.0000 12.0000 28.0000 20. 16.0000 11.0000 14.0000 10. -22.6274 -15.5563 -19.7990 -14. 16.0000 11.0000 14.0000 10.