Input: 2-D list (m by n) with m >= n
Output: U,W V so that A = U*W*VT
- Translated from python code by TANG ZhiXiong
- GitHub: https://github.com/district10/svd.js
- Origin: http://stitchpanorama.sourceforge.net/Python/svd.py
- FYI: http://stackoverflow.com/questions/960060/singular-value-decomposition-svd-in-php
Usage:
// <script src="svd.js"></script>
var a = [
[22.,10., 2., 3., 7.],
[14., 7.,10., 0., 8.],
[-1.,13.,-1.,-11., 3.],
[-3.,-2.,13., -2., 4.],
[ 9., 8., 1., -2., 4.],
[ 9., 1.,-7., 5.,-1.],
[ 2.,-6., 6., 5., 1.],
[ 4., 5., 0., -2., 2.]
];
var ret = svd(a);
var u, w, v;
if (ret) {
u = ret[0];
w = ret[1];
v = ret[2];
_print(a);
_print(_mult(_mult(u,_diag(w)), _trans(v)));
}
"\n" to sep rows, ", " to sep entries, "#" to add comment