how to plot linear regression ?

4 ビュー (過去 30 日間)
Rand Ardat
Rand Ardat 2021 年 2 月 8 日
コメント済み: Star Strider 2021 年 2 月 8 日
i want to do linear regression for : log(vp)=A-B/(T+273.15) !!
vp = [ 1 5 10 20 40 60 100 200 400 760]
T = [-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1 42.2 60.6 80.1]
y = log10(vp);
x = 1./(T+273.15);
% fit the polynomial
p = polyfit(x,y,1)
% p = -2035.33 8.75201
y=polyval(p,x)
plot(T,y,'or',T,vp,'b')
xlabel('T (C)')
ylabel('vp (mm Hg)')

採用された回答

Star Strider
Star Strider 2021 年 2 月 8 日
Try this:
figure
plot(T,vp,'or',T,10.^y,'b')
xlabel('T (C)')
ylabel('vp (mm Hg)')
The rest of the code is unchanged.
  2 件のコメント
Rand Ardat
Rand Ardat 2021 年 2 月 8 日
thank you!
Star Strider
Star Strider 2021 年 2 月 8 日
As always, my pleasure!

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

その他の回答 (1 件)

the cyclist
the cyclist 2021 年 2 月 8 日
編集済み: the cyclist 2021 年 2 月 8 日
You should plot
plot(T,10.^y,'or',T,vp,'b')
because you did the regression on log10(y), not y itself.
vp = [ 1 5 10 20 40 60 100 200 400 760]
T = [-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1 42.2 60.6 80.1]
y = log10(vp);
x = 1./(T+273.15);
% fit the polynomial
p = polyfit(x,y,1)
% p = -2035.33 8.75201
y=polyval(p,x)
plot(T,10.^y,'or',T,vp,'b')
xlabel('T (C)')
ylabel('vp (mm Hg)')
Also, it looks like you plotted the data as a line, and the fit as individual circles. I expect you want the opposite, which is more conventional.
  1 件のコメント
Rand Ardat
Rand Ardat 2021 年 2 月 8 日
thank you

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

カテゴリ

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