フィルターのクリア

How to set a polyfit line to zero

13 ビュー (過去 30 日間)
sophp
sophp 2020 年 4 月 26 日
回答済み: Ameer Hamza 2020 年 4 月 26 日
How do I force this polyfit line through zero? I tried polyfitzero but it returns an error:
x = [0.000484659 0.000927045 0.001328826 0.001670395 0.002119719];
y = [0.00E+0 1.08E+04 2.06E+04 3.21E+04 4.19E+04];
yneg = [0 620.4663 357.383 320.5892 1121.352];
ypos = yneg;
xneg = [0 2.67524E-05 2.17661E-05 3.18628E-05 6.86184E-05];
xpos = xneg;
errorbar(x,y,yneg,ypos,xneg,xpos,'x')
xlabel('[H] (g/g)')
ylabel('1H signal intensity')
p = polyfit(x,y,1)
f = polyval(p,x);
hold on
plot(x,f,'r')

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 26 日
Try this. It fits a linear linear curve without the constant term so that the line passes through origin.
x = [0.000484659 0.000927045 0.001328826 0.001670395 0.002119719];
y = [0.00E+0 1.08E+04 2.06E+04 3.21E+04 4.19E+04];
yneg = [0 620.4663 357.383 320.5892 1121.352];
ypos = yneg;
xneg = [0 2.67524E-05 2.17661E-05 3.18628E-05 6.86184E-05];
xpos = xneg;
errorbar(x,y,yneg,ypos,xneg,xpos,'x')
xlabel('[H] (g/g)')
ylabel('1H signal intensity')
p = [x.'\y.' 0];
x_plot = linspace(0, max(x));
f = polyval(p,x_plot);
hold on
plot(x_plot,f,'r')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeology についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by