Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

Output1

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.

Ooutput2

Thanks for any help.

share|improve this question
    
@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 ? –  Steve Mar 19 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 :) –  belisarius Mar 19 at 17:17

2 Answers 2

up vote 1 down vote accepted

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]

Mathematica graphics

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).

share|improve this answer

Given: $X\sim 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.
share|improve this answer
    
Hi! Could you please add the code instead of an image? Thanks! –  belisarius Mar 19 at 17:14
    
@belisarius The problem is the parsing of the Greek characters in Stackexchange code ... here goes anyway ... –  wolfies Mar 19 at 17:22
    
This thingie does it for you meta.mathematica.stackexchange.com/q/1043/193 (I already edited your code using it) –  belisarius Mar 19 at 17:43
    
Thanks! ........ –  wolfies Mar 19 at 18:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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