Docsity

CAAM 551 Problem Set 2: Solving Linear Algebra Problems in Matlab, Assignments of Linear Algebra

Toggle sidebar
bg1
CAAM 551 Problem set 2
Due Wed. 17 Sep. 08.
Note: If you are a CAAM major, you must do problem 3 instead of prob-
lem 1. If you are not a CAAM major, you may do problem 1 or problem 3
(DO NOT DO BOTH).
Problem 1
1. Write a Matlab code that will convert a sparse matrix in Matlab format
[i, j, Aij] to CSR storage. You should store the pointers to row starts
in an array IA, the column indices of the nonzero elements in an array
JA and the nonzero matrix elements of Ain an array AA.
For example the matrix of EX3.7 p 89 of Saad is:
% CSR Storage
%
% AA = [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ]
% JA = [ 1 4 1 2 4 1 3 4 5 3 4 5]
% ^ ^ ^ ^ ^
% IA = [ 1 3 6 10 12 13]
2. Write a Matlab code that will multply a square matrix Ain CSR
storage times a vector x. i.e. code w=Ax.
3. Write a Matlab code that will solve Lx =bwhere Lis a sparse non-
singular real n×nlower triangular matrix. (bis a given n-vector and
xis solution vector). Your Matlab function should be of the form
function [x] = SLsolve(AA,JA,IA,b);
1
pf3
pf4

Partial preview of the text

Download CAAM 551 Problem Set 2: Solving Linear Algebra Problems in Matlab and more Assignments Linear Algebra in PDF only on Docsity!

CAAM 551 Problem set 2 Due Wed. 17 Sep. 08.

Note: If you are a CAAM major, you must do problem 3 instead of prob- lem 1. If you are not a CAAM major, you may do problem 1 or problem 3 (DO NOT DO BOTH).

Problem 1

  1. Write a Matlab code that will convert a sparse matrix in Matlab format [i, j, Aij ] to CSR storage. You should store the pointers to row starts in an array IA, the column indices of the nonzero elements in an array JA and the nonzero matrix elements of A in an array AA. For example the matrix of EX3.7 p 89 of Saad is:

% CSR Storage % % AA = [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ] % JA = [ 1 4 1 2 4 1 3 4 5 3 4 5] % ^ ^ ^ ^ ^ % IA = [ 1 3 6 10 12 13]

  1. Write a Matlab code that will multply a square matrix A in CSR storage times a vector x. i.e. code w = Ax.
  2. Write a Matlab code that will solve Lx = b where L is a sparse non- singular real n × n lower triangular matrix. (b is a given n-vector and x is solution vector). Your Matlab function should be of the form

function [x] = SLsolve(AA,JA,IA,b);

where the lower triangular matrix L is stored in the AA, JA, IA CSR data structure. (You can use L in place of A in the notation if you wish.) Write a test function to demonstrate your solver works correctly and test in on a random sparse lower triangular L (set the diagonals to 1 to assure non-singularity, but don’t assume this in the code).

Problem 2

Do problems 4 a,b,c,d and 12 on pages 98-100 of Saad. For problem 4, you can save some time by creating the matrices A and B in Matlab putting the numerical value 1 in place of *. Then you can do the matrix multiplications in Matlab. You may display the matlab results instead of writing them out by hand.

For problem 12, you may wish to use a consequence of the Cayley- Hamilton theorem which says that if a matix A is nonsingular (hence square) then A−^1 = γ 0 I + γ 1 A + γ 2 A^2 +... + γn− 1 An−^1 ,

where the γj are scalars. We shall prove this later in the course but you may assume it is true for this problem.

Problem 3

The following function will create a struct in which you can create the CSR storage scheme and then just refer to a single entity instead of having to pass three arrays.

function [s] = csr(nz,m,n); % % This sets up a struct s to hold a matrix A in CSR format %

s = struct(’nz’,nz,’m’,m,’n’,n,’ia’,[1:n+1],’ja’,[1:nz],’aa’,randn(nz,1));

Problem 4

Given an m × n matrix A with m > n and a positive number λ, a regularized least squares solution xλ may be computed by solving

min ‖

( A μI

) x −

( b 0

) ‖ 2 ,

where μ =

λ.

a. Derive the normal equations for the regularized least squares problem given above.

b. Show AT^ A + λI is symmetric and positive definite for every positive value of λ. Prove that the regularized least squares solution xλ is unique for every postive value of λ.

c. Use the Singular Value Decomposition of A to express the solution xλ to the problem min‖

( A μI

) x −

( b 0

) ‖ 2

where b ∈ Rm^ and μ^2 = λ.

d. Prove that limλ→ 0 + xλ = xLS the minimum norm least squares solu- tion (Regardless of the rank of A).