Unit 3 Pre-Lab Assignment 3
Unit 3 Pre-Lab Assignment 3
When we interpret any kind of data, our scientific result may be a number that comes from
the average of the data points, or it can be some kind of correlation. There are some kinds of
correlations in physics we expect. For example, if we are dropping an object from a certain
height, we know that the position will be
$x = \frac{1}{2} gt^2$
Therefore, if we measure positions and measure times and plot them, we should see a
parabola. However, if we have some systematic errors, meaning some effect of our system
that will affect all measurements, we won't get a perfect parabola. We therefore need to fit
our data.
Below I'm going to use some functions that will create arrays x_data and y_data which hold
some linear data.
# Show data
plt.scatter(x_data, y_data)
The second function will get the residuals of the function. This function can just be a formula
for any fitting as it will be the same for any fitting function where we don't have error bars.
The get residuals will go point by point on the data points and will find the distance between
each data point and the fitted line. The best fit will have the smallest residuals.
Inputs:
x: a coordinate
parameters: [slope of the line, y offset of the line]
'''
m = parameters[0]
b = parameters[1]
y = m * x + b
return y
We now use the least squares which will maximize the function get residuals, finding the
best fit. Note where x and y data are input
[ 2.95787579 29.64514846]
plt.legend()
$v = v_0(1-exp(-t/\tau))$
where tau is the RC time constant and v0 is the maximum voltage the circuit will acheive. Use
the RC values descirbed in the slides and v0 = 1 V.
In [24]: # Create a time array that is 5 times the length of the time constant
time_constant = 10e-3
time = np.linspace(0, 5 * time_constant, 500)
Plot 1: 10 uF Capacitor with 100 Ohm Resistor and 10 uF Capacitor with 1k Ohm Resistor
Plot 2: 1k Ohm Resistor with 10 uF Capacitor and 1k Ohm Resistor with 100 uF Capacitor
To make your graphs look nice and even, choose you time vector to be as a function of the
greatest tau value.
In [25]: # Plot 1: 10 uF Capacitor with 100 Ohm Resistor and 10 uF Capacitor with 1k Ohm Res
# Define parameters for Plot 1
v0 = 1 # Initial voltage in volts
Take your RC charge plot you created in the previous python notebook and add 5-10% noise
to it. After adding noise to your theoretical plot, create
Inputs:
t: time
parameters: [initial voltage, time constant]
'''
v0, tau = parameters
return v0 * (1 - np.exp(-t / tau))
Lastly, take your noisy data and fit a the theoretical function back to it.
In [ ]: