1
$\begingroup$

I'm trying to plot the following CDF: $$\sum^n_{k=1}{n-1\choose k-1}F(x)^{k-1}(1-F(x))^{n-k}\sum^n_{i=k}{n\choose i}G(y)^i(1-G(y))^{n-i}$$ at $x=1/2$, where $F(x)=x$ and $G(y)=y^2$. I try to plot it when $n=3,10,30,100$ to see the convergence, but the problem is that the graph is very nice when $n$ is smaller than $35$, but it fluctuates a lot if $n$ is greater than that.

The code I'm using is

ClearAll;

F[x_] = x;

G[y_] = y^2;

G1[y_, i_, n_] = Binomial[n, i]*G[y]^i*(1 - G[y])^(n - i);

G2[y_, k_, n_] = Sum[G1[y, i, n], {i, k, n}];

h[x_, y_, k_, n_] =   Binomial[n - 1, k - 1]*F[x]^(k - 1)*(1 - F[x])^(n - k)*G2[y, k, n];

h3[x_, y_] =   Assuming[Element[k, Integers] , Sum[h[x, y, k, 3], {k, 1, 3}]];

h10[x_, y_] =   Assuming[Element[k, Integers] , Sum[h[x, y, k, 10], {k, 1, 10}]];

h30[x_, y_] =   Assuming[Element[k, Integers] , Sum[h[x, y, k, 30], {k, 1, 30}]];

h40[x_, y_] =   Assuming[Element[k, Integers] , Sum[h[x, y, k, 40], {k, 1, 40}]];


Plot[{h3[1/2, y], h10[1/2, y], h30[1/2, y], h40[1/2, y]}, {y, 0, 1}, 
 PlotLabels -> {"n=3", "n=10", "n=30", "n=40"}]

Analytically, the CDF is well defined. Can anyone tell what's wrong with the code?

$\endgroup$
4
  • 1
    $\begingroup$ Have you already tried to set the option PlotPoints to higher values? See e.g. reference.wolfram.com/language/ref/PlotPoints.html $\endgroup$
    – Quit007
    Nov 8, 2017 at 16:29
  • $\begingroup$ Try including WorkingPrecision->20 in your plot. $\endgroup$
    – Carl Woll
    Nov 8, 2017 at 16:35
  • $\begingroup$ OMG WorkingPrecision totally works! $\endgroup$
    – Andeanlll
    Nov 8, 2017 at 16:37
  • $\begingroup$ Hmm, it works for n=40, but does not for larger n.. Would there be any other way to plot them? $\endgroup$
    – Andeanlll
    Nov 8, 2017 at 17:07

1 Answer 1

1
$\begingroup$

Since BernsteinBasis[] is built-in, do this:

With[{x = 1/2}, 
     Plot[Table[Sum[BernsteinBasis[n - 1, k - 1, x] BernsteinBasis[n, i, y^2],
                    {k, 1, n}, {i, k, n}], {n, {3, 10, 30, 100}}] // Evaluate,
          {y, 0, 1}, PlotLegends -> {3, 10, 30, 100}]]

CDFs

$\endgroup$
1
  • $\begingroup$ Wow. I didn't know about this polynomial function. Thank you. Now it works well. $\endgroup$
    – Andeanlll
    Nov 8, 2017 at 20:25

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.