Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tricky RegionPlot question (Mathematica)

I use the following to visualize the range of means when averaging n coin tosses as a function of n.

p = 1/2;
e = 1/4;
pp[n_, x_] = CDF[BinomialDistribution[n, p], x];
p3 = RegionPlot[pp[n, n x] > p - e && pp[n, n x] < p + e, {n, 1, 20}, {x, 0, 1}]

For aesthetic reasons, I want that plot to be contiguous even though this range doesn't make sense for non-integer n. The solution above gives a "saw-tooth" appearance, but instead I want it to look like a step ladder, So, for any non-integer n0 the region would be the same as for the largest integer n not greater than n0, any idea how to accomplish this?

like image 411
Yaroslav Bulatov Avatar asked Aug 02 '26 18:08

Yaroslav Bulatov


1 Answers

Assuming you want n to be integers, try

p3 = RegionPlot[
        p - e < pp[nn, nn x] < p + e /. nn -> Floor[n],
        {n, 1, 20}, {x, 0, 1}
     ]
like image 59
kennytm Avatar answered Aug 07 '26 07:08

kennytm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!