Matrix Construction - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Matrix

construct a Matrix

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

Matrix(r, c, init, ro, sym, sc, sh, st, o, dt, f, a)

Parameters

r

-

(optional) non-negative integer or integer range with left-hand endpoint 1; row dimension of Matrix

c

-

(optional) non-negative integer or integer range with left-hand endpoint 1; column dimension of Matrix

init

-

(optional) Maple procedure, table, array, list, Array, Matrix, Vector, set of equations, or expression of type algebraic; initial values for the Matrix

ro

-

(optional) equation of the form readonly=true or false; specify whether Matrix entries can be changed

sym

-

(optional) equation of the form symbol=name; specifies the symbolic name to be used for the Matrix entries

sc

-

(optional) equation of the form scan=name or scan=list specifying the structure and/or data order for interpreting initial values; interpreter for initial values in parameter init

sh

-

(optional) equation of the form shape=name or shape=list specifying one or more built-in or user-defined indexing functions; storage allocation for Matrix entries

st

-

(optional) equation of the form storage=name, where name is a permitted storage mode; storage requirements for Matrix entries

o

-

(optional) equation of the form order=name, where name is either C_order or Fortran_order; specifies if Matrix entries are stored by rows or columns

dt

-

(optional) equation of the form datatype=name, where name is any Maple type, float[8], float[4], double, complex[8], or integer[n] for n=1,2,4, or 8; type of data stored in Matrix

f

-

(optional) equation of the form fill=value, where value is of the type specified by the dt parameter; specifies Matrix entries at locations not otherwise set

a

-

(optional) equation of the form attributes=list, where list specifies permitted attributes; specifies additional mathematical properties of the Matrix

Description

• 

The Matrix(..) function is the constructor for the Matrix data structure. It is one of the principal data structures on which the LinearAlgebra routines operate.

• 

Only small Matrices are displayed inline in Maple. By default, a small Matrix is defined as one whose dimensions are in the range 1..25 (Command-line version of Maple)  or the range 1..10 (worksheet version of Maple). Any Matrix whose dimension(s) are larger than this size is displayed by using a placeholder. For information on how to view the placeholder, see structuredview.

  

You can display larger Matrices inline by using the interface(rtablesize=value) command, where value is an integer that represents the upper bound of the dimension range.

  

To change the environment so that Maple always displays rtables inline, include the interface(rtablesize=infinity) command in a Maple initialization file (see maple).

  

For more information, see interface.

• 

All parameters are optional. However, enough information must be provided in the calling sequence for the mathematical shape of the Matrix and the storage requirements for its entries to be determined. In particular, if no parameters are specified, the result is a 0 x 0 Matrix.

• 

The Matrix(r) function constructs an r x r Matrix whose entries are determined by the fill value in parameter f (default = 0). If the row dimension is not provided, it defaults to zero.

  

The Matrix(r,c) function constructs an r x c Matrix whose entries are determined by the fill value in parameter f (default = 0). If the column dimension is not provided, it defaults to the row dimension. The column dimension cannot be specified without specifying the row dimension.

• 

The Matrix(init) function constructs a Matrix whose shape and entries are determined by parameter init.

  

The Matrix(r,c,init) function constructs an r x c Matrix whose initial entries are determined by parameter init (and parameter f if all of the entries in the Matrix are not set by init). If the initial entries of the Matrix are not provided, all of the entry values default to the fill value (default = 0).

  

Parameter init can take any one of the following forms. (Dimensions must be provided in the calling sequence if init is one of the first four forms (procedure, expression, table, or set).)

  

procedure

  

The procedure must accept pairs of positive integer arguments (i.e., Matrix indices) and return the value for the corresponding entry in the Matrix.

  

expression of type algebraic

  

The expression is evaluated as a function (or procedure) which takes a pair of positive integers as arguments (i.e., Matrix indices) and returns the value of the corresponding entry of the Matrix.

  

table

  

The table is referenced by indices of the form [i, j] where i and j are positive integers (i.e., Matrix indices). (The table may include entries for indices of other forms.  These will be ignored.)

  

set of equations

  

The set of equations must take the form (i, j) = <value> where i and  j are positive integers (i.e., Matrix indices). It is an error to specify entries for locations that are outside the index range of the resulting Matrix.

  

array or Array

  

