# Simulation of P(X + Y < 1) in matlab [closed]

I am trying to solve the following problem, but I do not know how to go about it.

Let $$X \sim \mathcal{U}(0;1)$$ and $$Y \sim \mathcal{Exp}(1)$$ be independent. Simulate in MATLAB how you can find the probability $$\mathbb{P}[X + Y < 1]$$.

Thank you.

• Something like: take a large sample of $X$; take a similarly large sample of $Y$; add them together pointwise; find the proportion of the sums that are less than $1$. In R you could try something like X<-runif(10^6);Y<-rexp(10^6,1);mean(X+Y<1) – Henry Mar 26 at 1:36

I think you have learned that $$-\ln(U)$$ where $$U$$ is uniform on $$(0;1)$$ follows an $$\mathcal{Exp}(1)$$ law. Therefore, it will be a privilegized way to simulate such a distribution.

Here is a Matlab program that gives the result :

n=100000;
X=rand(1,n);
Y=-log(rand(1,n));
Z=X+Y;
U=Z<1;
P=mean(U)
hist(Z,60);% optional !


($$Z$$ is a boolean array with entries $$0$$ (resp. $$1$$) if the condition is not fulfilled (resp. fulfilled) ; the number of "ones" is the number of successes).

The numerical result $$P \approx 0.3678$$ coincides very well with the theoretical result $$e^{-1}$$...

... that can be computed using the underlying density of Random Variable $$Z=X+Y$$ which is the convolution of the densities of $$X$$ and $$Y$$, i.e. :

$$(\text{for} \ x>0) : \ \ f_Z(x)=e^{-x}(e^{-min(x,1)}-1)$$

Here is a histogram of the simulation of $$Z$$ :

• Thanks, makes sense. – FilipPPPILA Mar 27 at 4:08