Question

Do the following using Matlab: Let A be a matrix where each row corresponds to an article, and each column to how often a specific word appears in the article. Patterns among the articles and words can often be identified by analyzing the singular values and vectors of the singular value decomposition of A.

(a) Use the Matlab svd function to find the singular values of the following matriar . Note this problem does not ask you to print out the entire single value decomposition, only the singular values.

A = [9 0 3 4 0 0 0 0 0 4 1 0 0 1 3 2 1 8 0 1

8 0 3 5 0 0 1 0 0 3 1 0 0 2 3 2 1 7 0 1

0 1 0 1 2 3 4 5 3 1 0 0 0 0 0 1 1 0 2 7

7 0 3 4 0 0 1 0 0 5 1 0 0 0 2 2 1 8 1 1

0 1 2 0 2 3 4 5 2 1 0 1 0 0 0 1 1 0 2 7

9 0 4 5 0 0 1 0 0 4 1 0 1 0 2 2 0 7 0 1

0 1 0 2 4 3 5 6 3 2 0 0 0 0 0 1 0 0 2 6]

(b) Have Matlab print the ratio of the largest singular value to the smallest singular value. Also have Matlab print out the condition number of A (recall the Matlab cond(A) function returns the condition number of A).

(c) Use the Matlab svds functions with arguments A and 2 to find the singular value decomposition associated with the largest two singular values of A. For this part have Matlab return U, ?, and V matrices. (Here, U, ?, and V refer to the portion of those matrices returned by svds when the second argument is 2.)

(d) Have Matlab multiply U\Sigma V^{T} from part (c), print the product, and then compare the result to the original A matrix by printing the norm of U\Sigma V^{T}-A . In this problem, make sure you use the U, ?, and V from part (c).

For this problem, turn in a diary or script — showing both the Matlab statements used and Matlab’s output — for parts (a) through (d)).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A = [9 0 3 4 0 0 0 0 0 4 1 0 0 1 3 2 1 8 0 1;
8 0 3 5 0 0 1 0 0 3 1 0 0 2 3 2 1 7 0 1;
0 1 0 1 2 3 4 5 3 1 0 0 0 0 0 1 1 0 2 7;
7 0 3 4 0 0 1 0 0 5 1 0 0 0 2 2 1 8 1 1;
0 1 2 0 2 3 4 5 2 1 0 1 0 0 0 1 1 0 2 7;
9 0 4 5 0 0 1 0 0 4 1 0 1 0 2 2 0 7 0 1;
0 1 0 2 4 3 5 6 3 2 0 0 0 0 0 1 0 0 2 6];

%% part a
s = svd(A); % print singular values of matrix A
display(s);
% output
% s =
%
% 27.5875
% 18.8616
% 3.0180
% 2.5743
% 2.2455
% 1.4063
% 1.1891

%% part b
r = s(1)/s(end);
display(r); % print the ratio of largest to smallest singular value
% output
% r =
%
% 23.2005
%% part c
[U,S,V] = svd(A);
% extracting 2 colm from U
u2 = U(1:end,1:2);
% extracting 2 row and 2 colm from S
s2 = S(1:2,1:2);
% extracting 2 colms from V
v2 = V(1:end,1:2);
% ans = u2, s2, v2
display(u2);
display(s2);
display(v2);
% output
% u2 =
%
% -0.5056 -0.1387
% -0.4723 -0.1026
% -0.1162 0.5537
% -0.4715 -0.0835
% -0.1203 0.5413
% -0.5013 -0.1096
% -0.1406 0.5931
% s2 =
%
% 27.5875 0
% 0 18.8616
% v2 =
%
% -0.5851 -0.1929
% -0.0137 0.0895
% -0.2390 -0.0175
% -0.3325 -0.0111
% -0.0375 0.2419
% -0.0410 0.2685
% -0.1121 0.3738
% -0.0734 0.4789
% -0.0366 0.2398
% -0.3016 0.0299
% -0.0707 -0.0230
% -0.0044 0.0287
% -0.0182 -0.0058
% -0.0526 -0.0182
% -0.1769 -0.0588
% -0.1551 0.0434
% -0.0611 0.0408
% -0.5304 -0.1729
% -0.0444 0.1746
% -0.1613 0.5720
%% part d
m = u2*s2*v2'; % calculate U*S*V' for 2 singular value
d = norm(m - A); % calculate norm of diff os U*S*V' and A
display(d); % finally print the norm
% output
% d =
%
% 3.0180

Add a comment
Know the answer?
Add Answer to:
Do the following using Matlab: Let A be a matrix where each row corresponds to an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT