2
$\begingroup$

Good morning everyone, regarding my research "high resolution laser spectroscopy" I would like to fit the data obtained from the experiment with a Lorentzian curve using Mathematica, so as to calculate the value of FWHM (full width at half maximum). To do this I have started to transcribe the data into "data", as you can see in the picture and also I written the basic instruction to do this:

data = {{1.098`, -1.064`}, {1.1`, -1.064`}, {1.102`, -1.06`}, 
{1.104`, -1.06`}, {1.106`, -1.056`}, {1.108`, -1.056`}, {1.11`, 
-1.056`}, {1.112`, -1.056`}, {1.114`, -1.056`}, {1.116`, -1.056`}, 
{1.118`, -1.052`}, {1.12`, -1.052`}, {1.122`, -1.048`}, {1.124`, 
-1.048`}, {1.126`, -1.044`}, {1.128`, -1.044`}, {1.13`, -1.044`}, 
{1.132`, -1.044`}, {1.134`, -1.044`}, {1.136`, -1.044`}, {1.138`, 
-1.04`}, {1.14`, -1.04`}, {1.142`, -1.04`}, {1.144`, -1.04`},
{1.146`, -1.036`}, {1.148`, -1.036`}, {1.15`, -1.036`}, {1.152`, 
-1.032`}, {1.154`, -1.032`}, {1.156`, -1.032`}, {1.158`, -1.028`}, 
{1.16`, -1.028`}, {1.162`, -1.028`}, {1.164`, -1.028`}, {1.166`, 
-1.024`}, {1.168`, -1.024`}, {1.17`, -1.024`}, {1.172`, -1.024`}, 
{1.174`, -1.02`}, {1.176`, -1.02`}, {1.178`, -1.024`}, {1.18`, 
-1.02`}, {1.182`, -1.016`}, {1.184`, -1.016`}, {1.186`, -1.016`},
{1.188`, -1.012`}, {1.19`, -1.012`}, {1.192`, -1.012`}, {1.194`, 
-1.008`}, {1.196`, -1.008`}, {1.198`, -1.008`}, {1.2`, -1.008`}, 
{1.202`, -1.008`}, {1.204`, -1.004`}, {1.206`, -1.004`}, {1.208`, 
-1.004`}, {1.21`, -1}, {1.212`, -1}, {1.214`, -1}, {1.216`, -1}, 
{1.218`, -1}, {1.22`, -0.996`}, {1.222`, -1}, {1.224`, -0.996`}, 
{1.226`, -0.992`}, {1.228`, -0.996`}, {1.23`, -0.992`}, {1.232`, 
-0.992`}, {1.234`, -0.992`}, {1.236`, -0.992`}, {1.238`, -0.988`}, 
{1.24`, -0.988`}, {1.242`, -0.988`}, {1.244`, -0.984`}, {1.246`, 
-0.984`}, {1.248`, -0.984`}, {1.25`, -0.98`}, {1.252`, -0.98`}, 
{1.254`, -0.98`}, {1.256`, -0.98`}, {1.258`, -0.976`}, {1.26`, 
-0.976`}, {1.262`, -0.976`}, {1.264`, -0.976`}, {1.266`, -0.976`}, 
{1.268`, -0.972`}, {1.27`, -0.972`}, {1.272`, -0.972`}, {1.274`, 
-0.972`}, {1.276`, -0.968`}, {1.278`, -0.968`}, {1.28`, -0.964`}, 
{1.282`, -0.964`}, {1.284`, -0.964`}, {1.286`, -0.964`}, {1.288`, 
-0.96`}, {1.29`, -0.96`}, {1.292`, -0.96`}, {1.294`, -0.956`}, 
{1.296`, -0.952`}, {1.298`, -0.952`}, {1.3`, -0.952`}, {1.302`, 
-0.952`}, {1.304`, -0.952`}, {1.306`, -0.952`}, {1.308`, -0.948`}, 
{1.31`, -0.952`}, {1.312`, -0.948`}, {1.314`, -0.948`}, {1.316`, 
-0.948`}, {1.318`, -0.944`}, {1.32`, -0.948`}, {1.322`, -0.944`}, 
{1.324`, -0.944`}, {1.326`, -0.944`}, {1.328`, -0.94`}, {1.33`, 
-0.944`}, {1.332`, -0.944`}, {1.334`, -0.94`}, {1.336`, -0.94`}, 
{1.338`, -0.94`}, {1.34`, -0.936`}, {1.342`, -0.936`}, {1.344`, 
-0.936`}, {1.346`, -0.936`}, {1.348`, -0.936`}, {1.35`, -0.932`}, 
{1.352`, -0.928`}, {1.354`, -0.928`}, {1.356`, -0.928`}, {1.358`, 
-0.928`}, {1.36`, -0.928`}, {1.362`, -0.928`}, {1.364`, -0.928`}, 
{1.366`, -0.924`}, {1.368`, -0.924`}, {1.37`, -0.924`}, {1.372`, 
-0.92`}, {1.374`, -0.924`}, {1.376`, -0.92`}, {1.378`, -0.92`}, 
{1.38`, -0.92`}, {1.382`, -0.92`}, {1.384`, -0.92`}, {1.386`, 
-0.92`}, {1.388`, -0.916`}, {1.39`, -0.916`}, {1.392`, -0.916`}, 
{1.394`, -0.92`}, {1.396`, -0.916`}, {1.398`, -0.916`}, {1.4`, 
-0.916`}, {1.402`, -0.916`}, {1.404`, -0.912`}, {1.406`, -0.912`}, 
{1.408`, -0.912`}, {1.41`, -0.912`}, {1.412`, -0.912`}, {1.414`, 
-0.908`}, {1.416`, -0.912`}, {1.418`, -0.912`}, {1.42`, -0.908`}, 
{1.422`, -0.908`}, {1.424`, -0.908`}, {1.426`, -0.908`}, {1.428`, 
-0.908`}, {1.43`, -0.908`}, {1.432`, -0.908`}, {1.434`, -0.908`}, 
{1.436`, -0.908`}, {1.438`, -0.908`}, {1.44`, -0.904`}, {1.442`,
-0.908`}, {1.444`, -0.904`}, {1.446`, -0.904`}, {1.448`, -0.904`}, 
{1.45`, -0.9`}, {1.452`, -0.9`}, {1.454`, -0.904`}, {1.456`, -0.9`}, 
{1.458`, -0.9`}, {1.46`, -0.9`}, {1.462`, -0.9`}, {1.464`, -0.9`}, 
{1.466`, -0.9`}, {1.468`, -0.9`}, {1.47`, -0.904`}, {1.472`, -0.9`}, 
{1.474`, -0.9`}, {1.476`, -0.9`}, {1.478`, -0.9`}, {1.48`, -0.896`}, 
{1.482`, -0.9`}, {1.484`, -0.9`}, {1.486`, -0.896`}, {1.488`, -0.9`},
{1.49`, -0.9`}, {1.492`, -0.896`}, {1.494`, -0.9`}, {1.496`, -0.9`}, 
{1.498`, -0.9`}, {1.5`, -0.896`}, {1.502`, -0.9`}, {1.504`, -0.9`}, 
{1.506`, -0.9`}, {1.508`, -0.9`}, {1.51`, -0.9`}, {1.512`, -0.9`}, 
{1.514`, -0.904`}, {1.516`, -0.9`}, {1.518`, -0.9`}, {1.52`, -0.9`}, 
{1.522`, -0.9`}, {1.524`, -0.9`}, {1.526`, -0.9`}, {1.528`, -0.9`}, 
{1.53`, -0.904`}, {1.532`, -0.904`}, {1.534`, -0.904`}, {1.536`, 
-0.904`}, {1.538`, -0.904`}, {1.54`, -0.904`}, {1.542`, -0.904`}, 
{1.544`, -0.904`}, {1.546`, -0.904`}, {1.548`, -0.908`}, {1.55`, 
-0.904`}, {1.552`, -0.904`}, {1.554`, -0.908`}, {1.556`, -0.908`}, 
{1.558`, -0.904`}, {1.56`, -0.916`}, {1.562`, -0.92`}, {1.564`, 
-0.92`}, {1.566`, -0.92`}, {1.568`, -0.924`}, {1.57`, -0.92`}, 
{1.572`, -0.924`}, {1.574`, -0.92`}, {1.576`, -0.92`}, {1.578`, 
-0.928`}, {1.58`, -0.924`}, {1.582`, -0.924`}, {1.584`, -0.928`}, 
{1.586`, -0.928`}, {1.588`, -0.924`}, {1.59`, -0.928`}, {1.592`, 
-0.928`}, {1.594`, -0.928`}, {1.596`, -0.932`}, {1.598`, -0.932`}, 
{1.6`, -0.932`}, {1.602`, -0.932`}, {1.604`, -0.932`}, {1.606`, 
-0.932`}, {1.608`, -0.932`}, {1.61`, -0.936`}, {1.612`, -0.936`}, 
{1.614`, -0.94`}, {1.616`, -0.94`}, {1.618`, -0.94`}, {1.62`, 
-0.94`}, {1.622`, -0.94`}, {1.624`, -0.94`}, {1.626`, -0.944`}, 
{1.628`, -0.944`}, {1.63`, -0.944`}, {1.632`, -0.944`}, {1.634`, 
-0.944`}, {1.636`, -0.944`}, {1.638`, -0.948`}, {1.64`, -0.944`}, 
{1.642`, -0.948`}, {1.644`, -0.948`}, {1.646`, -0.948`}, {1.648`, 
-0.952`}, {1.65`, -0.952`}, {1.652`, -0.952`}, {1.654`, -0.952`}, 
{1.656`, -0.952`}, {1.658`, -0.956`}, {1.66`, -0.96`}, {1.662`, 
-0.96`}, {1.664`, -0.96`}, {1.666`, -0.96`}, {1.668`, -0.96`}, 
{1.67`, -0.964`}, {1.672`, -0.968`}, {1.674`, -0.964`}, {1.676`, 
-0.968`}, {1.678`, -0.968`}, {1.68`, -0.968`}, {1.682`, -0.968`}, 
{1.684`, -0.968`}, {1.686`, -0.972`}, {1.688`, -0.972`}, {1.69`, 
-0.972`}, {1.692`, -0.976`}, {1.694`, -0.976`}, {1.696`, -0.976`}, 
{1.698`, -0.976`}, {1.7`, -0.976`}, {1.702`, -0.976`}, {1.704`, 
-0.976`}, {1.706`, -0.976`}, {1.708`, -0.98`}, {1.71`, -0.98`}, 
{1.712`, -0.984`}, {1.714`, -0.984`}, {1.716`, -0.984`}, {1.718`, 
-0.984`}, {1.72`, -0.984`}, {1.722`, -0.988`}, {1.724`, -0.988`}, 
{1.726`, -0.992`}, {1.728`, -0.988`}, {1.73`, -0.992`}, {1.732`, 
-0.992`}, {1.734`, -0.996`}, {1.736`, -0.996`}, {1.738`, -0.996`}, 
{1.74`, -0.996`}, {1.742`, -0.996`}, {1.744`, -1}, {1.746`, -1}, 
{1.748`, -1}, {1.75`, -1}, {1.752`, -1.004`}, {1.754`, -1.004`}, 
{1.756`, -1.004`}, {1.758`, -1.004`}, {1.76`, -1.008`}, {1.762`, 
-1.008`}, {1.764`, -1.008`}, {1.766`, -1.008`}, {1.768`, -1.008`}, 
{1.77`, -1.012`}, {1.772`, -1.012`}, {1.774`, -1.012`}, {1.776`, 
-1.016`}, {1.778`, -1.016`}, {1.78`, -1.016`}, {1.782`, -1.016`}, 
{1.784`, -1.02`}, {1.786`, -1.02`}, {1.788`, -1.02`}, {1.79`, 
-1.024`}, {1.792`, -1.024`}, {1.794`, -1.024`}, {1.796`, -1.024`}, 
{1.798`, -1.028`}, {1.8`, -1.024`}, {1.802`, -1.028`}, {1.804`, 
-1.028`}, {1.806`, -1.032`}, {1.808`, -1.032`}, {1.81`, -1.032`}, 
{1.812`, -1.036`}, {1.814`, -1.036`}, {1.816`, -1.036`}, {1.818`, 
-1.04`}, {1.82`, -1.036`}, {1.822`, -1.04`}, {1.824`, -1.04`}, 
{1.826`, -1.04`}, {1.828`, -1.04`}, {1.83`, -1.044`}, {1.832`, 
-1.044`}, {1.834`, -1.044`}, {1.836`, -1.048`}, {1.838`, -1.048`}, 
{1.84`, -1.048`}, {1.842`, -1.048`}, {1.844`, -1.048`}, {1.846`, 
-1.052`}, {1.848`, -1.052`}, {1.85`, -1.052`}, {1.852`, -1.056`}, 
{1.854`, -1.056`}, {1.856`, -1.056`}, {1.858`, -1.06`}, {1.86`, 
-1.06`}
ListPlot[data, PlotTheme -> "Scientific"]
model = a/((b - t)^2 + d) + c;
result = 
 NonlinearModelFit[data, {model}, {a, b, c, d}, t, 
  Method -> "NMinimize"]
Show[ListPlot[data], 
 Plot[result[t], {t, 1.098`, 1.86`}, PlotRange -> Full]]
max = NMaximize[result[t], t][[1]] 
min = NMinimize[result[t], t][[1]] 
minmax = data[[All, 1]] // MinMax
fwhm = t /. 
    NSolve[{result[t] == (max + min)/2, 1.098` < t < 1.86`}, t] // 
   Differences // First
max1 = FindMaximum[result[t], t] // First
min1 = FindMinimum[{result[t], 1.098` < t < 1.86`}, t] // First
middle = max1 + min1/2
t1t2 = NSolve[{result[t] == (max1 + min1)/2, 1.098` < t < 1.86`}, t]
fwhm1 = t /. 
    NSolve[{result[t] == (max1 + min1)/2, 1.098` < t < 1.86`}, t] // 
   Differences // First

The problem is that the Lorentziana does not come out as it should:

enter image description here

Can anyone help me? My goal afterwards will be to use the obtained Lorentzian and make it the sum of three Lorentzians.

$\endgroup$
2
  • 4
    $\begingroup$ I tried your code by removing Method -> "NMinimize". That gives a nice fit. Did not execute the remainder of the code though. $\endgroup$
    – josh
    Jul 8, 2022 at 14:24
  • $\begingroup$ A similar problem is discussed here. $\endgroup$
    – Flow
    Jul 8, 2022 at 15:38

1 Answer 1

4
$\begingroup$
Clear["Global`*"]
    
plt = ListPlot[data, PlotTheme -> "Scientific"];
model = a/((b - t)^2 + d) + c;

(result = NonlinearModelFit[data, {model}, {a, b, c, d}, t]) // Normal

(* -1.23954 + 0.0569007/(0.168084 + (1.48017 - t)^2) *)

minmax = data[[All, 1]] // MinMax

(* {1.098, 1.86} *)

Show[
 plt,
 Plot[result[t],
  {t, minmax[[1]], minmax[[-1]]}]]

enter image description here

{min, max} = #[{result[t], minmax[[1]] < t < minmax[[-1]]}, t] & /@ 
  {MinValue, MaxValue}

(* {-1.0584, -1.57806} *)

The value of max is clearly wrong (reported Mathematica Tech Support CASE: 4951661). (EDIT: This has been resolved in version 13.2)

The correct value is

max = result[
   SolveValues[
     {result'[t] == 0, result''[t] < 0}, t][[1]]] //
  Quiet

(* -0.901011 *)

fwhm = t /. 
     Solve[{result[t] == (max + min)/2, minmax[[1]] < t < minmax[[-1]]}, t] //
     Differences // First // Quiet

(* 0.451257 *)
$\endgroup$
2
  • $\begingroup$ This is with 13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022) $\endgroup$
    – Bob Hanlon
    Jul 8, 2022 at 16:28
  • $\begingroup$ MinValue[{result[t], minmax[[1]] < t < minmax[[-1]]}, t] (*-1.0584*) and MaxValue[{result[t], minmax[[1]] < t < minmax[[-1]]}, t] (*-0.901011*) give correct result in v12.2 $\endgroup$ Jul 9, 2022 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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