![]() |
Intro to Scientific ComputingPHYS 27/193Physics Department University of the Pacific |
Suppose you and a friend are confronted with the following circuit in lab (likely you did this in the 3rd grade, or in PHYS 55).
You have a variable (i.e. at your control) current source, I, in a simple circuit with a resistor, R, whose value you do not know. However, as your friend varies the current, you are able to measure the voltage, V, across the resistor. As you know from your studies of electromagnetism, the voltage should be related to the current by Ohm's Law:
V = IR
Thus, if you plot your measurements of V versus I, you could find the resistance, R, from the slope of the data.
Here's the data. You can also download the file iv.dat to save you typing it in by hand (right-click, Save Link).
|
Before we begin, notice that the data file has
You can see that the voltage rises sort of linearly with increasing current.
What is your estimate (write it down or remember it for later)?
Let's try to fit a line to the data "by hand".
Define a linear function: B
(that's a line, right?)f(x) = a*x + b
Since the first data point is (0,0), and since Ohm's law has no constant term, let's set:
Knowing this, we could just as easily defined f(x) = a*x.
To set a, take your in initial guess from above:
gnuplot>a = your estimate from above # this is a number!
Now, plot the data and your function together.
gnuplot> |
How well does your guess match?
You can refine your guess by typing a new value for a, and doing replot.
Do you see how the line changes as you change the slope, a?
gnuplot> |
The syntax of the fit command is:
Here
When you run the
...
After 3 iterations the fit converged.
final sum of squares of residuals : 231.793
rel. change during last iteration : -8.79516e-08
degrees of freedom (FIT_NDF) : 10
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 4.81449
variance of residuals (reduced chisquare) = WSSR/ndf : 23.1793
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = 130.403 +/- 2.454 (1.882%)
correlation matrix of the fit parameters:
a
a 1.000
This contains a wealth of statistical information about your data and the
level of its randomness, most of which is beyond the scope of this course.
However, it's nice to know that it's there as you learn more about statistics
in subsequent courses. We'll look at these things a little bit soon.
The important line is:
Final set of parameters Asymptotic Standard Error ======================= ========================== a = 130.403 +/- 2.454 (1.882%)
This is your result: you have analyzed your data and found the resistance, R, to be about 130 Ohms, plus or minus 2.5 Ohms.
Whoa...
Next: Fitting Data II