MATLAB: Exponential fit using Linear Regression

linear regressionMATLAB

I am trying to fit an exponential line in my graph. I can get a linear line, but I can't seem to figure out how to make it an exponential. clear T = (10:10:150); H = [7.741, 5.906, 4.762, 3.838, 3.019, 2.415, 1.544, 1.316, 1.199, 0.676, 0.537, 0.316, 0.201, 0.168, 0.123]; TH = polyfit(T, H, 1); plot(T, H,'*',T, line, '-');
I don't know where to go from here any help is appreciated.

Best Answer

Write down the model you want to use. DO IT! You can't solve this unless you understand & think about what you are doing. That requires you know the model.
First, let me plot the curve, so we can all see it.
plot(T,H)
So I'll assume, when you say an exponential model, that you mean the simple model:
H(T) = a*exp(b*T)
That model is consistent with your data if b is negative, since it approaches zero for large T, and gets large for small T.
Take the log of your model. The natural log, so use log.
log(H) = log(a) + b*T
Now, you have no idea what log(a) is, so you also have no idea what a is. a is just an unknown here. Who cares? Just call log(a) some other number.
log(H) = c + b*T
Can you fit that model? (Hint: Can you use polyfit?) What would this do for you?
bc = polyfit(T,log(H),1);
What are b and c here? Can you now recover the value of a, given that c=log(a)? Remember that is a natural log.
Finally, there is one issue here, in that you do screw around with the error structure of your model, implicitly assuming a lognormal noise structure. At some point in your modeling career, this will be something you might start thinking about. But for now, it is a somewhat minor issue.