How do I apply exponential and logarithmic curve fitting
조회 수: 121 (최근 30일)
이전 댓글 표시
Hi,
I have some scatterplots and I want to check the relationships between the variables which resemble exponential and logarithmic functions. I have tried to use the functions
nlinfit
fittype
fit
but so far not successfully (poor fitting or code not working at all).
How can I check the curves for the above scatters which seem to have the following functions:
y= a*exp(b*x)+c and y=log_a(x)+b
in matlab?
Thanks
Iro
댓글 수: 3
yeungor
2016년 9월 25일
Have you tried fitting an exponential of the inverse? If x = f(y), then y = f^-1(x) and you can use 'fit' and the 'exp' for an exponential fit.
채택된 답변
Star Strider
2014년 2월 22일
The nlinfit function requires that the first argument of the objective function is the parameter vector and the second the vector of independent variables. Using anonymous functions,
y = a*exp(b*x)+c
becomes
y = @(B,x) B(1).*exp(B(2).*x) + B(3); % B(1) = a, B(2) = b, B(3) = c
For the logarithmic fit, all logs to various bases are simply scaled by a constant. Consider:
a^y = b^x
Taking the log to base a (denoted by loga()) of both sides gives:
y = x*loga(b)
so the log to any base will work.
The anonymous function for your logarithmic regression is then:
y = @(B,x) log(x) + B; % B = b
or alternatively,
y = @(B,x) B(1).*log(x) + B(2);
Those should work with nlinfit.
댓글 수: 0
추가 답변 (1개)
Danilo NASCIMENTO
2014년 2월 19일
You can use cf = fit(x,y,'exp1'); where x and y are your set of points.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!