Last active
December 7, 2015 15:41
-
-
Save paulhayes/8888586 to your computer and use it in GitHub Desktop.
Linear least square solver using svd, written for numeric js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function svd_solve(A,b){ | |
var A_svd,r,s,ut,d,x; | |
A_svd = numeric.svd(A); | |
s = numeric.transpose( [ A_svd.S ] ); | |
r = 1; | |
while( r < numeric.dim(A)[1] & s[r] >= Math.max.apply( Math, numeric.dim(A) )*numeric.epsilon*s[0] ) r++; | |
d = numeric.dot( numeric.transpose( A_svd.U ), b); | |
x = numeric.dot(A_svd.V, numeric.div(d,s) ); | |
return x; | |
} |
Damn, you're right. That's annoying. So long ago now, I can't event remember my source.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
r, which seems to calculate the rank(A), is calculated but not used.