polynm.c

00001 /*
00002 
00003 $Id: polynm.c,v 1.1 2005/09/13 13:25:30 jim Exp $
00004 
00005 */
00006 #include <stdlib.h>
00007 #include "imcore.h"
00008 #include "floatmath.h"
00009 #include "util.h"
00010 
00011 /* least-squares fit of order m polynomial to n data points */
00012 
00013 void polynm (float xdat[], float xcor[], int n, float polycf[], int m, int ilim) {
00014   double a[25][25], b[25], temp;
00015   int i, j, k;
00016 
00017 /*   if(n < m)  bomboutx(1, "polynm: too few data points"); */
00018 /*   if(m > 25) bomboutx(1, "polynm: order of polynomial too large"); */
00019 
00020   /* clear arrays */
00021   for(i = 0; i < 25; i++) {
00022     b[i] = 0.0;
00023     for(j = 0; j < 25; j++) a[i][j] = 0.0;
00024   }
00025 
00026   /* cumulate sums */
00027   for(i = 0; i < n; i++) {
00028     for(k = 0; k < m; k++) {
00029       temp = 1.0;
00030       if(k+ilim != 0)temp = pow(xcor[i], (float) (k+ilim));
00031       b[k] += xdat[i]*temp;
00032 
00033       for(j = 0; j <= k; j++) {
00034         temp = 1.0;
00035         if(k+j+2*ilim != 0)temp = pow(xcor[i], (float) (k+j+2*ilim));
00036         a[j][k] += temp;
00037       }
00038     }
00039   }
00040 
00041   for(k = 1; k < m; k++) {
00042     for(j = 0; j < k; j++) a[k][j] = a[j][k];
00043   }
00044 
00045   /* solve linear equations */
00046   solve(a, b, m);
00047 
00048   for(i = 0; i < m; i++) polycf[i] = b[i];
00049 }
00050 
00051 /*
00052 
00053 $Log: polynm.c,v $
00054 Revision 1.1  2005/09/13 13:25:30  jim
00055 Initial entry after modifications to make cpl compliant
00056 
00057 
00058 */

Generated on 7 Feb 2011 for VIRCAM Pipeline by  doxygen 1.6.1