# Error in nonlinearmodel fit for a function with Definite Integral and complex number

I am trying to fit a function and Here is the code which I am trying, Please find the data here dataset

    Data = Import["E:\\datat.asc"];
real = Data[[All, {1, 2}]];
imag = Data[[All, {1, 3}]];
w = 1.26*10^8;
k = 1.38*10^-23;

dynamicReal[T_?NumericQ, s_?NumericQ, d_?NumericQ, A_?NumericQ,t_?NumericQ] := A*(1 - (NIntegrate[(((1/(Sqrt[2*Pi]*s*H))*Exp[(-(Log[(H/d)])^2/(2*s^2))]))/((1 + (w^2*t^2*Exp[((2*H)/(k*T))]))), {H, 0, 6*10^-22}]))
dynamicImag[T_?NumericQ, s_?NumericQ, d_?NumericQ, A_?NumericQ,t_?NumericQ] := A (NIntegrate[(w*t*Exp[H/(k*T)] (((1/(Sqrt[2*Pi]*s*H))*Exp[(-(Log[(H/d)])^2/(2*s^2))])))/((1 + (w^2*t^2*Exp[((2*H)/(k*T))]))), {H, 0, 6*10^-22}])
fit = ResourceFunction["MultiNonlinearModelFit"][Rationalize[{real, imag}, 0], {dynamicReal[T, s, d, A, t],dynamicImag[T, s, d, A, t]}, Rationalize[{{t, 1.0*10^-12}, {s, 0.25}, {d, 8*10^-23}, {A, 1.0*10^-4}}, 0], {T}]
fit["ParameterTable"]

Show[ListPlot[{real, imag}], Plot[{fit[1, x], fit[2, x]}, {x, 0, Max[real[[All, 1]], imag[[All, 1]]]}, PlotRange -> All], PlotRange -> All


I am getting an error called integral and error estimates are 0 on all integration subregions. Try
increasing the value of the MinRecursion option. If value of integral
may be 0, specify a finite value for the AccuracyGoal option

• Your edit may have introduced an error in the definition of dynamicImag. Instead of the imaginary unit I in the numerator of the integrand, I think you need Exp[H/(k*x)] Commented Oct 3, 2020 at 7:42
• Have you tried getting regular plots of dynamicReal and dynamicImag with some reasonable values of s, d, A and t? It's always a good way to check that your fitting functions are behaving correctly. Commented Oct 3, 2020 at 9:06
• Please. What is the expression for $\tau\left(E,T\right)$ ? Commented Oct 3, 2020 at 11:19
• @Cesareo, sorry about that. I have edited the question. Commented Oct 3, 2020 at 14:43
• @SjoerdSmit I tried the regular plot of dynamicReal and dynamicImag function and I am getting reasonable plot, but while fitting I am getting an error "Catastrophic loss of precision in the global error estimate due to insufficient WorkingPrecision or divergent integral." Commented Oct 4, 2020 at 19:18

The ComplexExpand[ReIm @ ...] trick doesn't work here because it doesn't evaluate to a list. You will need to re-phrase your problem as two separate functions that return the real and imaginary part of your model. So it should look something like:

dynamicReal[x_?NumericQ, s_?NumericQ, d_?NumericQ, A_?NumericQ, t_?NumericQ] := NIntegrate[...];
dynamicImag[x_?NumericQ, s_?NumericQ, d_?NumericQ, A_?NumericQ, t_?NumericQ] := NIntegrate[...];


Then you call the fit as:

fit = ResourceFunction["MultiNonlinearModelFit"][
Rationalize[{real, imag}, 0],
{dynamicReal[x, s, d, A, t]], dynamicImag[x, s, d, A, t]]},
...
]


It shouldn't be to difficult to split the integrand in NIntegrate into real and imaginary parts like this.

• @Sjored Smit. Thanks a lot for the help. I have edited the code but still getting the same error. Commented Oct 3, 2020 at 7:17