svbksb(float **u, float *w, float **v, int m, int n, float *b, float *x) /* solve Ax=b for a vector x, where A[0..m-1][0..n-1] is specified by u[0..m-1][0..n-1], w[0..n-1], and v[0..n-1][0..n-1] as returned by svdcmp. b[0..m-1] is the input right-hand side, and x[0..n-1] is the output solution vector. No input quantities are destroyed, so the routine can be called sequentially with different b's. */ { int jj,j,i; float s, *tmp; tmp=alloc1df(n); for (j=0; j (bt=fabs(b)) ? (ct=bt/at, at*sqrt(1.0+ct*ct)) : (bt ? (ct=at/bt, bt*sqrt(1.0+ct*ct)) : 0.0)) static float maxarg1,maxarg2; #define MAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2) ? (maxarg1) : (maxarg2)) #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) void svdcmp(float **a, int m, int n, float *w, float **v) /* given a matrix a[0..m-1][0..n-1], compute its SVD A=UWV^t. U replaces a on output. The diagonal matrix of singular values W is output as a vector w[0..n-1]. The matrix V (not V^t) is output as v[0..n-1][0..n-1], m must be greater or equal to n; if it is smaller, then a should be filled up to square with zero rows. */ { int flag,i,its,j,jj,k,l,nm; float c,f,h,s,x,y,z; float anorm=0.0, g=0.0, scale=0.0; float *rv1; printf("Singular value decomposition...\n"); if (m=0; i--) { if (i=0; i--) { l=i+1; g=w[i]; if (i=0; k--) { for (its=1; its<=30; its++) { flag=1; for (l=k; l>=0; l--) { nm=l-1; if ((float)(fabs(rv1[l])+anorm) == anorm) { flag=0; break; } if ((float)(fabs(w[nm])+anorm) == anorm) break; } if (flag) { c=0.0; s=1.0; for (i=l; i<=k; i++) { f=s*rv1[i]; rv1[i]=c*rv1[i]; if ((float)(fabs(f)+anorm) != anorm) break; g=w[i]; h=PYTHAG(f,g); w[i]=h; h=1.0/h; c=g*h; s=-f*h; for (j=0; j