Map a procedure onto an expression, operating on Matrices and Vectors in-place - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Linear Algebra : LinearAlgebra Package : Standard : LinearAlgebra/Map

LinearAlgebra[Map] - Map a procedure onto an expression, operating on Matrices and Vectors in-place

LinearAlgebra[Map2] - Map a procedure onto an expression, operating on Matrices and Vectors in-place

Calling Sequence

Map[filter](f, expr, arg2, ...)

Map2[filter](f, arg1, expr, arg2, ...)

Parameters

filter

-

(optional) boolean-valued procedure; selects locations at which the function f is applied

f

-

procedure or name; procedure to apply to the operands of expr

expr

-

expression; expression being mapped

arg1

-

first argument to pass to f (Map2 only)

arg2, ...

-

(optional) further arguments to f

Description

• 

The Map(f, expr) calling sequence applies f to the operands of expr.

  

The ith operand of expr is replaced by the result of applying f to the ith operand.  This is done for all the operands of expr.

  

If f takes more than one argument, they are included in the calling sequence as additional arguments arg2, arg3, ..., argn. They are passed as the second, third, ..., nth arguments to f.

• 

The Map2(f, arg1, expr) calling sequence is similar to Map, except that for each operand of expr, arg1 is passed as the first argument to f, the operand of expr is passed as the second argument, and arg3, ..., argn are passed as the third, ..., nth arguments.

• 

The Map and Map2 commands are identical to the map and map2 commands, respectively, except that if expr is a Matrix or Vector, then f is applied to the elements of that Matrix or Vector, and the application is done in-place.

  

Additionally, if any such application of f to an element of the Matrix or Vector fails to store (for example, in the case where the shape indicates that the corresponding location is not mutable), then that element is left unchanged. Thus, Map( ) and Map2( ) can be used to update the entries of an upper triangular Matrix. The diagonal entries of a unit triangular Matrix, for example, are not updated by Map( ) or Map2( ).

• 

The optional filter parameter, passed as the index to the Map or Map2 command, restricts the application of f to the entries of expr for which the filter returns true. The filter is passed the index of the entry: for a Vector, it is passed one argument; for a Matrix, two arguments.

  

The filter parameter is ignored if expr is not a Matrix or Vector.

• 

These functions are part of the LinearAlgebra package, and so they can be used in the form Map(..) or Map2(..) only after executing the command with(LinearAlgebra). However, they can always be accessed through the long form of the command by using LinearAlgebra[Map](..) or LinearAlgebra[Map2](..).

Examples

withLinearAlgebra:

A:=Matrix1,2,3,0,1,4,shape=triangularupper,unit

A:=123014

(1)

M:=Mapx→x+1,A

M:=134015

(2)

evalbaddressofA=addressofM

true

(3)

B:=1,2,3|4,5,6

B:=142536

(4)

Map2i,j→evalbi=1x,a→ax,3,B

3122536

(5)

Mapx→x+1,g3,A

g4,234025

(6)

By default, these routines act only on the upper triangle of symmetric and skew-symmetric Matrices.

C:=Matrix1,2,3,scan=triangularupper,shape=symmetric

C:=1223

(7)

Mapx→x+1,C

2334

(8)

Map[proc(i,j) type(i+j,odd) end proc](x->x^2, C);

2994

(9)

See Also

map, Matrix, name, procedure, Vector


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam