Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

extract/lib/nllsqfit_fn.c

Go to the documentation of this file.
00001 /* === Doxygen Comment ======================================= */
00014 /* =========================================================== */
00015 
00016 #include <IFU_io.h>
00017 #include <IFU_math.h>
00018 
00019 /* === Doxygen Comment ======================================== */
00032 /* =========================================================== */
00033 
00034 long nllsqfit_lorentz(long *mode, long *npts, long *npar, long *ldfj, 
00035                       double par[], double f[], double fjac[], 
00036                       long *nstate, long *iuser, double x_n_sig[])
00037 {
00038   int n;
00039   double *x, *sig, norm, xx, x2, fac;
00040 
00041   x  = x_n_sig;           /* x   in the 1st half of x_n_sig */
00042   sig= x_n_sig + (*npts); /* sig in the 2nd half of x_n_sig */
00043 
00044   /* Sigma should not be null */
00045   if (par[2] == 0) {
00046     *mode = -1;
00047     return(UNKNOWN);
00048   }
00049 
00050   norm = par[2]*M_PI;
00051   for (n=0; n<*npts; n++) {
00052     xx  = (x[n]-par[1])/par[2];
00053     x2  = xx*xx;
00054     fac = 1./(1+x2)/norm/sig[n];
00055     /* Function */
00056     f[n] = par[0]*fac;
00057     if (*mode) {
00058       /* Derivatives */
00059       fjac[n]           = fac;                       /* df/dI */
00060       fjac[n+  (*npts)] =   2*xx/(1+x2)/par[2]*f[n]; /* df/dV */
00061       fjac[n+2*(*npts)] = (x2-1)/(1+x2)/par[2]*f[n]; /* df/dS */
00062     }
00063   }
00064 
00065   return(OK);
00066 }
00067 
00068 /* === Doxygen Comment ======================================== */
00081 /* =========================================================== */
00082 
00083 long nllsqfit_gaussian(long *mode, long *npts, long *npar, long *ldfj, 
00084                        double par[], double f[], double fjac[], 
00085                        long *nstate, long *iuser, double x_n_sig[])
00086 {
00087   int n;
00088   double *x, *sig, norm, xx, x2, expo;
00089 
00090   x  = x_n_sig;           /* x   in the 1st half of x_n_sig */
00091   sig= x_n_sig + (*npts); /* sig in the 2nd half of x_n_sig */
00092 
00093   /* Sigma should not be null */
00094   if (par[2] == 0) {
00095     *mode = -1;
00096     return(UNKNOWN);
00097   }
00098 
00099   norm = par[2]*M_SQRT2PI;
00100   for (n=0; n<*npts; n++) {
00101     xx   = (x[n]-par[1])/par[2];
00102     x2   = xx*xx;
00103     expo = exp(-x2/2.)/norm/sig[n];
00104     /* Function */
00105     f[n] = par[0]*expo;
00106     if (*mode) {
00107       /* Derivatives */
00108       fjac[n]           = expo;                /* df/dI */
00109       fjac[n+  (*npts)] = f[n]/par[2]*xx;      /* df/dV */
00110       fjac[n+2*(*npts)] = f[n]/par[2]*(x2-1.); /* df/dS */
00111     }
00112   }
00113 
00114   return(OK);
00115 }
00116 
00117 /* === Doxygen Comment ======================================== */
00129 /* =========================================================== */
00130 
00131 long nllsqfit_NNgaussian(long *mode, long *npts, long *npar, long *ldfj, 
00132                          double par[], double f[], double fjac[], 
00133                          long *nstate, long *iuser, double x_n_sig[])
00134 {
00135   int n;
00136   double *x, *sig, xx, x2, expo;
00137 
00138   x  = x_n_sig;           /* x   in the 1st half of x_n_sig */
00139   sig= x_n_sig + (*npts); /* sig in the 2nd half of x_n_sig */
00140 
00141   /* Sigma should not be null */
00142   if (par[2] == 0) {
00143     *mode = -1;
00144     return(UNKNOWN);
00145   }
00146 
00147   for (n=0; n<*npts; n++) {
00148     xx   = (x[n]-par[1])/par[2];
00149     x2   = xx*xx;
00150     expo = exp(-x2/2.)/sig[n];
00151     /* Function */
00152     f[n] = par[0]*expo;
00153     if (*mode) {
00154       /* Derivatives */
00155       fjac[n]           = expo;           /* df/dI */
00156       fjac[n+  (*npts)] = f[n]/par[2]*xx; /* df/dV */
00157       fjac[n+2*(*npts)] = f[n]/par[2]*x2; /* df/dS */
00158     }
00159   }
00160 
00161   return(OK);
00162 }
00163 
00164 /* === Doxygen Comment ======================================== */
00176 /* =========================================================== */
00177 
00178 long nllsqfit_quad(long *mode, long *npts, long *npar, long *ldfj, 
00179                    double par[], double f[], double fjac[], 
00180                    long *nstate, long *iuser, double x_n_sig[])
00181 {
00182   int n;
00183   double *x, *sig, xx, x2;
00184 
00185   x  = x_n_sig;           /* x   in the 1st half of x_n_sig */
00186   sig= x_n_sig + (*npts); /* sig in the 2nd half of x_n_sig */
00187 
00188   for (n=0; n<*npts; n++) {
00189     xx  = (x[n]-par[1]);
00190     x2  = xx*xx;
00191     /* Function */
00192     f[n] = (par[0]*x2 + par[2]) / sig[n];
00193     if (*mode) {
00194       /* Derivatives */
00195       fjac[n]           = x2/sig[n];           /* df/da */
00196       fjac[n+  (*npts)] = -2*par[0]*xx/sig[n]; /* df/db */
00197       fjac[n+2*(*npts)] = 1/sig[n];            /* df/dc */
00198     }
00199   }
00200 
00201   return(OK);
00202 }
00203 

Generated on Wed Oct 26 23:59:39 2005 for Snifs by doxygen 1.3.5