# Finding an exponential curve

I'm working on an exercise in Stewart's Single Variable Calculus: Early Transcendentals, 8th Edition, which asks you to find an exponential curve that fits some data. I tried using the FindFit function in Mathematica as follows

Data = {{0, 37}, {4, 47}, {8, 63}, {12, 78}, {16, 105}, {20,
130}, {24, 173}}

FindFit[Data, a*b^t, {a, b}, t]

(*  {a -> 36.7826, b -> 1.06633}  *)


As a result, f(t)=36.7826(1.06633)^t. But I'm not sure how to arrive at the book's solution, which is f(t)=36.89301(1.06614)^t.

And how would we use the TRACE feature or the equivalent Mathematica function to determine how long it takes for the bacteria count to double?

• Is there any hint how the book solution is derived? Aug 14 at 10:32
• Nope. Though the function produced by Mathematica does seem like a good fit when graphed together with the scatter plot of the data. Aug 14 at 10:38

The short answer is that if you fit the Log of your data using Fit, where the model is a linear function of t, then you get the result in the book. Concretely,

logData = Map[{#[],Log[#[]]}&, Data];
Exp[Fit[logData,{1,t},t]]


gives

E^(3.6080221696332897 + 0.06404214613230091*t)


which matches the result you quote since

Exp[3.6080221696332897]
(* 36.8930124875266 *)

Exp[0.06404214613230091]
(* 1.0661373313796498 *)


Comment. Fitting an $$a \cdot b^t$$ model is a common thing, and reducing to simple linear regression using $$\log(a\cdot b^t) = \log a + t \log b$$ is a common trick, see for example here.

The result differs slightly from nonlinear least squares fit using FindFit since taking the log changes the error function that is minimized.

• I'm having trouble trying to make this code work for an $a \cdot b^{-t}$ model; that is, I'm unable to arrive at the solution given in my book. Data = {{1,76},{4,53},{8,18},{11,9.4},{15,5.2},{22,3.6}}. Book's solution is $96.39785 \cdot (0.818656)^{t}$. Aug 14 at 14:55
• The model $a \cdot b^{-t}$ and the model $a \cdot B^t$ are equivalent, by identifying $b = 1/B$. I agree with you, for your new Data I also do not obtain 96.39785*0.818656^t. Looking at Show[{ListLogPlot[Data], LogPlot[96.39785*0.818656^t, {t,1,22}]}, PlotRange->All] one sees that the $t=22$ point comes with a big error. Perhaps the fit was made without the $t=22$ point? I therefore tried to fit Most[Data] and this gives something closer to 96.39785*0.818656^t but it does not match exactly. Aug 14 at 16:20

Without additional information it isn't possible to verify the book solution!

For second part of your question try

data={{0, 37}, {4, 47}, {8, 63}, {12, 78}, {16,105}, {20, 130}, {24,173}};
fit = NonlinearModelFit[data, a*b^t, {a, b}, t ]

Solve[fit[T] == 2 fit, T]
(*{{T -> 10.7922}}*)

• I used Solve[f[t]==2f,t] to get {{t->10.7928}}. But the output says Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. With your approach, I get {{InverseFunction[ NonLinearModelFit[{{0, 37}, {4, 47}, {8, 63}, {12, 78}, {16, 105}, {20, 130}, {24, 173}}, a b^t, {a, b}, t], 1, 1][ 2 NonLinearModelFit[{{0, 37}, {4, 47}, {8, 63}, {12, 78}, {16, 105}, {20, 130}, {24, 173}}, a b^t, {a, b}, t]] ->.. along with the same error message Aug 14 at 11:00
• @Karam That's only a warning message. Alternatively try NSolve[{fit[T] == 2 fit, 50 > T > 0}, T] Aug 14 at 11:05
• That doesn't work either. I get the warning messages: (1) InverseFunction: Inverse functions are being used. Values may be lost for multivalued inverses, (2) NSolve:: The solution set contains a full-dimensional component; use Reduce for complete solution information. Output={{}} Aug 14 at 11:21
• Restart your kernel and execute the code from my answer Aug 14 at 11:24
• Works now! Output is FittedModel[36.7826*1.06633^t] and {{T->10.7922}}. Thanks :) Aug 14 at 11:31