Hello,
I've corrected your code a bit (attached). Also included is a plot
of the data and fitted model. The output I get from running the
program is below. Note that I rescaled the x axis by subtracting the
mean of all x values - this makes the problem better conditioned and
easier to converge. You can add back the mean later to get back to the
original scale of the problem. To solve the problem with the original
X values you'll probably need either a very accurate initial guess
vector, or an analytic Jacobian function.
====
$ ./nlfit > dat
summary from method 'lmsder'
number of iterations: 7
function evaluations: 80
Jacobian evaluations: 0
reason for stopping: small step size
initial |f(x)| = 6393.58
final |f(x)| = 2100.08
chisq/dof = 19092.3
Amp = 946.59642 +/- 65.37942
mu = -2.41481 +/- 0.01003
sigma = 0.12576 +/- 0.01003
Amp = 5620.88963 +/- 67.58526
mu = 0.13784 +/- 0.00163
sigma = 0.11744 +/- 0.00163
Amp = 2608.71157 +/- 65.71170
mu = 1.27723 +/- 0.00361
sigma = 0.12409 +/- 0.00361
status = success
====
On 03/21/2016 09:26 AM, Hinxx wrote:
Hi all,
I'm new to GSL and numerical methods so please bear with me. I'm
using GSL-2.1.
I'm trying to fit a 3-peak gaussian curve onto experiment data that I
have (800W5-95kv_ROI.txt).
I started from expfit.c and nlfit.c and modified the code to handle
gauss curve.
For my initial tests I also used code/data from test_gaussian.c. I've
played around with the test set and managed to get proper amplitude,
sigma and peak location(s), also when extending test set to hold
three peaks (copies of first) and code to handle three peaks.
When using the real data of some 240 points, I'm seeing weird
behavior. Solver bails out after 1st iteration and I get my initial
guessed parameters back, unchanged.
If I fiddle with the data set a bit to make all the points between
the peaks near zero I get better results, bat still good enough.
Maybe it is worth noting that I also have some sample Matlab code
that manages to find the fit on the presented data set. It is using
code from http://www2.imm.dtu.dk/projects/immoptibox/.
I'm attaching the modified GSL code and real data set if someone
might be able to help out.
Thanks in advance,
Hinko