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

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Overview/Matrix/Construct

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

Description

• 

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.

1. 

Use the Matrix construction shortcuts to quickly construct a Matrix with a small number of elements.

2. 

Use the Matrix palette to specify the initial type and shape for the Matrix as well as its data type.

3. 

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.

4. 

Use the ImportMatrix function to import data stored in a file into a Matrix.

Using the Matrix construction shortcuts

• 

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

Matrix1abcdef

(1)
• 

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

Matrix2adbecf

(2)
• 

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

RowVector1123

(3)

RowVector2 := <4 | 5 | 6>;

RowVector2456

(4)

Matrix3 := <RowVector1; RowVector2>;

Matrix3123456

(5)
• 

Use the vertical bar (|) to separate the columns of the Matrix when the elements are column Vectors.

ColumnVector1 := <7, 8, 9>;

ColumnVector1789

(6)

ColumnVector2 := <10, 11, 12>;

ColumnVector2101112

(7)

Matrix4 := <ColumnVector1 | ColumnVector2>;

Matrix4710811912

(8)
• 

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

Matrix5710138111491215

(9)

Matrix6 := <Matrix3, <7 | 8 | 9>>;

Matrix6123456789

(10)

<Matrix5; Matrix6>;

710138111491215123456789

(11)
• 

For more information, see Matrix and Vector Construction Shortcuts.

Using the Matrix palette

• 

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.

Using the Matrix function

• 

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

pzz2z2z3

(12)

z:=3:

p;

zz2z2z3

(13)

as well as other objects like lists and Arrays.

M := Matrix([[1, -1, 0], [1, 1, 0], [0, 0, 1]]);

M1−10110001

(14)

A := Array(0..2, 0..1, {(0, 0) = 1, (0, 1) = 2, (1, 0) = 3, (1, 1) = 4, (2, 0) = 5, (2, 1) = 6 } );

(15)

M := Matrix(A);

M123456

(16)

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

sym124235456

(17)

sym[1, 3] := -8:

sym;

12−8235−856

(18)

For more information on these and other options, see the Matrix command page.

Using the ImportMatrix function

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