I am trying to fit the real and imaginary part of the Lorentzian, using MultiNonlinearModelfit function, I am having two independent variables in the problem (x and w, please see the code below), I am not sure how to go about the two independent variables, Here is my data Data

Data = Import["E:\\Shelender\\codes\\Mathematica\\Aelastic \
real = Data[[All, {1, 2}]];
imag = Data[[All, {1, 3}]];
w = Data[[All, {4}]];
Model = (A*E^(d/x)*tw)/(-I + E^(d/x)*tw);
fit = ResourceFunction["MultiNonlinearModelFit"][
Rationalize[{real, imag}, 0], ComplexExpand[ReIm@Model], 
Rationalize[{{A, 1.0*10^-4}, {t, 1.0*10^-12}, {d, 10}}, 0], {x}, 
PrecisionGoal -> 5, AccuracyGoal -> 10];

I think you want something like this?

real = Data[[All, {1, 4, 2}]];
imag = Data[[All, {1, 4, 3}]];
Model = (A*E^(d/x)*t*w)/(-I + E^(d/x)*t*w);
fit = ResourceFunction["MultiNonlinearModelFit"][
  Rationalize[{real, imag}, 0],
  ComplexExpand[ReIm @ Model],
  Rationalize[{{A, 1.0*10^-4}, {t, 1.0*10^-12}, {d, 10}}, 0],
  {x, w},
  WorkingPrecision -> 30,
  MaxIterations -> 1000

The w variable doesn't change a whole lot, so it doesn't seem to impact the fit all that much.


You can plot the fit for example like this:

  ListPlot[{real[[All, {1, 3}]], imag[[All, {1, 3}]]}],
  Quiet @ Plot[
    {fit[1, x, w], fit[2, x, w]}, {x, 0, 1.5597}, 
    PlotRange -> All
 {w, 1.255 10^8, 1.256*10^8}

As you can see, the value of w really doesn't influence the fit much.

| improve this answer | |
  • $\begingroup$ @Sjored Smit for plotting I defined two more variables as real1 = Data[[All, {1, 2}]]; imag1 = Data[[All, {1, 3}]]; and tried plotting using how[ListPlot[{real1, imag1}], Plot[{fit[1, x], fit[2, x]}, {x, 0, Max[real1[[All, 1]], imag1[[All, 1]]]}, PlotRange -> All], PlotRange -> All] but I think the problem is with fit[1,x] and fit[2,x] but could not figure out $\endgroup$ – Shelender Kumar Oct 2 at 16:24
  • $\begingroup$ @ShelenderKumar fit is a function of x and w. You can't plot it without giving it values for w as well, so you need to call is as fit[1, x, w] and fit[2, x, w]} (with appropriate values for x and w of course). $\endgroup$ – Sjoerd Smit Oct 2 at 18:37
  • $\begingroup$ @Sjored Smit My bad, but I think it is not a good idea to plot like this, because in reality w is not monotonic, but I tried this Plot[{fit[1, x, w], fit[2, x, w]}, {x, 0, 1.5597}, {w, 1.255 10^8,1.256*10^8}, PlotRange -> All] and it gave me error An option must be a rule or a list of rules $\endgroup$ – Shelender Kumar Oct 2 at 19:04
  • 1
    $\begingroup$ Plot is for x-y plots only. Try setting a constant value for w instead. I'll update with an example. $\endgroup$ – Sjoerd Smit Oct 2 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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