Q:

Finding exponential model from data

I'm trying to find an exponential model from data for a homework problem.  There is an accompanying video explaining how to do the bigger problem but it omits any instructions on the step where the model is determined. Here is a screenshot of the video after the model is found:

I've attempted to follow the instructions in "The Student's Introduction to Mathematica" for using FindFit to determine such a model:

As you can see, the results don't match those in the video and there's some type of warning/error that I don't understand.  I also attempted to use NonlinearModelFit with similar results.
Any help is greatly appreciated.

A:

Exponents are always a headache for fitting. Fit the Log instead:
data = {{0, 100}, {.02, 81.87}, {.04, 67.03}, {0.06, 54.88}, {.08, 44.93}, {.1, 36.76}};
sol = FindFit[data /. {x_, y_} :> {x, Log@y}, la + t lb, {la, lb}, t];
{a, b} = Exp[{la, lb} /. sol];

(* {100.012, 0.0000451495} *)

A:

data = {{0., 100.}, {0.02, 81.87}, {0.04, 67.03}, {0.06, 54.88}, {0.08, 44.93}, {0.1, 36.76}};

model = a Exp[-k t];

fit = FindFit[data, model, {a, k}, t]

{a -> 100.004, k -> 10.0033}

fun = Function[{t}, Evaluate[model /. fit]]

Plot[fun[t], {t, 0, 0.3},
 Epilog -> {PointSize[0.02], Red, Point[data]},
 PlotRange -> All,
 PlotTheme -> "Detailed"]

fun[0.2]

13.525

TableForm[Map[{#, Round[fun @ #, 0.01]} &, Range[0, 1, 0.1]],
 TableHeadings -> {None, {"t", "Q"}},
 TableDirections -> Row]

A:

Check out the formula for capacitor discharge, it takes the form
chargeDecay=initialCharge Exp[- r/c t]
So
t = {0, 0.02, 0.04, 0.06, 0.08, .1}; 
q = {100, 81.87, 67.03, 54.88, 
 44.93, 36.76};
modelData = Transpose[{t, q}];
soln=FindFit[modelData, a Exp[-b x], {a, b}, x]
(*{a -> 100.004, b -> 10.0033}*)
Show[ListPlot[modelData, PlotStyle -> Red], 
Plot[a Exp[-b x] /. soln, {x, 0, 0.1}]]

You can also use the following function which also provides more information.
nlm = NonlinearModelFit[modelData, a Exp[-b x], {a, b}, x]
nlm["AdjustedRSquared"]
(*1*)
nlm["ParameterTable"]

