2023T1 MATH2089 – Numerical Methods Tutorial Problems Week 3
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
2023T1 MATH2089 – Numerical Methods Tutorial Problems (MATLAB*)
Week 3
*Python version for this tutorial is available as a Jupyter notebook from the course Moodle page. Topic: §2 Linear Systems (continued)
1. [M] Let
A = l 」 b = l 」4(2)
「 2 −1 3 , 「1 .
(a) Show that A is symmetric.
(b) Use the Matlab function chol to ind the Cholesky factorization A = RT R, where R is upper triangular.
(c) Use the Cholesky factorization to solve A北 = b.
2. [M] The Matlab script tulu .m
% MATH2089: File = tulu .m
format compact
A = [1 1 3 0; 1 3 0 0; -2 0 0 1; 3 0 0 2];
b = [0; 5; -6; 2];
[L1, U1, P1] = lu(A)
chk = norm(A-L1*U1, 1)
x1 = U1 \ (L1 \ (P1*b)); x1T = x1’
p = colamd(A)
B = A(:,p);
[L2, U2, P2] = lu(B)
x2 = U2 \ (L2 \ (P2*b)); x2T = x2’
produces the output
L1 = 1.0000 0.3333 0.3333 -0 .6667 U1 = 3.0000 0 0 0 P1 = 0 0 1 |
0 1 0 |
0 1.0000 0.3333 0 0 3 .0000 0 0 0 0 0 |
0 0 1.0000 0 0 0 3 .0000 0 1 0 0 |
0 0 0 1 .0000 2.0000 -0 .6667 -0 .4444 2.3333 |
0 chk = 10 x1T = 2 .0000 p = 3 L2 = 1.0000 0 0 0 U2 = 3.0000 0 0 0 P2 = 1 0 0 0 x2T = -1 .0000 |
0
2
0 1 0 0 |
1
1 .0000 1 0 1.0000 0 0 1.0000 3.0000 0 0 0 0 0 1 1 .0000 |
0
-1 .0000 4 0 0 1.0000 -0 .6667 1.0000 1.0000 3.0000 0 0 0 1 0 2 .0000 |
-2 .0000
0 0 0 1 .0000 0 0 2.0000 2.3333
-2 .0000 |
(a) Why is chk not equal to zero?
(b) What is the value of B?
(c) Why are x1T and x2T not the same?
3. [M] Consider the spy plots of the 156 by 156 matrix A from the chemical plant model http://math.nist.gov/MatrixMarket/data/Harwell-Boeing/chemwest/west0156.html
A = west0156
0
50
100
150
0 50 100 150 nz = 362
B = A’*A
0
50
100
150
0 50 100 150 nz = 818
p = symrcm(B), B(p,p)
0
50
100
150
0 50 100 150 nz = 818
(a) Create a sparse matrix A containing the data from west0156 .dat.
i. Download the data ile west0156 .dat from the course Moodle page. This ile contains the data for the coecient matrix A in sparse format (i, j, Aij ) for the non-zero entries.
ii. Clear all variables from your Matlab workspace using the clear command.
iii. Load the data using load west0156 .dat. This should produce a 371 by 3 array – check using the whos command. (There are in fact 9 rows with value 0 included!)
iv. Store the irst column (row indices) in the variable I, the second column (column indices) in the variable J and the third column (values) in the column vector V.
v. Create the sparse matrix A using the command A = sparse(I, J, V);
(b) Check that A is a 156 by 156 sparse matrix, using either the whos command or the size and issparse commands.
(c) Find the values of Ai,j for i = 146, . . . , 156 and j = 1, . . . , 5. There is one negative value among these; what are its indices?
(d) Form the matrix B = AT A. Calculate p = symrcm(B) and then form the matrix C = B(p,p).
(e) Create spy plots of the non-zero elements in A, B, and C .
(f) Check if A is symmetric by calculating |A − AT |∞ . Is B symmetric? Is C symmetric? (g) Calculate the density of A, B, and C .
(h) What does B(p,p) give and why is it useful?
(i) Calculate the bandwidth of C using [lower,upper] = bandwidth(C).
(j) Try to calculate the Cholesky factorization of B using [R, k] = chol(B);. What is the value of k and what does this mean? Calculate the smallest eigenvalue of B .
2023-04-29