# CDF of TransformedDistribution Not Returned And No Error Message Produced

I am unable to get Mathematica to return the CDF of a distribution produced by TransformedDistribution. It "executes" for 6 hours on my machine and then returns a blank plot. Could someone execute the code below and explain why this is happening and offer a solution ? Is there something wrong with my code ?

beg = AbsoluteTime[];
dist1 = ExponentialDistribution[0.1];
pdf1 = PDF[dist1, x];
cdf1 = CDF[dist1, x];
plot1 = Plot[pdf1, {x, 0, 100}, Frame -> True,
FrameLabel -> {"X", "PDF"}, PlotLabel -> "PDF of X (dist1)",
PlotStyle -> Red, PlotRange -> All]
plot2 = Plot[cdf1, {x, 0, 100}, Frame -> True,
FrameLabel -> {"X", "CDF"}, PlotLabel -> "CDF of X (dist1)",
PlotStyle -> Red, PlotRange -> All]

dist2 = NormalDistribution[53, 2.4];
pdf2 = PDF[dist2, x];
cdf2 = CDF[dist2, x];
plot3 = Plot[pdf2, {x, 0, 100}, Frame -> True,
FrameLabel -> {"X", "PDF"}, PlotLabel -> "PDF of X (dist2)",
PlotStyle -> Red, PlotRange -> All]
plot4 = Plot[cdf2, {x, 0, 100}, Frame -> True,
FrameLabel -> {"X", "CDF"}, PlotLabel -> "CDF of X (dist2)",
PlotStyle -> Red, PlotRange -> All]
end = AbsoluteTime[];
executiontime = (end - beg)/60  (* minutes *)


Here is the output, so far so good. Now here is where the problem is.

beg = AbsoluteTime[];
dist3 = TransformedDistribution[
a + b, {a \[Distributed] dist1, b \[Distributed] dist2}]
pdf3 = PDF[dist3, x];
cdf3 = CDF[dist3, x];
plot5 = Plot[pdf3, {x, 0, 100}, Frame -> True,
FrameLabel -> {"X", "PDF"}, PlotLabel -> "PDF of X (dist3)",
PlotStyle -> Red, PlotRange -> All]
plot6 = Plot[cdf3, {x, 0, 100}, Frame -> True,
FrameLabel -> {"X", "CDF"}, PlotLabel -> "CDF of X (dist3)",
PlotStyle -> Red, PlotRange -> All]
end = AbsoluteTime[];
executiontime = (end - beg)/60  (* minutes *)


And here is the output. Thanks for any help.

• @Belasarius and wolfies, thank you for the workarounds. Any idea why my original code did not work ? Was the CDF function unable to do the integration ? In a perfect world should an error message have been produced ? Mar 19, 2014 at 15:01
• No,sorry. I really don't know why that happens. But usually in Mma one learn that is better to circumvent those non-working edges than fighting them :) Mar 19, 2014 at 17:17

There is nothing wrong with your code. Mathematica just fails to calculate the CDF.

But you can always go by calculating the CDF explicitly (and numerically):

cdf3N[y_?NumericQ] := NIntegrate[pdf3, {x, 0., y}, Method -> "LocalAdaptive"]
Plot[cdf3N[x], {x, 0, 100}, Frame -> True, FrameLabel -> {"X", "CDF"},
PlotLabel -> "CDF of X (dist3)", PlotStyle -> Red, PlotRange -> All] If you're going to do serious work with this, you should try to find the better integration method for your function (which is not always a trivial task).

Given: $X\sim \text{Exponential}(\lambda)$ and $Y\sim N(\mu,\sigma^2)$. Then, if $X$ and $Y$ are independent, the joint pdf of $(X,Y)$ is say $f(x,y)$: Let $Z = X + Y$. You seek the cdf of $Z$, i.e. $P(Z<z) = P(X+Y<z)$: All done.

Here is a plot of the solution cdf given your parameter values (i.e. with $\lambda = 10$):

Plot[cdf /. {λ -> 10, μ -> 53, σ -> 2.4}, {z, 0, 100}, AxesLabel -> {z, "cdf"}] Notes

1. The Prob function used above is from the mathStatica package for Mathematica. As disclosure, I should add that I am one of the authors.
• Hi! Could you please add the code instead of an image? Thanks! Mar 19, 2014 at 17:14
• @belisarius The problem is the parsing of the Greek characters in Stackexchange code ... here goes anyway ... Mar 19, 2014 at 17:22
• This thingie does it for you meta.mathematica.stackexchange.com/q/1043/193 (I already edited your code using it) Mar 19, 2014 at 17:43