Unformatted text preview:

Appendix C: fit & plot ExampleThis appendix provides a longer example using fit and plot to analyze and display data.The example data set is a recapitulation of work done in your last PHYS 200 lab on a.c.circuits and resonance: the current flowing in a LRC circuit is measured as a function of thefrequency f of the a.c. voltage sour ce. You may recall1that because of frequen cy dependentreactances, a series LRC circuit has a current, I, that depends on frequency. You can followalong with this example if you grab a copy of the data file. At the linux % promp t type:% cp /usr/local/physics/help/LRC.dat .and a copy of the datafile should appear in your current directory (which is called “.”).Similarly you can get a copy of the actual commands used in the below example by:% cp /usr/local/physics/help/LRC.com .Theoretically the current as a function of frequency should be given by:I =VrR2+12πfC− 2πf L2(C.1)Start the pr ogram fit by typing to the linux % prompt:% fit*1or see Electrical Measurements Review particularly Fig. 3.1 on page 800.01 µFVrms = 2.4 VA47 ΩKEITHLEY 196WAVETEK 238.6 mHFigure C.1: This series LRC circuit was constructed. A Wavetek 23 function generatorprovided a GPIB-controlled sine wave; a keithley 196 reported the resulting current viaGPIB. The program LRC.f controlled the data collection.179180 Appendix C: fit & plot ExampleThe program responds with its own p rompt: * . We need to tell fit the name of the datafilewe want to analyze and then read in that data:* set file=LRC.dat* readfreq(Hz) I(A) dI(A) by default this line ignored!READ Done.The first line of the file (freq(Hz). . . ) is simply echoed back as a way of confirming thatyou are reading the intended file. It should be noted the file LRC.dat was written in th edefault form, with x values in the first column (XCOL=1) , y values in the s econd column(YCOL=2), and y-error values in the third column (YECOL=3). Next we need to tell fit wh atfunction should match the data.* set f(x)=k1/sqrt(k2^2+(1/(2*pi*k3*x)-2*pi*k4*x)^2)where V = k1, R = k2, C = k3, L = k4and f = x. For nonlinear fits we must always givestarting parameter estimates. In this case that’s easy as I measured the component valueswhen I built the circuit:* set k1=2.4 k2=47 k3=1e-8 k4=.0086Next I command a fit: please adjust the parameters k1–k4to achieve the smallest possiblereduced χ2:* fitEnter list of Ks to vary, e.g. K1-K3,K5 k1-k4FIT finished with change in chi-square= 1.5258789E-046 iterations usedREDUCED chi-squared= 3.790897 chi-squared= 363.9261K1= 2.262721 K2= 190.7750 K3= 0.9930065E-08K4= 0.8230284E-02Display covariance/curvature matrices? No, Screen, File [N,S,F]The result is pretty much as expected: reduced χ2is high, but in the usually acceptablerange, the p arameters are close to my original guess, with the exception of k2= R. Onreflection even R is OK as the inductor itself has resistance (77.8 Ω) and according toFig. 3.1 on page 80, the function generator also has an internal 50 Ω resistor. Thus:47 + 77.8 + 50 = 167.8 Ω should have been expected. Currently fit is asking if I want tolook at the covariance matrix, but I’ll delay replying No, Screen, or File u ntil I look at thefitted curve.I start another terminal to display, using the program plot, what the fitted curve lookslike: at the linux % prompt I type:Appendix C: fit & plot Example 181% plotA new blue terminal (labeled plot.exe) pops up with its own * prompt. Exactly as withfit I must tell the program the name of the datafile and then read in the data:* set file LRC.dat* readfreq(Hz) I(A) dI(A) by default this line ignored!READ Done.The x-data (frequency) ranges from 10000 to 30000; y-d ata (current) ranges from .002 to.012. I could set by hand those ranges (e.g., XMIN=10000), but its much easier to have theprogram make what it thinks are reasonable choices using th e command:* scaleI could now draw a border and display the datapoints, but first I tell plot the proper axeslabels:* set xlabel=’Frequency (Hz)’ ylabel="RMS Current (A)" title=Resonance* border* dpointPlot is to use exactly the same function as fit:* set f(x)=k1/sqrt(k2^2+(1/(2*pi*k3*x)-2*pi*k4*x)^2)and I can copy&paste2from the fit screen the values fit found for those parameters:* set K1= 2.262721 K2= 190.7750 K3= 0.9930065E-08* set K4= 0.8230284E-02Then I can have plot display that function cur ve and print a hardcopy:* fcurve* pcopy2Warning rep eated: Ctrl C kills n ot copies; highlight and middle-mouse for copy182 Appendix C: fit & plot Example10000 15000 20000 25000 30000.012.010.008.006.004.002ResonanceFrequency (Hz)RMS Current (A)If I go back to the fit screen and type s in answer to th e question about matrices:Display covariance/curvature matrices? No, Screen, File [N,S,F] sResults of a fit to the functionf(x)=K1/SQRT(K2^2+(1/(2*PI*K3*X)-2*PI*K4*X)^2)at 15:15 on 13-MAY-2009found a REDUCED chi-square of 3.790897 and a chi-squared of 363.9261using the following parameter estimatesK1= 2.262721 K2= 190.7750 K3= 0.9930065E-08K4= 0.8230284E-02and 100 data points at row 2 in the file:LRC.datBelow are displayed the covariance matrix = inverse curvature matrix and thecurvature matrix = .5 * Hessian = .5 * matrix of 2nd partials of chi-squaresee Numerical Recipes 15.5-15.6 for a discussion of these matricesMatrix form: K1 K2 K3 K4K1K2K3K4COVARIANCE MATRIX:-.55E+01 -.46E+03 0.24E-07 -.20E-01-.46E+03 -.39E+05 0.20E-05 -.17E+010.24E-07 0.20E-05 -.11E-15 0.87E-10-.20E-01 -.17E+01 0.87E-10 -.72E-04CURVATURE MATRIX:0.37E+06 -.12E+04 0.34E+14 -.34E+08-.12E+04 0.83E+01 -.54E+11 0.63E+050.34E+14 -.54E+11 0.53E+23 0.56E+17-.34E+08 0.63E+05 0.56E+17 0.76E+11Appendix C: fit & plot Example 183The error results are a total disaster! The usual rule is that the error in a parameter is givenby the square root of the diagonal element of the covariance matrix. Thus (supposedly):δk1=p−.55 ×101(C.2)δk2=p−.39 × 105(C.3)δk3=p−.11 × 10−15(C.4)δk4=p−.72 × 10−4(C.5)Clearly this is some sort of nonsense as the errors cannot be imaginary. Fu rther note thatin every case |δki| ∼ ki.A hint about what’s going on is gained by making a different starting guess for the valuesof the parameters:* set k1=240 k2=.47 k3=1e-7 k4=.00086Fit results show the same reduced χ2, but with radically different parameters:REDUCED chi-squared= 3.790896 chi-squared= 363.9260K1= 0.2419768 K2= 20.40159 K3= 0.9285606E-07K4= 0.8801518E-03There is a curve of (L, R, C , V ) values that produces exactly the s


View Full Document

CSBSJU PHYS 370 - PHYS 370- fit & plot Example

Download PHYS 370- fit & plot Example
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view PHYS 370- fit & plot Example and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view PHYS 370- fit & plot Example 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?