Expand All Collapse All


General
I’m using IntelliJ. Which project folder should I use?
We provide an IntelliJ project folder for each assignment. Click the Project at the top of the page to download.
Generalized harmonic numbers
Can I use a while loop instead of a for loop?
No. If the assignment specification says to use a for loop, then use a for loop!
What's the Java operator for exponentiation?
Sorry, Java (and many other programming languages) reserve the ^ operator for exclusive or, not exponentiation. Use Math.pow(x, y).
Band matrices
Can I use arrays?
No. On this assignment, arrays are neither permitted nor necessary.
How can I determine the distance of element (i, j) from the main diagonal?
Hint: use Math.abs().
Random walk
How can I generate a random direction?
Use Math.random() and the idiom from lecture to generate a random integer between 0 and 3.
What is the Manhattan distance between two points (x0, y0) and (x1, y1)?
It's the sum of the absolute differences of their Cartesian coordinates: \(|x_0 - x_1| + |y_0 - y_1|\).
Random walk statistics
My program takes a long time when r and trials are large. Why?
It's doing a lot of computation. For example, when r = 160 and trials = 100,000, the Monte Carlo simulation performs more than 1.5 billion steps (100,000 random walks, with each random walk averaging more than 15,000 steps).