Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Last active December 7, 2015 15:41
Show Gist options
  • Save paulhayes/8888586 to your computer and use it in GitHub Desktop.
Save paulhayes/8888586 to your computer and use it in GitHub Desktop.
Linear least square solver using svd, written for numeric js
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;
}
@sohale
Copy link

sohale commented Nov 2, 2015

r, which seems to calculate the rank(A), is calculated but not used.

@paulhayes
Copy link
Author

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