Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do the following using Matlab: Let A be a matrix where each row corresponds to a

ID: 3831817 • Letter: D

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 = [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.)

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

matriar

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote