Matlab Demos in the Week-4 Lecture
Contents
A matix for which the growth factor reaches the maximum
For an order-n matrix, the growth factor of partial-pivot Gauss elimination can reach at most 2^(n-1). This is a theoretical maximum. For matrices in real applications this is hardly reachable.
n= 6; A= eye(n,n)-tril(ones(n,n), -1); A(:,n)= 1; A lugui(A, 'partial') % Let's see the growth factor from complete-pivot Gauss elimination. figure(2); lugui(A, 'complete')
A = 1 0 0 0 0 1 -1 1 0 0 0 1 -1 -1 1 0 0 1 -1 -1 -1 1 0 1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 1
Sparse matrix operations
n=20; S= spdiags([ones(n,1), -2*ones(n,1)], [-1, 2], n,n); figure(3); spy(S) S A= full(S); A whos
S = (2,1) 1 (3,2) 1 (1,3) -2 (4,3) 1 (2,4) -2 (5,4) 1 (3,5) -2 (6,5) 1 (4,6) -2 (7,6) 1 (5,7) -2 (8,7) 1 (6,8) -2 (9,8) 1 (7,9) -2 (10,9) 1 (8,10) -2 (11,10) 1 (9,11) -2 (12,11) 1 (10,12) -2 (13,12) 1 (11,13) -2 (14,13) 1 (12,14) -2 (15,14) 1 (13,15) -2 (16,15) 1 (14,16) -2 (17,16) 1 (15,17) -2 (18,17) 1 (16,18) -2 (19,18) 1 (17,19) -2 (20,19) 1 (18,20) -2 A = Columns 1 through 13 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 -2 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 14 through 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 0 0 0 0 0 0 0 -2 0 0 0 0 0 0 0 -2 0 0 0 0 1 0 0 -2 0 0 0 0 1 0 0 -2 0 0 0 0 1 0 0 -2 0 0 0 0 1 0 0 -2 0 0 0 0 1 0 0 0 0 0 0 0 1 0 Name Size Bytes Class Attributes A 20x20 3200 double S 20x20 528 double sparse n 1x1 8 double