0
$\begingroup$

I tried to do a Lorentzian fit for a Spectroscopy data.I found that I have to actually give the precise value for this fit.[i do not like to call this as fit ,if that is the case]?

Am I missing something here The notebook , the data and a plot pic from Igor have been added

https://www.transferbigfiles.com/0844eafa-5317-420b-acd6-f9553e283b3e/n9xrkyLWyjM0RLlFGj7TTw2

I appreciate your comments and help, I also want to know is there any other function i can use it for plotting this

$\endgroup$
7
  • $\begingroup$ Did you check, for example, this Q&A? $\endgroup$
    – Karsten7
    Commented Nov 27, 2015 at 7:12
  • 3
    $\begingroup$ Creating a minimal working example for your problem might result in more responses than just a link to somewhere. $\endgroup$
    – Karsten7
    Commented Nov 27, 2015 at 7:16
  • $\begingroup$ By the way I do not know how to attach a notebook file and data, and the size of the file is very small. I want to know about this particular situation cause generally nonlinear fitting function in mathematica works just fine $\endgroup$
    – TM90
    Commented Nov 27, 2015 at 7:28
  • $\begingroup$ Could you explain in more detail what is the problem. In your notebook it looks like the NonLinearFit[] finds the local minima of the parameters when using default start values. $\endgroup$ Commented Nov 27, 2015 at 8:04
  • 3
    $\begingroup$ I'm voting to close this question as off-topic because it is highly localized and probably of no value to future visitors, especially once the provided link is no longer valid. $\endgroup$
    – Karsten7
    Commented Nov 27, 2015 at 8:31

1 Answer 1

2
$\begingroup$

You were very unclear about what your actual question is. But I'm trying to procrastinate so here's what I would do,

data = Get["http://pastebin.com/raw.php?i=FeEa2MU9"];
lorentzianModel = y0 - a/(b + (x - x0)^2);

I took your CSV file, which you generally can't ask people on this site to download, imported it, and used the command CopyToClipboard[data[[All,;;2]]] and then pasted the result into pastebin.com. That's the easiest way to share example data.

To get the nonlinear fit to work, you need decent guesses for the parameters, which I found by just plotting the model and varying the parameters.

fit = NonlinearModelFit[data, 
  lorentzianModel, {{y0, .03}, {a, 5 10^(-7)}, {b, 3 10^-5}, {x0, 
    10.25}}, x]

enter image description here

There is really no benefit to multiplying the frequency axis by 10^10 before fitting, you can just do that later. So check the results of the fit,

fit["ParameterConfidenceIntervalTable"]

enter image description here

and compare them to what you got from Igor,

enter image description here

and it looks good. Then plot the results,

Show[ListPlot[data, PlotRange -> All], 
 Plot[fit[x], {x, 10.0, 10.5}, PlotStyle -> Red]]

enter image description here

Let me reiterate though, that it is not clear what your question is.

$\endgroup$
14
  • $\begingroup$ First of all I am extremely sorry for not making my question very clear, sorry about the ignorance. Thank you so much Jason for clarifying things. I understand my mistake, because of the bad guesses; The code could not find the global minimum, it might have trapped into some minimum, when I computed. Thanks a lot $\endgroup$
    – TM90
    Commented Nov 27, 2015 at 9:48
  • $\begingroup$ No worries, it just seems from the notebook that you got it all worked out fine, so I didn't know where exactly you need help $\endgroup$
    – Jason B.
    Commented Nov 27, 2015 at 9:49
  • $\begingroup$ But now might be a good time to ask: what were you looking to improve from your code? I've cleaned it up a bit I think, but in general you had a decent fit to the data $\endgroup$
    – Jason B.
    Commented Nov 27, 2015 at 10:28
  • $\begingroup$ Essentially I have been trying to make a code in which mathematica automatically detect the guesses for the Lorenztian fit, I realized that it is the x0 which matters the most , So the code will be $k = Position[data[[All, 2]], Min[data[[All, 2]]]]$ and I have to map this location to put to the fit, by the way it is giving something like (1026). which is the location, How do I use as a parameter in the Nonlinearfit. What i meant to say is how do you remove thebracket of the index location $\endgroup$
    – TM90
    Commented Nov 27, 2015 at 10:43
  • $\begingroup$ Actually, I found that if I didn't put in reasonable guesses for the other parameters, it would have trouble then as well $\endgroup$
    – Jason B.
    Commented Nov 27, 2015 at 10:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.