This must be a 2-D table-based array or rtable-based Array. The indexing is shifted to be 1-based. It is an error to specify entries for locations that are outside the index range of the resulting Matrix.

  

Matrix

  

The Matrix constructor accepts another Matrix as an initializer for the entries.  It is an error to specify entries for locations that are outside the index range of the resulting Matrix.

  

list or list of lists

  

The case when init is a list of scalars (specifically, of objects which are of type algebraic and not of type indexable), at least one dimension is explicitly given and the only other options given are the readonly, datatype and/or order options is treated specially. In this case, the dimensions of the resulting Matrix are determined as described above, and then the list init is partitioned accordingly.  The resulting list of lists is then used to initialize the Matrix, as described below.  Note that if the row dimension is r and the column dimension is c and nopsinit<rc, then init will be padded with zeroes as needed.

  

Otherwise, if init is a list whose elements are not themselves lists, it is interpreted as [init].

  

 

  

If init is a list of lists, the first row of the Matrix is constructed from init[1], the second row from init[2], and so on, unless a scan parameter is provided. It is an error to specify entries for locations that are outside the index range of the resulting Matrix.

  

The sublists in init must satisfy the following Conformance Rule: The components of the sublists of the `init` parameter  must define a complete partition of the Matrix being constructed.

  

Vector

  

If the sh parameter is included in the calling sequence and set to shape = diagonal or shape = [diagonal], then the Vector is used to initialize the main diagonal of the resulting Matrix, regardless of the Vector's orientation. Otherwise, the elements of the Vector are placed in the first column or row of the resulting Matrix, according to the orientation of the Vector.

• 

If the ro option is included in the calling sequence as either readonly or readonly=true, then the resulting Matrix is "readonly" (i.e., its entries cannot be changed after construction).

• 

The sym option, in the form symbol=name, provides a symbolic name to use for the Matrix entries if no initializer is provided.  This parameter is ignored if an initializer is given.

• 

Parameters may be included more than once.  If more than 2 integers are included in the calling sequence, the first is r, the second is c, and the last is init (algebraic expression case). Otherwise, if a parameter is repeated, the last occurrence is the effective one.

• 

Parameters may be given in any order (except that the interpretation of integer parameters is always that the first is r and the second is c).

• 

The remaining parameters in the calling sequence have been provided for achieving maximal efficiency in computations with Matrices.

  

scan=name or scan=list

  

Specifies the structure and/or the data order for interpreting the initial values of a Matrix when init is a list. If the scan parameter is not provided in the calling sequence and init is a list, scan defaults to [rectangular,rows].  In the case that init is not a list, the scan parameter is ignored. For more information regarding scan methods in Matrices, see scan.

  

shape=name or shape=list

  

Specifies one or more built-in or user-defined indexing functions that determine the nonzero structure of the Matrix. If more than one indexing function is included, they must be entered as a list. The default shape is [] (none). For Matrices, the built-in indexing functions are:

antihermitian

antisymmetric

band

constant

diagonal

identity

hermitian

scalar

symmetric

triangular

zero

Hessenberg

  

For more information, see storage and rtable_indexfcn.

  

storage=name

  

Specifies how physical memory is allocated for storing the entries of the Matrix.   The default storage is rectangular.

  

For more information, see storage.

  

order=name

  

Specifies the internal ordering of the Matrix structure. Permissible values are C_order (stored by rows) and Fortran_order (stored by columns). The default order is Fortran_order.

  

datatype=name

  

Specifies the type of data stored in the Matrix. It can be one of integer[n], float[n], double, complex[n], or any Maple type specification.

  

For integer[n], n can be 1, 2, 4, or 8, indicating the number of bytes per integer. For float[n], n can be 4 or 8, again indicating the number of bytes per floating-point number. The double datatype is the same as the float[8] datatype. For complex[n], the only allowable value of n is 8, indicating the number of bytes allocated for each of the real and imaginary parts of the values stored in the Matrix. The default datatype is the general Maple type anything.

  

fill=value

  

Specifies the value for unspecified Matrix elements. This value must meet the same evaluation requirements as the initializer values. The default fill value is 0.

  

Note:  The fill value is only used to fill those elements of the Matrix that are unspecified in spite of the indexing function. For instance, the fill value is not used to fill the lower triangle of an upper triangular Matrix. In the case of a sparse Matrix, the fill value is always ignored.

  

attributes=list

  

