- Available 2016-09-14
- Due 2016-09-23, 17:30

### Overview

The goals of this assignment are are to review the basics of matrix and vector arithmetic, and to learn the basics of JavaScript.

### Before you start.

See the assignment notes for the required repository structure. You may also want to refer to the lab guide.

Since you'll need to know a little git to hand in this assignment, you may want to work through Lab 1 in advance.

This assignment must be your own individual work. It may surprise you to learn that profs are quite good at finding the same code on the internet you found. The consequences are not fun.

### Software Environment

This assignment will be be done using standard JavaScript in a browser. No extra frameworks or libraries are permitted.

### Tests

You should write unit tests for each function and method. Be sure to think about what the corner and error cases are. A substantial part of the marks for this assignment will be for the quality of your tests. Your tests should focus on the algorithmic aspects (i.e. do the matrices to be multiplied have the appropriate dimension), rather than JavaScript specific issues like "did the user actually pass us an array of numbers". Make sure you document what you are not testing for.

### Vector functions

For the first part of the assignment, represent (arbitrary dimensional) vectors as JavaScript arrays. You are to write functions

- dotProduct(vec1,vec2) -> number
- crossProduct(vec1,vec2) -> array

The latter should throw an exception in cases when cross product is not defined. For simplicity, you can assume cross product is only defined in 3 dimensions.

### Matrix methods

Write a matrix class. Note that JavaScript classes are based on prototypes, which is quite different than e.g. Java or Python. Your class should support the following methods

- constructor Matrix([ [number, number, number... ], [number, number, number... ], [number, number, number... ] ...])
- height -> number
- width -> number
- elem(int,int) -> number
- toString -> string
- transpose() -> Matrix
- matMul(matrix) -> Matrix
- vecMul(array) -> array

All of your methods should do appropriate error checking and throw exceptions cases on bad input (and document what kinds of checks are not done).

### Deliverables

Your assignment directory in coursegit should include

vector.js | vector functions as above |

vector-test.js | tests for vector functions |

matrix.js | matrix objects as above |

matrix-test.js | tests for matrix objects |

### Evaluation

- 3 marks for completeness, correctness of vector part
- 7 marks for compeleness, correctness of matrix part
- 6 marks for unit tests
- 4 marks for code style and documentation