# Having Trouble Fitting Complicated Exponential Function with FindFit

I am working on high pressure shock experiments and am trying to figure out a the temperature of a sample under strong shocks. I have a measure value from 4 wavelengths of a pyrometer and am using a model to fit these points to a blackbody-like spectrum in order to back out a bulk true temperature, and a temperature of the hot spots/cracks that might also get viewed.

The 4 temperature data points, namely:

{{1.8*10^-6, 1266.38}, {2.3*10^-6, 1137.87}, {3.5*10^-6, 901.019}, {4.8*10^-6, 751.279}}


with the second value of each pair corresponding to a real temperature. I am fitting them using the following hot spot model:

hotspotmodel = c2/(lam Log[(1/((1 - alpha)/(Exp[c2/(lam TT)] - 1) + alpha/(Exp[c2/(lam THS)] - 1))) + 1])


I am trying to use FindFit in te following way, but cannot get an answer that makes realistic sense:

pointsfit = FindFit[points, {hotspotmodel, TT > 0}, {{alpha, 0.05}, {TT, 500}, {THS, 2000}}, lam]

""

function = Function[{lam}, Evaluate[hotspotmodel /. pointsfit]];
p1 = Plot[function[lam], {lam, 10^-7, 6 10^-6}, PlotStyle -> Thickness[.005]];
p2 = ListPlot[points2, AxesOrigin -> {0, 0},  PlotMarkers -> {Automatic, 12}];
Show[{p1, p2}, AxesOrigin -> {10^-7, 400}, PlotRange -> All,  AxesLabel -> {"\[Lambda (m)", "T (K)"}]


The problem is the function is not fitting properly, or returning sensible results. If I take away the constants, it returns a negative true temperature (TT), or a negative hot spot temperature (THS) and then has issues with trying to fit complex variables. My sense of the physical system says that true values should be within ~25% of those guesses. Any idea where I am going wrong?

Thanks.

• When I try to evaluate your code it complains about c2. Where is it defined? Also, 'points' and 'points2' are undefined. – WalkingRandomly Nov 28 '12 at 23:11
• could you edit the example so we can try it out please? – WalkingRandomly Nov 28 '12 at 23:29

pointsfit = FindFit[points,
{hotspotmodel a > 0, c2 > 0},
{{c2, .04}, {a, 0.008}, {TT, 500}, {THS, 1500}},
lam]

{c2 -> 0.0326106, a -> 0.00234026, TT -> 543.889, THS -> 2197.32}


and specifying constraints on the parameters prevents FindFit from looking at negative values and triggering an error for the presence of complex numbers. Even if the fit does not converge perfectly, you still get a feasible result.

Show[
ListPlot[points, PlotStyle -> {Red, PointSize[Large]}],
Plot[hotspotmodel /. pointsfit, {lam, 10^-7, 6 10^-6}, PlotStyle -> Black]
] Apparently it was an initial value issue. This happens often when fit parameters show up in the exponent.

To fix it you can either transform your dataset (e.g., try to fit {x,Log[y]}) or manually tune the parameter with a Manipulate, as I did.