Test multifit linear regression GSL function. More...
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <libgen.h>
#include <utils.h>
#include <regress.h>
Go to the source code of this file.
Defines | |
#define | _GNU_SOURCE |
GNU extensions. | |
Functions | |
void | show_usage (char *pgm) |
C prototypes. | |
int | main (int argc, char **argv) |
Main program. |
Test multifit linear regression GSL function.
Definition in file testregress.c.
#define _GNU_SOURCE |
GNU extensions.
Definition at line 59 of file testregress.c.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Main program.
[in] | argc | Number of command-line arguments. |
[in] | argv | Vector of command-line argument strings. |
Definition at line 100 of file testregress.c.
References alloc_error(), banner(), regress(), and show_usage().
00101 { 00109 int npts; 00110 int nterm; 00111 int pts; 00112 #if DEBUG >= 6 00113 int term; 00114 #endif 00115 00116 int i; 00117 int istat; 00118 00119 double *x = NULL; 00120 double *y = NULL; 00121 double *yreg = NULL; 00122 double *coef = NULL; 00123 double *yerr = NULL; 00124 double *vif = NULL; 00125 double cte; 00126 double chisq; 00127 double rsq; 00128 double autocor; 00129 00130 /* Print BEGIN banner */ 00131 (void) banner(basename(argv[0]), "1.0", "BEGIN"); 00132 00133 /* Get command-line arguments and set appropriate variables */ 00134 for (i=1; i<argc; i++) { 00135 if ( !strcmp(argv[i], "-h") ) { 00136 (void) show_usage(basename(argv[0])); 00137 (void) banner(basename(argv[0]), "OK", "END"); 00138 return 0; 00139 } 00140 else { 00141 (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]); 00142 (void) show_usage(basename(argv[0])); 00143 (void) banner(basename(argv[0]), "ABORT", "END"); 00144 (void) abort(); 00145 } 00146 } 00147 00148 npts = 6; 00149 nterm = 2; 00150 00151 x = (double *) calloc(npts*nterm, sizeof(double)); 00152 if (x == NULL) alloc_error(__FILE__, __LINE__); 00153 00154 x[0+0*npts] = 1.0; 00155 x[1+0*npts] = 2.0; 00156 x[2+0*npts] = 4.0; 00157 x[3+0*npts] = 8.0; 00158 x[4+0*npts] = 16.0; 00159 x[5+0*npts] = 32.0; 00160 00161 x[0+1*npts] = 0.0; 00162 x[1+1*npts] = 1.0; 00163 x[2+1*npts] = 2.0; 00164 x[3+1*npts] = 3.0; 00165 x[4+1*npts] = 4.0; 00166 x[5+1*npts] = 5.0; 00167 00168 y = (double *) calloc(npts, sizeof(double)); 00169 if (y == NULL) alloc_error(__FILE__, __LINE__); 00170 yreg = (double *) calloc(npts, sizeof(double)); 00171 if (yreg == NULL) alloc_error(__FILE__, __LINE__); 00172 yerr = (double *) calloc(npts, sizeof(double)); 00173 if (yerr == NULL) alloc_error(__FILE__, __LINE__); 00174 coef = (double *) calloc(nterm, sizeof(double)); 00175 if (coef == NULL) alloc_error(__FILE__, __LINE__); 00176 vif = (double *) calloc(nterm, sizeof(double)); 00177 if (vif == NULL) alloc_error(__FILE__, __LINE__); 00178 00179 for (pts=0; pts<npts; pts++) 00180 y[pts] = 5.0 + 3.0 * x[pts+0*npts] - 4.0 * x[pts+1*npts]; 00181 00182 istat = regress(coef, x, y, &cte, yreg, yerr, &chisq, &rsq, vif, &autocor, nterm, npts); 00183 00184 #if DEBUG >= 6 00185 for (term=0; term<nterm; term++) 00186 for (pts=0; pts<npts; pts++) 00187 (void) fprintf(stdout, "%s: term=%d pts=%d x=%lf\n", __FILE__, term, pts, x[pts+term*npts]); 00188 00189 for (term=0; term<nterm; term++) 00190 (void) fprintf(stdout, "%s: term=%d coef=%lf\n", __FILE__, term, coef[term]); 00191 00192 (void) fprintf(stdout, "%s: cte=%lf chisq=%lf\n", __FILE__, cte, chisq); 00193 00194 for (pts=0; pts<npts; pts++) 00195 (void) fprintf(stdout, "%s: pts=%d y=%lf yreg=%lf yerr=%lf\n", __FILE__, pts, y[pts], yreg[pts], yerr[pts]); 00196 #endif 00197 00198 (void) free(coef); 00199 (void) free(yreg); 00200 (void) free(yerr); 00201 (void) free(vif); 00202 (void) free(y); 00203 (void) free(x); 00204 00205 /* Print END banner */ 00206 (void) banner(basename(argv[0]), "OK", "END"); 00207 00208 return 0; 00209 }
void show_usage | ( | char * | pgm | ) |
C prototypes.
Local Subroutines.
Show usage for program command-line arguments.
[in] | pgm | Program name. |
Definition at line 215 of file testregress.c.