0
$\begingroup$

I'm having trouble fitting this transition temperature equation to my data. Physically speaking, the intensity should flatten out for T>Tc, which seems to be the biggest problem here. The equation I've chosen to fit (SHGfit) uses a generic polarization as a function of temperature P[T_,B_,Tc], and an additional contribution to the measured intensity, an arbitrary B*Exp[I*\[Phi]] phase shift. I keep getting the error that the NonlinearModelFit did not converge, but the fit looks very close to working, or at least converging.

Failed nonlinear fit

Modsq[z_] := ComplexExpand[Re[z]]^2 + ComplexExpand[Im[z]]^2; 
SHGfit[A_, P_, B_, \[Phi]_] := Modsq[A*P + B*Exp[I*\[Phi]]]
P[T_, B_, Tc_] := 1/(T - Tc)^B

data={{22, 8325.33}, {75, 6112.66}, {125, 4495.}, 
  {175, 2948.66}, {225, 1847.66}, {275, 798.33}, 
   {300, 504.}, {325, 357.}, {350, 279.66}, {375, 223.}, {395, 192.}}

g = NonlinearModelFit[data, {SHGfit[A, P[t, \[Gamma], Tc], B, \[Phi]], \[Gamma] < 0, Tc > 300}, 
    {{A, -0.7}, {\[Gamma], -0.8}, {\[Phi], 2.29}, {Tc, 379}, {B, -34.8}}, t, 
    WorkingPrecision -> 25]; 
Show[Plot[g[t], {t, 20, 500}, PlotRange -> All, PlotStyle -> {Red, Thickness[0.01]}, 
   AxesStyle -> {{Thick, Black}, {Thick, Black}}, 
   TicksStyle -> {{Large, Black}, {Large, Black}}, 
   AxesLabel -> {Style["Temperature", Bold, 16], 
     Style["\!\(\*SubscriptBox[\(I\), \(SHG\)]\)", Bold, 16]}, ImageSize -> Large], 
  ListPlot[data, PlotStyle -> {PointSize[0.02], Black}]]

Is there anything obvious that I'm doing wrong? I would really appreciate some advice on nonlinear fitting. Thanks!

EDIT: I realized that my data points were a bit sparse so here is a fuller data set:

{{30, 8782}, {40, 8674}, {50, 8313}, {60, 8016}, {70, 7577}, {80, 7368}, {90, 6930}, {100, 6447}, {110, 6111}, {120, 5673}, {130, 5321}, {140, 5019}, {150, 4680}, {160, 4311}, {170, 3985}, {180, 3593}, {190, 3290}, {200, 2983}, {210, 2640}, {220, 2408}, {230, 2059}, {240, 1837}, {250, 1526}, {260, 1198},  {270, 918}, {280, 638}, {290, 402}, {300, 258}, {310, 184}, {320, 140}, {330, 113}, {340, 98}, {350, 86}, {360, 75}, {370, 66}, {380, 62}, {390, 54}, {400, 51}}

And implementing a couple new ideas (thank you JimB and Ulrich Neumann) such as setting MaxIterations->2000 and Model->"NMinimize" yield the following converging fits, although they physically don't describe the temperature dependence, which should flatten out to a constant at higher temperatures. maxiterations2000 nminimize

From here, I guess it's a matter of choosing the correct physical constraints?

$\endgroup$
3
  • 1
    $\begingroup$ Yes, several obvious things. (1) you're trying to fit 6 parameters ($A$, $\gamma$, $\phi$, $Tc$, $B$, and the error variance) with just 11 data points. (2) The model is far too complex for the kind of data (rather than the amount of data) as N[g["CorrelationMatrix"] // MatrixForm, 5] contains correlation coefficients are are all nearly 1.0 in magnitude. Another indication of this is that the standard errors of all parameters are huge compared to the estimates resulting in nearly all of the P-values being very close to 1. $\endgroup$
    – JimB
    Commented Jun 20, 2019 at 18:52
  • $\begingroup$ You can get convergence by data=Rationalize[data,0] and adding in MaxIterations->2000 to NonlinearModelFit. Then the correlation matrix looks much better and the standard errors for the parameters are much, much smaller. $\endgroup$
    – JimB
    Commented Jun 20, 2019 at 19:03
  • $\begingroup$ @JimB thank you for those suggestions, I have implemented them in the new data set above. The standard errors are much more acceptable now. $\endgroup$
    – user66091
    Commented Jun 20, 2019 at 21:07

1 Answer 1

1
$\begingroup$

Try the option Method->"NMinimize (needs no starting values for the parameters!)

g = NonlinearModelFit[data, {SHGfit[A, P[t, \[Gamma], Tc], B, \[Phi]], \[Gamma] < 0,Tc > 300}, { A , \[Gamma] , \[Phi], Tc , B }, t, 
Method -> "NMinimize"];

Alternativly you could use option MaxIterations -> 5000 in your approach

g = NonlinearModelFit[data, {SHGfit[A, P[t, \[Gamma], Tc], B, \[Phi]], \[Gamma] < 0,Tc > 300}, {{A, -0.7}, {\[Gamma], -0.8}, {\[Phi], 2.29}, {Tc,379}, {B, -34.8}}, t , MaxIterations -> 5000];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.