Week 2 Pre-Lab
ucla | PHYSICS 4AL | 2023-01-16T16:28
Table of Contents
Definitions
Big Ideas
# assuming the data is given by numpy arrays "x,y"
# assuming matplotlib imported as "plt"
# assigning variables
res, cov = np.polyfit(x,y,1,cov=True)
# fitting data to liner function
plt.plot(x,res[0]*x+res[1],'r',label="fit")
# extracting fit coeff(s)
slope = res[0]
intercept = res[1]
# extracting covariance matrix elements
var_slope = cov[0][0]
var_intercept = cov[1][1]
covar = cov[0][1] # or cov[1][0]
Resources
📌
**SUMMARY
**