updated to sort U in addition to S & V such that A = U*S*V' holds when sort=true

release/4.3a0
Chris Beall 2010-09-28 17:56:29 +00:00
parent 4455bd0c1a
commit ea92ad7be4
1 changed files with 8 additions and 0 deletions

View File

@ -267,14 +267,22 @@ void svdcmp(double **a, int m, int n, double w[], double **v, bool sort) {
for (int i1 = 1; i1 <= n; i1++) {
for (int i2 = i1+1; i2 <= n; i2++) {
if (w[i1] < w[i2]) {
// sort S
double temp = w[i1];
w[i1] = w[i2];
w[i2] = temp;
// sort V
for (int j = 1; j <= n; j++) {
double temp1 = v[j][i1];
v[j][i1] = v[j][i2];
v[j][i2] = temp1;
}
// sort U
for (int j = 1; j <= m; j++) {
double temp1 = a[j][i1];
a[j][i1] = a[j][i2];
a[j][i2] = temp1;
}
}
}
}