How to do a rank-1 approximation?

61 vues (au cours des 30 derniers jours)
Jessica
Jessica le 20 Fév 2024
Commenté : Jessica le 21 Fév 2024
I am able to perform most all this question is asking. I am NEW to coding (let me preface with that), and as such, we have not done anything with parts of what this question is asking (gasp). Here is what I did thus far in MatLab and the Question. I also do not understand why the answers are displayed as fractions when I did not type "format rat" in ... off in the workspace, the answers are displayed rounded to 4 decimal points. But, I am unsure how to get them displayed as such in my main display. THANK YOU!
  • Use the svd() function in MATLAB to compute , the rank-1 approximation of A. Clearly state what is, rounded to 4 decimal places. Also, compute the root-mean square error (RMSE) between A and .

Réponse acceptée

Karl
Karl le 21 Fév 2024
You can check the display format that's set, and change if necessary:
% Show the current display format.
display(format)
DisplayFormatOptions with properties: NumericFormat: "short" LineSpacing: "loose"
% Set short fixed point format, with 4 digits after the decimal point.
format short
When you know the functions that you need to use, but want to check their details, the help available at the MATLAB prompt can be really useful:
help help
help - Help for functions in Command Window This MATLAB function displays the help text for the functionality specified by name, such as a function, method, class, toolbox, or variable. Syntax help name help Input Arguments name - Functionality name character vector | string scalar See also doc, lookfor, more, what, which, whos Introduced in MATLAB before R2006a Documentation for help doc help Other uses of help dsp/help parallel-computing/help simulink/help Folders named help toolstrip/help ppt/help xml/help xml_xpath/help dom/help re/help xml_transform/help
From the help for svd, the formula that you've used for A1 isn't quite right.
From the help for rmse, you need to specify the two arrays that you want to compare.
  3 commentaires
Torsten
Torsten le 21 Fév 2024
Modifié(e) : Torsten le 21 Fév 2024
A = [1 2 3; 3 3 4; 5 6 7]
A = 3×3
1 2 3 3 3 4 5 6 7
[U, S, V] = svd(A)
U = 3×3
-0.2904 0.9504 -0.1114 -0.4644 -0.2418 -0.8520 -0.8367 -0.1957 0.5115
S = 3×3
12.5318 0 0 0 0.9122 0 0 0 0.3499
V = 3×3
-0.4682 -0.8261 -0.3136 -0.5581 0.0012 0.8298 -0.6851 0.5635 -0.4616
A1 = S(1,1)*U(:,1)*V(:,1).'
A1 = 3×3
1.7039 2.0313 2.4935 2.7243 3.2477 3.9867 4.9087 5.8517 7.1832
A2 = A1 + S(2,2)*U(:,2)*V(:,2).'
A2 = 3×3
0.9878 2.0324 2.9820 2.9065 3.2474 3.8624 5.0561 5.8515 7.0826
A3 = A2 + S(3,3)*U(:,3)*V(:,3).'
A3 = 3×3
1.0000 2.0000 3.0000 3.0000 3.0000 4.0000 5.0000 6.0000 7.0000
norm(A-A1,'fro')/3
ans = 0.3257
rmse(A,A1,'All')
ans = 0.3257
norm(A-A2,'fro')/3
ans = 0.1166
rmse(A,A2,'All')
ans = 0.1166
norm(A-A3,'fro')/3
ans = 1.1028e-15
rmse(A,A3,'All')
ans = 1.1028e-15
Jessica
Jessica le 21 Fév 2024
Thank you so much! Upon looking up what 'fro' meant, that is what I was missing: Frobenius norm! I can totally do Euclidean norm by hand -- it's this coding that is brand new to me that has me all jumbled.
I appreciate you all for jumping in to my rescue!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Encryption / Cryptography dans Help Center et File Exchange

Tags

Produits


Version

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by