Alec Mihailovs

Dr. Aleksandrs Mihailovs

4455 Reputation

21 Badges

20 years, 308 days
Mihailovs, Inc.
Owner, President, and CEO
Tyngsboro, Massachusetts, United States

Social Networks and Content at Maplesoft.com

I received my Ph.D. from the University of Pennsylvania in 1998 and I have been teaching since then at SUNY Oneonta for 1 year, at Shepherd University for 5 years, at Tennessee Tech for 2 years, at Lane College for 1 year, and this year I taught at the University of Massachusetts Lowell. My research interests include Representation Theory and Combinatorics.

MaplePrimes Activity


These are answers submitted by Alec Mihailovs

The wrong printing in the second example seems to be a bug.

It seems as if the first procedure starts executing and switches to the second procedure only after using the second parameter, which causes an error.

Thus, the workaround in this case is to use the second parameter before printing,

g:= overload ( [
    proc(R::list , S::list) option overload;
        S;
        print("this is the version with TWO lists")
    end,
    proc(R::list) option overload;
        print("this is the version with a list")
    end]);

g([3]);
                  "this is the version with a list"

g([1],[2]);

                 "this is the version with TWO lists"

Alec

If you add the end of parameters marker (i.e. $) to the parameters in the first overloaded procedure in the first example, it would work as expected,

f:= overload ( [
    proc(R::list, $) option overload;
        print (" this is the version with a list")
    end,
    proc(R::list , S::list) option overload;
        print (" this is the version with TWO lists");
    end]):

f([1]);

                  " this is the version with a list"

f([1],[2]);

                " this is the version with TWO lists"

Alec

J:=Int(exp(1/(x-a)/(x-b)),x=a..b);
                          b
                         /
                        |              1
                  J :=  |   exp(---------------) dx
                        |       (x - a) (x - b)
                       /
                         a

First, notice that by shifting x that integral can be written as

IntegrationTools:-Change(J,x=(a+b)/2+u,u);

            b/2 - a/2
           /
          |                               4
          |            exp(- ---------------------------) du
          |                  (a - b - 2 u) (a - b + 2 u)
         /
           - b/2 + a/2

simplify(algsubs((b-a)/2=c,%));

                       c
                      /
                     |                1
                     |   exp(- ---------------) du
                     |         (c + u) (c - u)
                    /
                      -c

J1:=2*Int(exp(1/(u^2-c^2)),u=0..c);

                                c
                               /
                              |          1
                     J1 := 2  |   exp(-------) du
                              |        2    2
                             /        u  - c
                               0

Now, substitute 1/(u^2-c^2) = -t,

IntegrationTools:-Change(J1,u=sqrt(c^2-1/t),t) assuming c>0;

                     infinity
                    /
                   |                  exp(-t)
                2  |          1/2 ---------------- dt
                   |              / 2      \1/2
                   |              |c  t - 1|     2
                  /               |--------|    t
                     1            \   t    /
                    ----
                      2
                     c

simplify(%,symbolic);

                    infinity
                   /
                  |                   exp(-t)
               2  |          1/2 ------------------ dt
                  |               3/2   2       1/2
                 /               t    (c  t - 1)
                    1
                   ----
                     2
                    c

value(%) assuming c>0;

        /   2        1                1
        |  c  exp(- ----) BesselK(0, ----)
        |              2                2
    1/2 |           2 c              2 c
  Pi    |- -------------------------------
        |                 1/2
        \               Pi

            2        1                1   \
           c  exp(- ----) BesselK(1, ----)|
                       2                2 |
                    2 c              2 c  |   /    2 1/2  2
         + -------------------------------|  /  ((c )    c )
                          1/2             | /
                        Pi                /

simplify(%) assuming c>0;

                  1    /            1                  1   \
           exp(- ----) |BesselK(0, ----) - BesselK(1, ----)|
                    2  |              2                  2 |
                 2 c   \           2 c                2 c  /
         - -------------------------------------------------
                                   c

eval(%,c=(b-a)/2);

                1
  - exp(- --------------)
                       2
          2 (b/2 - a/2)

        /                 1                            1        \
        |BesselK(0, --------------) - BesselK(1, --------------)|/(
        |                        2                            2 |
        \           2 (b/2 - a/2)                2 (b/2 - a/2)  /

        b/2 - a/2)

