0
$\begingroup$

I'm having an extremely hard time getting linearmodelFit, findFit, or nonlinearModelFit to give me an output that I can work with and I can't seem to find the problem.

My list is

j2={{0., 5.5*10^6}, {2000., 5.*10^6}, {3500., 7.5*10^6}, {5000., 1.25*10^7}, {6000., 7.*10^6}, {7000., 1.4*10^7}, {8000., 2.7*10^7}, {9000., 5.*10^7}, {9500., 1.*10^8}, {9600., 1.62*10^8}, {9800., 1.905*10^8}, {10001., 2.85*10^8}, {10200., 2.23*10^8}, {10400., 1.98*10^8}, {10500., 1.98*10^8}, {10600., 2.03*10^8}, {10700., 2.085*10^8}, {10800., 2.22*10^8}, {10900., 2.33*10^8}, {11000., 2.995*10^8}, {11100., 3.105*10^8}, {11200., 4.05*10^8}, {11250., 4.08*10^8}, {11300., 3.96*10^8}, {11340., 4.43*10^8}, {11400., 3.62*10^8}, {11500., 4.825*10^8}, {11600., 5.62*10^8}, {11650., 5.075*10^8}, {11700., 6.395*10^8}, {11750., 7.95*10^8}, {11800., 9.69*10^8}, {11850., 1.265*10^9}, {11900., 1.656*10^9}, {11910., 1.75*10^9}, {11920., 1.86*10^9}, {11930., 2.07*10^9}, {11940., 2.3*10^9}, {11950., 2.479*10^9}}

And my equations are

FindFit[j2, A exp (Bt), {A, B}, t]
FindFit[j2, A\(B+exp(Ct)), {A, B, C}, t]

Neither of them are working. I don't see what I'm doing wrong, please help.

$\endgroup$

closed as off-topic by AccidentalFourierTransform, Henrik Schumacher, C. E., m_goldberg, Chris K Oct 31 '18 at 14:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – AccidentalFourierTransform, Henrik Schumacher, C. E., m_goldberg, Chris K
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Use Exp[B t] etc, rather than exp(Bt) (note spacing) $\endgroup$ – mikado Oct 30 '18 at 23:14
  • 1
    $\begingroup$ And you might be better off using the log of the dependent variable. $\endgroup$ – JimB Oct 30 '18 at 23:50
  • $\begingroup$ Backslash ( \ ) is not a Mathematica operator, so what to mean by it in your 2nd FindFit expression? $\endgroup$ – m_goldberg Oct 31 '18 at 10:40
2
$\begingroup$

It is possible that a piecewise function must be used for data processing.I will show one example how to do it (In the source data, I deleted the first item.).

j2 = {{2000., 5.*10^6}, {3500., 7.5*10^6}, {5000., 1.25*10^7}, {6000.,
     7.*10^6}, {7000., 1.4*10^7}, {8000., 2.7*10^7}, {9000., 
    5.*10^7}, {9500., 1.*10^8}, {9600., 1.62*10^8}, {9800., 
    1.905*10^8}, {10001., 2.85*10^8}, {10200., 2.23*10^8}, {10400., 
    1.98*10^8}, {10500., 1.98*10^8}, {10600., 2.03*10^8}, {10700., 
    2.085*10^8}, {10800., 2.22*10^8}, {10900., 2.33*10^8}, {11000., 
    2.995*10^8}, {11100., 3.105*10^8}, {11200., 4.05*10^8}, {11250., 
    4.08*10^8}, {11300., 3.96*10^8}, {11340., 4.43*10^8}, {11400., 
    3.62*10^8}, {11500., 4.825*10^8}, {11600., 5.62*10^8}, {11650., 
    5.075*10^8}, {11700., 6.395*10^8}, {11750., 7.95*10^8}, {11800., 
    9.69*10^8}, {11850., 1.265*10^9}, {11900., 1.656*10^9}, {11910., 
    1.75*10^9}, {11920., 1.86*10^9}, {11930., 2.07*10^9}, {11940., 
    2.3*10^9}, {11950., 2.479*10^9}};
data2 = Table[{Log[j2[[i, 1]]], Log[j2[[i, 2]]]}, {i, 11, Length[j2]}];
data1 = Table[{Log[j2[[i, 1]]], Log[j2[[i, 2]]]}, {i, 1, 11}];
nlm1 = NonlinearModelFit[data1, 
  e*x^4 + d*x^3 + a*x^2 + b*x + c, {a, b, c, d, e}, x];
nlm2 = NonlinearModelFit[data2, 
  e*x^4 + d*x^3 + a*x^2 + b*x + c, {a, b, c, d, e}, x];
F[x_] := Piecewise[{{nlm1[x], 7.6 <= x <= 9.215}, {nlm2[x], 
9.215 < x <= 10}}]
Show[ListPlot[j2, PlotRange -> All, AxesOrigin -> {1000, -10^8}], 
 Plot[Exp[F[Log[t]]], {t, 2000, 14000}]]

fig1

$\endgroup$
1
$\begingroup$

I've had some bad experiences with Mathematicas NonlinearModelFit to exponentials, so I feel qualified to answer this question. It appears that you may be running into trouble because the values that you are trying to fit are rather large. Try re-scaling your data, either by a constant factor or taking the logarithm as JimB suggested to obtain the fit. Then the scaling factors can be removed when a fit is obtained.

yscale = 3*^8;
xscale = 5000;
y = Transpose[j2][[2]]/yscale;
x = Transpose[j2][[1]]/xscale;
data = Transpose[{x, y}];
nlm = NonlinearModelFit[data, A + Exp[B (t + C)], {A, B, C}, t]
p = Plot[nlm["Function"][t], {t, 0, 2.7}, 
  PlotRange -> {{0, 2.5}, {-1, 10}}];
Show[{p, ListPlot[j3]}]

Resulting in the following fit Exponential fit to re-scaled data

Unfortunately, when I attempted to re-scale the data, Mathematica threw some errors about numbers being too small. Hopefully you don't need a plot with your actual values!

I've also had success using excel to get a fit, then putting in those values for a starting point in Mathematica which could then find the fit.

$\endgroup$

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