MATLAB: Does Curve Fitting Toolbox produce a good exponential fit graph with a wrong equation

Curve Fitting Toolboxexponential fitextracting equationwrong confidence boundswrong equation

Hello everyone,
I have created a graph for my data points using second order exponent (a * exp(bx) + c * exp(dx)). You can see it on the first picture. It looks good to me, there is no problem with the graph. However, I need to get the equation of this graph and that is where the problem comes out.
On the second picture you can see the constants for my equation with unusually large 95% confidence bounds. The graph shows these boundaries to be very small, almost insignificant. Also if I plug in some value of x in the equation and the graph, for example x=25, the results are very different:
Equation: -1.297 * exp(-2.486 * 25) + 1.325 * exp(-2.48 * 25) = 2.47 * 10^-20
Graph: at x = 25, y = 0.183 (shown on the first picture)
You can find my variables by clicking on this link and downloading the excel file.
https://drive.google.com/file/d/1YVOYX0Mno68Ab5pr53ytZEC5_GuEKC6H/view?usp=sharing
The value on the graph is correct. My question is what is the problem and how can I solve it?

Best Answer

NEVER use 4 or 5 digit approximations to coefficients. In fact, even if you display the coefficients in the command window using format long, STILL don't copy them out, because you won't get the exact coefficient!
I don't have your data, so I can't show results for your data. I'll just make up some garbage data.
x = rand(10,1);
y = rand(10,1);
F = fit(x,y,'exp1')
F =
General model Exp1:
poly(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
a = 0.6954 (0.1274, 1.263)
b = -0.7068 (-2.599, 1.186)
Now, NEVER just copy those coefficients.
Instead, use coeffvalues to extract them.
C = coeffvalues(F)
ans =
0.69543 -0.70679
That is not their true values though. Instead, the numbers are closer to this:
format long g
coeffvalues(F)
ans =
0.695433813207908 -0.706794760999295
So C has the final set of coefficients used for the model.
Again however, try not to use 0.695433813207908 as the number. Instead, the model is:
y = C(1)*exp(C(2)*x)
Use it that way.
Ok, now to what I think is the more important part of your question. Why are those bounds so wide?
LOOK AT YOUR CURVE!!!!!!
Your curve basically looks like a negative exponential, with a minor tweak at the beginning. So the fit with one exponential term in there was probably not terribly bad. But sums of exponentials are moderately difficult things to estimate. Why do I say that?
Think of it as arising from the fact that exp(x) looks a lot like exp(2*x), or exp(k*x) in general. So the nonlinear solver can have some problems.
Now, look at the coefficients that it found! Don't just build a model and then assume it is correct! In fact, the model you estimated was probably complete crap! (Sorry, but true.)
LOOK AT THE COEFFICIENTS.
b = -2.486, with bounds [-56,51]
d = -2.48 with bounds of [-55,50]
Both exponentials are almost identical in shape, with the exception that the coefficients out front had opposite signs. This is a sign that the fit gave you lower error, but it is probably meaningless. Those coefficients have no value at all. Were the noise in the data to change by a small amount, you would get different numbers.
Again, those hugely wide bounds on the coefficients suggests that the model is terribly poorly estimated. (I say poorly because you really have no clue as to the actual values of those coefficients, if that was indeed the true model for this process.) Your data is simply insufficient to estimate a two term exponential fit. The noise is way too high, and you have way too little data for this model.
This is not a problem of the curve fitting toolbox, or of MATLAB at all, but in your choice of model for this data.
Is there a better choice for the model? Perhaps. But I don't know why you chose the model you did. Perhaps you have some reason for thinking it should be a sum of two exponentials. Honestly, I doubt that is true. Most of the time, people use an exponential model, then decide that it the curve is basically a negative exponential, then a sum of two of them MUST be better. Sorry, but that does not follow.