help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] 1st attempt at fitting a Gaussian function with GSL.


From: David Eric Miller
Subject: [Help-gsl] 1st attempt at fitting a Gaussian function with GSL.
Date: Fri, 16 Dec 2005 18:28:27 -0600
User-agent: Opera M2/8.50 (Linux, build 1358)

Hello.

I need to fit a Gaussian function to an array of data points.

The example given in the gsl manual is a bit too advanced for
me to bootstrap (although I'm sure it will help after I get
started).

Any help is very much appreciated.


In psuedo code, I have something like the following:

// Input Parameters
int n = number of data points.
double Data[n]={whatever};
double DataErr[n]={whatever};
double FitParGuess[3]={whatever};

double GaussianFunction(&x, FitPar) {
  double xFactor = (x - FitPar[1]);
  double z = - 0.5 * xFactor * xFactor / FitPar[2];
  double GaussianValue =   FitPar[0] * exp(z);
  return GaussianValue;
}

double GaussianDerivative_X(x, FitPar) {
  /* Derivative of Gaussian /wrt x. */
  .
  .
  .
}

double GaussianDerivative_C(x, FitPar) {
  /* Derivative of Gaussian /wrt Constant. */
  .
  .
  .
}

double GaussianDerivative_C(x, FitPar) {
  /* Derivative of Gaussian /wrt Mean. */
  .
  .
  .
}

double GaussianDerivative_C(x, FitPar) {
  /* Derivative of Gaussian /wrt Sigma. */
  .
  .
  .
}

// Return Parameters
double FitPar[3]; // The Fit Parameters {constant, mean, sigma}
double FitParErr[3]; // The Error on the fit parameters.
double Chi2;



int FitGauss(Data, DataErr, FitParGuess,
             &n, GaussianFunction, GaussianDerivatives,
             FitPar, FitParErr, &Chi2){

  // Use gsl_multifit_nlin functions to solve.

  .
  .
  .

  return ;

}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]