Suppose $Y = \sqrt{2T}\cos(U)$, $ 0 \le u \le \pi $, and $ 0 \le \cos^{-1}(\frac{y}{\sqrt {2t}}) \le \pi ) $, so $ -1 \le \frac{y}{\sqrt{2t}} \le 1 $, with all $ \mathbb{R}$. The iterated integral is $$ G(y)= P(Y \le y) =P(\sqrt{2T}\cos(U) \le y)=\int_{0}^{y}\int_{0}^{\cos^{-1}(\frac{y}{\sqrt {2t}})} \frac{e^{-t}}{\pi } \mathrm{d}u \mathrm{d}t$$

My Mathematica code is

Integrate[((E^-t)/(\[Pi])), {u, 0,  ArcCos[y/((2 t)^(1/2))]}, 
 Assumptions -> 
  0 <= u <= \[Pi] && -1 <= ArcCos[y/((2 t)^(1/2))] <= 1 && 
   Element[t, Reals] > 0]

Integrate[%, {t, 0, y}, 
 Assumptions -> -1 <= ArcCos[y/((2 t)^(1/2))] <= 1 && 
   Element[t, Reals] > 0]

but then Mathematica never seems to finish evaluating the second one, and so I have to Abort it. Is there any way to find this as a function of $y$? $G(y)$ is a CDF of $Y$.

  • 1
    $\begingroup$ Just to make sure, your original expression under the integral is independent of u ? If this is the case, you don't really have to write the whole thing as a double integral. The result of inner integration is obvious - it's just the upper limit. $\endgroup$ Sep 6 '12 at 4:43
  • $\begingroup$ Yes, it is independent of $u$. That's a good point, I will just need to make sure it would be valid for this problem, and should have included that $Y = \sqrt{2T}\cos(U)$, and will do so now. $\endgroup$
    – T. Webster
    Sep 6 '12 at 4:55
  • $\begingroup$ How can you satisfy $ -1 \le \frac{y}{\sqrt{2t}} \le 1 $ when t is close to zero ? $\endgroup$ Sep 6 '12 at 5:47
  • 1
    $\begingroup$ @b.g is right: executing Plot[ArcCos[1/Sqrt[2 t]], {t, 0, 1}] will immediately show that the inverse cosine is not even defined for sufficiently small values of $t$. The difficulty is that this problem--which appears to compute a probability by integration (assuming $T$ and $t$ are the same)--plays fast and loose with inverse trig functions and suffers accordingly. The solution is to re-solve the problem to generate an integral without the inverse cosine. $\endgroup$
    – whuber
    Sep 6 '12 at 15:28

Your second integral:

f[y_?NumericQ] := NIntegrate[E^-t ArcCos[y/Sqrt[2 t]]/ Pi, {t, y ^2/2, y}]

Plot[f[x], {x, 0, 2}]

Mathematica graphics

  • $\begingroup$ This is an interesting problem, and I suggest to reopen it with the correct formulation: given two random varibales T and U with the distributions T ~ Exp[-t],{t,0,inf} and U ~ 1, {u,0,pi} calculate with MMA the CDF of the variable Y = Sqrt[ 2 T] Cos[U]. $\endgroup$ Aug 24 '14 at 7:51
  • $\begingroup$ @Dr.WolfgangHintze The question isn't "closed". You can post an answer here and the OP can change the accepted answer tickmark. If you believe that you can improve the question formulation without changing the focus, you can also edit the question text. $\endgroup$ Aug 24 '14 at 16:28
  • $\begingroup$ @ Belisarius: thank you for your answer. But you were writing your advice just 2 hours ago, without noticing my answers here, one of them already two days ago, the other 11 hours, which more than cover your advice. I'm really asking myself why I posted them here? $\endgroup$ Aug 24 '14 at 19:10

As I said in a comment I object to the downvaluing of my solution by somebody anonymus without giving the reasong for it.

Now you can convince yourself here that my solution of the real problem is correct. And, consequently, that the second integral of "identy" (and sequel) is not.

Here we go:

I gather from your first lines that you wanted to calculate the probability distribution G[y] of the variable Y = Sqrt[2 T]Cos[U], i.e. the probability that Y < y, when

U and T are variables subject to the probability distributions, respectively,

U ~ 1 du, 0 <= u <= \[Pi]
T ~ Exp[-t] dt, 0<= t < \[Infinity]

Therefore the distribution function G[y] is given by the double integral, using the function Boole to take care for the condition y > Y,

