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

PDEtools

Three Dimensional Geometry

Strings

Arrays of Hardware Floats

Algebraic Curves

Groebner Bases and Ore Algebras

Lexical Scoping

  

Introduction

  

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
        end;
        RETURN( incr );
end;

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

(1)

add2 := makeincr( 2 );

add2incr

(2)

add2( 0 );

2

(3)

add2( 5 );

7

(4)

addminus1 := makeincr( -1 );

addminus1incr

(5)

addminus1( 0 );

−1

(6)

addminus1( 5 );

4

(7)
• 

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 );

AreSimilar,Closure,DEnormal,DEplot,DEplot3d,DEplot_polygon,DFactor,DFactorLCLM,DFactorsols,Dchangevar,Desingularize,FindODE,FunctionDecomposition,GCRD,Gosper,Heunsols,Homomorphisms,IVPsol,IsHyperexponential,LCLM,MeijerGsols,MultiplicativeDecomposition,ODEInvariants,PDEchangecoords,PolynomialNormalForm,RationalCanonicalForm,ReduceHyperexp,RiemannPsols,Xchange,Xcommutator,Xgauge,Zeilberger,abelsol,adjoint,autonomous,bernoullisol,buildsol,buildsym,canoni,caseplot,casesplit,checkrank,chinisol,clairautsol,constcoeffsols,convertAlg,convertsys,dalembertsol,dcoeffs,de2diffop,dfieldplot,diff_table,diffop2de,dperiodic_sols,dpolyform,dsubs,eigenring,endomorphism_charpoly,equinv,eta_k,eulersols,exactsol,expsols,exterior_power,firint,firtest,formal_sol,gen_exp,generate_ic,genhomosol,gensys,hamilton_eqs,hypergeometricsols,hypergeomsols,hyperode,indicialeq,infgen,initialdata,integrate_sols,intfactor,invariants,kovacicsols,leftdivision,liesol,line_int,linearsol,matrixDE,matrix_riccati,maxdimsystems,moser_reduce,muchange,mult,mutest,newton_polygon,normalG2,ode_int_y,ode_y1,odeadvisor,odepde,parametricsol,particularsol,phaseportrait,poincare,polysols,power_equivalent,rational_equivalent,ratsols,redode,reduceOrder,reduce_order,regular_parts,regularsp,remove_RootOf,riccati_system,riccatisol,rifread,rifsimp,rightdivision,rtaylor,separablesol,singularities,solve_group,super_reduce,symgen,symmetric_power,symmetric_product,symtest,transinv,translate,untranslate,varparam,zoom

(8)
• 

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;

odex4ⅆ2ⅆx2yx+xⅆⅆxyxyx3=0

(9)
• 

The new odeadvisor command, classifies this differential equation as follows

odeadvisor( ode );

_2nd_order,_with_linear_symmetries

(10)
• 

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

odeadvisor( ode, 'help' );

_2nd_order,_with_linear_symmetries

(11)
• 

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 );

_ξ=0,_η=x,_ξ=x,_η=y

(12)
• 

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

dsolve( ode );

yx=arctan1_C1x21+_C2x,yx=arctan1_C1x21+_C2x

(13)
• 

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)];

sym_ξ=0,_η=ⅇylnx

(14)
  

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) );

ODEⅆⅆxyx=1lnxx+ⅇyx_F1x

(15)
  

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 );

ansyx=lnlnx_F1xⅆx+_C1lnx

(16)
  

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

buildsym(ans, y(x));

_ξ=0,_η=ⅇylnx

(17)
  

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) );

TR_1r=x,sr=lnlnx_αⅇyxlnx+yx

(18)
  

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)});

ITR_1x=r,yx=srlnⅇsr_α+lnrlnr

(19)
  

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);

ⅆⅆrsrlnr2r+ⅇsr_αlnrrⅇsr_α+lnr=ⅇsrlnⅇsr_α+lnrlnr_F1rrlnr+1rlnr

(20)

expand(simplify(solve((20),{diff(s(r),r)})));

ⅆⅆrsr=_F1rⅇsr+1lnrr

(21)
  

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));

TR_2r=x,sr=lnxⅇyx

(22)

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

ITR_2x=r,yx=lnlnrsr

(23)
  

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

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

ⅆⅆrsrlnrr+srsrrlnr=lnr2_F1rr+srsrrlnr

(24)

expand(simplify(solve((24),{diff(s(r),r)})));

ⅆⅆrsr=lnr_F1r

(25)
  

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:

ODE;

ⅆⅆxyx=1lnxx+ⅇyx_F1x

(26)

mu := intfactor(ODE);

μⅇyxlnx

(27)

odeadvisor( mu * ODE );

_exact,_1st_order,_with_symmetry_[F(x),G(x)]

(28)
• 

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

PDEtools

  

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.

with(PDEtools);

CanonicalCoordinates,ChangeSymmetry,CharacteristicQ,CharacteristicQInvariants,ConservedCurrentTest,ConservedCurrents,ConsistencyTest,D_Dx,DeterminingPDE,Eta_k,Euler,FirstIntegralSolver,FromJet,FunctionFieldSolutions,InfinitesimalGenerator,Infinitesimals,IntegratingFactorTest,IntegratingFactors,InvariantEquation,InvariantSolutions,InvariantTransformation,Invariants,Laplace,Library,PDEplot,PolynomialSolutions,ReducedForm,SimilaritySolutions,SimilarityTransformation,Solve,SymmetryCommutator,SymmetryGauge,SymmetrySolutions,SymmetryTest,SymmetryTransformation,TWSolutions,ToJet,ToMissingDependentVariable,build,casesplit,charstrip,dchange,dcoeffs,declare,diff_table,difforder,dpolyform,dsubs,mapde,separability,splitstrip,splitsys,undeclare

(29)
• 

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);

PDEyfx,y,z+xfx,y,zxz=zfx,y,z

(30)

ans := pdsolve(PDE);

ansfx,y,z=_F1zⅇx22,y+z

(31)
• 

Answers can be tested using pdetest

pdetest(ans, PDE);

0

(32)
• 

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);

PDEyfx,y,z2ⅇ2y+xfx,y,zcosxz=zfx,y,z

(33)

ans := pdsolve(PDE);

ansfx,y,z=_F1x+_F2y+_F3z&whereⅆⅆy_F2y2=ⅇ2y_c2,ⅆⅆx_F1x=_c1cosx,ⅆⅆz_F3z=_c1z+_c2

(34)
  

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:

build(ans);

fx,y,z=_c1sinx+_C1_c2ⅇy2+_C2+_c1lnz+_c2z+_C3

(35)
• 

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);

PDE1+Fx,y2+yxFx,yxyFx,y

(36)
  

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)};

TRx=rcosφ,y=rsinφ

(37)

dchange(TR, PDE, simplify);

1+Fφ,r2φFφ,r

(38)
  

The resulting PDE is easily solvable

ans := pdsolve((38));

ansFφ,r=tanφ+_F1r

(39)
  

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

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

ITRφ=arctanyx,r=x2+y2

(40)

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

Fx,y=tanarctanyx+_F1x2+y2

(41)

pdetest((41),PDE);

0

(42)
• 

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.

restart;

with( geom3d ):

• 

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

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

T

(43)

faces( T );

3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

(44)

area( T );

243

(45)

volume( T );

83

(46)
• 

You can visualize geometric objects using the draw command.

draw( T );

• 

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

Strings

  

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

(47)

type( s, 'string' );

true

(48)

type( s, 'name' );

false

(49)

n := `This is a name`;

nThis is a name

(50)

type( n, 'string' );

false

(51)

type( n, 'name' );

true

(52)
• 

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

`A name` := 5;

A name5

(53)

"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 );

m−722−55−9487−560−6297−73−4−83−1062−8280

(54)
  

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

(55)

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;
            fi;
        od;

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

        # 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 ];
            od;
        od;

    od;

    m;
end;

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

(56)
• 

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 ] ) );

4123013412140044134130004011

(57)
• 

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" );
    fi;

    lm := matrix( rows, rows );