$24
MA-423 : Matrix Computations Lab
Singular value decomposition (svd) of a nonsingular matrix A can be computed as fol-lows.
Compute spectral decomposition A A = V diag( 1; · · · ; n)V such that j ≥ j+1:
√
2.
De ne := diag( 1; : : : ; n):
3.
Compute U := AV 1: Then A = U V is an svd of A:
Write a matlab function, say, [U, S, V] = mysvd1(A) that implements the above method. Use built in matlab functions such as eig and svd in your function and write comments about input and output. Your function may look like this
function [U, S, V] = mysvd1(A)
[U, S, V] = mysvd1(A) produces a diagonal matrix S of singular
values of nonsingular matrix A and two unitary matrices U and V
whose columns are the corresponding left and right singular
vectors so that A * V = U * S.
Singular value decomposition (svd) of an m-by-n matrix A can be computed as follows.
Compute spectral decomposition A A = V diag( 12; : : : ; r2; 0; : : : ; 0)V ; where r = rank(A) and j ≥ j+1:
Set V1 := V (:; 1 : r); the rst r columns of V; and set r := diag( 1; · · · ; r):
Compute spectral decomposition AA = Zdiag( 12; : : : ; r2; 0; : : : ; 0)Z and set U2 :=
Z(:; r + 1 : m); the last m − r columns of Z:
4.
Compute U1 := AV1 r 1:
Set U := [U1; U2] and := [
0
] ∈ Cm n: Then A = U V is an SVD of A:
5.
0r
0
Write a matlab function [U, S, V] = mysvd2(A) that implements the above method.
Experiment: Your task is to compare mysvd1 and mysvd2 with the matlab function svd by applying these functions on some test matrices. For this purpose, compute ∥V V −I∥2; ∥U U − I∥2 and ∥AV − U S∥2 when U, S and V are obtained by your functions as well as by svd(A). Plot these results and conclude which method is better and reliable. Plot the singular values and compare the smallest singular value obtained by all three methods. Consider the following test matrices.
Consider the magic squares magic(n) for n = 4; 5; 6:
Consider the Hilbert matrix hilb(n) for n = 4; 5; : : : ; 12:
The frank matrix F = gallery(’frank’,n) for n = 8; 10; 12:
Random matrix with normalized columns and speci ed singular values generated by matlab command gallery(’randcolu’, x). For more information type help private/randcolu. If j’s are speci ed singular values and ^j’s are computed singular values then compute the relative errors | j − ^j|= j for all three methods. Which method is better?
End ***
1