Consider independent random variates $X_0, X_1, . . .$ each uniformly distributed on the support $[0, 1)$
Let's say $Y = X_0 + X_1$, where $X_0$ and $X_1$ are independent uniform random variables with range $[0,1)$
I then derived the following PDF to describe the distribution of the sum $Y = X_0 + X_1$ using a convolution.
$$f(y) = \begin{cases} y & \text{for $0 < y < 1$} \\ 2-y & \text{for $1 \le y < 2$} \\ 0 & \text{otherwise.} \end{cases}$$
I want to check the derived distribution against a numerical calculation/histogram (in python)
Any help is appreciated
import numpy as np
import matplotlib.pyplot as plt
X_0 = np.random.uniform(0.0,1.0,1000)
X_1 = np.random.uniform(0.0,1.0,1000)
Y = X_0 + X_1
#Plot 3 normalised histograms
plt.hist(X_0,bins=100,density=True)
plt.hist(X_1,bins=100,density=True)
plt.hist(Y,bins=100,density=True)
#desired distribution
if 0<Y<1:
F_Y = Y
if 1<=Y<2:
F_Y = 2 - Y
if Y < 0:
F_Y = 0
plt.plot(Y,F_Y)
plt.title('desired distibution')
plt.show()