Physics 222 Assignment 6

Due March 14


Only do this assignment if you are not doing a project.

Please turn in this assignment by emailing them to me . Please use the subject of "Physics 222 HW6" for this assignment (if you use the link above, the subject will be added automatically). Please attach the source code to any programs that you write for this assignment. If you write more than one program, attach each separately. When answering the questions themselves feel free to answer directly in the body of your message (or attach your answers).

  1. Least Squares Fit of Exponential Data

    In this problem , you will write a program to read in data from a file, calculate a least square fit of the data, and then plot the resulting data and fit. The method of doing least squares fits is outlined in detail in Chapter 8 of Taylor's Introduction to Error Analysis, p. 194-6 and p.201. Most of you should have a copy. If you don't have a copy then borrow one.

    For this problem, I will provide you with two data files (Data set 1 and Data set 2), though if you have data from previous lab work, feel free to use one data file that you provide and one that I provide. In the provided data file, the first line will be the title of the graph, the second line will be the x-axis label for the graph, the third line will be the y-axis label for the graph, and the fourth line will be the number of data points in the plot. The lines after that will be the x data, the y data, and the uncertainty in y. For this program you can assume that the x uncertainty is negligible.

    As explained by Taylor, to fit an exponential, you take the natural log of your y data and fit that a line to log y versus x. The fit that you are doing is to the equation:

     ln y = ln A + Bx 
    which is equivalent to
    y = AeBx
    where A and B are the fit parameters. To take into account the fact that the uncertainties will vary for y, we will use equations 8.37-8.39 on page 201 in Taylor's book to find A and B. Look there for the equations and how to use them. Note that in this case, as is explained on page 196 of Taylor, the uncertainty of y (σ) should be replaced by the uncertainty of the ln y which is σ/y (equation 8.34). Also note that in this case equation 8.37 will give you ln A, not A itself.

    The calculations for this program require taking many sums, so you should write a function to calculate sums. Your function would take an array and integer standing for its size, and return the sum of the components of the array.

    The calculations also require multiplying the elements of two arrays together to make a third array. You should write a function to do this as well. You would pass three arrays — the two that you will multiply and a third that will hold their product — and an integer holding the size of the arrays to your function. Your function should then loop through and put the product of your first two arrays in the third array. As well as calculating the fit parameters A and B, you should calculate the uncertainties in A and B using equations 8.12 and 8.15-8.17. --> Your program should print out the values of the constant , as well as the plot described below.

    Send me postscript copies of plots of both of your sets of data including line for your least squares fit, as well as the output specified above. For your plots, use the PLPlot library again. You can use the pls.line method of PLPlot to make the lines. You should plot the points with error bars - look at the plerrx and plerry functions "(man plerrx" and "man plerry"). For the plots, you can either make semi-log plots using the axis option of plenv (see "man plenv"). Or, you can use linear axes, but then explicitly plot the fits as exponentials.

    1. Turn in copies of your programs results from running on each of the two files and copies of your plots for each input file.
    2. Compare your fit parameters to what Linfit gives you for the data sets. Comment on any differences.
  2. Review Questions from book: