Re: Fitting Experimental Data
- To: mathgroup at smc.vnet.net
- Subject: [mg116485] Re: Fitting Experimental Data
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Wed, 16 Feb 2011 06:45:45 -0500 (EST)
Hi Mathilde, You could save yourself a lot of trouble if you include the x values in the data set. You claim that the x-values are separated by 1, but is that really true? That's not the case in the figure you sent me. Anyway, I'll assume you have to arrays, one with the x values (let's call it xdata; you should do this even if they are spaced with 1; otherwise you can't cut holes in your data set) and one with the y-values (ydata). You can transform these into x,y data pairs using xydata = Transpose[{xdata,ydata}]; Of course, for this to work, the data points have to be in corresponding positions in each table. Now you remove the points corresponding to the spurious peaks from xydata. You could do this interactively, for instance, like below: xydata = Table[{x, 2 Sin[\[Pi] x/100] + RandomReal[]}, {x, 1, 400}]; (* generating an example data set; use your own data set here *) ymax = Max[xydata[[All, 2]]]; ymin = Min[xydata[[All, 2]]]; Manipulate[ If[x1b >= x1e, x1b = x1e - 1]; If[x2b >= x2e, x2b = x2e - 1]; If[x1e >= x2b, x1e = x2b - 1]; xydataCropped = Join[Take[xydata, {x1b, x1e}], Take[xydata, {x2b, x2e}]]; Row[ { ListLinePlot[xydata, PlotRange -> {ymin, ymax}, ImageSize -> 400, Epilog -> {Red, Line[{{x1b, ymin}, {x1b, ymax}}], {Dashed, Line[{{x1e, ymin}, {x1e, ymax}}]}, Green, {Dashed, Line[{{x2b, ymin}, {x2b, ymax}}]}, Line[{{x2e, ymin}, {x2e, ymax}}]}], ListLinePlot[xydataCropped, ImageSize -> 400] } ], {{x1b, 1}, 1, Length[xydata] - 3, 1}, {{x1e, Length[xydata]/4}, 2, Length[xydata] - 2, 1}, {{x2b, Length[xydata]/2}, 3, Length[xydata] - 1, 1}, {{x2e, Length[xydata] 3/4}, 4, Length[xydata], 1} ] As a result you now have a table named xydataCropped with only the x,y data set you want to fit. You can now proceed more or less as before: fit=FindFit[xydataCropped,model,{b,a,s,m}, x, MaxIterations->100] modelfit = Table[{x,Evaluate[model/.fit]},{x, xdata} (* note that we are using the original x data set here, and that we are creating x,y pairs*) This can now be ListPlotted or so, but given that you also have the continuous fit model why don't you use that? One final remark: Your data looks like an FFT because of the strong symmetry in it. In an FFT the second part of the output is just the first part mirrored. Are you sure that fitting both gaussians makes sense? In an FFT the second part of the output is just the first part mirrored; no extra information there. Hope this helps. Cheers -- Sjoerd From: mathilde Favier [mailto:fmath at hotmail.fr] Sent: Wednesday, 16 February 2011 09:06 To: sjoerd.c.devries at gmail.com Subject: [mg116485] RE: Fitting Experimental Data Hi Sjoerd, Thank you for you answer. I am only fitting the Y values as ''dataleftlowband''. The X values are points spaced by one. To reexplain my trouble, I am trying to Fit a curve which looks like an asymetric Gaussian only with the rising and falling edge because I had to remove the top of my plot which was full of picks. I want to reconstitute the top of my curve. I am manually removing the picks using a threshold. PS: I have 2 asymetric Gaussian given by my Data, the Goal is to Find a fit for them separatly. Are those explanation more clear? I am enclosing the problem with all the plots in a PDF file that way you will more see what I am talking about. Thank you Mathilde > Date: Tue, 15 Feb 2011 14:22:56 -0800 > Subject: Re: Fitting Experimental Data > From: sjoerd.c.devries at gmail.com > To: fmath at hotmail.fr > > Before answering your question I feel we need some more details: > > - what's in dataleftlowband? {x,y} pairs of data or just y? In the > latter case, is your dataset sorted and with datapoint spaced at a > distance of 1? Is this data set with your spurious peaks or did you > (manually) remove them? > - what's in xdataleftlowband? > > Cheers -- Sjoerd > > On Feb 15, 12:33 pm, mathilde Favier <fm... at hotmail.fr> wrote: > > 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 96fm... at hotmail.fr >