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?

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

2 Answers 2


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[{#[[1]],Log[#[[2]]]}&, Data];


E^(3.6080221696332897 + 0.06404214613230091*t)

which matches the result you quote since

(* 36.8930124875266` *)

(* 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.

  • $\begingroup$ 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}$. $\endgroup$
    – Karam
    Aug 14 at 14:55
  • 1
    $\begingroup$ 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. $\endgroup$
    – user293787
    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[0], T]
(*{{T -> 10.7922}}*)
  • $\begingroup$ I used Solve[f[t]==2f[0],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][0]] ->.. along with the same error message $\endgroup$
    – Karam
    Aug 14 at 11:00
  • $\begingroup$ @Karam That's only a warning message. Alternatively try NSolve[{fit[T] == 2 fit[0], 50 > T > 0}, T] $\endgroup$ Aug 14 at 11:05
  • $\begingroup$ 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={{}} $\endgroup$
    – Karam
    Aug 14 at 11:21
  • $\begingroup$ Restart your kernel and execute the code from my answer $\endgroup$ Aug 14 at 11:24
  • $\begingroup$ Works now! Output is FittedModel[36.7826*1.06633^t] and {{T->10.7922}}. Thanks :) $\endgroup$
    – Karam
    Aug 14 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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