Specifies the attributes with which the Matrix is created. This option can be used to attach mathematical properties to the Matrix. Anything that is a valid argument to setattribute can be an attribute of a Matrix.

  

This information can be used by various routines, for example, when choosing between algorithms.  In particular, the following LinearAlgebra package routines efficiently choose an appropriate algorithm if attributes=[positive_definite] is included in the calling sequence to construct the Matrices used in the routines.

  

 

ConditionNumber

Eigenvalues

Eigenvectors

LinearSolve

LUDecomposition

MatrixInverse

  

The default is to have no attributes.

• 

After creation, it is possible to change the entries and some of the mathematical properties of the Matrix.  See Matrix assignment and Matrix options for more information.

• 

For additional information on accessing elements or groups of elements of a Matrix, see Matrix indexing.

• 

If expr is a Matrix expression, the nopsexpr function returns 3.

  

If expr is a Matrix expression, the opn&comma;expr function returns the following operands for the specified values of n.

n

returned operand

 

 

0

Matrix

1

dimensions as an expression sequence of two integers

2

Matrix elements as a set of equations of the form (indices)=value  *

3

Matrix options as an expression sequence of equations of the

 

form option=value  **

  

* Only the elements that explicitly need to be specified, taking into account storage, are returned.

  

** The subtype option is not returned since it is implicitly Matrix. The user and built-in indexing functions are returned as options.  The scan and fill options are not returned.

• 

Matrices do not have last name evaluation.

Examples

A 2 x 2 Matrix.

Matrix2

0000

(1)

 

A 3 x 3 identity Matrix.

Matrix3&comma;shape=identity

100010001

(2)

A 2 x 3 Matrix.

Matrix2&comma;3

000000

(3)

 

A 2 x 3 Matrix with all entries set to 5.

m1Matrix1..2&comma;1..3&comma;5

m1555555

(4)

 

When the initial values are given as list of lists, the first row of the Matrix is constructed by the first list, the second row by the second list, and so on.

m2Matrix1&comma;2&comma;3&comma;4&comma;5&comma;6

m2123456

(5)

 

Matrices with matching row and column dimensions can be added.

Matrixm1+m2

67891011

(6)

 

Matrices with same number of columns can be stacked.

Matrixm1&comma;m2

555555123456

(7)

 

In the following calling sequence, the list specifies entries of the 3 x 2 Matrix.

Note that specifying entries for locations that are outside the index range of the resulting Matrix will return an error.

m3Matrix3&comma;2&comma;1&comma;2&comma;3&comma;4&comma;5

m3123450

(8)

 

The option fill specifies entries for any otherwise unspecified Matrix elements.

Matrix4&comma;3&comma;m3&comma;fill=9

129349509999

(9)

 

You can use functions to return values for corresponding entries in a Matrix.

fi&comma;jxi+j1&colon;

Matrix2&comma;f

xx2x2x3

(10)

 

Use set notation to specify entries at each location.

Method 1:

s1&comma;1=0&comma;1&comma;2=1&colon;

Matrix1&comma;2&comma;s

01

(11)

Method 2:

Matrix4&comma;1&comma;2=5&comma;1&comma;3=6&comma;1&comma;4=7&comma;fill=1&comma;shape=symmetric

1567511161117111

(12)

 

Create Matrix using symbolic name for the entries.

Matrix2&comma;3&comma;symbol=m

m1,1m1,2m1,3m2,1m2,2m2,3

(13)

 

It is an error to attempt to write to a read-only Matrix.

AMatrix3&comma;4&comma;1&comma;2&comma;3&comma;4&comma;5&comma;6&comma;readonly=true

A123045600000

(14)

A1,1Matrix2

Error, cannot assign to a read-only Matrix

 

A column Matrix is not a Vector, but it can be converted to one.

v1Matrix3&comma;1&comma;1&comma;2&comma;3

v1123

(15)

whattypev1

Matrix

(16)

v1convertv1&comma;Vector

v1123

(17)

whattypev1

Vectorcolumn

(18)

Compatibility

• 

The datatype option was updated in Maple 2015.

See Also

Array

convert/Matrix

convert/Vector

efficient computations

indexing function

list

lowerbound

Matrix assignment

Matrix indexing

Matrix options

numelems

procedure

scan

set

storage

syntax shortcuts

table

type/algebraic

type/indexable

upperbound

Vector