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 encountered this when I was trying to answer this question. I just can't understand why the following code will only give a line at $y=0$:

Plot[PDF[PolyaAeppliDistribution[7, 1/4], x], {x, 0, 35}, Axes -> {False, True}]

enter image description here

While with Evaluate I'll get the desired result:

Plot[Evaluate@PDF[PolyaAeppliDistribution[7, 1/4], x], {x, 0, 35}]

enter image description here

DiscretePlot, which is a function with Attributes similar to Plot, doesn't suffer this:

DiscretePlot[PDF[PolyaAeppliDistribution[7, 1/4], x], {x, 0, 35}]

enter image description here

nor do many other distributions, for example NormalDistribution:

Plot[PDF[NormalDistribution[7, 2], x], {x, 0, 35}]

enter image description here

I haven't do a complete test so I'm not sure if there's other distribution behaved like PolyaAeppliDistribution. Has it got any deep reasons? Or it's just a bug?

I'm using Mathematica 8, Windows Vista Home Basic 32-bit.

share|improve this question
    
Same behavior in 9.0.1 on Win7. –  Ymareth Jan 23 at 11:08
    
You'll get the same result with other non-continuous distributions. Use DiscretePlot. –  rasher Jan 23 at 11:28
    
@rasher Oh, I see! Why not give an answer? –  xzczd Jan 23 at 11:39
    
@xzczd: Are you requesting I put the comment as an answer? I'll assume so and do so, if not let me know and I'll delete it. –  rasher Jan 23 at 12:06
    
@rasher Yeah, just enlarge it into an answer :) –  xzczd Jan 23 at 12:10

2 Answers 2

You'll get the same result with other non-continuous distributions. Use DiscretePlot.

You can observe that the under-the-covers behavior is different when you evaluate the PDF (use EvaluationMonitor), many more points are sampled. The plot showing up is a side-effect I've not investigated enough to explain. You can also set WorkingPrecision to 1, and you'll get a (rough) plot, since MM is basically forced into using values that actually have PDF values. In any case, Plot is not appropriate for non-continuous distribution PDF, just use DiscretePlot with Joined->True.

share|improve this answer
    
The WorkingPrecision -> 1 method is interesting! And I take the liberty to add some further exploration to your answer, feel free to undo it if you don't like it. –  xzczd Jan 23 at 12:52
    
@xzczd: I'd rather you just post it as your own answer and accept it, completely re-writing someone else's answer in this way is... yes, please just post it as your own, feel free to use anything from my original answer, that's fine by me. –  rasher Jan 23 at 12:58
    
Undone. Sorry, I seemed to be a little excited 囧. –  xzczd Jan 23 at 13:16
    
@xzczd: No worries! –  rasher Jan 24 at 3:56
up vote 0 down vote accepted

As @rasher mentioned, it's all because PolyaAeppliDistribution is a discrete distribution.

The PDF of non-continuous distributions only have non-zero values at discrete points. Still choose the PolyaAeppliDistribution as the example:

ListPlot[PDF[PolyaAeppliDistribution[7, 1/4], #] & /@ Range[0, 35, 1/10]]

enter image description here

The plot showing up when evaluating the PDF isn't that of the PDF of PolyaAeppliDistribution at all. In fact the expression is no longer a discrete function after evaluated:

PDF[PolyaAeppliDistribution[7, 1/4], x]
Piecewise[{{1/E^7, x == 0}, {(21 Hypergeometric1F1[1 - x, 2, -21])/(4^x*E^7), x > 0}}, 0]

Hypergeometric1F1 is continuous.

share|improve this answer

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.