Department of Mathematics

Math 583: Mathematical Hacking


As usual, we recognize that this is a stupid way to approach a problem mathematically - it is just a fun way to make a point, and to use the linalg subpackage of scipy.

Use the data from (probably already on your computer) to write a Python script to do the following.

  1. It should average the flows in the last column of the data array by month, over all the years of the measurements. Store the result in an array of length 12. We denote that resulting vector \(y\).
  2. Choose a degree for a least-squares fit to the data.
  3. Form a matrix whose columns are the values of monic polynomials at the months of the study. I.e. if the degree of the polynomial fit is to be 2, then the matrix is: \[ A = \begin{bmatrix} 1 & 1 & 1\\ 1 & 2 & 2^2\\ 1 & 3 & 3^2\\ \vdots & \vdots & \vdots\\ 1 & 12 & 12^2 \end{bmatrix} \]
  4. Solve the normal equations \(A^TAc=A^Ty\). The array \(c\) contains the coefficients of the polynomial fit.
  5. Plot the months against the data \(y\) and the polynomial that resulted from solving the normal equations.

Assignment 1 is posted.

Department of Mathematics, PO Box 643113, Neill Hall 103, Washington State University, Pullman WA 99164-3113, 509-335-3926, Contact Us
Copyright © 2009-15 Kevin Cooper