construct a Matrix - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Data Types : Rtables, Arrays, Matrices, and Vectors : Data Types : Matrix

Matrix - construct a Matrix

Calling Sequence

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




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



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



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



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



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



(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



(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



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



(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



(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



(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



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



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




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.




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.




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.




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 non-zero 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:














For more information, see storage and rtable_indexfcn.




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


For more information, see storage.




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.




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.




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.




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.










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.


returned operand






dimensions as an expression sequence of two integers


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


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.

















































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





Error, cannot assign to a read-only Matrix

A column matrix is not recognized as type Vector unless specified.













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/BooleanOpt, type/indexable, upperbound, 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