How to find a linear approximation on loglog scale?

5 ビュー (過去 30 日間)
Nimrod Daniel
Nimrod Daniel 2014 年 1 月 17 日
コメント済み: Nimrod Daniel 2014 年 1 月 17 日
Hello,
I have two data vectors and a loglog plot of a frequency as a function of mass, and I want to do a linear approximation on the loglog scale.
mass=[8.55 3.08 3.24 1.23 0.418 0.155 0.035 0.122 0.133 2.23 1.69 0.89 0.61 0.437 8.5];
frequency= [2.49 2.97 3.14 3.93 5.61 5.42 7.65 12.3 12.3 5.85 3.95 3.46 6.35 7.62 3.56];
loglog(freq,mass,'.b');
I tried using the basic fitting tool, but I'm not getting a linear approx. on the loglog plot. Maybe polyfit could help here ? how do I do the linear approx. in the loglog scale case ?
Thanks :)

採用された回答

Mischa Kim
Mischa Kim 2014 年 1 月 17 日
Hello Daniel, you could log your data before doing the curve fit and take it from there.
  2 件のコメント
Mischa Kim
Mischa Kim 2014 年 1 月 17 日
freq= [2.49 2.97 3.14 3.93 5.61 5.42 7.65 12.3 12.3 5.85 3.95 3.46 6.35 7.62 3.56];
mass=[8.55 3.08 3.24 1.23 0.418 0.155 0.035 0.122 0.133 2.23 1.69 0.89 0.61 0.437 8.5];
loglog(freq,mass,'.b');
lfreq = log(freq);
lmass = log(mass);
p = polyfit(lfreq, lmass, 1);
x_fitlin = linspace(0,4,2);
y_fitlin = p(1)*x_fitlin + p(2);
x_fitlog = exp(x_fitlin);
y_fitlog = exp(y_fitlin);
hold on
plot(x_fitlog,y_fitlog,'r')
Is that what you are looking for? First, log the data, then do the curve fit. In this case a polynomial of degree 1 (linear approx.). Once you have the coefficients you need to un-do the log, that's where the exp comes into play.
Nimrod Daniel
Nimrod Daniel 2014 年 1 月 17 日
Indeed. Thanks !

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

その他の回答 (1 件)

Nimrod Daniel
Nimrod Daniel 2014 年 1 月 17 日
Assuming I want to show the linear approx. on the loglog graph:
and not on the log of the values, how should I do it ?

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by