Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- %matplotlib inline
- from __future__ import division
- from scipy.optimize import least_squares
- import scipy.odr as odr
- import matplotlib.pyplot as plt
- nPoints = 4
- AlphaArr = np.zeros(4)
- PubArr = np.zeros(4)
- AlphaErr = np.zeros(4)
- PubErr = np.zeros(4)
- AlphaArr = [popt1[1], popt2[1], popt3[1], popt4[1]]
- PubArr = [8.04, 8.63, 7.47, 6.40]
- AlphaErr = [FWHM1_1,FWHM1_2,FWHM1_3,FWHM1_4]
- PubErr = [0.1,0.1,0.1,0.1]
- xData = AlphaArr
- yData = PubArr
- xError = AlphaErr
- yError = PubErr
- def fitFunc(p, x):
- '''
- Fit function
- '''
- f = p[0] + p[1]*x
- return f
- def fitFuncDiff(p, x):
- '''
- Differential of fit function
- '''
- df = p[1]
- return df
- def calcChiSq(p, x, y, xerr, yerr):
- '''
- Error function for fit
- '''
- e = (y - fitFunc(p, x))/(np.sqrt(yerr**2 + fitFuncDiff(p, x)**2*xerr**2))
- return e
- fig = plt.figure(figsize = (8, 6))
- plt.errorbar(xdata, ydata, yerror, xerror, marker=".", linestyle = '')
- plt.show
- linearModel_1 = odr.Model(fitFunc)
- fitData_1 = odr.Data(xdata, ydata, xdata, ydata)
- odrObject_1 = odr.ODR(fitData_1, linearModel_1, beta0=[1.,1.])
- odrFit_1 = odrObject_1.run()
- odrFit_1.pprint()
- plt.plot(xdata, fitFunc(odrFit_1.beta, xdata))
- chi_array = calcChiSq(odrFit_1.beta, xdata, ydata, xerror, yerror)**2
- chisqndf = np.sum(chi_array)/np.sqrt(len(xdata)-2)
- print("ChiSq/NDF: {0:.3f}".format(chisqndf))
- #
- #
- #
- nPoints = 4
- BetaArr = np.zeros(4)
- PubArr = np.zeros(4)
- BetaErr = np.zeros(4)
- PubErr = np.zeros(4)
- BetaArr = [popt1[1], popt2[1], popt3[1], popt4[1]]
- PubArr = [8.04, 8.63, 7.47, 6.40]
- BetaErr = [FWHM1_1,FWHM1_2,FWHM1_3,FWHM1_4]
- PubErr = [0.1,0.1,0.1,0.1]
- xData = AlphaArr
- yData = PubArr
- xError = AlphaErr
- yError = PubErr
- def fitFunc(p, x):
- '''
- Fit function
- '''
- f = p[0] + p[1]*x
- return f
- def fitFuncDiff(p, x):
- '''
- Differential of fit function
- '''
- df = p[1]
- return df
- def calcChiSq(p, x, y, xerr, yerr):
- '''
- Error function for fit
- '''
- e = (y - fitFunc(p, x))/(np.sqrt(yerr**2 + fitFuncDiff(p, x)**2*xerr**2))
- return e
- fig = plt.figure(figsize = (8, 6))
- plt.errorbar(xdata, ydata, yerror, xerror, marker=".", linestyle = '')
- plt.show
- linearModel_1 = odr.Model(fitFunc)
- fitData_1 = odr.Data(xdata, ydata, xdata, ydata)
- odrObject_1 = odr.ODR(fitData_1, linearModel_1, beta0=[1.,1.])
- odrFit_1 = odrObject_1.run()
- odrFit_1.pprint()
- plt.plot(xdata, fitFunc(odrFit_1.beta, xdata))
- chi_array = calcChiSq(odrFit_1.beta, xdata, ydata, xerror, yerror)**2
- chisqndf = np.sum(chi_array)/np.sqrt(len(xdata)-2)
- print("ChiSq/NDF: {0:.3f}".format(chisqndf))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement