Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %matplotlib inline
- import numpy as np
- import math
- import matplotlib.pyplot as pl
- #1ST PART: Argon collected current vs accelerating voltage - peaks
- #X = [1,2,3,4,5,6]
- #Y = [20.7, 30.2, 40.7, 52.1, 63.6, 76.1]
- #pl.plot(X,Y,'o', label = 'Accelerating Voltage at each peak number')
- #pl.xlabel('Peak Number')
- #pl.ylabel('Accelerating Voltage')
- #pl.show()
- # number of parameters for line fit (2)
- npar = 2
- # vector with data (Y); std of measurement error is sigma =.1
- sigma = 0.1
- # here is data to fit
- Y = np.array([20.7, 30.2, 40.7, 52.1, 63.6, 76.1])
- Yerror = 1
- # here are X positions of data
- X = np.array([1,2,3,4,5,6]);
- # number of data points
- nobs = len(X)
- # create M – ones in first column, X in second column
- M = np.column_stack( (np.ones(nobs),X) )
- # solve
- MTM = np.dot(M.transpose(),M)
- MTMINV = np.linalg.inv(MTM)
- MTY = np.dot(M.transpose(),Y)
- P = np.dot(MTMINV,MTY) # SOLUTION
- C = MTMINV * sigma**2 # COVARIANCE MATRIX
- # compute RMS and print it
- Residuals = Y - np.dot(M,P)
- ChiSq = np.dot(Residuals.transpose(),Residuals)
- RMS = math.sqrt(ChiSq/nobs)
- #print('RMS = %f'%(RMS))
- # plot the result of the fit
- pl.ion()
- pl.plot(X,Y,'ro', label = 'Accelerating Voltage at each peak number')
- pl.errorbar(X,Y,yerr=Yerror)
- xx = np.linspace(0.5,6.5,101)
- ModelY = P[0] + P[1]*xx
- pl.plot(xx,ModelY,'k')
- pl.xlabel('Peak Number')
- pl.ylabel('Accelerating Voltage (V)')
- pl.title('Accelerating Voltage at Peak Versus Peak Number')
- pl.show()
- # print solution
- print(' Intercept= %f +/- %f'%( P[0],math.sqrt(C[0,0]) ))
- print(' Slope = %f +/- %f'%( P[1],math.sqrt(C[1,1]) ))
- #2ND PART: Argon collected current vs accelerating voltage - dips
- #X = [1,2,3,4,5,6]
- #Y = [23.8, 35.2, 46.3, 57.6, 69, 79.6]
- #pl.plot(X,Y,'o', label = 'Accelerating Voltage at each peak number')
- #pl.xlabel('Peak Number')
- #pl.ylabel('Accelerating Voltage')
- #pl.show()
- # number of parameters for line fit (2)
- npar = 2
- # vector with data (Y); std of measurement error is sigma =.1
- sigma = 0.1
- # here is data to fit
- Y = np.array([23.8, 35.2, 46.3, 57.6, 69, 79.6])
- Yerror = 1
- # here are X positions of data
- X = np.array([1,2,3,4,5,6]);
- # number of data points
- nobs = len(X)
- # create M – ones in first column, X in second column
- M = np.column_stack( (np.ones(nobs),X) )
- # solve
- MTM = np.dot(M.transpose(),M)
- MTMINV = np.linalg.inv(MTM)
- MTY = np.dot(M.transpose(),Y)
- P = np.dot(MTMINV,MTY) # SOLUTION
- C = MTMINV * sigma**2 # COVARIANCE MATRIX
- # compute RMS and print it
- Residuals = Y - np.dot(M,P)
- ChiSq = np.dot(Residuals.transpose(),Residuals)
- RMS = math.sqrt(ChiSq/nobs)
- #print('RMS = %f'%(RMS))
- # plot the result of the fit
- pl.ion()
- pl.plot(X,Y,'ro', label = 'Accelerating Voltage at each peak number')
- pl.errorbar(X,Y,yerr=Yerror)
- xx = np.linspace(0.5,6.5,101)
- ModelY = P[0] + P[1]*xx
- pl.plot(xx,ModelY,'k')
- pl.xlabel('Dip Number')
- pl.ylabel('Accelerating Voltage (V)')
- pl.title('Accelerating Voltage at Dip Versus Dip Number')
- pl.show()
- # print solution
- print(' Intercept= %f +/- %f'%( P[0],math.sqrt(C[0,0]) ))
- print(' Slope = %f +/- %f'%( P[1],math.sqrt(C[1,1]) ))
- #3RD PART: Neon collected current vs accelerating voltage - peaks
- #X = [1,2,3,4]
- #Y = [19.2,38.3,61.6,80.6]
- #pl.plot(X,Y,'o', label = 'Accelerating Voltage at each peak number')
- #pl.xlabel('Peak Number')
- #pl.ylabel('Accelerating Voltage')
- #pl.show()
- # number of parameters for line fit (2)
- npar = 2
- # vector with data (Y); std of measurement error is sigma =.1
- sigma = 0.1
- # here is data to fit
- Y = np.array([19.2,38.3,61.6,80.6])
- Yerror = 1
- # here are X positions of data
- X = np.array([1,2,3,4]);
- # number of data points
- nobs = len(X)
- # create M – ones in first column, X in second column
- M = np.column_stack( (np.ones(nobs),X) )
- # solve
- MTM = np.dot(M.transpose(),M)
- MTMINV = np.linalg.inv(MTM)
- MTY = np.dot(M.transpose(),Y)
- P = np.dot(MTMINV,MTY) # SOLUTION
- C = MTMINV * sigma**2 # COVARIANCE MATRIX
- # compute RMS and print it
- Residuals = Y - np.dot(M,P)
- ChiSq = np.dot(Residuals.transpose(),Residuals)
- RMS = math.sqrt(ChiSq/nobs)
- #print('RMS = %f'%(RMS))
- # plot the result of the fit
- pl.ion()
- pl.plot(X,Y,'ro', label = 'Accelerating Voltage at each peak number')
- pl.errorbar(X,Y,yerr=Yerror)
- xx = np.linspace(0.99,4.01,101)
- ModelY = P[0] + P[1]*xx
- pl.plot(xx,ModelY,'k')
- pl.xlabel('Peak Number')
- pl.ylabel('Accelerating Voltage (V)')
- pl.title('Accelerating Voltage at Peak Versus Peak Number (Neon)')
- pl.show()
- # print solution
- print(' Intercept= %f +/- %f'%( P[0],math.sqrt(C[0,0]) ))
- print(' Slope = %f +/- %f'%( P[1],math.sqrt(C[1,1]) ))
- #4TH PART: Neon collected current vs accelerating voltage - dips
- #X = [1,2,3]
- #Y = [25.5,46.7,69.4]
- #pl.plot(X,Y,'o', label = 'Accelerating Voltage at each peak number')
- #pl.xlabel('Peak Number')
- #pl.ylabel('Accelerating Voltage')
- #pl.show()
- # number of parameters for line fit (2)
- npar = 2
- # vector with data (Y); std of measurement error is sigma =.1
- sigma = 0.1
- # here is data to fit
- Y = np.array([25.5,46.7,69.4])
- Yerror = 1
- # here are X positions of data
- X = np.array([1,2,3]);
- # number of data points
- nobs = len(X)
- # create M – ones in first column, X in second column
- M = np.column_stack( (np.ones(nobs),X) )
- # solve
- MTM = np.dot(M.transpose(),M)
- MTMINV = np.linalg.inv(MTM)
- MTY = np.dot(M.transpose(),Y)
- P = np.dot(MTMINV,MTY) # SOLUTION
- C = MTMINV * sigma**2 # COVARIANCE MATRIX
- # compute RMS and print it
- Residuals = Y - np.dot(M,P)
- ChiSq = np.dot(Residuals.transpose(),Residuals)
- RMS = math.sqrt(ChiSq/nobs)
- #print('RMS = %f'%(RMS))
- # plot the result of the fit
- pl.ion()
- pl.plot(X,Y,'ro', label = 'Accelerating Voltage at each peak number')
- pl.errorbar(X,Y,yerr=Yerror)
- xx = np.linspace(0.99,3.01,101)
- ModelY = P[0] + P[1]*xx
- pl.plot(xx,ModelY,'k')
- pl.xlabel('Dip Number')
- pl.ylabel('Accelerating Voltage (V)')
- pl.title('Accelerating Voltage at Dip Versus Dip Number (Neon)')
- pl.show()
- # print solution
- print(' Intercept= %f +/- %f'%( P[0],math.sqrt(C[0,0]) ))
- print(' Slope = %f +/- %f'%( P[1],math.sqrt(C[1,1]) ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement