49 lines
1.5 KiB
Text
49 lines
1.5 KiB
Text
<math>A</math> is any m by n matrix, square or rectangular. Its rank is r. We will diagonalize this A, but not by <math>X^{−1}AX</math>.
|
||
The eigenvectors in <math>X</math> have three big problems: They are usually not orthogonal, there
|
||
are not always enough eigenvectors, and <math>Ax</math> = <math>λx</math> requires <math>A</math> to be a square matrix. The
|
||
singular vectors of <math>A</math> solve all those problems in a perfect way.
|
||
|
||
[https://math.mit.edu/classes/18.095/2016IAP/lec2/SVD_Notes.pdf The Singular Value Decomposition (SVD)]
|
||
|
||
According to the web page above, for any rectangular matrix <math>A</math>, we can decomposite it as <math>A=UΣV^T</math>
|
||
|
||
''' Task Description'''
|
||
|
||
Firstly, input two numbers "m" and "n".
|
||
|
||
Then, input a square/rectangular matrix <math>A^{m\times n}</math>.
|
||
|
||
Finally, output <math>U,Σ,V</math> with respect to <math>A</math>.
|
||
|
||
''' Example '''
|
||
|
||
<b>Sample Input</b>
|
||
<pre>
|
||
2 2
|
||
3 0
|
||
4 5
|
||
</pre>
|
||
|
||
From the input above we can know that <math>A</math> is a 2 by 2 matrix.
|
||
|
||
<b>Sample Output</b>
|
||
<pre>
|
||
0.31622776601683794 -0.9486832980505138
|
||
0.9486832980505138 0.31622776601683794
|
||
|
||
6.708203932499369 0
|
||
0 2.23606797749979
|
||
|
||
0.7071067811865475 -0.7071067811865475
|
||
0.7071067811865475 0.7071067811865475
|
||
</pre>
|
||
|
||
The output may vary depending your choice of the data types.
|
||
|
||
'''Remark'''
|
||
|
||
1. It’s encouraged to implement the algorithm by yourself while using libraries is still acceptible.
|
||
|
||
2. The algorithm should be applicable for general case(<math>m\times n</math>).
|
||
|
||
|