Exponential Regression

Stiganator

Platinum Member
Oct 14, 2001
2,492
3
81
I have a data set that can be fitted pretty well with a linear fit. However I would like to do an exponential fit to see if that would also cover the range I haven't yet sampled (it looks to be tapering towards the extremes so I'll have to widen the range)

If I take the natural log of the data and then fit a linear curve the exponential coefficients will be

linear fit of ln(X) vs Y is y=ax+b


exponential equivalent is y = e^a*e^x + e^b or y= e^ax+e^b

Is that right? I don't know why this is eluding me since it is pretty basic.

Any quick way to do this with Matlab? I know there is a polyfit function, but help didn't pop up anything on exponential fits.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Simple to do in MATLAB.

%input the data as x= and y=
%after data is loaded,
logy=log(y);
params=[1,1];%initial parameter estimates
[params,SSR]=fminunc(@(params) FitExponentials(x,y,logy),params);

[SSR,yhat]=FitExponential(x,y,logy)

function [SSR,yhat]=FitExponential(x,y,logy)
yhat=params(1)*exp(params(2)*x);
logyhat=log(yhat);
SSR=sum((logy-logyhat).^2);
end

edit: added a re-run of the function so you get the fitted values (yhat).
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
Another software program that's very simple to use and fit all sorts of curves is graphical analysis. It's sold by Vernier. They have a free demo (which, IIRC, is the complete version that expires after one month.) Google search for it... my wife just beeped her horn or I would.