A complicated integral that Mathematica can’t compute

closed-formgaussianintegrationprobabilityprobability distributions

I have a very complicated distribution function of which I want to find the expected value.

The distribution I got for a function having the cosine of the samples taken from a Gaussian distribution.

$$ y = \cos(x) $$

Where $x$ values are drawn from a Gaussian distribution and we assume $x \in [-\pi, \pi]$.

$$ p(x) = \frac{1}{\sqrt{2\pi\sigma_x^2}}e^{-\frac{(x – \mu_x)^2}{2\sigma_x^2}} $$

The distribution of $y$ hence can be written as below:

So, now the distribution of $y$ becomes:

$$ p(y) = \frac{2}{\sqrt{1 – y^2}} \frac{1}{\sqrt{2\pi\sigma_x^2}}e^{-\frac{(\cos^{-1}(y) – \mu_x)^2}{2\sigma_x^2}} $$

I referred this article for the formulation. They do it when $x$ follows a uniform distribution. However, here I have a Gaussian distribution.

The main question that I want to ask is to sum the random numbers one would generate using this distribution.

$$ \sum_i y_i$$

Where $y_i$ are the samples drawn from $p(y)$. I thought of solving this by the following integral. I thought like a Frequentist and found that the sum of a number of variables is the sum of the independent variables (samples) I have multiplied with the probability of those samples occurring out of some number of draws from the distribution. Please let me know if this thinking is not adequate enough.

So, at the end it becomes:

$$ \sum_i y_i = \sum_{i = 1}^{N_s} y_i p(y_i) $$

Where $N_s$ is the number of independent samples. This can be written in integral form as:

$$ \int_{-1}^{+1} \frac{2y}{\sqrt{1 – y^2}} \frac{1}{\sqrt{2\pi\sigma_x^2}}e^{-\frac{(\cos^{-1}(y) – \mu_x)^2}{2\sigma_x^2}} dy$$

I say $-1$ to $+1$ instead of a finite length here because I assume $N_s$ in the previous expression to be large enough. This looks like the expected value of the distribution. Is there a way to find a closed form solution to this equation (Or approximate closed form)? When it comes to Gaussian distribution, this quite nicely explained before and I have seen it here. When I tried this integral with the complicated distribution, it said that it can't converge. Is there way to do this?

EDIT:

I implemented a wrong function on mathematica. Now, I do the correct one. It doesn't say it can't converge anymore, however, it doesn't compute it now. It just returns with the integral expression.

EDIT Version 2 =====================================================

I took $y = \cos(\theta)$ to solve the integral and I have now,

$$ \int_{-\pi}^{\pi} \frac{2 \cos(\theta) e^{-\frac{\theta – \mu_x^2}{2\sigma_x^2}} }{\sqrt{2\pi \sigma_x^2}} d\theta$$

The solution I have from Mathematica looks like the following.

$$ \frac{e^{-i \mu_x – \frac{1}{2\sigma_x^2}}}{2\sigma_x^2} \Bigg[ -\operatorname{erf}\Big( {\frac{\mu_x}{\sigma_x} – \frac{i \sigma_x}{2} – \frac{\pi}{\sigma}}\Big) + \operatorname{erf}\Big( {\frac{\mu_x}{\sigma_x} – \frac{i \sigma_x}{2} + \frac{\pi}{\sigma}}\Big) + e^{i 2 \mu_x} \Bigg( -\operatorname{erf}\Big( {\frac{\mu_x}{\sigma_x} + \frac{i \sigma_x}{2} – \frac{\pi}{\sigma}}\Big) + \operatorname{erf}\Big( {\frac{\mu_x}{\sigma_x} + \frac{i \sigma_x}{2} + \frac{\pi}{\sigma}}\Big) \Bigg) \Bigg) \Bigg] \Bigg[ \operatorname{erf}[\frac{i + \sigma_x^2 (-\mu_x + \pi)}{\sqrt{2} \sigma_x}] –
\operatorname{erf}[\frac{i – \sigma_x^2 (\mu_x + \pi)}{\sqrt{2} \sigma_x}] –
i e^{i2 \mu_x} (\operatorname{erfi}[\frac{1 + i \sigma_x^2 (-\mu_x + \pi)}{\sqrt{2} \sigma_x}] –
\operatorname{erfi}[\frac{1 – i \sigma_x^2 (\mu_x + \pi)}{\sqrt{2} \sigma_x}] \Bigg] $$

Is there a relation between this and the nice solution given by @snoop ?

Best Answer

Use characteristic functions and the fact that $\cos(x)=(e^{ix}+e^{-ix})/2$: $$E[\cos(X)]=\frac{1}{2}(E[e^{iX}]+E[e^{-i X}])=\frac{e^{-\frac{\sigma^2}{2}}}{2}(e^{i\mu}+e^{-i\mu})=e^{-\frac{\sigma^2}{2}}\cos(\mu)$$