How do I apply exponential and logarithmic curve fitting

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 件のコメント

Star Strider
Star Strider 2014 年 2 月 19 日
What do you mean by ‘code not working at all’?
It’s not obvious to me what you mean here: y=log_a(x)+b. (I don’t understand ‘log_a(x)’.)
Iro
Iro 2014 年 2 月 20 日
編集済み: Iro 2014 年 2 月 20 日
I mean that I make some kind of mistake in the definition of the function when I use nlinfit so the code does not work.
With log_a(x) I mean the logarithm of x with base a.
yeungor
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
Star Strider 2014 年 2 月 22 日

1 投票

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.

その他の回答 (1 件)

Danilo NASCIMENTO
Danilo NASCIMENTO 2014 年 2 月 19 日

0 投票

You can use cf = fit(x,y,'exp1'); where x and y are your set of points.

1 件のコメント

Iro
Iro 2014 年 2 月 20 日
Hi, thanks for your answer. I have used this function for the exxponential scatter but it doesn't give me good fitting. Do you know how I can get into account the constant c in the above equation using fit with 'exp1' ?
Thanks

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLinear and Nonlinear Regression についてさらに検索

質問済み:

Iro
2014 年 2 月 19 日

コメント済み:

2016 年 9 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by