# Trouble using Integrate as the model in NonlinearModelFit

I'm trying to fit a set of heat capacity data to the Debye model.

This is the sample dataset that I'm using:

dataset = {{2.05899, 0.0966062}, {2.06815, 0.0963254}, {2.11413,
0.0978416}, {2.16795, 0.0991946}, {2.22744, 0.100566}, {2.29526,
0.102113}, {2.37157, 0.103468}, {2.4522, 0.104557}, {2.5393,
0.106795}, {2.63797, 0.107489}, {2.75074, 0.110521}, {2.86724,
0.113042}, {2.98851, 0.114997}, {3.10926, 0.119145}, {3.23705,
0.12385}, {3.37318, 0.128375}, {3.51821, 0.134831}, {3.66603,
0.142051}, {3.82298, 0.151682}, {3.99139, 0.162452}, {4.16682,
0.175691}, {4.34705, 0.197153}, {4.53399, 0.216079}, {4.73028,
0.245886}, {4.93872, 0.276781}, {5.15496, 0.324267}};
R = 8.314;
\$Assumptions = \[CapitalTheta]D > 0 && nD > 0;


I then make a function for the Debye model, as shown below. I think the issue is the integration limits.

CvD[Tt_, \[CapitalTheta]Dt_, nDt_] :=
9 R nDt (Tt/\[CapitalTheta]Dt)^3*
Integrate[(
Exp[x]*x^4)/(Exp[x] - 1)^2, {x, 0, \[CapitalTheta]Dt/Tt}];


Here is where I set my starting parameters and attempt to call NonlinearModelFit.

coeffs = {\[CapitalTheta]D, nD};
startingpoints = {127, .9};
mixedCoeffs = {coeffs, startingpoints} // Transpose;

CpFit = NonlinearModelFit[dataset, {CvD[T, \[CapitalTheta]D, nD]},
coeffs, T]


I'm not sure what the issue could be unless this approach won't work. Any tips?

You did not mention that you get error messages like:

Now try:

{1/ΘD^374.826 nD T^3 (-((4 π^4)/15) +
1/((-1 + E^(ΘD/
T)) T^4) (-E^((ΘD/T)) ΘD^4 -
4 T ΘD^3 Log[1 - E^(ΘD/T)] +
4 E^(ΘD/T)
T ΘD^3 Log[1 - E^(ΘD/T)] +
12 (-1 + E^(ΘD/
T)) T^2 ΘD^2 PolyLog[2, E^(ΘD/
T)] - 24 (-1 + E^(ΘD/
T)) T^3 ΘD PolyLog[3, E^(ΘD/
T)] - 24 T^4 PolyLog[4, E^(ΘD/T)] +
24 E^(ΘD/T)
T^4 PolyLog[4, E^(ΘD/
T)]))} /. {ΘD -> 1, nD -> 1, T -> 8}

{24.9225 + 6.18925*10^-11 I}


This results in a complex number. I think this is due to numerical errors. Therefore, the fix is to wrap "CvD" in "Re" like:

CvD[Tt_, \[CapitalTheta]Dt_, nDt_] :=
Re[9 R nDt (Tt/\[CapitalTheta]Dt)^3*
Integrate[(Exp[x]*x^4)/(Exp[x] - 1)^2, {x,
0, \[CapitalTheta]Dt/Tt}]];


Now we get:

CpFit = NonlinearModelFit[dataset, {CvD[T, \[CapitalTheta]D, nD]},
coeffs, T]
`

although with a warning.