I have a set of 8 peaks, x- and y-coordinates in vxPeaks and vyPeaks, respectively.
2.10556 0.13497
2.25417 0.1951
2.40556 0.24147
2.54583 0.30253
2.69306 0.32074
2.83194 0.31069
2.96111 0.2639
3.09861 0.19809
When I try to fit a Guassian function through them, I receive FITITER_FAILED_MUTUAL_DEPEND errors
// Let's fill the start fitting parameters
vector vParams(4);
vParams[0] = 0; // y0
vParams[1] = 2.7; // xc
vParams[2] = 0.9; // w
vParams[3] = 0.3; // A
// Start fitting
NLFitSession FitSession;
if( !FitSession.SetFunction("Gauss")) {
out_str("invalid fit function");
exit(0);
}
if( !FitSession.SetData(vxPeaks, vyPeaks)) {
out_str("fail to set data");
return;
}
// Set the parameters to start values
if( !FitSession.ParamsInitValues()) {
out_str("fail to initialize parameters");
return;
}
if( 0 != FitSession.SetParamValues( vParams ) ) {
out_str("fail to set parameters");
return;
}
FitSession.SetParamFix(0,true); // Fix the offset to zero
FitSession.GetChiSqr();
// Now, we fit!
int nOutcome;
if( !FitSession.Fit(&nOutcome) ) {
printf("Fail to do fitting: %d\n", nOutcome);
continue;
}
vector vParamValues, vErrors;
FitSession.GetFitResultsParams(vParamValues, vErrors);
However, when I just put the values in a column and then fit using Analysis -> Fitting -> Nonlinear Curve Fit -> Open Dialog, and use the same parameters and the Guass function, it succeeds with no problem.
Why does this difference occur and how do I fit in my code?