Normal distribution for $Z=X+Y$ where $X,Y$ are both normally distributed

completing-the-squaremarginal-distributionnormal distributionprobability

I need to find the probability distribution for $Z = X+Y$ where $X \sim \mathcal{N}(x_0,\sigma_x^2)$ and $Y \sim \mathcal{N}(y_0,\sigma_y^2)$. $X$ and $Y$ are independent.

In order to do this, we use marginalization:

$$p(z) = \int p(z,x,y) dxdy = \int p(z|x,y)p(x,y)dxdy =\int p(z|x,y)p(x)p(y)dxdy $$

Notice now that $p(z|x,y) = \delta(z-(x+y))$
because of our definition. Therefore, we can evaluate one of the integrals, i.e. for $y$, to be left with:

$$\int p(x)p(y=z-x)dx \propto \int \exp\left(-\frac{(x-x_0)^2}{2\sigma_x^2}\right)\exp\left(-\frac{(z-x-y_0)^2}{2\sigma_y^2}\right)dx$$

For which we then have to complete the square for $x$ in the expression given by:

$$ \sigma_y^2(x-x_0)^2 + \sigma_x^2(z-x-y_0)^2$$

I have tried very long with trying to completing the square, but I'm getting lost in all the variables and would like some help into completing the square so I can continue solving the problem.

Thank you in advance.

Best Answer

We want to complete the square for:

$$ \frac{\sigma_y^2(x-x_0)^2 + \sigma_x^2(z-x-y_0)^2}{\sigma_x^2 \sigma_y^2}$$

After expanding and rearranging for $x$, we get:

$$\frac{x^2(\sigma_x^2+\sigma_y^2) -2x(x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2)+x_0^2\sigma_y^2+\sigma_x^2z^2-2zy_0\sigma_x^2+\sigma_x^2y_0^2}{\sigma_x^2 \sigma_y^2}$$

Factorizing out $(\sigma_x^2+\sigma_y^2)$ for the first two terms gives us:

$$\frac{(\sigma_x^2+\sigma_y^2)\left(x^2 -2x\left(\frac{x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2}{(\sigma_x^2+\sigma_y^2)}\right)\right)+x_0^2\sigma_y^2+\sigma_x^2z^2-2zy_0\sigma_x^2+\sigma_x^2y_0^2}{\sigma_x^2 \sigma_y^2}$$

Which then after completing the square for $x$ yields:

$$\frac{(\sigma_x^2+\sigma_y^2)\left(x- \left(\frac{x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2}{(\sigma_x^2+\sigma_y^2)}\right)\right)^2+x_0^2\sigma_y^2+\sigma_x^2z^2-2zy_0\sigma_x^2+\sigma_x^2y_0^2 - \left(\frac{(x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2)^2}{\sigma_x^2+\sigma_y^2}\right)}{\sigma_x^2 \sigma_y^2}$$

Where we now focus on the last terms in the expression above found in the numerator:

$$x_0^2\sigma_y^2+\sigma_x^2z^2-2zy_0\sigma_x^2+\sigma_x^2y_0^2 - \left(\frac{(x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2)^2}{\sigma_x^2+\sigma_y^2}\right) = $$

$$ = \frac{(x_0^2\sigma_y^2+\sigma_x^2z^2-2zy_0\sigma_x^2+\sigma_x^2y_0^2)(\sigma_x^2+\sigma_y^2)-(x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2)^2}{\sigma_x^2+\sigma_y^2} = $$

$$\require{cancel} = \frac{x_0^2\sigma_y^2\sigma_x^2 + \cancel{x_0^2\sigma_y^4} + \cancel{\sigma_x^4 z^2}+ \sigma_y^2\sigma_x^2z^2-\cancel{2zy_0\sigma_x^4}-2zy_0\sigma_x^2\sigma_y^2 + \cancel{\sigma_x^4y_0^2}+\sigma_x^2\sigma_y^2y_0^2-\cancel{x_0^2\sigma_y^4}-\cancel{z^2\sigma_x^4}-\cancel{y_0^2\sigma_x^4}-2zx_0\sigma_y^2\sigma_x^2+2x_0y_0\sigma_x^2\sigma_y^2+\cancel{2zy_0\sigma_x^4}} {\sigma_x^2+\sigma_y^2} = $$

$$ = \frac{z^2\sigma_x^2\sigma_y^2 - 2z\sigma_x^2\sigma_y^2(y_0+x_0)+\sigma_x^2\sigma_y^2(x_0^2+y_0^2+2x_0y_0)} {\sigma_x^2+\sigma_y^2} = $$

$$ = \sigma_x^2\sigma_y^2\frac{(z-(x_0+y_0))^2} {\sigma_x^2+\sigma_y^2}$$

Substituting this back into our original expression we get:

$$\frac{(\sigma_x^2+\sigma_y^2)\left(x- \left(\frac{x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2}{(\sigma_x^2+\sigma_y^2)}\right)\right)^2+\sigma_x^2\sigma_y^2\frac{(z-(x_0+y_0))^2} {\sigma_x^2+\sigma_y^2}}{\sigma_x^2 \sigma_y^2} = $$

$$ = \frac{(\sigma_x^2+\sigma_y^2)\left(x- \left(\frac{x_0\sigma_y^2+z\sigma_x^2-y_0\sigma_x^2}{(\sigma_x^2+\sigma_y^2)}\right)\right)^2}{\sigma_x^2 \sigma_y^2}+\frac{(z-(x_0+y_0))^2} {\sigma_x^2+\sigma_y^2}$$

The second term is the argument for one of our exponentials, and since it's independent of $x$, we'll be able to put it outside of our integrand as a factor. The first term will just be the integration of a pdf with respect to $x$, and so we will end up with a normal distribution for $z$ where $p(z) \sim \mathcal{N}(x_0+y_0, \sigma_x^2+\sigma_y^2)$ by observing the second term in the expression above.

Related Question