_Maxim_

729 Reputation

12 Badges

9 years, 21 days

MaplePrimes Activity


These are questions asked by _Maxim_

with(Statistics):

Variance(Distribution(ProbabilityFunction = (k -> piecewise(k > 0, 2^(-k)))));
Error, invalid input: Statistics:-Variance expects its 1st argument, X, to be of type
{algebraic, {array, list, rtable, DataFrame, DataSeries}}, but received _m1085629680096

dd := Distribution(ProbabilityFunction = (k -> piecewise(k > 0, 2^(-k))));

Variance(dd);
                               6

The first input works in neither 2D nor 1D input mode.

Another issue is that the value of the variance is in fact wrong; Maple takes the probability function to have value 1 at zero.

x/2 seems completely wrong as a CDF. In other cases Maple correctly writes the CDF as a piecewise-constant function clipped to 0..1:

with(Statistics):

dd := Distribution(ProbabilityFunction = 1/2, Support = 1 .. 2);

PDF(dd, x); # OK
                   (1/2)*Dirac(x-1)+(1/2)*Dirac(x-2)

CDF(dd, x);
                                (1/2)*x

Also CDF seems to have issues with DiscreteValueMap specified using a list, a table or piecewise():

dd := Distribution(ProbabilityFunction = 1/2, DiscreteValueMap = (n -> [1, 2][n]), Support = 1 .. 2);

PDF(dd, x); # OK
                    (1/2)*Dirac(x-1)+(1/2)*Dirac(x-2)

CDF(dd, x); # indeterminate
  int((1/2)*Dirac(0)*Dirac(_t-1)+(1/2)*Dirac(0)*Dirac(_t-2), _t = -infinity .. x)

 

with(Statistics):

CDF(Binomial(2, 1/2), x); # wrong
               piecewise(x < 0, 0, 2 <= x, 1, 1)

CDF(Binomial(2, p), x); # also wrong
     piecewise(x < 0, 0, 2 <= x, 1, p = 0, 1, p = 1, 0, 1)

Maple can actually generate PDFs for discrete distributions:

bpdf := unapply(PDF(Binomial(2, 1/2), x), x);
          x -> (1/4)*Dirac(x)+(1/2)*Dirac(x-1)+(1/4)*Dirac(x-2)

int(bpdf(t), t = -infinity .. x); # correct CDF
         (1/4)*Heaviside(x)+(1/2)*Heaviside(x-1)+(1/4)*Heaviside(x-2)

But then functions of random variables do not seem to work :

bdist := Distribution(PDF = bpdf, Support = -infinity .. infinity);

CDF(bdist, x); # OK
           piecewise(x < 0, 0, x = 0, undefined, x < 1, 1/4, x = 1, undefined, x < 2, 3/4, x = 2,
           undefined, 2 < x, 1)

CDF(add(RandomVariable(bdist), i = 1 .. 2), x); # indeterminate
          int((1/16)*Dirac(_t)^2+(1/4)*Dirac(0)*Dirac(_t-1)+(3/8)*Dirac(0)*Dirac(_t-2)+(1/4)*Dirac(0)*
          Dirac(_t-3)+(1/16)*Dirac(0)*Dirac(_t-4), _t = -infinity .. x)

It's a bit disappointing that Maple generates PDFs in terms of the delta function but doesn't support them properly, because that could be an easy and natural way to define mixed distributions.

Spawned from here.

1. series() shows some strange dependence on the session history, the first call breaking subsequent computations. Also, for F(x, y), the zeroth term is RootOf(F(0, _Z)), even though 1 is the only solution, but for G(x, y), RootOf(G(0, _Z)) is evaluated to 1, even though 1 is not the only solution:

F := (x, y) -> ln((1+x)*y)+exp(x^2*y^2)-x-cos(x):
G := (x, y) -> ln((1+x)*y)+exp(x^2+y-1)-x-cos(x):

series(RootOf(G(x, y), y), x = 0, 5);
                 1-(1/2)*x^2-(1/6)*x^3+(7/48)*x^4+O(x^5)

series(RootOf(G(x, y), y), x = 0, 6);
Error, (in series/RootOf) unable to compute series

forget(series);
series(RootOf(G(x, y), y), x = 0, 6);
           1-(1/2)*x^2-(1/6)*x^3+(7/48)*x^4-(1/60)*x^5+O(x^6)

series(RootOf(F(x, y), y), x = 0, 1);
                         RootOf(ln(_Z)) + O(x)

2. For some reason solve hangs the first time, then returns a result quickly, and apparently doesn't go along well with simplify, because the last output contains an escaped local variable ans. Besides, I'm not sure why solve generates a huge answer. Is it expanding something to a high order? I was expecting just RootOf(_Z+tan(_Z))+O(x).

ser := series(y+tan(y)+x, x = 0, 1);

iser := timelimit(30, solve(ser, y)): # appears to run indefinitely without timelimit
Error, (in ArrayTools:-NumElems) time expired

iser := solve(ser, y): # returns immediately

evalf(iser); # OK
                                             O(x)

evalf(simplify(iser)); # less OK
       .1250000000*(eval(RootOf(_Z+tan(_Z)), [RootOf = ans, tan(_Z) = sin(_Z)/cos(_Z)]))+O(x)

This is in Maple 2017.3.

a := powseries:-powsolve(diff(f(z), z)-f(z)/z = 0);

seq(a(i), i = 0 .. 5);
                        0, 0, 0, 0, 0, 0

Seems that powsolve is constructing the relation k*a(k)-a(k) = 0 and solving it as a(k)=0. I think powsolve should detect such cases (regardless of whether or not they're supported).

1 2 3 4 5 6 7 Last Page 2 of 14