Computer Science 15-100 (Sections T & U), Spring 2008
Notes:  Bonus Lecture #2

2d Arrays, Matrix Inversion, Power Sums


Logistics

  1. Bonus points
  2. Due date
  3. What to submit
  4. Project quiz

Bonus Projects

You may do any, or all (or, of course, none!) of these.  Actual hours credited will depend on the amount and quality of work submitted, and to some extent on the timesheets.  In any case, there is a limit of 10 hours total bonus for this activity, and that includes the 2-to-4 hours of bonus you already received for attending the lecture.

The main project for this lecture is just to reproduce the code we wrote during the bonus lecture, along with test code to verify it works properly.

Part 1:  Write a Java program that takes a square array "a" and returns a new array "aInverse", where "a" times "aInverse" equals the identity matrix I.  If "a" is not invertible, return null.

Part 2:  Using part 1, write a Java program that takes N linear equations and N unknowns, and returns an array of size N with the unique solution to these equations, or null if no such unique solution exists.  Note that the parameters to this method should be an n-by-n array, "A", and an n-by-1 array "b", so you are solving the matrix equation Ax = b.  Recall that you do this by finding A-1  (A's inverse).  Then if Ax = b, then x = A-1b.

Part 3:  Using part 2, write a Java program that takes N points (represented as two arrays of doubles, x and y, both of size N), and returns an array holding the coefficients of a degree (N-1) polynomial that fits those N points.  For example, given 2 points, return the line (that is, the degree 1 polynomial) that fits the two points.  Given three points, return the coefficients of the quadratic that fits the 3 points.  And so on.

Part 4:  Using part 3, write a Java program that takes a small positive integer p, and returns an array containing the coefficients of the (p+1)-degree polynomial f such that f(n) = 1p + 2p + ... + np.  For example, if p=1, you should return the array {0.5, 0.5}, as 11 + 21 + ... + n1 = 0.5n2 + 0.5n.

Part 5:  Even more bonus: modify the preceding programs so that they operate over exact-valued Ratios rather than approximate-valued doubles.  To do this, create a Ratio class that has instance variables "numerator" and "denominator".  Then your answers will be given as ratios rather than approximate doubles.  So, in the previous example, given p=1, you should return the array {1/2, 1/2}, as 11 + 21 + ... + n1 = (1/2)n2 + (1/2)n.

Finally, there is always the option to create your own bonus project on this material.  Just be sure to run it by the course instructor first, to ensure that it is bonus-worthy!


carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem