Let us take a look at the following random walk:
with
You can see this as a combination of two independent univariate normal distributions, one on the X axis and one on the Y axis, and both with a mean 0 and a standard deviation of 1.
Write a function randomwalk()
that takes an argument n
and that calculates the first n steps in a two-dimensional random walk. Return the positions at the different timepoints as a matrix with the columns names x
and y
. Be sure to include the necessary checks and messages for the user.
There is no need to generate an actual nx2 matrix since Dodona will already do that.