This is a naive implementation of SVD with
- Diagonizing symmetric matrix by
$A^TA$ or$AA^T$ - Calculating
$U,S,V$
The basic ideas for diagonization of symmetric matrix are:
-
Use the iteration
$x_{n+1} = ||Ax_{n}||$ ,$x = x / ||x||$ to find x with respect to eigenvalue with largest absolute value. THIS WORKABLE AND STABLE ONLY FOR SYMMETRIC MATRIX -
Every iteration amplifies the components in different eigenvalues subspaces with amplitude of norm of respecting eigenvalues. Using
$Gram-smith$ normalization to eliminate projection on known eigenvector space. This has to be done onece every several iterations since even projection on previous eigenvectors with$10^{-16}$ precision error can be amplified only after several iterations and take dominance. -
For zeros vectors, we use
$B = A + I$ instead to iterate. The previous eigenvalue - eigenvetor pairs are not changed with just increase 1 in each eigenvalues, while for remaining zero egienvalues would be changed to 1. We only do so to obtain orthogonal basis for null space.
Given target matrix
(1)
(2)
Step (1) takes
Step (2) takes