Overview: How to Construct Matrices in Maple
Description
Using the Matrix construction shortcuts
Using the Matrix palette
Using the Matrix function
Using the ImportMatrix function
There are four ways to construct a Matrix in Maple. Which method you use depends on your data and needs. The following are some guidelines on when to use which method.
Use the Matrix construction shortcuts to quickly construct a Matrix with a small number of elements.
Use the Matrix palette to specify the initial type and shape for the Matrix as well as its data type.
Use the Matrix function to access more initialization options (for example, using a procedure or lists as initializers) and options that maximize the efficiency of reading from the Matrix, storing the Matrix, or both.
Use the ImportMatrix function to import data stored in a file into a Matrix.
Use a pair of matching angle brackets (< >) to enclose the comma-separated values of the Matrix elements.
To have sequences of comma-separated values define the rows of your Matrix, separate the rows with a semicolon (;).
Matrix1 := <a , b , c ; d , e , f>;
Matrix1≔abcdef
To have sequences of comma-separated values define the columns of your Matrix, separate the columns with a vertical bar (|).
Matrix2 := <a , b , c | d , e , f>;
Matrix2≔adbecf
Vectors and Matrices can be used for the elements of a Matrix. The type of Vector (that is, row or column) determines whether the Vectors are interpreted as rows or columns in the Matrix.
Use either a comma or a semicolon to separate the rows of the Matrix when the elements are row Vectors.
RowVector1 := <1 | 2 | 3>;
RowVector1≔123
RowVector2 := <4 | 5 | 6>;
RowVector2≔456
Matrix3 := <RowVector1; RowVector2>;
Matrix3≔123456
Use the vertical bar (|) to separate the columns of the Matrix when the elements are column Vectors.
ColumnVector1 := <7, 8, 9>;
ColumnVector1≔789
ColumnVector2 := <10, 11, 12>;
ColumnVector2≔101112
Matrix4 := <ColumnVector1 | ColumnVector2>;
Matrix4≔710811912
You can also concatenate a Matrix with Vectors and other Matrices to create a new Matrix. The same separators apply (vertical bar to append columns and either a comma or semicolon to append rows).
Matrix5 := <Matrix4 | <13, 14, 15>>;
Matrix5≔710138111491215
Matrix6 := <Matrix3, <7 | 8 | 9>>;
Matrix6≔123456789
<Matrix5; Matrix6>;
710138111491215123456789
For more information, see Matrix and Vector Construction Shortcuts.
If you are using the standard worksheet interface, the Matrix palette can be used to specify additional properties for a Matrix.
The following are the additional properties that you can specify with the Matrix palette.
Type: Specify the initial Matrix type. Select from Custom Values, Zero-filled, One-filled, Identity, or Random.
Shape: Specify the initial shape of the Matrix (for example, Diagonal, Hermitian, or Symmetric). See shape for more information on these choices.
Data type: Specify the type of data stored in the Matrix. The available choices are: Any, float[8], integer[1], integer[2], integer[4], integer[8], and complex[8].
For more information on using the Matrix palette, see Use the Matrix Palette or watch the Matrix Palette Training Video.
The Matrix function gives you access to a wider variety of initializer options. These options include using a procedure to define the Matrix elements
f:= (i,j) -> z^(i+j-1):
p:=Matrix(2,f);
p≔zz2z2z3
z:=3:
p;
zz2z2z3
as well as other objects like lists and Arrays.
M := Matrix([[1, -1, 0], [1, 1, 0], [0, 0, 1]]);
M≔1−10110001
A := Array(0..2, 0..1, {(0, 0) = 1, (0, 1) = 2, (1, 0) = 3, (1, 1) = 4, (2, 0) = 5, (2, 1) = 6 } );
M := Matrix(A);
M≔123456
The storage and shape options can be used to save memory when not all of the elements of a Matrix need to be stored. For example, not all of the elements of a symmetric Matrix need to be stored in memory. Using the storage=triangular[lower] and shape=symmetric options in the following command is more efficient because only six elements are needed to define the Matrix.
sym := Matrix([[1], [2, 3], [4, 5, 6]], storage=triangular[lower], shape=symmetric );
sym≔124235456
sym[1, 3] := -8:
sym;
12−8235−856
For more information on these and other options, see the Matrix command page.
The ImportMatrix function reads data from a file to construct and initialize a Matrix.
You can import Matrices from numerous formats, including:
MATLAB® binary
MATLAB® ASCII
Matrix Market
Comma-Separated Values (CSV)
Generic Delimited
For more information, see ImportMatrix.
See Also
Array
ImportMatrix
LinearAlgebra
Matrix
Matrix and Vector Construction Shortcuts
Matrix Palette Training Video
Shapes and Storage Modes for Matrices and Vectors
Student[LinearAlgebra]
Use the Matrix Palette
Vector
Download Help Document