Maths 162 Semester 2, 2020
Assignment 4: Randomness and Modelling
1. In this problem, you’re going to simulate the amount of rainfall in Auckland! Specifically,
you’re going to write a MATLAB function named rainfall that takes in as input a number
of days n and outputs the total amount of rain simulated over those n days. To do this: first,
initialize a set of values totalrain = 0 and rainchancem = −25. Then, do the following n
times, once for each day simulated:
Create a random value israin by using a normal distribution with mean rainchancem
and standard deviation 50.
If this value is negative, it does not rain on that day. If so, add +1 to rainchancem to
increase the odds that it rains on the next day.
If this value is nonnegative, create a random value dayrain by using a normal distribution
with mean 10 and standard deviation 8. If this value is nonnegative, this is the amount
of rain on that day; add this value to totalrain. (If this value is negative, do not add
it to totalrain, as negative rain doesn’t make sense.)
If dayrain was positive, add −2 to rainchancem to decrease the odds that it rains on
the next day. Otherwise, add +1 to rainchancem.