1
$\begingroup$

I have a problem while trying to make a nonlinear fit of the following data:

qn = NSolve[Tan[q] == 3*q/(3 + 1870715*q^2) && 0 < q <= 65, q]
Qn = {3.141593164052022`, 6.283185562410763`, 9.424778130923505`, 
      12.566370741974769`, 15.707963370041444`, 18.849556006615824`, 
      21.99114864805175`, 25.132741292526145`, 28.27433393902618`, 
      31.41592658694417`, 34.557519235893395`, 37.69911188561605`, 
      40.840704535933654`, 43.982297186718704`, 47.12388983787773`, 
      50.26548248934059`, 53.40707514105368`, 56.5486677929753`, 
      59.69026044507251`, 62.831853097318984`}
eq1 = 1 - Sum[6*alpha*(1 + alpha)/(9 + 9*alpha + 
 (alpha*Qn[[i]])^2)*Exp[-(Qn[[i]])^2*d*t/r^2], {i, 1, 10}] /. alpha -> 1870715 
 /. r -> 4*10^(-4)

NonlinearModelFit[{{0.17*60, 0.0301}, {0.5*60, 0.02408}, {0.83*60, 0.01806}, 
  {1*60, 0.02408}, {1.5*60, 0.07224}, {2*60, 0.16856}, {3*60, 0.13244}, 
  {5*60, 0.13244}, {8*60, 0.1505}, {9*60, 0.14448}, {10*60, 0.13244}}, eq1, d, t]

General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.

Throw::sysexc: Uncaught SystemException returned to top level. Can be caught with Catch[[Ellipsis], _SystemException]. >>

SystemException["MemoryAllocationFailure"]

Thank you!

$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Commented May 16, 2016 at 15:57
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this meta Q&A helpful $\endgroup$
    – Michael E2
    Commented May 16, 2016 at 15:57

1 Answer 1

2
$\begingroup$

You need to scale down the parameter d. One way is to modify the equation by dividing d by 10^12:

Qn = {3.141593164052022, 6.283185562410763, 9.424778130923505, 
   12.566370741974769, 15.707963370041444, 18.849556006615824, 
   21.99114864805175, 25.132741292526145, 28.27433393902618, 
   31.41592658694417, 34.557519235893395, 37.69911188561605, 
   40.840704535933654, 43.982297186718704, 47.12388983787773, 
   50.26548248934059, 53.40707514105368, 56.5486677929753, 
   59.69026044507251, 62.831853097318984};

eq1 = 1 - Sum[6*alpha*(1 + alpha)/(9 + 9*alpha + (alpha*Qn[[i]])^2)*
       Exp[-(Qn[[i]])^2*(d/10^12)*t/r^2], {i, 1, 10}] /. 
    alpha -> 1870715 /. r -> 4*10^(-4);

data = {{0.17*60, 0.0301}, {0.5*60, 0.02408}, {0.83*60, 0.01806},
 {1*60, 0.02408}, {1.5*60, 0.07224}, {2*60, 0.16856}, {3*60, 0.13244},
 {5*60, 0.13244}, {8*60, 0.1505}, {9*60, 0.14448}, {10*60, 0.13244}};

nlm = NonlinearModelFit[data, eq1, d, t] ;
nlm["BestFitParameters"]
(* {d -> 0.6517443755400871`} *)
nlm["ParameterErrors"]
(* {0.1906294119832146`} *)

That gets you a value of d being 6.517443755400871*10^11 on the original scale with the corresponding standard error of 1.906294119832146*10^11.

But the fit looks pretty horrible:

Show[ListPlot[data, Frame -> True, PlotRange -> All], Plot[nlm[t], {t, 0, 600}]]

Data and model fit

$\endgroup$
5
  • $\begingroup$ Thank you, Jim! It works better for other data sets. $\endgroup$
    – Dmitry
    Commented May 20, 2016 at 4:04
  • $\begingroup$ Now I have one more question. What kind of exponential term can be added to the current fitting in order to have decay for large values of t? $\endgroup$
    – Dmitry
    Commented May 20, 2016 at 4:07
  • $\begingroup$ I know nothing about the subject matter but it sure looks like the model is constructed with some theory in mind. Are you looking for a new theory or just want to predict the observations well? Will you be needing to compare estimated parameters among different datasets? In any event, I think that's a new and legitimate question. $\endgroup$
    – JimB
    Commented May 20, 2016 at 4:12
  • $\begingroup$ I need to predict observations well. My idea is that smth like 1- (1/a)*exp(-x)-(1/(1-a))*exp(x) should lead to competition of exponents. Here a is one more parameter for fitting. $\endgroup$
    – Dmitry
    Commented May 20, 2016 at 4:21
  • $\begingroup$ There is no need to compare parameters for different data sets. Parameter d is determined from each data set separately $\endgroup$
    – Dmitry
    Commented May 20, 2016 at 4:27

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.