Skip to main content
edited title
Link
NLambert
  • 331
  • 3
  • 8

FindFit works, NolinearModelFitNonlinearModelFit doesn't

Source Link
NLambert
  • 331
  • 3
  • 8

FindFit works, NolinearModelFit doesn't

I have a problem using NonlinearModelFit vs FindFit. Here is my code.

vsGdata={{405, 1252.43},{404.022, 1593.51},{401.078,1027.},{396.132,1395.1},{389.123,1432.3},{379.959,1680.32},{368.512,1953.14},{354.609,2294.16},{338.013,2870.8},{318.399,4929.35},{295.312,65586.6}} h = 6.62*10^-34; c = 3*10^8; e = 1.6*10^-19; k = 1.38*10^-23; PlanckPhotonDensity2 = a (2 e^3 10^-12 En^2)/(h^2 c^2) 1/(Exp[( 10^-6 e En)/(k T1)] - 1) + b (2 e^3 10^-12 En^2)/(h^2 c^2) 1/(Exp[( 10^-6 e En)/(k T2)] - 1); func2[T1_?NumberQ, a_?NumberQ, T2_?NumberQ, b_?NumberQ, Enl_?NumberQ] := NIntegrate[PlanckPhotonDensity2, {En, Enl, \[Infinity]}] fit = FindFit[vsGdata, func2[T1, a, T2, b, Enl], {{T1, 0.6}, {a, 1.3*10^18}, {T2, 0.06}, {b, 1.3*10^42}}, Enl] nlm = NonlinearModelFit[vsGdata, func2[T1, a, T2, b, Enl], {{T1, 0.6}, {a, 1.3*10^18}, {T2, 0.06}, {b, 1.3*10^42}}, Enl] 

Find fit returns

{T1 -> 0.643718, a -> 7.13416*10^17, T2 -> 0.0631721, b -> 2.04144*10^41} 

which is a good fit.

NonlinearModelFit returns

FittedModel[func2[0.643718, 7.13416*10^17, 0.0631721, 2.04144*10^41]] 

and then nlm["ParameterTable"] returns repeated

integrand ... has evaluated to non-numerical values for all sampling points in the region with boundaries ... 

messages, and then

Missing[] 

Why is there this difference between FindFit and NonlinearModelFit here, and is there a way to fix it? I'd really like to know the error on the fit...