Question

Write a function that generates a random number which is uniformly distributed between -1 and 1and varies linearly on the interval [-3, -2] and [2, 3], being zero elsewhere. A plot of this distribution is shown below. Use your code to compute numerically the mean and variance of such a distribution. What is the mean?

Fig: 1

Fig: 2

Fig: 3

Fig: 4