# Fitting an integral function given a set of data points

I have a set of measures of the resistivity of a given material at different thicknesses and I'm trying to fit them using the Fuchs-Sondheimer model. My code is:

data = {{8.1, 60.166323}, {8.5, 47.01784}, {14, 52.534961}, {15,
50.4681111501753}, {20, 39.0704975714401}, {30,
29.7737879177201}, {45, 22.4406}, {50, 15.2659673601299}, {54,
18.189933218482}, {73, 14.8377093467966}, {100,
15.249523361101}, {137, 15.249523361101}, {170,
10.7190970441753}, {202, 15.249523361101}, {230, 10.9744085456615}}

G[d_, l_, p_] := NIntegrate[(y^(-3) - y^(-5)) (1 - Exp[-yd/l])/(1 - pExp[-yd/l]), {y,0.01, 1000}];

nlm  = NonlinearModelFit[data, 1/(1 - (3 l/(2 d)) G [d, l, p]) , {{l, 200}, {p, 4}}, d, Method -> NMinimize]


However it returns me these errors:

NIntegrate::inumr: The integrand ((1-E^(-(yd/l))) (-(1/y^5)+1/y^3))/(1-pExp[-(yd/l)]) has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.01,1000}}.

NonLinearModelFit: the function value is not a real number at {l,p} = {200.,4.}


I think that the problem is in the way in which I defined the integral function G[d, l, p], because I had to fit a different set of data points with a different function of only one variable which I defined through the NIntegrate function and it gave me no error. Could anyone please help me?

I modified it in this way:

G[d_?NumericQ, l_?NumericQ, p_?NumericQ] := NIntegrate[(y^(-3) - y^(-5)) (1 - Exp[-y (d)/l])/(1 - (p) Exp[-y (d)/l]), {y, 0.01, Infinity}, WorkingPrecision -> 16, MaxRecursion -> 500];


and now the only error is:

NMinimize: the function value is not a number at {l,p} = {4.08538,1.34658}

• Looks similar: mathematica.stackexchange.com/questions/224594/… Commented Jun 24, 2020 at 16:56
• There are some issues with the multiplications. For example, yd is not the same as y d or y*p. Also maybe G should be restricted to take only explicitly numeric values. Commented Jun 24, 2020 at 18:27
• You need to get the NIntegrate part to work first. You have the range of integration going from 0.01 to $\infty$ but it looks like maybe only integrating to 0.1 is all that's necessary. Also, when plugging in the starting values one gets very small negative numbers for the function being fit with NonlinearModelFit (and the response variable is always positive).
– JimB
Commented Jun 24, 2020 at 19:28
• And how can I modify it? Commented Jun 25, 2020 at 10:52

I played a little with the integration limits and the offset for the fit.

I used the definitions below with integration limits {0.1,200}, fitting offset 10. Note that I am using much smaller precision and accuracy goals.

Experiments with that code might produce better results.

Clear[G];
G[d_?NumericQ, l_?NumericQ, p_?NumericQ] :=
NIntegrate[(y^(-3) -
y^(-5)) (1 - Exp[-y (d)/l])/(1 - (p) Exp[-y (d)/l]), {y, 0.1,
200}, WorkingPrecision -> MachinePrecision, MaxRecursion -> 500,
PrecisionGoal -> 2, AccuracyGoal -> 3];

nlm = NonlinearModelFit[data,
10 + 1/(1 - (3 l/(2 d)) G[d, l, p]), {{l, 200}, {p, 4}}, d,
Method -> NMinimize]