0

I have two sets of data and I am wondering how to find a polyfit (so that I can get a linear line of best fit) when there are constant errors present in both x and y variables.

Import numpy as np
Import matplotlib as plt                 
data=np.loadtxt('Data/Resistors.csv',skiprows=2,delimiter=',')

print(data)

[[ 0.162032  2.      ]
 [ 0.254001  3.      ]
 [ 0.249856  4.      ]
 [ 0.420033  5.      ]
[ 0.364007  6.      ]]


#Define
I=data[0:,0]
diff_V=data[:,1]
#Error of each variable
err_I=0.03 #Constant error
err_diff_V=0.5 #Constant error

#Polyfitting
fit_diff_V,cov_diff_V=np.polyfit(I,diff_V,1,w=1/(#what should I enter here?),cov=True)

What should I enter in the weight argument so that my line of best fit can take into account the errors contributed by both I and diff_V ?

(my lecturer demonstrated the weighting thing with just one error which is for the independent variable)

Chern-Simons
  • 101
  • 5
  • 1
    Please don't post images, instead post your code – Roshin Raphel Oct 25 '20 at 10:20
  • 1
    Please also don't paste data as images. Please have a look at how to provide sample data in a [reproducible way](https://stackoverflow.com/questions/20109391). – Bill Huang Oct 25 '20 at 15:08
  • Hi, `np.polyfit` cannot handle errors in both variables. Check [ODR](https://docs.scipy.org/doc/scipy/reference/odr.html) instead. – mikuszefski Oct 26 '20 at 07:13

0 Answers0