simplify(%);

             2      /              2                      2     \
  2 exp(- --------) |BesselK(0, --------) - BesselK(1, --------)|/(
                 2  |                  2                      2 |
          (a - b)   \           (a - b)                (a - b)  /

        a - b)

Alec

2/(b-a)*exp(-2/(b-a)^2)*(BesselK(1,2/(b-a)^2)-BesselK(0,2/(b-a)^2));

Alec

For statistics and financial calculations, no doubt that Excel is better, and R is better than both Excel and Maple.

Both R and Excel are professional tools, while Maple is amateurish.

Alec

Here is the formula for this sequence,

a:=proc(n) local x;
    lcoeff(primpart(
        add((2*x+1)^(2*n-2*i)/(2*i+1),i=0..n)))
end;

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

                    1, 3, 240, 840, 80640, 887040

Alec

Actually, primpart works also with polynomials with rational coefficients,

primpart(1/4*x+1/6);

                               3 x + 2

So the multiplication by the doublefactorial, making coefficients of p integer, is not necessary, and the formula can be written more simple,

p:=(n,x)->sort(primpart(
    add((2*x+1)^(2*n-2*i)/(2*i+1),i=0..n))):

Alec

Verification is good for simple cases, but it also has problems in more complicated situations. For example, it is not that easy to verify that [[1,2],3] is equal to [[1.0,2.0],3.0]. I remember posting something about that (nested verification) few years ago on this site.

Edit: Here is the link.

Alec

That works for (at least small enough) integers, but might not work in other situations. In particular,

is([1.]=[1.0]);
                                false

Alec

After copying the code, In Classic Maple, in the Edit menu, click Paste Maple text. The prompts are pasted, but that doesn't matter - the code works. There is no such an entry in the Standard Maple Edit menu.

Alec

Here is the pattern and the way of generating these polynomials,

p:=(n,x)->sort(primpart(doublefactorial(2*n+1)*
    add((2*x+1)^(2*n-2*i)/(2*i+1),i=0..n))):

p(0,x);
                                  1

Vector(4,rcurry(p,x));

        [   2          ]
        [3 x  + 3 x + 1]

        [     4        3        2             ]
        [240 x  + 480 x  + 380 x  + 140 x + 23]

        [     6         5         4         3        2             ]
        [840 x  + 2520 x  + 3220 x  + 2240 x  + 903 x  + 203 x + 22]

        [       8           7           6           5           4
        [80640 x  + 322560 x  + 571200 x  + 584640 x  + 379008 x

                   3          2               ]
         + 159936 x  + 43272 x  + 6984 x + 563]

Alec

For example,

plots:-spacecurve(eval([x, y, x^3*y], 
    [x = sqrt(8)*cos(t), y = 2*sin(t)]), t = 0 .. 2*Pi, 
    axes = boxed, labels = [x, y, z]);

Another way,

plots:-intersectplot(x^2+2*y^2=8, z=x^3*y, 
    x=-sqrt(8)..sqrt(8), y=-2..2, z=-20..20, axes=box);

Alec

It would be, probably, much faster and more precise to apply one of the numerical integration methods directly to the data instead of interpolating it and then numerically integrating.

For example, something like Simpson's method gives

s:=unapply(eval(factor~(int(interp([a,b,c],[d,e,f],x),x=c..a)),
[a=A[1,1],b=A[2,1],c=A[3,1],d=A[1,2],e=A[2,2],f=A[3,2]]),A);

add(s(data[i..i+2]),i=seq(2..98,2));

                             4.931471403

The first interval is missing, but it is much shorter than the others, and trapezoid formula for it gives a rather small addition,

(data[1,2]+data[2,2])/2*(data[1,1]-data[2,1]);

                          -0.00003367656869

%+%%;
                             4.931437726

Alec

For example,

select(i->igcd(i,2*3*7)=1,[$1..100])[];

  1, 5, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41, 43, 47, 53, 55, 59,

        61, 65, 67, 71, 73, 79, 83, 85, 89, 95, 97

Alec

First 17 18 19 20 21 22 23 Last Page 19 of 76