MATLAB: Fitting an exponential curve to data and comparing it to excel

excelexponential fit

Hi,
I'm trying to fit an exponential curve to the following dataset: x = [3.9; 8.6; 13.3; 17.9; 22.6]; y = [100; 10; 1; 0.1; 0.01]; I fit an exp curve using: cf = fit(x,y,'exp1'); It gives me the following results: a = 675.8 and b = -0.4899. When I compare it to the equation obtained in Excel, a = 690.81 and b = -0.493. I think that Excel is giving the correct solution. But can anyone explain the difference in results?
Thanks.

Best Answer

Hi Alice
I just ran this same example using MATLAB and Excel. In both cases, the coefficients from the nonlinear regression agree with the ones that you provided.
I would argue that MATLAB's answer is more accurate. The coefficients that are output by Excel are generated from a regression model with an R^2 of 98.78. (The regression model is able to explain 98.78% of the variability in the data set). The MATLAB regression model has an R^2 which is (essentially) 1.00. The regression model produced by MATLAB explains almost 100% of the variabily.
You posed an example of what's known as nonlinear regression. Linear regression is solved using linear algebra techniques. Nonlinear regression is solved with optimization based techniques. As a result, the quality of the solution can vary depending on what starting conditions get provided to the optimization solvers.
One nice feature of Curve Fitting Toolbox is that the library of standard regression models includes code that automatically chooses good starting conditions for the Optim solvers.
I suspect that this explains the difference in the results.
There is another possibility: Some nonlinear regression problems can be transformed into linear regression models and then solved with linear algebra techniques (bypassing the whole starting condition issue). For example, I could linearize the following model with a log transform.
Y = a*exp(b*x)
This technique has its advantages, but it can lead to some problems. The Statistics Toolbox demo page has a great demo that discusses this topic in detail.
regards,
Richard