Re: Fitting Experimental Data

*To*: mathgroup at smc.vnet.net*Subject*: [mg116478] Re: Fitting Experimental Data*From*: Alexei Boulbitch <alexei.boulbitch at iee.lu>*Date*: Wed, 16 Feb 2011 06:44:30 -0500 (EST)

Dear Mathilde, I have several points concerning your question: 1. I am not quite sure, if I caught you right, but your description sounds as if you should model your data by two Gaussians, rather than one. At least like this I understood the words: "data looking like a plot with two round (more Gaussian) shape". If this is indeed the case you should take a model consisting of sum of two Gaussians. 2. It would be helpful, if you give an example of your data massive. You cannot attach a file, but you could include the data as a plain text say, below your question. Then we could play with it. 3. Do you have serious reasons to think that the data should be fitted by true Gaussians? For example, do you know that the prefactor MUST provide normalization? Otherwise you could try a more simple model: model = a*Exp[-b (x - m)^2] + c. This could help, since the calculation for Mathematica will be simplified. You anyway include the pre-factor a in your model, so the pre-factor 1/(Sqrt[2 \[Pi]] s) only seems to introduce an unnecessary complexity into the calculation. 4. In principle, I would try to avoid to drop experimental points. The fitting procedure does not require this. One alternative to fitting would be to use Manipulate and to find the values of the parameters manually. To illustrate this possibility evaluate the following and play with sliders: (* This produces an array named "tab" with two almost Gaussian peaks *) f[x_] = 3 (Exp[-2*(x - 1)^2] + Exp[-7*(x - 2)^2]); tab = Table[{x, f[x] + RandomReal[{-0.3, 0.3}]}, {x, 0, 3, 0.05}]; (* and this plots the double Gaussian on the background of the array *) Manipulate[ Show[{ ListPlot[tab, PlotStyle -> Red, PlotRange -> All], Plot[a1*Exp[-b1*(x - c1)^2] + a2*Exp[-b2*(x - c2)^2], {x, 0, 3}, PlotStyle -> Blue] }], {{a1, 3}, 1, 5}, {{b1, 2}, 1, 10}, {{c1, 1}, 0, 3}, {{a2, 2}, 1, 5}, {{b2, 7}, 1, 10}, {{c2, 2}, 0, 3} ] You can apply a hybrid approach, that is first find the function manually as it is illustrated above, and then take the obtained function as a first guess for the FindFit procedure thus, refining the parameters values. Alternatively within the Manipulate you can count the sum of squares of residuals, and stop varying parameters as soon as this sum is mimimum. 5. You can go for smoothing of your data instead of dropping. Check Help/MovingAverage. After smoothing your fitting may become easier. Have fun, Alexei I am in trouble in trying to do a Fit using Mathematica7. Here my problem: My instrument on which I am working is giving me data looking like a plot with two round (more Gaussian) shape but with some picks on the top of each, the figures would have shown it, but you told me that I cannot enclose any file. I am only interested in the 2 round shapes, . My goal is to do a fit of those them. First I am isolating those 2 parts (ie: Plotting them whithout the data between them.) But the problem is that the picks on the top of each round shape will disturber my fit so I have to remove them.So now I have removed the picks, I have just 2 kind of asymetrics Gaussians with a hall on the top of each. To describe it more properly, I would say I have the rising and falling edge of two differente asymetric Gaussian. Now I start to look for a first Fit corresponding to the first asymetric Gaussian. Here is my code: model= b+ a*(1/(s*\[Sqrt](2*Pi)))* Exp[-(x-m)^2/(2*s^2)]; fit=FindFit[dataleftlowband,model,{b,a,s,m}, x, MaxIterations->100] modelfit = Table[Evaluate[model/.fit],{x,1,Length[dataleftlowband]}]; tmodelfit = Transpose[{xdataleftlowband,modelfit}]; My big problem is that I removed some data in the middle of my curve and I want that according to the values kept, the fitting find out which should be the missing values, because I need to approximately trace the top of my Gaussian shape. I've tried a lot of stuff to find out how to solve that as, random points in the Gap... Is there a method like considering the first part as the rising edge and the second as the falling edge of a Gaussian? Is Mathematica able to solve that? I hope that my problem is clearly explained. It's not that easy without any pictures to show how my data look like. Tell me if you have any idea to find a solution. Thank you in advance FAVIER MathildeTel: + 33 (0)6 35 29 36 96fmath at hotmail.fr -- Alexei Boulbitch, Dr. habil. Senior Scientist Material Development IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 CONTERN Luxembourg Tel: +352 2454 2566 Fax: +352 2454 3566 Mobile: +49 (0) 151 52 40 66 44 e-mail: alexei.boulbitch at iee.lu www.iee.lu -- This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.