**How can we compile and test the code?**You can compile

`Predictor.java`

and`ConstPredictor.java`

by typing$ javac *.java

If you try to compile`hw1.java`

the compiler will give various error messages because it will be looking for the other five classes (which you will be writing in the course of the assignment). Fortunately, you don't have to compile`hw1.java`

because the compiled version`hw1.class`

is provided for you. The best idea is to put`hw1.java`

in a separate directory and use it only as a reference; then you will not be bothered by the error messages. You can run and test the code by typing$ java hw1 < s01.in > s01.out $ diff s01.out s01.tgt $

The`diff`

utility looks for differences between two files. The fact that it returns your prompt to you without producing any output is a good sign, because it tells you that the actual output`s01.out`

is the same as the target output`s01.tgt`

. As you write more and more of the required classes, you should be able to compile them and test them on more of the sample inputs.You can alternatively type the input directly from the keyboard, followed by the

`Return`

or`Enter`

key, followed by`^D`

or`^Z`

(hold down the Control key and press the`D`

or`Z`

key, depending on your operating system), e.g.$ java hw1 2 2 ^D Constant [2 2 2 2 2] Arithmetic [2 2 2 2 2] Geometric [2 2 2 2 2] $

Notes:- typing the square brackets in the input is optional,
- if you have not yet implemented the Arithmetic or Geometric predictor classes, only the Constant line of the above output will be produced.

**If we generate more inputs, how will we know what the outputs should be?**The compiled C program

`hw1test`

has been provided for this purpose. You can run it on most of the lab machines. In theory, it should function exactly the same way as`java hw1`

, e.g.$ hw1test 1 2 3 ^D Arithmetic [4 5 6 7 8] Quadratic [4 5 6 7 8] $

Similarly,`hw1btest`

has been provided for testing the bonus challenge.**Can you give us some hints on how to compute the parameters?**`QuadraticPredictor`

Write down equations for the first three items in the sequence

`u0`

,`u1`

and`u2`

in terms of`a`

,`b`

,`c`

. Solve these equations simultaneously to find expressions for`a`

,`b`

,`c`

in terms of`u0`

,`u1`

,`u2`

.`HomogeneousPredictor`

| u2 | = | u1 u0 | | a |, so | a | = | u1 u0 |-1 | u2 | | u3 | | u2 u1 | | b | | b | | u2 u1 | | u3 |

`RecurrentPredictor`

| u2 | | u1 u0 1 | | a | | a | | u1 u0 1 |-1 | u2 | | u3 | = | u2 u1 1 | | b |, so | b | = | u2 u1 1 | | u3 | | u4 | | u3 u2 1 | | c | | c | | u3 u2 1 | | u4 |

Look up formulas for inverting`2x2`

and`3x3`

matrices. (Note: remember to check the determinant is not zero before dividing!)**Should**`[0 0 0]`

be regarded as a Geometric sequence?After some discussion we have decided that

`[0 0 0]`

should**not**be regarded a Geometric sequence, because the parameter r is not uniquely determined (Note:`hw1test`

has been updated accordingly). However, this particular case will not be tested in the auto-marking.**I tried running**`hw1test`

, but it says "Permission denied" ?In that case, you need to change the file permissions:

$ chmod a+x hw1test

**What can we do about precision and roundoff errors?**Several of you have pointed out that your programs, and even

`hw1test`

, sometimes give erroneous answers because of roundoff errors.

The best way to handle it is this: instead of checking if a number is zero, or if two numbers are equal, you should check using`Math.abs()`

whether the absolute value of the number (or the difference between two numbers) is less than some very small constant (for example, 0.000000001). The binary file`hw1test`

has now been modified to reflect this functionality - please download it again if necessary.

Here is an example of what the output**should**be:$ hw1test 1.2 1.3 1.5 1.9 2.7 ^D Homogeneous [4.3 7.5 13.9 26.7 52.3] $

**Can you give us some hints for the Bonus Challenge ?**Yes, we have now provided a hints page for this purpose.

**My program gives a different output for the roundoff example, but I still can't see what's wrong with it ?**In that case, test your program on these two inputs:

[12 13 15 19 27 ] [1.2 1.3 1.5 1.9 2.7]

Obviously, your program should produce identical output but with the decimal point in a different place. If it doesn't, there is a problem somewhere.