You will write Python code to read in the Pullman temperature data, and then form and solve normal equations to find a least squares fit of a polynomial to those data. After reading the data, the least squares part will be handled by a function you will write to do that. Your least squares function will require three arguments: the x-values where the data appear (years, in this case); the y-values of the data (temperatures in Fahrenheit degrees here); and the degree of the polynomial we are choosing to fit the data. It will return the array of values of the polynomial that was found to fit the data in the least-squares sense, as well as the r-squared value for the fit. Note that it will be written in a general way, so that it does not depend on this particular data file.
One way to do this is to form a matrix \(A\) whose columns are pointwise evaluations of the functions in a well-chosen polynomial basis for the space of degree \(n\) polynomials over your domain. Then you can form the normal equations and just solve. Be sure to print the condition number of \(A^TA\) along the way, using the cond() function. If you can find a good statistics package to do all this for you, go for it, but don't tell anyone else.
To emphasize, be sure to write the least squares function so that it is independent of the data file - it will be tested by reading in a different data file (with the same format) and seeing whether it gets the same numbers as I do.
You should use the results from your function to create a plot of the data points together with the fitted curve. A sample of such a plot is shown in Figure 1. You can whatever colors and markers you want, but be sure not to connect the dots on the data points.
You will email the Python script file to the instructor to turn the assignment in. The assignment is worth 25 points and is due in the instructor's email inbox by 9:00 AM on Thursday, 7 May.
Welcome to Math 583, Hacking Mathematics.