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

For example,

expand(add(mul(add(i,i=Matrix(2,(i,j)->X[i,j,k])),
    X in [x,y,z]),k=0..7));

Alec

They are not built-in. One implementation is available in the XMLTools package through XMLElement. Another one (for binary trees) can be found in examples,binarytree.

Alec

Programming is not a spectator sport. If you want to learn it, you have to try to do it yourself. Show your work, and ask questions if you tried unsuccessfully to perform some step for some time, or want to know how to improve the code you wrote. There is a lot of code posted on this site. If you were not able to learn from that was already posted, I don't think that this one particular problem would make any differemce.

Besides, why do you want to learn Maple? The language is quite obscure, and the community is practically not existing. I understand why older folks (like me) stick to it - because we started using it a long time ago, when it was not so bad choice. But now? Python is much better language, with a great community. Everything that can be done in Maple, can be done much more simple, much more efficient, and with much better quality plots in Python. Learn Python instead! And I've already provided a link to the Python code.

Alec

PS Thinking about that - I never refuse to give change (meaning $20) being asked about that on a street. Why would I refuse a request for a donation here? So I posted a blog entry with the code. -Alec

del_el:=(A,el)->A[LinearAlgebra:-ComplementaryIndices(
    el,LinearAlgebra:-Dimension(A))]:

A:=<4,5,3,0,8,12>;

                                   [ 4]
                                   [  ]
                                   [ 5]
                                   [  ]
                                   [ 3]
                              A := [  ]
                                   [ 0]
                                   [  ]
                                   [ 8]
                                   [  ]
                                   [12]

elim_order:=[2,3,5];

                       elim_order := [2, 3, 5]

answer:=del_el(A,elim_order);

                                      [ 4]
                                      [  ]
                            answer := [ 0]
                                      [  ]
                                      [12]

It works the same as Joe Riel's suggestion above, just written in a different form.

Alec

a) Symbolically it can be done using VectorCalculus:-int. The help page has an example with a triangle. Numerically one still has to use evalf with double Int and limits calculated manually. See evalf/Int help page.

b) See evalf/Int.

There is also Student:-NumericalAnalysis:-Quadrature, which can be used for finding weights and points in one dimension. Multi-dimensional Gaussian quadrature for triangles (and other regions) seems to be not implemented in Maple.

Alec

In case of functions of one variable t, that can be done using

dorder:=(S,x)->
 PDEtools:-difforder(
  select(has,indets(S,specfunc(anything,diff)),x));

which gives

dorder(S,X);

                                  1

dorder(S,Y);

                                  2

Alec

It may be a copying and pasting issue, because it also works if you do it like

expr1:=BooleanSimplify(expr);
Equivalent(expr,expr1);
                                 true

Alec

If the sets of elements of the row and the column vectors don't intersect, that can be done as in following example,

a:=x1*y1+2*x1*y2+3*x2*y3;

                    a := x1 y1 + 2 x1 y2 + 3 x2 y3

v:=[x1,x2];

                            v := [x1, x2]

w:=[y1,y2,y3];

                          w := [y1, y2, y3]

A:=Matrix(nops(v),nops(w),
    (i,j)->coeff(coeff(a,v[i]),w[j]));

                               [1    2    0]
                          A := [           ]
                               [0    0    3]

Vector[row](v).A.Vector(w);

                      x1 y1 + 2 x1 y2 + 3 x2 y3

evalb(%=a);

                                 true

Another simple way of doing that is

B:=LinearAlgebra:-GenerateMatrix(map2(coeff,a,v),w)[1];

                               [1    2    0]
                          B := [           ]
                               [0    0    3]

Coeffs with 3 arguments also can be used, and it looks like a more efficient way of doing that, but there is a slight problem that, say x1*y1 can appear in the 3rd parameter in 2 forms - as x1*y1 and y1*x1, so additional searches (using member command, for example) have to be used, which decreases efficiency. One way around it is using a (m+n)×(m+n) symmetric matric and then returning its submatrix,

f:=proc(a,v,w) 
local c,i,m,n,t,T,A;
m,n:=nops(v),nops(w);
for i to m do T[v[i]]:=i od;
for i to n do T[w[i]]:=i+m od;
c:=coeffs(a,[op(v),op(w)],t);
A:=Matrix(m+n,shape=symmetric);
for i to nops([t]) do 
    A[T[op(1,t[i])],T[op(2,t[i])]]:=c[i] od;
A[1..m,m+1..m+n] 
end;

f(a,v,w);
                            [1    2    0]
                            [           ]
                            [0    0    3]

By the way, the Hessian (i.e. second derivatives) works quite well, and simple,

VectorCalculus:-Hessian(a,[op(v),op(w)])
    [1..nops(v),nops(v)+1..nops(v)+nops(w)];

                            [1    2    0]
                            [           ]
                            [0    0    3]

Alec

Is it a homework or a course project?

There are many implementations available on the web in various programming languages. In particular, in Python, which could be rather simple rewritten in Maple.

Alec

c1 :=CurveFitting:-ArrayInterpolation(R, X, v);

                      c1 := 2.18999999999999994

evalf(%,3);

                                 2.19

Alec

As far as I recall, some (rather long) time ago, there was a Maple plots gallery somewhere on the maplesoft site, with a link to it from the main maplesoft page. Robert Israel's plots in this thread certainly belong there. Does it still exist? I don't recall seeing a link to it on the main maplesoft page recently.

Alec

A normal way of doing that is

eqn:=Vector[row](5,i->i);

                        eqn := [1, 2, 3, 4, 5]

Using a loop in such constructions is a popular misconception. It is good inside a procedure with option autocompile though, in which case it should be passed as a parameter of the procedure and defined before using it. For example,

 

myproc:=proc(v::Vector(datatype=integer[4]), n::integer[4])
    local i::integer[4];
    option autocompile;
    for i to n do v[i]:=i od;
    NULL 
end:

eqn:=Vector[row](5,datatype=integer[4]);

                        eqn := [0, 0, 0, 0, 0]

myproc(eqn,5);
eqn;

                           [1, 2, 3, 4, 5]

Maple has many indexed datatypes: tables, lists, sets, arrays, vectors, Arrays, Vectors (and a few more - expression sequences and hashtables, for instance). And if it is not defined previously, assigning eqn[1] makes eqn a table by default, which is a quite efficient data type, but needs some care in using it. The easiest way to fix that, without rewriting big chunks of code, is to define eqn as a Vector[row] before assigning its elements,

eqn:=Vector[row](5):
for i to 5 do eqn[i]:=i od:
eqn;

                           [1, 2, 3, 4, 5]

Alec

Increasing digits is often useful. In examples like that, also using log(LF) instead of LF helps,

LF := (1/1658880)*(1-p)^12*p^6*lambda^20/(exp(lambda)-1)^6:

Optimization:-NLPSolve(log(LF), p = 0 .. 1, lambda = 0.1..100, maximize);

  [-21.4661871284769994,

        [p = 0.333333333149784139, lambda = 3.19705917923756732]]

exp(%[1]);

                                         -9
                          0.4757221598 10

Alec

LF := (1/1658880)*(1-p)^12*p^6*lambda^20/(exp(lambda)-1)^6;

                                       12  6       20
                                (1 - p)   p  lambda
                LF := 1/1658880 ---------------------
                                                  6
                                 (exp(lambda) - 1)

maximize(LF,p=0..1,lambda=0..infinity, location):
simplify([%]);

                                   14   6
  [1/750473176484995605 (3 %1 + 10)   %1 , {[

        {p = 1/3, lambda = %1 + 10/3},

                                        14   6
        1/750473176484995605 (3 %1 + 10)   %1 ]}]

  %1 := LambertW(-10/3 exp(-10/3))

evalf(%)[];

                 -9
  0.4757221607 10  , {

                                                                  -9
        [{p = 0.3333333333, lambda = 3.197059146}, 0.4757221607 10  ]

        }

Alec

By the way, both the Möbius strip and the Boy's surface are built-in in Mayavi2 (which is one of Python 3D visualization tools.) It is a part of python(x,y) distribution for Windows.

135_boy1.png

135_param.jpg

The first picture came from saving the scene in Mayavi2 in the png format (note the small file size) - many other formats are available, including jpg and pdf.

The second picture is from the Mayavi2 documentation - it is located in C:\Python25\Lib\site-packages\Mayavi-3.2.0-py2.5-win32.egg\enthought\docs\html\mayavi\_images\param.jpg

Alec

First 25 26 27 28 29 30 31 Last Page 27 of 76