Astro 503, Spring 2006 Homework #6: Due Feb 14, 2006 1. Alter the Matrix3x3 class that you constructed last week so that it will cache its inverse, i.e. the calculation of the inverse will only be done once as long as the elements of the matrix are not altered. Then test with a driver program. 2. Alter the Table class used in lecture this week so that, a) on construction of the table, you can indicate whether the table should implement linear interpolation or the cubic spline interpolation described in Numerical Recipes. Your class will slightly alter the definition so it begins with: class Table { public: enum Interpolant {Linear, Spline}; Table(const string& filename, Interpolant ii=Linear); ... and then when it is used in main(), it'll be created like this: Table a("mytable.dat", Table::Spline); b) The findIndex() routine will start its search from the value of the last argument, implement the "upwards" binary search as described in the Numerical Recipes (and implemented in their "hunt.c" routine). 3. (This one can be done collaboratively). Write a program called "rpnstream" which takes, on its command line, a set of RPN arithmetic instructions (explained below) and then applies them to every line of its standard input, producing 1 line of standard output for every line of input. What's RPN (reverse Polish notation)? It's a very efficient way to describe a series of arithmetic operations. Consider a set of numbers to occupy a "stack" of values at positions 0, 1, 2. When you start reading a fresh line, the stack is empty. The program then executes a series of commands. The commands can be any of the following: r read the next numerical value from the stack and push it into position 0. Any values already on the stack get pushed into the next-highest slot, e.g. 0->1, 1->2, etc. = print (to cout) the value at the bottom of the stack d roll the stack down (pop) by discarding value in posn 0, then moving 1->0, 2->1, etc. + add the 2 values at the bottom of the stack, replacing them with the sum, i.e. (1+0)->0, 2->1, 3->2, etc. - subtract the 2 values at the bottom of the stack, replacing them with the sum, i.e. (1-0)->0, 2->1, 3->2, etc. *,/ multiply and divide, in analogy to +/-. As an example, if your comand line says % rpnstream r r - r * = then your output will end up being (v1-v2)*v3, where vn is the nth value on the input line. So if your input file is 3 5 -1.5 1.5 0.5 4. Then your output will be 3. 4. Hope that's clear, for those of you who've never used an HP calculator. Look up "RPN" on Wikipedia for more explanation (or ask me). Obviously you will have to write some kind of "parser" that interprets the command-line arguments into a set of instructions, and then a processor that executes them on an istringstream created from a line of input.