4 static double dmaxarg1,dmaxarg2;
5 #define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1) > (dmaxarg2) ?\
6 (dmaxarg1) : (dmaxarg2))
7 static int iminarg1,iminarg2;
8 #define IMIN(a,b) (iminarg1=(a),iminarg2=(b),(iminarg1) < (iminarg2) ?\
9 (iminarg1) : (iminarg2))
11 #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
15 void dsvdcmp(
double **a,
int m,
int n,
double w[],
double **
v)
17 double dpythag(
double a,
double b);
18 int flag,i,its,j,jj,k,l,nm;
19 double anorm,
c,
f,g,h,
s,scale,x,y,
z,*rv1;
28 for (k=i;k<=m;k++) scale += fabs(a[k][i]);
39 for (
s=0.0,k=i;k<=m;k++)
s += a[k][i]*a[k][j];
41 for (k=i;k<=m;k++) a[k][j] +=
f*a[k][i];
43 for (k=i;k<=m;k++) a[k][i] *= scale;
48 if (i <= m && i !=
n) {
49 for (k=l;k<=
n;k++) scale += fabs(a[i][k]);
59 for (k=l;k<=
n;k++) rv1[k]=a[i][k]/h;
61 for (
s=0.0,k=l;k<=
n;k++)
s += a[j][k]*a[i][k];
62 for (k=l;k<=
n;k++) a[j][k] +=
s*rv1[k];
64 for (k=l;k<=
n;k++) a[i][k] *= scale;
67 anorm=
DMAX(anorm,(fabs(
w[i])+fabs(rv1[i])));
72 for (j=l;j<=
n;j++)
v[j][i]=(a[i][j]/a[i][l])/g;
74 for (
s=0.0,k=l;k<=
n;k++)
s += a[i][k]*
v[k][j];
75 for (k=l;k<=
n;k++)
v[k][j] +=
s*
v[k][i];
78 for (j=l;j<=
n;j++)
v[i][j]=
v[j][i]=0.0;
84 for (i=
IMIN(m,
n);i>=1;i--) {
87 for (j=l;j<=
n;j++) a[i][j]=0.0;
91 for (
s=0.0,k=l;k<=m;k++)
s += a[k][i]*a[k][j];
93 for (k=i;k<=m;k++) a[k][j] +=
f*a[k][i];
95 for (j=i;j<=m;j++) a[j][i] *= g;
96 }
else for (j=i;j<=m;j++) a[j][i]=0.0;
100 for (its=1;its<=30;its++) {
104 if ((
double)(fabs(rv1[l])+anorm) == anorm) {
108 if ((
double)(fabs(
w[nm])+anorm) == anorm)
break;
116 if ((
double)(fabs(
f)+anorm) == anorm)
break;
135 for (j=1;j<=
n;j++)
v[j][k] = -
v[j][k];
139 if (its == 50) {fprintf(stderr,
"no convergence in 30 dsvdcmp iterations");}
145 f=((y-
z)*(y+
z)+(g-h)*(g+h))/(2.0*h*y);
147 f=((x-
z)*(x+
z)+h*((y/(
f+
SIGN(g,
f)))-h))/x;
149 for (j=l;j<=nm;j++) {
163 for (jj=1;jj<=
n;jj++) {
178 for (jj=1;jj<=m;jj++) {