G[y_] := Integrate[(1/\[Pi]) Exp[-t] Boole[ y > Sqrt[2 t] Cos[u]], {u, 0, \[Pi]}, {t, 0, \[Infinity]}]

This double integral was not evaluated by Mathematica in reasonable time. Therefore we do the integrals one after the other. We could do the u-integral first or the t-integral.

Let's do the t-integral first, and let's for definiteness assume y>0 here (the case y<0 can be done similarly).

The t-integral under this assumption is done immediately:

Integrate[(1/\[Pi]) Exp[-t] Boole[ y > Sqrt[2 t] Cos[u]], {t, 
   0, \[Infinity]}, Assumptions -> {y > 0}] // Simplify

(* $\begin{array}{ll} \{ & \begin{array}{ll} \frac{1}{\pi } & y\leq 0\|\text{Cos}[u]\leq 0 \\ \frac{1-e^{-\frac{1}{2} y^2 \text{Sec}[u]^2}}{\pi } & \text{True} \\ \end{array} \\ \end{array}$ *)

The first branch is valid for Cos[u]<=0 i.e. \[Pi]/2 < u < \[Pi], and the u-integral here gives trivially

Integrate[1/\[Pi], {u, \[Pi]/2, \[Pi]}]

(* 1/2 *)

The second branch is valid for the contrary, i.e. for y > 0 && Cos[u] > 0, which means 0 <= u <= \[Pi]/2, and the u-integral becomes

Integrate[(1 - E^(-(1/2) y^2 Sec[u]^2))/\[Pi], {u, 0, \[Pi]/2}, Assumptions -> y > 0]

(* 1/2 Erf[y/Sqrt[2]] *)

Now adding both contributions we have

G[y_] := 1/2 (1 + Erf[y/Sqrt[2]])

Proceeding similarly for y < 0 we find the same result. Hence G[y] is the sought probability for all y.

This is in agreement with my previous solution where, however, I have calculated the opposite probability. In fact,

1 - 1/2 Erfc[y/Sqrt[2]] // FullSimplify

(* 1/2 (1 + Erf[y/Sqrt[2]]) *)

Finally, as a bonus, the differential distribution for y is given by

f[y_] = D[G[y], y]

(* E^(-(y^2/2))/Sqrt[2 \[Pi]] *)

Which is the Standard normal (or Gaussian) Distribution.

Best regards, Wolfgang

Addendum 24.08.14

1) The second integral can't be a CDF because it is not monotoneous, as can be seen from the graph of Belisarius.

2) Using the variable y = Sqrt[2t]Cos[u] is one of the possible ways to generate normally distributed random variables.

Take two random variables r1 and r2, with a flat distribution between 0 and 1 (like the function Random[]) and let t = - Log[r1] and u = \[Pi] r2, then y is normally distributed.

You might wish to make experiments like this

r := Random[]

a = Table[t = - Log[r]; u = \[Pi] r; y = t Cos[u], {10^3}];

(* 140824_plot _rnd _dots.jpg *)

enter image description here

(* 140824_plot _rnd _dots _sorted.jpg *)

enter image description here

Best regards, Wolfgang


I think what you mean in your second integral is the integral between y^2/2 and \[Infinity]:

Integrate[(E^-t ArcCos[y/(Sqrt[2] Sqrt[t])])/\[Pi], {t, 1/2 y^2, \[Infinity]}]

It is returned unevaluated by Mathematica:

(* $\int_{\frac{y^2}{2}}^{\infty } \frac{e^{-t} \text{ArcCos}\left[\frac{y}{\sqrt{2} \sqrt{t}}\right]}{\pi } \, dt$*)

Therefore, let's change the integration variable such that

y/Sqrt[2t ]->z, 
i.e. t -> (y^2/z^2)/2, dt -> - y^2/z^3 dz, t = {y^2/2, \[Infinity]} -> z = {1,0}.

The resulting integral is then readily solved analytically by Mathematica:

f[y_] = y^2 Integrate[(1/\[Pi]) (1/z^3) ArcCos[z] Exp[-y^2/(2 z^2)], {z, 0, 
    1}, Assumptions -> y > 0]

(* 1/2 Erfc[y/Sqrt[2]] *)

Hope this helps. Best regards, Wolfgang

  • $\begingroup$ @ NN? please identify yourself and explain why when you downvalue an answer. Mine had already 2+ votes. Thank you. $\endgroup$ Aug 22 '14 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.