Lab05_prelab
html
keyboard_arrow_up
School
University of British Columbia *
*We aren’t endorsed by this school
Course
119
Subject
Electrical Engineering
Date
Apr 3, 2024
Type
html
Pages
20
Uploaded by MateDiscovery15175
Lab 05 Prelab
¶
Ohm's Law, Plots, and Models
¶
Ohm's law relates the electrical potential applied across a device ($V$) to the current that passes through it, $I$.
Like Hooke's law, Ohm's law isn't really a physical law, rather it is an empirical relation that does a good job of describing many devices or materials under specific ranges of circumstances. Ohm's law takes the form:
$$ V = IR. $$
An example related to this lab is as follows. Consider the circuit below, where we have a voltage source (battery) with an adjustable voltage $V.$ The battery is connected to a resistor of unknown, but fixed resistance $R$. We have access to tools to measure the voltage $V$ (using a voltmeter) across the resistor as well as the current $I$ (using an ammeter) in the circuit. Knowing that we can vary the voltage $V$, how can we go about extracting the resistance $R$?
Given multiple datapoints $(V_1 \pm u\_V_1, I_1 \pm u\_I_1)$, $(V_2 \pm u\_V_2, I_2 \pm u\_I_2)$, $\ldots (V_n \pm u\_V_n, I_n \pm u\_I_n)$, a useful way to visualize the relationship (and extract information from the
relationship) is by plotting the two variables against each other. We have done so below for a mock dataset of voltages and currents. It is worth noting that this issue is one of great general interest in science. We may have two variables which are related---in this case the current $I$ through the resistor as a result of the voltage of the potential across the resistor $V_R$) and a model that describes how they may be related (here, Ohm's law). What we can do as experimental scientists is to collect data of the two variables and try to fit a model to them; from this we may extract parameters of interest (here, the resistance of our circuit), as well as evaluate how good the model is at describing the phenomena we see.
Your turn #1 (short answer questions):
If you get stuck or want to make sure you are on the right track in this
question sequence, the answers are provided below.
Your turn #1a:
What is the relationship between voltage and current as shown in the experimental data above?
From the above graph, it appears to be that there is a positive correlation between "applied voltage" and "Current through resistor" and at the same time the same time the relationship seems to be quite proportional
Your turn #1b:
What is the relationship theoretically predicted by Ohm's law?
Ohm's Law predicts that V and I are positively correlated and are proportional to each other. The constant of this proportionality is decribed by R.
Your turn #1c:
How is the slope of the above plot related to the resistance $R$ of the resistor?
Since V = IR, the differentiation of the equation leads to R, and hence the slope is R.
Your turn #1d:
Finally, estimate the resistance $R$ of the resistor by estimating the slope of the experimental data above.
The estimate of R can be donw by using 2 data points: The last one and the first one. Therefore, (0.08A - 0A)/(0.8V -0V) = 0.1. Hence R is 0.1 ohms
Answers (uncollapse to reveal):
A1a:
¶
A1a:
The relationship between current and voltage appears linear.
A1b:
¶
A1b:
The relationship predicted by Ohm's law is $I = (1/R)V$, i.e. the two are linearly related via the resistance.
A1c:
¶
A1c:
The slope of the above plot is related to the resistance of the resistor via Ohm's law to be $m = 1/R$.
A1d:
¶
A1d:
The slope of the above plot looks to be roughly $m = \frac{0.08A - 0A}{0.8V - 0V} = 0.1$, and so the resistance is approximately $R = \frac{1}{m} = 10\Omega$.
Plotting with Python
¶
An important first step to finding relationships between variables is data visualization; such as through producing plots of data. Fortunately, python is an excellent medium for this task. The rest of this pre-lab will be walking through how to produce a scatter plot of experimental data and extract useful information, which we will be doing time and time again for future experiments in this lab.
Much like with the case of recording data in tables, plotting is not a native functionality of python; instead, we import a library which carries this functionality. In this case, the library of interest is matplotlib
. You can import it (along with the data_entry2 and numpy libraries we have been using) by running the cell below.
In [29]:
%reset -f
# Run me to import the relevant libraries
import data_entry2
import numpy as np
import matplotlib.pyplot as plt
We will go through an example together of creating a scatter plot, and then at the end we will ask you to take what you've learned to recreate the scatter plot we showed in the beginning of the notebook. For our example together, we consider an example akin to the very first experiment in the lab. We suppose that we have some spring, and we have measured the force the spring exerts $F$ for a variety of compressions $\Delta x$. The data
are given in the spreadsheet below:
In [30]:
# Run me to import example data
de1 = data_entry2.sheet("lab05_prelab_hookes_law")
Sheet name: lab05_prelab_hookes_law.csv
Your turn #2:
We will want to work with vectors of this data, so click the Generate Vectors
button in the
spreadsheet.
Next, let's create an initial plot of the datapoints of force vs displacement and nothing else.
In [31]:
# Run me to create a simple ply of FVec vs dxVec wuth y-uncertainties u_FVec
plt.errorbar(dxVec, FVec, u_FVec, fmt='bo')
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
plt.show()
We use plt
to specify that we want to be using the matplotlib
plotting library. We then use the plt.errorbar
function to specify that we want a plot with error bars. The first argument we give it (
dxVec
)
provides data for the x-axis, the second argument (
FVec
) provides the data for the y-axis, and the third argument (
u_FVec
) provides the error bars for the y-axis data (we will often find that the errors in the y-values are more significant than those on the x-values, so the x errors can often be neglected). The final argument (
fmt='bo'
) specifies that we want blue (
b
) circles (
o
) for the datapoints. Finally, the plt.show()
at the end displays the plot.
Your turn #3:
Try replacing the blue dot symbol with a red x symbol using fmt='rx'
above.
Let's start adding further important information to our plot, such as axis labels and a title. We will also show how to adjust the size of the markers in the plot and then add a legend (though this plot doesn't really need one).
In [32]:
# Run me to reproduce the previous plot and add further detail
plt.errorbar(dxVec, FVec, u_FVec, fmt="rx", markersize = 3, label="Experimental data")
plt.title("Force vs. Displacement for spring")
plt.xlabel("Displacement of spring from equilibrium (m)")
plt.ylabel("Force (N)")
plt.legend()
plt.show()
We now have a complete plot! Notice that the plot title describes what is being plotted against what (y quantity plotted vs. x quantity), and the axis labels describe the quantities (with the units). Experiment with the title and axis labels by changing the text inside plt.title("..."), plt.xlabel("..."),
and plt.ylabel("...")
functions in the cell above.
The markersize = ...
argument in plt.errorbar
specifies how large the markers in the plot are. In the first version of the plot above, the error bars of the first datapoint were hidden behind the marker so here we shrink the size of the markers to make the small error bars more visible.
Finally, by providing a label="..."
argument to plt.errorbar
, we can specify the label for the plot when we include a legend with plt.legend()
. We don't really need a legend here as we are only plotting a single dataset, but later on when we have multiple things on the same plot, a legend will become very useful.
Note that the plot will (usually) automatically give reasonable axis tick marks (the specific numbers displayed along each axis), and set appropriate limits for the plot so all datapoints are displayed. If you find the defaults aren't suitable, there are ways to control these (eg plt.xlim([min, max])
and plt.xticks([.1, .2, .3])
), though you probably won't need those in this course.
Your turn #4:
Recall that Hooke's law tells us that $F = k \Delta x$. Is the slope of this graph equal to $k$, $1/k$ or some other quantity?
The slope of this graph is equal to k
Answer The slope of this graph is equal to k
¶
A:
The slope of the above plot can be identified as the spring constant $k$ of the spring via Hooke's law.
Adding a model to our graph
¶
We've seen how to plot data. We will often want to add a line or curve to a plot to judge how well a model describes the experimental results. To do this, we break the process into four steps:
1.
Find the range of x-values that the data span 2.
Generate many x-values over the range of values for which we want to determine the model predictions. Why do we need many points? For a straight line the number of points used doesn't matter much, but if the model predicts a more complicated function, using many points will give a curve that looks smooth to the eye. 3.
Calculate the model prediction (model y-values) at each of the x-values 4.
Plot the model prediction on the graph. Here, our model is the linear model of $F = kx$. In order to create our model prediction, we will need a value for the model parameter $k$ (the spring constant of the spring, and the slope of the model). To start with, we can estimate this value by inspection; we have points at approximately $(0\,\text{m}, 0\,\text{N})$ and $(0.6\,\
text{m}, 1.2\,\text{N})$, so a reasonable estimate of the slope (which corresponds to $k$) would be $\
text{slope} = \frac{1.2 \text{N} - 0 \text{N}}{0.6 \text{m} - 0 \text{m}} = 2\,\text{N/m}$.
Let's use this value to add an initial estimate of our model to our graph:
In [33]:
# Run me to plot our model as a straight line and our data points, both on the same graph
# Scatter step 1: find the limits of the data:
xmin = np.min(dxVec) # use the np.min function to find the smallest x-value
xmax = np.max(dxVec) # same for max
print (xmin, xmax) # uncomment to see what the limits are
# Scatter step 2: generate a bunch of x points between xmin and xmax
xpoints = np.linspace(xmin, xmax, 200) # gives 200 evenly spaced points between xmin and xmax
print(xpoints) # uncomment to see the x values that were generated.
# Scatter step 3: calculate the model values:
slope = 2 # Our initial estimate of the slope from above (units: N/m).
ypoints = xpoints * slope # this calculates the model y-values at all 200 points.
# Scatter step 4: plot the curve. We plot this as a red line "r-" :
plt.plot(xpoints, ypoints, "r-", label = "F = kx")
# Scatter step 5: Add all the previous details from before
plt.errorbar(dxVec, FVec, u_FVec, fmt="bo", markersize = 3, label="Experimental data")
plt.title("Force vs. Displacement for spring")
plt.xlabel("Displacement of spring from equilibrium (m)")
plt.ylabel("Force (N)")
plt.legend()
plt.show()
0.0 0.6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
[0. 0.00301508 0.00603015 0.00904523 0.0120603 0.01507538
0.01809045 0.02110553 0.0241206 0.02713568 0.03015075 0.03316583
0.0361809 0.03919598 0.04221106 0.04522613 0.04824121 0.05125628
0.05427136 0.05728643 0.06030151 0.06331658 0.06633166 0.06934673
0.07236181 0.07537688 0.07839196 0.08140704 0.08442211 0.08743719
0.09045226 0.09346734 0.09648241 0.09949749 0.10251256 0.10552764
0.10854271 0.11155779 0.11457286 0.11758794 0.12060302 0.12361809
0.12663317 0.12964824 0.13266332 0.13567839 0.13869347 0.14170854
0.14472362 0.14773869 0.15075377 0.15376884 0.15678392 0.15979899
0.16281407 0.16582915 0.16884422 0.1718593 0.17487437 0.17788945
0.18090452 0.1839196 0.18693467 0.18994975 0.19296482 0.1959799
0.19899497 0.20201005 0.20502513 0.2080402 0.21105528 0.21407035
0.21708543 0.2201005 0.22311558 0.22613065 0.22914573 0.2321608
0.23517588 0.23819095 0.24120603 0.24422111 0.24723618 0.25025126
0.25326633 0.25628141 0.25929648 0.26231156 0.26532663 0.26834171
0.27135678 0.27437186 0.27738693 0.28040201 0.28341709 0.28643216
0.28944724 0.29246231 0.29547739 0.29849246 0.30150754 0.30452261
0.30753769 0.31055276 0.31356784 0.31658291 0.31959799 0.32261307
0.32562814 0.32864322 0.33165829 0.33467337 0.33768844 0.34070352
0.34371859 0.34673367 0.34974874 0.35276382 0.35577889 0.35879397
0.36180905 0.36482412 0.3678392 0.37085427 0.37386935 0.37688442
0.3798995 0.38291457 0.38592965 0.38894472 0.3919598 0.39497487
0.39798995 0.40100503 0.4040201 0.40703518 0.41005025 0.41306533
0.4160804 0.41909548 0.42211055 0.42512563 0.4281407 0.43115578
0.43417085 0.43718593 0.44020101 0.44321608 0.44623116 0.44924623
0.45226131 0.45527638 0.45829146 0.46130653 0.46432161 0.46733668
0.47035176 0.47336683 0.47638191 0.47939698 0.48241206 0.48542714
0.48844221 0.49145729 0.49447236 0.49748744 0.50050251 0.50351759
0.50653266 0.50954774 0.51256281 0.51557789 0.51859296 0.52160804
0.52462312 0.52763819 0.53065327 0.53366834 0.53668342 0.53969849
0.54271357 0.54572864 0.54874372 0.55175879 0.55477387 0.55778894
0.56080402 0.5638191 0.56683417 0.56984925 0.57286432 0.5758794
0.57889447 0.58190955 0.58492462 0.5879397 0.59095477 0.59396985
0.59698492 0.6 ]
A few things to note:
1.
plt.show()
helps ensure that plt.plot()
, plt.errorbar()
and the other plt.
functions will
appear on the same plot 2.
The syntax for plt.plot()
is a little different from plt.errorbar()
. For plt.errorbar()
you need fmt='bo'
, but for plt.plot()
the format for plotting can't include the fmt=
piece (annoying, but this is just how it is). Residuals - what they area and how to plot them
¶
This fit of the model to our data looks pretty good to the eye, but we are going to introduce a new tool, a residuals plot, which we will use in lab 5 (and future labs) as a tool to help improve the quality of our fits and to
estimate uncertainty in the fitting parameters, which in this case is the slope, which is often given the symbol $m$). For now, we will introduce what it is and how to create the plot.
A residual is a measure of how far a data point lies from the best fit line (the model) along the y-direction. So for a given data point on the graph $(x_i, y_i)$, the residual $(R_i)$ is given by:
$$R_i = y_i - \text{model}(x_i)$$
where $\text{model}(x_i)$ represents the $y$-value that our model, $y = mx$, predicts at the point $x_i$. Let’s
build a graph of the residuals that correspond to each $x$-value and then we will spend a bit more time learning
about how they are useful. We will break this process down into a few steps:
1.
Calculate the model prediction $\text{model}(x_i)$ points at all of the $x$-data values 2.
Calculate the residual vector $[R_1, R_2, \ldots R_n]$ as the difference of the $y$-data vector $[y_1, y_2, \ldots, y_n]$ and the model vector $[\text{model}(x_1), \text{model}(x_2), \ldots, \text{model}
(x_n)]$. 3.
Plot the residual vector against the $x$-data vector. 4.
Add a $R = 0$ x-axis to the plot. Let's create the residuals plot for our current model of the Hooke's law dataset.
In [34]:
# Run me to calculate residuals and create a well-labelled residuals plot
# Residuals step 1: Calculate the model prediction for each our data points from dxVec
ymodel = slope * dxVec # y = mx at each x_i
# Residuals step 2: Calcualte the residuals vector
RVec = FVec - ymodel
# Residuals step 3: Plot the residuals vector against the x-data vector
plt.errorbar(dxVec, RVec, u_FVec, fmt="bo", markersize = 3)
# Residuals step 4: Add a horizontal line at R=0 to the plot
plt.hlines(y=0, xmin=xmin, xmax=xmax, color='k') # draw a black axis at y = 0.
# Residuals step 5: Add axis labels and title, and show the graph
plt.title("Residuals for Force vs. displacement for spring")
plt.xlabel("Displacement (m)")
plt.ylabel("Residual = data - model (N)")
plt.show()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Note that we use use plt.errorbar()
to plot the residuals, and we use the same
uncertainties as our $y$-
data uncertainties, u_FVec
. This is because there are no uncertainties associated with the model predictions, thus the uncertainties in the residuals (the difference of data and model) are just the uncertainties in the data y-
values. We also modify the labelling of the plot (axis labels, title) to make sure what is being plotted is more clear.
Looking at the residuals (difference between model and data) gives us more resolving power than looking our original scatter plot that included the data and model. In this case, we can see from the residuals plot that the residuals trend upward as we go to the right. This suggests that we could improve out model to better fit to the data. In this case, we will want to increase the slope of the model to account for the current upward trend in the residuals.
Usually, it is standard to plot the data/model and residual plot in the same cell, for ease of viewing. We do this below.
In [35]:
# Run me to make our two plots together (this is all the same code from before)
# Scatter step 1: find the limits of the data:
xmin = np.min(dxVec) # use the np.min function to find the smallest x value
xmax = np.max(dxVec) # same for max
print (xmin, xmax) # uncomment to see what the limits are
# Scatter step 2: generate a bunch of x points between xmin and xmax
xpoints = np.linspace(xmin, xmax, 200) # gives 200 evenly spaced points between xmin and xmax
print(xpoints) # uncomment to see the x values that were generated.
# Scatter step 3: calculate the model values:
slope = 1.9 # Our initial estimate of the slope from above (units: N/m).
ypoints = xpoints * slope # this calculates the yvalues at all 200 points.
# Scatter step 4: plot the curve. We plot this as a red line "r-" :
plt.plot(xpoints, ypoints, "r-", label = "F = kx")
# Scatter step 5: plot the data:
plt.errorbar(dxVec, FVec, u_FVec, fmt="bo", markersize = 3, label="Experimental data")
plt.title("Force vs. Displacement for spring")
plt.xlabel("Displacement of spring from equilibrium (m)")
plt.ylabel("Force (N)")
plt.legend()
plt.show()
# Residuals step 1: Calculate the model at each x-datapoint
ymodel = slope * dxVec # y = mx at each x_i
# Residuals step 2: Calcualte the residual vector
RVec = FVec - ymodel
# Resoduals step 3: Plot the residual vector against the x-data vector
plt.errorbar(dxVec, RVec, u_FVec, fmt="bo", markersize = 3)
# Residuals step 4: Add a R = 0 x-axis (horizontal line) to the plot
plt.hlines(y=0, xmin=xmin, xmax=xmax, color='k') # draw axis at y = 0.
# Residuals step 5: Add axis labels and title, and show the graph
plt.title("Residuals for Force vs. displacement for spring")
plt.xlabel("Displacement of spring from equilibrium (m)")
plt.ylabel("Residual = data - model (N)")
plt.show()
0.0 0.6
[0. 0.00301508 0.00603015 0.00904523 0.0120603 0.01507538
0.01809045 0.02110553 0.0241206 0.02713568 0.03015075 0.03316583
0.0361809 0.03919598 0.04221106 0.04522613 0.04824121 0.05125628
0.05427136 0.05728643 0.06030151 0.06331658 0.06633166 0.06934673
0.07236181 0.07537688 0.07839196 0.08140704 0.08442211 0.08743719
0.09045226 0.09346734 0.09648241 0.09949749 0.10251256 0.10552764
0.10854271 0.11155779 0.11457286 0.11758794 0.12060302 0.12361809
0.12663317 0.12964824 0.13266332 0.13567839 0.13869347 0.14170854
0.14472362 0.14773869 0.15075377 0.15376884 0.15678392 0.15979899
0.16281407 0.16582915 0.16884422 0.1718593 0.17487437 0.17788945
0.18090452 0.1839196 0.18693467 0.18994975 0.19296482 0.1959799
0.19899497 0.20201005 0.20502513 0.2080402 0.21105528 0.21407035
0.21708543 0.2201005 0.22311558 0.22613065 0.22914573 0.2321608
0.23517588 0.23819095 0.24120603 0.24422111 0.24723618 0.25025126
0.25326633 0.25628141 0.25929648 0.26231156 0.26532663 0.26834171
0.27135678 0.27437186 0.27738693 0.28040201 0.28341709 0.28643216
0.28944724 0.29246231 0.29547739 0.29849246 0.30150754 0.30452261
0.30753769 0.31055276 0.31356784 0.31658291 0.31959799 0.32261307
0.32562814 0.32864322 0.33165829 0.33467337 0.33768844 0.34070352
0.34371859 0.34673367 0.34974874 0.35276382 0.35577889 0.35879397
0.36180905 0.36482412 0.3678392 0.37085427 0.37386935 0.37688442
0.3798995 0.38291457 0.38592965 0.38894472 0.3919598 0.39497487
0.39798995 0.40100503 0.4040201 0.40703518 0.41005025 0.41306533
0.4160804 0.41909548 0.42211055 0.42512563 0.4281407 0.43115578
0.43417085 0.43718593 0.44020101 0.44321608 0.44623116 0.44924623
0.45226131 0.45527638 0.45829146 0.46130653 0.46432161 0.46733668
0.47035176 0.47336683 0.47638191 0.47939698 0.48241206 0.48542714
0.48844221 0.49145729 0.49447236 0.49748744 0.50050251 0.50351759
0.50653266 0.50954774 0.51256281 0.51557789 0.51859296 0.52160804
0.52462312 0.52763819 0.53065327 0.53366834 0.53668342 0.53969849
0.54271357 0.54572864 0.54874372 0.55175879 0.55477387 0.55778894
0.56080402 0.5638191 0.56683417 0.56984925 0.57286432 0.5758794
0.57889447 0.58190955 0.58492462 0.5879397 0.59095477 0.59396985
0.59698492 0.6 ]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Let’s take a moment to see how these two graphs each present the same overall information, but with different emphases.
•
The main scatter-plot, on top, shows our data points and the model. We can see that, within their uncertainties, all of our data points lie along the model line or above it. •
The residuals plot, on the bottom, shows how far each data point is away from the model, thus we can see a bit more clearly that the left-most data point lies exactly at R = 0 (the model predicts this data point
exactly) and all of the other data points have positive residuals (data - model), meaning that model is providing a lower prediction than the actual data. The residuals graph can be thought of as a zoomed-in representation of the data points as seen from the perspective of the model line. The zoomed-in nature of the residual plot (in comparison to the raw scatterplot and model) allows us to better analyze the agreement between the two. This makes residual plots an extremely useful tool for evaluating the quality of fits and for modifying models, which you are now going to do below.
Your turn #5:
Let's see if we can improve the fit of our model to the data. Using the plots directly above, try out slopes of 1.7, 1.8, 1.9, 2.0, 2.1, 2.2 and 2.3 (N/m). Categorize each of the slopes as best fits
(fits where it seems like there is little room for improvement), decent fits
(reasonable fits where there is still room for small obvious improvements) or poor fits
using the list below.
Hints:
•
For a good fit we are looking to have approximately equal scatter of the residuals above and below the R=0 horizontal line, which would also correspond to an approximately equal scatter of the data points above and below the model on the scatter plot. •
For a good fit, there should be no obvious trends in the residuals. An example of an obvious trend is the small but noticeable upward trend we saw for slope = 2.0. •
Finally, if the uncertainties are well-characterized (neither overestimated or underestimated) and we are
using an appropriate model, we will expect that approximately 68% of the residuals will have their error bars touch the horizontal R=0 line. Categorize the slopes 1.7, 1.8, 1.9, 2.0, 2.1, 2.2 and 2.3 (N/m) here:
•
Best fits:2.1 •
Decent fits:2.0, 2.2 •
Poor fits:1.7, 1.8, 1.9, 2.3 Answer:
¶
•
Best fits: 2.1 •
Decent fits: 2.0, 2.2 •
Poor fits: 1.7, 1.8, 1.9, 2.3 Plotting with Python - Your turn!
¶
Your turn #6:
Now that we've gone through an example together, it is your turn to follow the steps above to create the current vs. voltage plot (including labels and title) that we saw at the beginning of the notebook. The data you need is provided below.
Hint: Instead of starting from scratch, you can copy the last code cell in the *Plotting with Python* section and
modify the names of the vectors being plotted, as well as the axis labels/title to fit the Current vs. Voltage plot.
In [36]:
# Run me to load the Ohm's Law data
# Make sure to press "Generate Vectors" afterward
de2 = data_entry2.sheet("lab05_prelab_ohms_law")
Sheet name: lab05_prelab_ohms_law.csv
In [37]:
# Use this cell to create your scatter plot Your turn #7:
Finally, plot a linear model on top of the current vs. voltage scatterplot in the cell below and add a residuals plot. Adjust the slope until your scatter plot and residuals plot both show a good fit of the model to the data.
Hints
•
You can use Your turn #1d to get a good initial estimate of the slope $m$ for the model •
You will likely find it convenient to copy and paste the last code cell in the Residuals - Making a plot
section and modify the variable names/plot elements accordingly. In [38]:
# Use this cell to create your scatter plot with model, and your residuals plot
# Scatter step 1: find the limits of the data:
xmin = np.min(VVec) # use the np.min function to find the smallest x value
xmax = np.max(VVec) # same for max
print (xmin, xmax) # uncomment to see what the limits are
# Scatter step 2: generate a bunch of x points between xmin and xmax
xpoints = np.linspace(xmin, xmax, 200) # gives 200 evenly spaced points between xmin and xmax
print(xpoints) # uncomment to see the x values that were generated.
# Scatter step 3: calculate the model values:
slope = 0.1 # Our initial estimate of the slope from above (units: N/m).
ypoints = xpoints*slope # this calculates the yvalues at all 200 points.
# Scatter step 4: plot the curve. We plot this as a red line "r-" :
plt.plot(xpoints, ypoints, "r-", label = "I = V/R")
# Scatter step 5: plot the data:
plt.errorbar(VVec, IVec, u_IVec, fmt="bo", markersize = 3, label="Experimental data")
plt.title("Current (I) vs Voltage (V)")
plt.xlabel("Voltage (V)")
plt.ylabel("Current through Resistor (I)")
plt.legend()
plt.show()
# Residuals step 1: Calculate the model at each x-datapoint
ymodel = slope * VVec # y = mx at each x_i
# Residuals step 2: Calcualte the residual vector
RVec = IVec - ymodel
# Resoduals step 3: Plot the residual vector against the x-data vector
plt.errorbar(VVec, RVec, u_IVec, fmt="bo", markersize = 3)
# Residuals step 4: Add a R = 0 x-axis (horizontal line) to the plot
plt.hlines(y=0, xmin=xmin, xmax=xmax, color='k') # draw axis at y = 0.
# Residuals step 5: Add axis labels and title, and show the graph
plt.title("Current (I) vs Voltage (V)")
plt.xlabel("Voltage (V)")
plt.ylabel("Current through Resistor (I)")
plt.show()
0.0 0.8
[0. 0.0040201 0.0080402 0.0120603 0.0160804 0.0201005
0.0241206 0.0281407 0.0321608 0.0361809 0.04020101 0.04422111
0.04824121 0.05226131 0.05628141 0.06030151 0.06432161 0.06834171
0.07236181 0.07638191 0.08040201 0.08442211 0.08844221 0.09246231
0.09648241 0.10050251 0.10452261 0.10854271 0.11256281 0.11658291
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
0.12060302 0.12462312 0.12864322 0.13266332 0.13668342 0.14070352
0.14472362 0.14874372 0.15276382 0.15678392 0.16080402 0.16482412
0.16884422 0.17286432 0.17688442 0.18090452 0.18492462 0.18894472
0.19296482 0.19698492 0.20100503 0.20502513 0.20904523 0.21306533
0.21708543 0.22110553 0.22512563 0.22914573 0.23316583 0.23718593
0.24120603 0.24522613 0.24924623 0.25326633 0.25728643 0.26130653
0.26532663 0.26934673 0.27336683 0.27738693 0.28140704 0.28542714
0.28944724 0.29346734 0.29748744 0.30150754 0.30552764 0.30954774
0.31356784 0.31758794 0.32160804 0.32562814 0.32964824 0.33366834
0.33768844 0.34170854 0.34572864 0.34974874 0.35376884 0.35778894
0.36180905 0.36582915 0.36984925 0.37386935 0.37788945 0.38190955
0.38592965 0.38994975 0.39396985 0.39798995 0.40201005 0.40603015
0.41005025 0.41407035 0.41809045 0.42211055 0.42613065 0.43015075
0.43417085 0.43819095 0.44221106 0.44623116 0.45025126 0.45427136
0.45829146 0.46231156 0.46633166 0.47035176 0.47437186 0.47839196
0.48241206 0.48643216 0.49045226 0.49447236 0.49849246 0.50251256
0.50653266 0.51055276 0.51457286 0.51859296 0.52261307 0.52663317
0.53065327 0.53467337 0.53869347 0.54271357 0.54673367 0.55075377
0.55477387 0.55879397 0.56281407 0.56683417 0.57085427 0.57487437
0.57889447 0.58291457 0.58693467 0.59095477 0.59497487 0.59899497
0.60301508 0.60703518 0.61105528 0.61507538 0.61909548 0.62311558
0.62713568 0.63115578 0.63517588 0.63919598 0.64321608 0.64723618
0.65125628 0.65527638 0.65929648 0.66331658 0.66733668 0.67135678
0.67537688 0.67939698 0.68341709 0.68743719 0.69145729 0.69547739
0.69949749 0.70351759 0.70753769 0.71155779 0.71557789 0.71959799
0.72361809 0.72763819 0.73165829 0.73567839 0.73969849 0.74371859
0.74773869 0.75175879 0.75577889 0.75979899 0.7638191 0.7678392
0.7718593 0.7758794 0.7798995 0.7839196 0.7879397 0.7919598
0.7959799 0.8 ]
Estimating uncertainty of the slope
¶
Now that we have a linear model, we can also estimate the uncertainty of the slope.
To estimate uncertainties in fitting parameters, we will use the method of looking at the range of reasonable best-fit lines and treating that as a confidence interval. We will make the steepest possible best-fit line "Max" (as in maximum slope) that still does a reasonable job of fitting the data and a least steep "Min" (as in minimum
slope) that also does a reasonable job of fitting the data. We will call our original model line "Best". Use the "Best" parameters for the starting guesses for the "Max" and "Min" fit parameters.
To calculate the uncertainty of the slope, the range between the maximum and minimum slope is our 68% confidence interval for the slope, and so the uncertainty is that 68% confidence interval divided by 2.
In the Hooke's Law data set we found in "your turn #5" that the graph has decent fits for slopes in the range 2.0-
2.2. So this would be the 68% confidence interval for the slope.
In [39]:
slope_max = 2.2
slope_min = 2.0
slope_best = 2.1
u_slope = (slope_max-slope_min)/2
print("The model slope is: {:.3f}+/-{:.3f} N/m".format(slope_best, u_slope))
The model slope is: 2.100+/-0.100 N/m
Your turn #8:
Find the uncertainty of the slope of the Ohm's law data, by adjusting the slope to find the models
that correspond to the maximum and minimum slopes that still correspond to reasonable fits.
Hints
•
To find the maximum slope, increase the slope from your best slope until the model no longer fits the data. In [40]:
# Copy and paste your code from the code cell above for #7 where you plotted your model and residual plot
# and adjust your slope variable
In [41]:
slope_max = 0.11
slope_min = 0.09
slope_best = 0.1
u_slope = (slope_max-slope_min)/2
print("The model slope is: {:.3f}+/-{:.3f} N/m".format(slope_best, u_slope))
The model slope is: 0.100+/-0.010 N/m
Answer
¶
In [42]:
slope_max = 0.111
slope_min = 0.092
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
slope_best = 0.101
u_slope = (slope_max-slope_min)/2
print("The model slope is: {:.3f}+/-{:.3f} N/m".format(slope_best, u_slope))
The model slope is: 0.101+/-0.010 N/m
Since we are approximating the slope uncertainty, your answer might be slightly different. Your uncertainty should be within 10% of the answer above.
Submit
¶
Steps for submission:
1.
Click: Run => Run_All_Cells 2.
Read through the notebook to ensure all the cells executed correctly and without error. 3.
File => Save_and_Export_Notebook_As->HTML 4.
Upload the HTML document to the lab submission assignment on Canvas. In [ ]:
In [43]:
display_sheets()
Sheet: de1 File: lab05_prelab_hookes_law.csv
dx
u_dx
F
u_F
Units
m
m
N
N
0
0
0.01
0
0.02
1
0.12 0.01
0.26 0.02
2
0.21 0.01
0.43 0.03
3
0.29 0.01
0.63 0.03
4
0.40 0.01
0.81 0.03
5
0.48 0.01
1.05 0.04
6
0.60 0.01
1.23 0.04
Sheet: de2 File: lab05_prelab_ohms_law.csv
V
u_V
I
u_I
Units
V
V
A
A
0
0
0.02 0
0.005
1
0.11 0.02 0.009 0.005
2
0.19 0.02 0.020 0.01
3
0.28 0.02 0.029 0.005
4
0.41 0.02 0.043 0.015
5
0.53 0.02 0.053 0.01
6
0.67 0.02 0.070 0.015
7
0.80 0.02 0.078 0.02
Related Documents
Related Questions
What is Lenz's law and derive its formula.
arrow_forward
3.12 A carbon brush used to conduct current from the commutator of a DC
generator has a length of 4 in. It must conduct a current of 400 A with a voltage drop
not exceeding 2 V. Determine the cross-sectional area of this carbon brush.
3.13 Early DC machines use brass brushes instead of carbon brushes. The com-
mutator bars do not last very long since brass is a rather hard metal. If a brass brush
of the dimensions determined in problem 3.12 is used instead to conduct the same
current, determine the voltage drop.
arrow_forward
quick please
arrow_forward
lell
L1
R
Ro
2. In this figure, assume arbitrary numbers for R1, R2, L1, and L2 including
some number for the battery E. Find the rate of current in which inductor one
(L1) is changing just after the switch is closed. Next, find the current in L1
after some time after the switch has been closed.
lell
arrow_forward
I. SOLVE THE
FOLLONING PROBLENS :
A COPPER WIRE OF
0,3 Mm RAAUS HAS
A LEN ETH OF
1.
JOM-
IF THE RESISTIVITY of cOpPER IS 1-7 x0
WHAT
WOULD BE THE RESISTANOE OF THE WIRE?
OF A 100m WIRE IS 1035 mm AND
3.7 OHMS. WHAT
2. THE DIAMETER
THE REISTANCE IS
IS THE CONDUCTIVITY
3. WHAT
WILL BE THE VALUE OF A CAPACITOR
WHEN IT HAS A CAPACITIVE REACTANCE OF 300R ANP
to A 6o HZ. SUPPLY?
IN FARADS
IS CONNECTED
4. WHAT Is THE VALUE OF THE RESISTOR WITH THE
FOLLOWING
COLORS ?
A. BROWN, BLACK, GOLD,
REP
B. BLUE YELON BROWN, SILVER
PED, SILVER, BROWN, VIOET
C.
5.
AND t WHEN V
220V AND R= 50n
WHEN I =
45 A
WHEN V = 120V
FIND V
ANO R 80n
AND
AND E= 11A-
arrow_forward
b) Describe the traces you would see on an oscilloscope monitoring voltage changes across a resistance which has:
- AC flowing through it
- DC flowing through it
You should include diagrams to support your descriptions for each trace.
arrow_forward
Goal:The intent of this problem is to understand how electrostatic models can be used outside of electrical engineering. This basic model is used to understand chemical
reactions, bonding, and other forms of atomic processes. It also shows you the strength of electrostatic forces in an atom.
The Thomson model of a hydrogen atom is a sphere of positive charge with radius Ro with an electron (a point charge) at its center. The total positive charge equals the electronic
charge q. What is the force of attraction between an electron at a distance R from the center of the sphere of positive charge?
OOOO
qR
4π€, Ro
O
q²R
3πEO
q²R
4π€, Ro
arrow_forward
electromagnetic field)I want a detailed solution because my teacher changes the numbers. I want a detailed solution. Understand the solution
arrow_forward
B) Define the permeability (ur) of the material. If you are required to design IH and IpH inductors,
what type of core will you use in your design and why? support your answer by equations.
arrow_forward
8. Liquids with solid impurities
a) Have higher dielectrie strength
b) Of large size have higher dielectric strength
c) Have lower dielectric strength as compared to pure liquids
d) None of the above
9. Peak to peak ripple is defined as
a) the difference between average de voltage and peak value
b) the difference between maximum and minimum de voltage
c) the difference between maximum ac and average dc voltages
d) the difference between ac (rms) and average de voltages
10. In a Cockroft-Walton circuit, input voltage 100 kV load current 25 mA, supply
frequency 100 Hz, each capacitor 10 nF. The optimum no. of stages for maximum
output voltage is
a) 1
b) 2
c) 10
d) 35
arrow_forward
only 9
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337900348/9781337900348_smallCoverImage.jpg)
Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:9781337900348
Author:Stephen L. Herman
Publisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337399128/9781337399128_smallCoverImage.gif)
Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning
Related Questions
- What is Lenz's law and derive its formula.arrow_forward3.12 A carbon brush used to conduct current from the commutator of a DC generator has a length of 4 in. It must conduct a current of 400 A with a voltage drop not exceeding 2 V. Determine the cross-sectional area of this carbon brush. 3.13 Early DC machines use brass brushes instead of carbon brushes. The com- mutator bars do not last very long since brass is a rather hard metal. If a brass brush of the dimensions determined in problem 3.12 is used instead to conduct the same current, determine the voltage drop.arrow_forwardquick pleasearrow_forward
- lell L1 R Ro 2. In this figure, assume arbitrary numbers for R1, R2, L1, and L2 including some number for the battery E. Find the rate of current in which inductor one (L1) is changing just after the switch is closed. Next, find the current in L1 after some time after the switch has been closed. lellarrow_forwardI. SOLVE THE FOLLONING PROBLENS : A COPPER WIRE OF 0,3 Mm RAAUS HAS A LEN ETH OF 1. JOM- IF THE RESISTIVITY of cOpPER IS 1-7 x0 WHAT WOULD BE THE RESISTANOE OF THE WIRE? OF A 100m WIRE IS 1035 mm AND 3.7 OHMS. WHAT 2. THE DIAMETER THE REISTANCE IS IS THE CONDUCTIVITY 3. WHAT WILL BE THE VALUE OF A CAPACITOR WHEN IT HAS A CAPACITIVE REACTANCE OF 300R ANP to A 6o HZ. SUPPLY? IN FARADS IS CONNECTED 4. WHAT Is THE VALUE OF THE RESISTOR WITH THE FOLLOWING COLORS ? A. BROWN, BLACK, GOLD, REP B. BLUE YELON BROWN, SILVER PED, SILVER, BROWN, VIOET C. 5. AND t WHEN V 220V AND R= 50n WHEN I = 45 A WHEN V = 120V FIND V ANO R 80n AND AND E= 11A-arrow_forwardb) Describe the traces you would see on an oscilloscope monitoring voltage changes across a resistance which has: - AC flowing through it - DC flowing through it You should include diagrams to support your descriptions for each trace.arrow_forward
- Goal:The intent of this problem is to understand how electrostatic models can be used outside of electrical engineering. This basic model is used to understand chemical reactions, bonding, and other forms of atomic processes. It also shows you the strength of electrostatic forces in an atom. The Thomson model of a hydrogen atom is a sphere of positive charge with radius Ro with an electron (a point charge) at its center. The total positive charge equals the electronic charge q. What is the force of attraction between an electron at a distance R from the center of the sphere of positive charge? OOOO qR 4π€, Ro O q²R 3πEO q²R 4π€, Roarrow_forwardelectromagnetic field)I want a detailed solution because my teacher changes the numbers. I want a detailed solution. Understand the solutionarrow_forwardB) Define the permeability (ur) of the material. If you are required to design IH and IpH inductors, what type of core will you use in your design and why? support your answer by equations.arrow_forward
- 8. Liquids with solid impurities a) Have higher dielectrie strength b) Of large size have higher dielectric strength c) Have lower dielectric strength as compared to pure liquids d) None of the above 9. Peak to peak ripple is defined as a) the difference between average de voltage and peak value b) the difference between maximum and minimum de voltage c) the difference between maximum ac and average dc voltages d) the difference between ac (rms) and average de voltages 10. In a Cockroft-Walton circuit, input voltage 100 kV load current 25 mA, supply frequency 100 Hz, each capacitor 10 nF. The optimum no. of stages for maximum output voltage is a) 1 b) 2 c) 10 d) 35arrow_forwardonly 9arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Delmar's Standard Textbook Of ElectricityElectrical EngineeringISBN:9781337900348Author:Stephen L. HermanPublisher:Cengage LearningElectricity for Refrigeration, Heating, and Air C...Mechanical EngineeringISBN:9781337399128Author:Russell E. SmithPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337900348/9781337900348_smallCoverImage.jpg)
Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:9781337900348
Author:Stephen L. Herman
Publisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337399128/9781337399128_smallCoverImage.gif)
Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning