Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #*************************************************************
- #
- # Experiment: E3, Measuring an electric current, voltage and resistance.
- # Names: Fraser McDonald & Robert Kyle
- # Date: 06/11/2018
- #
- #*************************************************************
- import numpy as np
- import matplotlib.pyplot as plt
- import lab1
- #********************************************************
- # Load the data from file "E3data.txt"
- # Create an numpy array "d" with the voltage in the 1st
- # column and the current in the 2nd column.
- #
- # d = ....
- #********************************************************
- d = np.loadtxt("E2data.txt")
- #********************************************************
- # Use d to create variables for the voltage and current
- # Use the variable names V and I.
- #
- # What are the units?
- #
- # suggestion: V = ...
- # I = ...
- #********************************************************
- V=d[:,0]
- I=d[:,1]
- #********************************************************
- # Convert V and I to SI units (Volts and Ampere) if necessary
- #
- # suggestion: V = V * ...; I = I * ...;
- #********************************************************
- #********************************************************
- # Plot your raw data with
- # (a) V on the x-axis
- # (b) I on the y-axis.
- # (c) circle symbol for the data points
- # (e) labels for x and y axes
- # (f) a helpful title
- #********************************************************
- plt.figure(1)
- plt.plot(V,I,"ro")
- plt.xlabel("Voltage (V)")
- plt.ylabel("Current (a)")
- plt.title("Relationship between Voltage and Current")
- #********************************************************
- # Create a linear fit for the data:
- #
- # Use the command c,m,dm = lab1.fitLine( V, I)
- #
- # m - is the gradient of the fitted line.
- # c - is the offset of the fitted line.
- # dm - is the the error of the gradient.
- #********************************************************
- c,m,dm = lab1.fitLine( V, I)
- #********************************************************
- # Plot the straight line on top of your linearized data:
- # (a) generate an array with x-data points, call it "xr"
- # e.g. from 1 to 1.5 with 0.1 spacint
- # xr = np.arange(1, 1.5, 0.1)
- # (b) calculate the corresponding y-values for a straight
- # line, e.g.
- # yr = m*xr + c
- # (c) plot yr vs. xr with a line style
- #********************************************************
- xr= np.arange(0.4,1.5,0.005)
- yr=(m * xr) + c
- plt.plot(xr,yr,"-")
- #********************************************************
- # Calculate the resitance R
- #
- # Use the eq. 3 of the script (I = 1/R*V) to determine R
- # from the gradient of you fit (y = m *x + c).
- #
- # R = ...
- #********************************************************
- print("Gradient = ",m)
- R = 1/m
- #********************************************************
- # Calculate the error of R
- #
- # (Help : The error dR of the derived quatity R = 1/m depends
- # on the error dm of parameter m with dR/R = dm/m.)
- #
- # dR = dm/m * ...
- #********************************************************
- dR=(dm/m*R)
- print("Measurement Results")
- print('R',R)
- print("dR",dR)
- #********************************************************
- # do not forget to print this script and the figures
- #********************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement