updates/R5/highlights - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : updates/R5/highlights

What Has Changed in Maple V Release 5


Maple V Release 5 includes significant enhancements to some existing features.  A brief description of the most interesting enhancements follows.


Lexical Scoping

Differential Equations and the DEtools package


Three Dimensional Geometry


Arrays of Hardware Floats

Algebraic Curves

Groebner Bases and Ore Algebras

Lexical Scoping




Maple allows you to create nested procedure definitions.  This means that procedures can be defined within other procedures, or return procedures as expected output.  Lexical scoping allows a nested procedure to access the variables which are located in surrounding procedures. You can now program in Maple and achieve better encapsulation.


In previous versions of Maple, it was difficult to have a nested procedure access the variables of an enclosing procedure.  Procedures could only share variables if the variables were global.


An Example


The simple example in this section uses the concept of lexical scoping of parameters to define a procedure that creates new procedures that depend upon the input to the top-level procedure.

makeincr := proc(n::integer) # outer procedure
        local   incr;

        incr := proc(i::integer) # inner procedure
                RETURN( i + n ); # n is the parameter to makeincr
        RETURN( incr );

makeincr:=procn::integerlocalincr;incr:=proci::integerRETURNi+nend proc;RETURNincrend proc


add2 := makeincr( 2 );



add2( 0 );



add2( 5 );



addminus1 := makeincr( -1 );



addminus1( 0 );



addminus1( 5 );



In the preceding example, a procedure incr is nested in an outer procedure makeincr.  The outer procedure returns as its value the nested procedure incr. The parameter n of makeincr is lexically scoped: its value is visible within the inner procedure incr, where it is used to determine by how much to increment its own parameter i. The value of  n is passed to makeincr as part of the definition of the inner procedure incr.


Notice that if one sets the kernel options variable warnlevel to 4, a warning is issued about the presence of a lexically scoped parameter.  The warning identifies the new feature in Release 5, whereas in previous versions of Maple, the variable n occurring in the definition of the inner procedure incr would be regarded as a global variable.


For more information about lexical scoping, please see the lexical example worksheet.

Differential Equations and the DEtools package


The DEtools package is not new in Release 5, but it has been significantly expanded, with dramatic improvements both in performance and power. DEtools incorporated packages that were previously share packages: ODEtools (here DEtools,Lie) for computing using Lie symmetry methods and classifying ODEs; diffop , for computing with linear differential operators; and Poincare for plotting 2D/3D projections of Poincare sections of Hamiltonian systems.


The dsolve command has also been rewritten to take direct advantage of the new implementation of symmetry methods now available in DEtools, resulting in a remarkable improvement in its solving performance.


Finally, the odeadvisor command, originally from ODEtools, can be used to classify ODEs in general, and contains more help pages with related information and solving tips.


Many more examples can be found in the example worksheets examples/diffop and examples/linearode.

with( DEtools );



As an example, consider the following second order, nonlinear ODE.

ode := x^4 * diff( y( x ), x, x ) + ( x * diff( y( x ), x ) - y( x ) )^3 = 0;



The new odeadvisor command, classifies this differential equation as follows

odeadvisor( ode );



Given the additional, optional argument help, odeadvisor will pop up a related help page.

odeadvisor( ode, 'help' );



The result from odeadvisor indicates that this is a second order ODE with linear symmetries. You can see the symmetries of this ODE using the symgen command (see DEtools,Lie)

symgen( ode );



The dsolve command, based on this information, will solve this ODE as follows (see dsolve,Lie)

dsolve( ode );



Most of the steps of the symmetry scheme are available as user-level commands. Consider for instance the symmetry cycle.


1) A pair of infinitesimals:

sym := [_xi = 0, _eta = exp(y)/ln(x)];



2) The most general first order ODE invariant under the symmetry group represented by the infinitesimals above can be obtained using equinv

ODE := equinv( sym, y(x) );



3) This ODE can then be solved by dsolve which calls symgen to determine the ODE symmetries and uses this information to arrive at

ans := dsolve( ODE );



4) The infinitesimals of the symmetry group can in turn be reobtained departing from the solution above using buildsym

buildsym(ans, y(x));



5) The concrete Lie group of transformation equations (changes of variables) which leaves the ODE invariant can be obtained using transinv

TR_1 := transinv( sym, y(x), s(r) );



In the above, _alpha; is the continuous parameter of the Lie group (that is, a real constant). The inverse transformation is given by

ITR_1 := solve(TR_1,{x,y(x)});



and can be used to check that the ODE is actually invariant under these transformation equations, arriving at an ODE with the same form as the original one (using dchange to change variables):

PDEtools[dchange](ITR_1, ODE, [r,s(r)], normal);






6) The canonical coordinates of this Lie group (the coordinates which reduce this ODE to a quadrature; see odeadvisor,quadrature) are obtained using canoni

TR_2 := canoni(sym,y(x),s(r));



ITR_2 := solve(TR_2,{x,y(x)});



These canonical coordinates are presently used by dsolve to reduce ODE to a quadrature by change of variables







Once the right hand side of the ODE above does not depend on s(r), it is a quadrature and is solved just integrating both sides with respect to r. Changing variables back one arrives at the answer for the original ODE returned by dsolve.


7) Finally, the infinitesimals of an underlying symmetry group can be used to build an integrating factor for this first order ODE (see odeadvisor,exact) by using the intfactor command:




mu := intfactor(ODE);



odeadvisor( mu * ODE );



There are a variety of optional arguments to dsolve (see the dsolve,Lie for details).



The PDEtools package is a new package in Maple. PDEtools is a collection of commands and routines for finding analytical solutions for partial differential equations (PDEs). The package is an implementation of known methods for solving PDEs; however, it also allows you to look for solutions of equations not yet automatically solved by the package, or for "different solutions" when the package returns a solution which is not the most general one. For this purpose, you can make use of the dchange command and of the HINT option of the pdsolve command (especially the functional hint), both explained in more detail in the corresponding help pages. Finally, PDEtools incorporates the PDEplot command, for plotting the solution for linear and nonlinear first order PDEs with given initial conditions.




When the general solution is found, it is returned directly in equation format

PDE := diff(f(x,y,z),y)+diff(f(x,y,z),x)/x/z=diff(f(x,y,z),z);



ans := pdsolve(PDE);



Answers can be tested using pdetest

pdetest(ans, PDE);



When the answer obtained is not the most general one, pdsolve returns using the structure of the solution, to allow the user to determine whether the answer is useful or not

PDE := diff(f(x,y,z),y)^2*exp(2*y)+diff(f(x,y,z),x)/cos(x)/z=diff(f(x,y,z),z);



ans := pdsolve(PDE);



That is, on the left is the result found for the indeterminate function, and on the right is a list. In this case, the list contains a set of ODEs for the functions _F1, _F2 and _F3, introduced by pdsolve when building the result. In other examples the list may contain, additionally, an indication of any arbitrary functions and/or change of variables introduced during the solving process. To see the resulting expression for the indeterminate function f(x,y,z), it is possible to use the build command:




A suitable change of variables is the most 'powerful' method when the solution cannot be found by other means. These changes or variables can now be performed using dchange. As a blackboard example, consider for instance the reduction of the number of differentiation variables in a given PDE

PDE := 1+F(x,y)^2+y*diff(F(x,y),x)-x*diff(F(x,y),y);



The solution to the PDE above is in fact invariant under rotations in the plane, which means that introducing polar coordinates (the natural coordinates for describing rotations) we will obtain the aforementioned reduction

TR := {x=r*cos(phi), y=r*sin(phi)};



dchange(TR, PDE, simplify);



The resulting PDE is easily solvable

ans := pdsolve((38));



and the answer to the original problem can be obtained changing variables back

ITR := {r=sqrt(x^2+y^2), phi=arctan(y/x)};



dchange(ITR, ans, known=_F1, simplify);






dchange is a general change of variables command and as such it can be used to change variables in procedures directly or in integrals (actually any valid Maple expression; see the related help page).

Three Dimensional Geometry


An extensive set of facilities for working with three-dimensional geometric objects and algorithms is provided in the new geom3d package.


Using the geom3d package, you can manipulate a wide variety of geometric objects, including points, lines, planes, spheres, polyhedra, and other solids.


Use the geom3d package by entering the with command.  You can refer to procedures in the package by their short names.


with( geom3d ):


It is very easy to create a variety of geometric objects.

tetrahedron( T, point( O, 0, 0, 0 ), 3 );



faces( T );



area( T );



volume( T );



You can visualize geometric objects using the draw command.

draw( T );


See the list of example worksheets for example worksheets available for this package.



True strings are added to Maple V Release 5.  Previously, names also acted as strings when necessary.


Strings and names are identified with a different syntax:

s := "This is a string";

sThis is a string


type( s, 'string' );



type( s, 'name' );



n := `This is a name`;

nThis is a name


type( n, 'string' );



type( n, 'name' );



A fundamental distinction between names and strings is that names may be assigned a value, while strings cannot.

`A name` := 5;

A name5


"A string" := 5;

Error, invalid left hand side of assignment


Many procedures which formerly took names or strings as parameters, or returned names for use as strings, now will accept strings (and names), and return strings.

save `A name`, "/tmp/junk.m";

printf( "%s: %d\n", "A String of length: ", length( "A String of length: " ) );

A String of length: : 20


The MATLAB® Link allows you to open a connection to the MATLAB® numeric software package, and carry out computations there, returning the results to your current Maple session.


To use this package, you must have a correctly installed, licensed copy of MATLAB® on your computer. The Matlab example worksheet provides further explanation and examples. (Note: you will need MATLAB® to execute this worksheet.)


Example Computation


To establish a connection with MATLAB®, and to make available the Maple commands for interacting with it, use the with command to load the Matlab package.

with( Matlab ):


First, define a four by four Maple matrix.  Use the Maple command below.

m := linalg[ 'randmatrix' ]( 4, 4 );



To define a MATLAB® variable, use the procedure setvar.

setvar( "m", m );


The MATLAB® variable "m" is defined to have the same value as the Maple variable m. Note that the variable "m" now exists in the current MATLAB® session to which Maple is connected.


Compute the Schur decomposition of this matrix m in MATLAB® by issuing the command

evalM( "r = schur( m )" );


Note the distinction between the evalM command and Maple's matrix evaluator, evalm.


This command sends the MATLAB® command enclosed in quotation marks to the running MATLAB® session to be executed. In this case, a MATLAB® variable "r" is assigned the value of the Schur decomposition of the MATLAB® variable "m".


Now retrieve the value of "r" from MATLAB®, using the getvar command.

s := getvar( "r" );


Finally, to convert this to a Maple matrix, use the command

a := evalm( convert( s, 'array' ) );

Arrays of Hardware Floats


Arrays of hardware floating point numbers have been added to Maple V Release 5. Using arrays of hardware floating point numbers (called hfarrays in Maple) can dramatically improve the performance of numerical algorithms.


If you write a procedure that will be evaluated within evalhf, be careful not to introduce any symbolic constructs.


A simple, but nontrivial example of hfarrays is an implementation of the ``forward elimination'' algorithm employed by traditional Gaussian Elimination for square numerical matrices. The main departure from the straightforward description of the algorithm is that we take a little care to choose our pivot in a way that helps to proscribe numerical instability.

macro( forelim = `HFGaussElim/forelim` );



forelim :=      proc(r::posint, m::{array,hfarray})

    local   i, j, k,        # indices
            max,            # used to choose the pivot row
            t;              # temporary for swapping

    # for each row
    for i from 1 to r do

        max := i;

        # find the pivot row
        # (should be modified for sparse implementation)
        for j from 1 + i to r do
            if abs( m[ j, i ] ) > abs( m[ max, i ] ) then
                max := j;

        # interchange
        for k from i to r do
            # swap
            t := m[ i, k ];
            m[ i, k ] := m[ max, k ];
            m[ max, k ] := t;

        # do the pivot
        for j from 1 + i to r do
            for k from r to i by -1 do
                m[ j, k ] := m[ j, k ] - m[ i, k ] * m[ j, i ] / m[ i, i ];



HFGaussElim/forelim:=procr::posint&comma;m::array&comma;hfarraylocali&comma;j&comma;k&comma;max&comma;t&semi;foritordomax:=i&semi;forjfromi&plus;1tordoifabsm&lsqb;max&comma;i&rsqb;<absm&lsqb;j&comma;i&rsqb;thenmax:=jend ifend do&semi;forkfromitordot:=m&lsqb;i&comma;k&rsqb;&semi;m&lsqb;i&comma;k&rsqb;:=m&lsqb;max&comma;k&rsqb;&semi;m&lsqb;max&comma;k&rsqb;:=tend do&semi;forjfromi&plus;1tordoforkfromrby&minus;1toidom&lsqb;j&comma;k&rsqb;:=m&lsqb;j&comma;k&rsqb;m&lsqb;i&comma;k&rsqb;&ast;m&lsqb;j&comma;i&rsqb;&sol;m&lsqb;i&comma;i&rsqb;end doend doend do&semi;mend proc


Given a square matrix as input, an upper triangular matrix, row- equivalent to the input, is produced.

forelim( 4, matrix( 4, 4, [ 1, 2, 3, 4, 2, 3, 4, 1, 3, 4, 1, 2, 4, 1, 2, 3 ] ) );



Now we can wrap forelim in a procedure HFGaussElim that checks its arguments and evaluates forelim with the evalhf environment.

HFGaussElim     :=      proc(m::matrix)
    local   rows, cols, i, j, lm;

    rows := linalg[ 'rowdim' ]( m );
    cols := linalg[ 'coldim' ]( m );

    if rows <> cols then
            ERROR( "Must be a square matrix" );

    lm := matrix( rows, rows );