I am using Mathematica for some time now for evaluating experimental data for my practical physics course but I always had problems with fitting nonlinear functions to data. Currently I’d like to fit a gaussian function to my dataset. I tired several options including “FindFit” and “NonlinearModelFit” but the resulting function not even remotely resembles the curve of the original data. Sometimes the gaussian is centered around a very small, insignificant peak in my dataset but most frequently the height of the peak is way too small.
The attachment contains some data as an example. If plotted, the quite significant peak at the right end is what I am interested in.
For example I used the function FindFit with the following parameters:
The variable A obviously is used to scale the area under the curve. Even if I cut down all the data but the peak I want to fit the gaussian to, using
Take[data, {1700, 1990}]
I get values like
{\[Sigma] -> 1.74659, \[Mu] -> 2.29208, A -> 1628.23}
Which is obviously no good, considering the highest value in my data-list is 38635 and therefore bigger than A. (mu and sigma are also way off)
I have to stress, that to this point I have never learned how fitting to nonlinear data generally works. I taught myself how to work with Mathematica using the incredibly detailed and well designed documentation of Mathematica. It might be, that I misunderstand something at a very basic level.
I guess part of the problem is that your data are very well described by a single gaussian and therefore the fit may end up in different local minima. One way to steer which part of the data are well approximated by the model function is to set start values for the parameters to be fitted. I prefer to use NonlinearModelFit
I was not aware that I can set start values. This information is very helpful
How do the start values influence the approximated values by mathematica? I have about 30 of these datasets where I do not expect sigma to change much but mu varies a lot. The point is, I want my notebook to evaluate the data automatically and I have set up everything to this point in that way. I have a formula to predict where mu should be, but if the start value affects the outcome of mu I’d rather use a different way.