Exponential fit using Linear Regression

13 次查看(过去 30 天)
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.

采纳的回答

John D'Errico
John D'Errico 2018-10-10
编辑:John D'Errico 2018-10-10
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.
  3 个评论
John D'Errico
John D'Errico 2018-10-11
编辑:John D'Errico 2018-10-11
What is y here? (Hint: H)
What is x here? T
TRY IT!!!!
bc = polyfit(T,log(H),1)
bc =
-0.0300522077208321 2.5345806082436
exp(bc(2))
ans =
12.6111407303375
Nathaniel Irvin
Nathaniel Irvin 2018-10-11
Thanks for replying again, sorry to keep bothering you but hopefully this is the last question I have. So now my code looks like this : 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]; c =12.611; k =-.03; G = log(c) + k.*T; TH = polyfit(T, G, 1); line = TH(1)*(G)+TH(2); plot(T, H,'*',T, line, '-'); I know there is something wrong with my "line =" line but I can't seem to put in the correct values to make it work.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by