MaplePrimes Posts

MaplePrimes Posts are for sharing your experiences, techniques and opinions about Maple, MapleSim and related products, as well as general interests in math and computing.

Latest Post
  • Latest Posts Feed
  • A number of MaplePrimers have asked how one might use the section and subsections of a Maple worksheet to structure the source code of an extended Maple package.  The usual answer is that it cannot be done; a module-based Maple package must be assigned in a single input region in a worksheet.  A recommended alternative is to write the source in text files and use either command line tools or the Maple read command from a worksheet to assign the package.  Because the read command handles Maple preprocessor macros, specifically the $include macro, the source can be conveniently split into smaller files.

    I prefer this file-based method for development because text files are generally more robust than Maple worksheets, can be edited with the user's preferred editor, can be put under version control, and can be searched and modified by standard Unix-based tools.  However, not everyone is familiar with this method of development.  With that in mind, I wrote a small Maple package, CodeBuilder, that permits splitting the source of a Maple package (or any Maple code) into separate code edit regions in a standard Maple worksheet, using $include macros to include the source of other regions.  To build the package, the code edit regions are written to external files, using the names of the regions as the local file name relative to a temporary directory.

    The package includes a method to run mint on the source code.  The result can be either printed in the worksheet or displayed in a pop-up maplet that allows selecting the infolevel and the region to check.

    CodeBuilder includes help pages and a simple example (referenced from the top-level help page) demonstrating the usage.  To install the package, unzip the attached zip file and follow the directions in the README file.

    CodeBuilder-1-0-3.zip

    Errata Just noticed that a last minute change broke some of the code.  Do not bother with the 1-0-1 version; I'll upload a new version shortly.  The latest version (1-0-3) is now available.

    Let us look in RealDomain and then in the RealDomain:-solve command. One is addressed to the usual solve command. The commands of the RealDomain package are not still documented since Maple 7 when the package was introduced. There is a general description only 

    • By default, Maple performs computations under the assumption that the underlying number system is the complex field. The RealDomain package provides an environment in which computations are performed under the assumption that the basic underlying number system is the field of real numbers.
    • Results returned by procedures are postprocessed by discarding values containing any detectable non-real answers or replacing them with undefined where appropriate.

    The above is not enough. Here is an example which confuses me: 

    RealDomain:-solve(exp(I*x) = -1, AllSolutions);
    NULL

    though 

    solve(exp(I*x) = -1, AllSolutions);
                             Pi (2 _Z1 + 1)
    

    and 

    RealDomain:-solve(exp(I*x) = -1);
                                   Pi
    

    I lie awake thinking about that. Maplesoft staff help me!

    The DFT windowing functions in the SignalProcessing package seem to be inconsistent in the type of data they will accept, and the type they return.

    BartlettHannWindow,  BlackmanHarrisWindow, BlackmanNuttallWindow,   BohmanWindow, CauchyWindow, CosineWindow, ExponentialWindow, FlatTopWindow,  GaussianWindow, HannPoissonWindow, ParzenWindow, PoissonWindow,  RectangleWindow, ReiszWindow, RiemannWindow, TaperedCosineWindow, TriangleWindow, TukeyWindow

    accept Arrays, containing almost any data type (haven't tried them all!) as input. and always return a Vector[row].

    But

    BartlettWindow, BlackmanWindow, HammingWindow, HannWindow, KaiserWindow

    require that the option datatype=float[8] be set in the Array() constructor, which is used as input and always return an hfarray.

    Thus, for example

    with(SignalProcessing);
    sig:= Array( -50..50,
                            fill=1
                        ):
    BartlettHannWindow(sig); # this works
    BartlettWindow(sig);# this fails with datatype unsupported error

    Very confusing!!!!

    Let us consider 

    Statistics:-Mode(Binomial(n, p));
                            floor((1 + n) p)
    

    Up to Wiki, the output is not correct. Simply no words.

    The copy paste and snip tool used to work.  I can no longer use either to paste in mapleprimes.

    There seems to be a bug in determining the folowing integral analytically:

    integrate(-(3/2*(exp(-(1/4)*x)*x-sqrt(Pi)*erf((1/2)*sqrt(x))*sqrt(x)))/(sqrt(x)*sqrt(Pi)*erf((1/2)*sqrt(x))), x = 0..1)

    Maple gives as a result

    3/2

    However, numerically integrating it

    integrate(-(3/2*(exp(-(1/4)*x)*x-sqrt(Pi)*erf((1/2)*sqrt(x))*sqrt(x)))/(sqrt(x)*sqrt(Pi)*erf((1/2)*sqrt(x))), x=0..1,numeric)

    gives

    0.1195461293

    In fact, integrating it from a to b,

    integrate(-(3/2*(exp(-(1/4)*x)*x-sqrt(Pi)*erf((1/2)*sqrt(x))*sqrt(x)))/(sqrt(x)*sqrt(Pi)*erf((1/2)*sqrt(x))), x=a..b)

    gives

    -3/2 a + 3/2 b

    suggesting that Maple thinks the integrand is just 3/2. If one plots it, then it becomes obvious that this is not the case.


     

    with(Statistics):````

    X := Statistics:-RandomVariable(Normal(0, 1)):

    PDF(sin(X), t)

    piecewise(t <= -1, 0, t < 1, 2^(1/2)*exp(-(1/2)*arcsin(t)^2)/(Pi^(1/2)*(-t^2+1)^(1/2)), 1 <= t, 0)

    (1)

    int(%, t = -1 .. 1)

    2*erf((1/4)*Pi*2^(1/2))

    (2)

    evalf(%)

    1.767540069

    (3)

    ``


    There were recently submitted a dozen Maple bugs by me and others. Maplesoft have brought no responses. They keep strategic silence. True merit is not afraid of criticism.

    Download Bug_in_Statistics_PDF.mw


     

    I found a strange bug in int.
    For some functions f(x), Maple is able to compute the antiderivative (correctly) but refuses to compute the definite integral.
    Or, computes the integral over 0..1  and  0..2  but refuses to compute over 1..2.

    int(exp(x^3), x);  #ok

    -(1/3)*(-1)^(2/3)*((2/3)*x*(-1)^(1/3)*Pi*3^(1/2)/(GAMMA(2/3)*(-x^3)^(1/3))-x*(-1)^(1/3)*GAMMA(1/3, -x^3)/(-x^3)^(1/3))

    (1)

    int(exp(x^3), x=1..2); #?

    int(exp(x^3), x = 1 .. 2)

    (2)

    int(exp(x^3), x=1..2, method=FTOC); #??

    int(exp(x^3), x = 1 .. 2, method = FTOC)

    (3)

    int(exp(x^3), x=0..2); #?

    int(exp(x^3), x = 0 .. 2)

    (4)

    int(exp(-x^3), x);  #ok

    (3/4)*x*exp(-(1/2)*x^3)*WhittakerM(1/6, 2/3, x^3)/(x^3)^(1/6)+exp(-(1/2)*x^3)*WhittakerM(7/6, 2/3, x^3)/(x^2*(x^3)^(1/6))

    (5)

    int(exp(-x^3), x=0..2);  #ok

    (3/4)*2^(1/2)*exp(-4)*WhittakerM(1/6, 2/3, 8)+(1/8)*2^(1/2)*exp(-4)*WhittakerM(7/6, 2/3, 8)

    (6)

    int(exp(-x^3), x=0..1);  #ok

    (3/4)*exp(-1/2)*WhittakerM(1/6, 2/3, 1)+exp(-1/2)*WhittakerM(7/6, 2/3, 1)

    (7)

    int(exp(-x^3), x=1 .. 2);  #???

    int(exp(-x^3), x = 1 .. 2)

    (8)


     

    Download !strange-bug-int.mw

    Let us consider 

    restart; J := int(cos(a*x)^2/(x^2-1), x = -infinity .. infinity, CPV);
    -(1/4)*Pi*sin(2*a)*csgn(I*a)-(1/4)*Pi*sin(2*a)*csgn(I/a)

    This result is not true for a=I:

    eval(J, a = I);
                                   0
    

    In this case the integral under consideration diverges because of 

    cos(I*x)^2;
                                    
                                cosh(x) ^2
    

     

    On some platforms, my editor of choice has become the aptly named Sublime Text. Unfortunately, it does not seem to have built in syntax highlighting for the Maple programming language and so I set out to write some.  In the end, I wrote enough highlighting to keep me sane when looking at Maple source, but it could use a lot more work.  So in case anyone is interested I've put what I have in a Github repository: SublimeTextMaple

    If you use Sublime Text, please download it and add your own enhacements and share in turn.

    I find it hard to believe when I enter the search term Maple 6 Maple 7 maple 8 etc.. old versions search prior to Maple 10 it only brings up a maximum of 4 pages.  I know there are more applications of old.  

    Are all applications still there and the search just not bringing them up?

    Let us consider 

    maximize(int(exp(-x^4), x = k .. 3*k), location);

    Error, (in maximize) invalid input: iscont expects its 1st argument, f, to be of type algebraic, but received x = k .. 3*k
    whereas the expected output is 

    [(2*((1/40)*GAMMA(1/4, (1/80)*ln(3))*5^(1/4)*ln(3)^(3/4)-(1/40)*GAMMA(1/4, (81/80)*ln(3))*5^(1/4)*ln(3)^(3/4)))*5^(3/4)*(1/ln(3))^(3/4), [k = (1/10)*10^(3/4)*ln(3)^(1/4)]]

    as Mma 11 produces. The following 

    RealDomain:-solve(diff(int(exp(-x^4), x = k .. 3*k), k));
      -(1/10)*5^(3/4)*ln(3)^(1/4), (1/10)*5^(3/4)*ln(3)^(1/4)

    is not a workaround because of 

    int(exp(-x^4), x = (1/10)*5^(3/4)*ln(3)^(1/4) .. (3/10)*5^(3/4)*ln(3)^(1/4));
      FAIL

     

    Let us consider 

    MultiSeries:-series(Psi((2*x+1)/(2*x))-Psi((x+1)/(2*x)), x = 0);
    
    x-(1/2)*x^2+(1/4)*x^4-(1/2)*x^6 +O(x^7)
    

    The above result contradicts 

    MultiSeries:-limit(diff(Psi((2*x+1)/(2*x))-Psi((x+1)/(2*x)), x), x = 0);
                               undefined
    MultiSeries:-limit((Psi((2*x+1)/(2*x))-Psi((x+1)/(2*x)))/x, x = 0, right);
                                   1
    MultiSeries:-limit((Psi((2*x+1)/(2*x))-Psi((x+1)/(2*x)))/x, x = 0, left);
                               undefined
    plot((Psi((2*x+1)/(2*x))-Psi((x+1)/(2*x)))/x, x = -0.1e-1 .. 0.1e-2, discont, y = -5 .. 5);
    

    Correct computatiton for

    for reasonable expressions f(x,y), g(x,y) would be very useful in double integrals.

    For the moment this is not possible. Too many bugs:

    int(Heaviside(1-x^2-y^2), x=-infinity..infinity, y=-infinity..infinity); #should be Pi
                               undefined
    int(Heaviside(1-x^2-y^2), x=-1..1, y=-1..1); #should be Pi
                                   0
    int(Heaviside(y-x^2), x=-1..1, y=-1..1); #should be 4/3
                                   -2

    int(Heaviside(y-x^2), y=-1..1, x=-1..1); #This one is OK!
                                  4/3

     

     

     

     

    restart; with(Statistics):
    X := RandomVariable(Normal(0, 1)): Y := RandomVariable(Uniform(-2, 2)):
    Probability(X*Y < 0);

    crashes my comp in approximately 600 s. Mma produces 1/2 on my comp in 0.078125 s.

    First 8 9 10 11 12 13 14 Last Page 10 of 254