Effacer les filtres
Effacer les filtres

How to set a polyfit line to zero

13 vues (au cours des 30 derniers jours)
sophp
sophp le 26 Avr 2020
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')

Réponse acceptée

Ameer Hamza
Ameer Hamza le 26 Avr 2020
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')

Plus de réponses (0)

Catégories

En savoir plus sur Geology dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by