Logarithmic trendline equation of data

조회 수: 13 (최근 30일)
Cem Eren Aslan
Cem Eren Aslan 2024년 7월 31일
편집: David Goodmanson 2024년 8월 1일
Hello eveyone,
I try to get a trendline equation of data. This equation must be like "e^x". How can i do that. are there any tools?
Thanks
Cem
  댓글 수: 2
Sam Chak
Sam Chak 2024년 7월 31일
Yes, single input, single output, you can use the 'fit()' command from Curve Fitting Toolbox to achieve this.
The desired equation (fit model) can be selected from the library using the 'fittype()' command.
But is an exponential function, thus it does not exhibit a logarithmic trend.

댓글을 달려면 로그인하십시오.

채택된 답변

David Goodmanson
David Goodmanson 2024년 8월 1일
편집: David Goodmanson 2024년 8월 1일
Hello Cem,
As has been mentioned you can use the curve fitting toolbox for this job, but if you don't have it you can try a simple linear fit. If
y = b*e^(ax), then log(y) = log(b) + ax
and the linear fit is of log(y) vs. x. Here is a quick example. Too be somewhat realistic, to the exponential y = e^(ax) is added a nonzero baseline (which is pretty common), a function that is proportonal to 20x near the origin, and some noise. The curve fitting toolbox will do better, but this fit is better than I thought it would be.
Whether the fit is great or not, I think a linear fit to log(y) is always worth doing, just to see if the idea of fitting an exponential to the given data is in the ballpark in the first place.
x = 0:.01:12;
a = .3;
b = 6;
r = .3*randn(size(x));
r(r<-b) = 0;
% exponential with some added stuff
y = b/3 + 20*x./(1+x) + b*exp(a*x) + b*r;
logy = log(y);
p = polyfit(x,logy,1)
ylogfit = x*p(1)+p(2);
figure(1)
grid on
plot(x,logy,x,ylogfit)
figure(2)
grid on
plot(x,y,x,exp(ylogfit))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by