/* minfit.c -- Minimum fit. Translated to 'C' from the * original Algol code in "Handbook for Automatic Computation, * vol. II, Linear Algebra", Springer-Verlag. * * (C) 2000, C. Bond. All rights reserved. * */ #include /* for allocation of vector 'e' */ #include /* for 'fabs' */ void minfit(int m,int n,int p,double eps,double tol, double **ab,double *q) { int i,j,k,l,l1,n1,np; double c,f,g,h,s,x,y,z; double *e; e = (double *)calloc(n,sizeof(double)); /* Householder's reduction to bidiagonal form. */ g = x = 0.0; np = n + p; for (i=0;i x) x = y; } /* end i */ /* accumulation of right-hand transformations */ for (i=n-1;i>=0;i--) { if (g != 0.0) { h = ab[i][i+1] * g; for (j=l;j=0;k--) { test_f_splitting: for (l=k;l>=0;l--) { if (fabs(e[l]) <= eps) goto test_f_convergence; if (fabs(q[l-1]) <= eps) goto cancellation; } /* end l */ /* cancellation of e[l] if l > 0 */ cancellation: c = 0.0; s = 1.0; l1 = l - 1; for (i=l;i<=k;i++) { f = s * e[i]; e[i] *= c; if (fabs(f) <= eps) goto test_f_convergence; g = q[i]; h = q[i] = sqrt(f*f + g*g); c = g / h; s = -f / h; for (j=n;j