(This is a post for CS320 Boston University.)

Please take a look at this. Get yourself familiar with matirx operations and high order functions. Also, it is a good example of functions/closures.