PHYS2010: Coupled Oscillators
Single Pendulum Analysis
NB: Read the instructions given before each grey code cell, edit what you need to, and run it. Make sure you run the cells in order so there's a higher chance they'll work!
When you're done, save/screenshot/print any graphs you've made and any fitted parameters that you find, and include them in your lab notebook/report.
Step 1: We need scientific packages to do the calculations and fitting that we want to do, so let's import Numpy, Pyplot from Matplotlib, and curve_fit from the relevant python packages.
Read function
Step 2: To be able to import your experimental data from the file from Picoscope, you will need to define the function to read the pico file format (a .csv file with some header information). Run the cell below to define it.
Fit function
Fitting a function to some data is a delicate art form. You need to understand what you're trying to do and what the algorithm you're using does. In this case we are using the curve_fit function from scipy.optimize. Take a look at the documentation of the function by googling curve_fit python - googling functions and reading their documentation is a vital skill for a programmer.
In a nutshell, any fitting algorithm minimises the difference between the data points and a given function. The function you use must have a set of free parameters that the algorithm changes in order to minimise the differences.
You typically have to provide the algorithm with a "starting point" for the parameters, so that the algorithm knows roughly where the expected optimum parameters are. Minimising nonlinear functions in multidimensional spaces is very tricky and you can easily fall in a "local minimum", that is a set of parameters which are not optimal, but that are better than any parameters in their neighbourhood.
Step 3: Run the next cell to define a function that fits a curve/function (generically called 'myFunc') to a data set of x's and y's, given a set of starting parameter values.
You can just run this.
Step 4: Define a particular function based loosely on Equation (2a) in the lab notes that describes a single pendulum's displacement as a function of time. The function should take as arguments: an array of time values, t, amplitude A, angular frequency omega, phase shift phi and a non-zero offset C.
You should have gathered displacement data for an oscillating, single pendulum for at least 8 different lengths. For each length, there is a different .csv file containing the data.
You are going to read in the pico file for a given length and fit the harmonicOscillator function to the experimental data, using your picoscope measurements of amplitude, phase and period as starting estimates for the fit. The fitted angular frequency parameter will a more accurate estimate of the period of the pendulum at that particular length.
Once you have repeated this for all the lengths of the single pendulum, you can plot a graph of as a function of and compare it to the relationship expected for an ideal, simple pendulum (Equation (1) in the notes).
Step 5: Load in your first .csv file, set the starting parameters for the curve fit from your experimental results, perform the curve fit and obtain a better estimate of the angular frequency and its uncertainty.
Step 6: Next plot the data and the optimal curve found by the algorithm together to see how good the fit is. If you're satisfied with the fit continue to Step 7!
Step 7: Save your new fitted estimate of period and its uncertainty so you can use them later.
Step 8: Repeat Steps 5-7 for every length of the single pendulum you tested until you have a complete set of fitted periods, their associated uncertainties and all the corresponding pendulum lengths and their uncertainties.
Length 2
Length 3
Length 4
Length 5
Length 6
Length 7
Length 8
Testing the relationship between period and length
Now that you've plotted and fitted all those curves, let's group together all the periods (both experimental and fitted) and the lengths, and see if we can find a relationship between them.
Theoretically, from Equation (1), the period of oscillation of a simple pendulum is proportional to the square root of the pendulum's length. To fit this using polyfit and polyval, it's easier to change it to being proportional to . According to Equation (1), this should be a linear relationship.
Step 9: Use Numpy's polyfit and polyval to find the best fitting parameters to your T and L experimental data, given Equation (1). Do the same for the fitted period values of as a function of . Make sure to estimate the uncertainty in the fitted parameters by setting the cov flag to "True". Plot the resulting fit. Is a linear trendline required for a good fit, or some other polynomial?
Step 10: Print the fitted parameters and their uncertainties and record them in your lab book.
Is this what you expected? Continue with the questions in your lab notes and discuss. If you have time, you could try modifying the above for a different degree polynomial fit (i.e. quadratic rather than linear) if the linear fit doesn't look that great.