 Overview/Matrix/Construct - Maple Help

Overview: How to Construct Matrices in Maple 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 := ;
 ${\mathrm{Matrix1}}{≔}\left[\begin{array}{ccc}{a}& {b}& {c}\\ {d}& {e}& {f}\end{array}\right]$ (1)
 • To have sequences of comma-separated values define the columns of your Matrix, separate the columns with a vertical bar (|).
 > Matrix2 := ;
 ${\mathrm{Matrix2}}{≔}\left[\begin{array}{cc}{a}& {d}\\ {b}& {e}\\ {c}& {f}\end{array}\right]$ (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>;
 ${\mathrm{RowVector1}}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\end{array}\right]$ (3)
 > RowVector2 := <4 | 5 | 6>;
 ${\mathrm{RowVector2}}{≔}\left[\begin{array}{ccc}{4}& {5}& {6}\end{array}\right]$ (4)
 > Matrix3 := ;
 ${\mathrm{Matrix3}}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\end{array}\right]$ (5)
 • Use the vertical bar (|) to separate the columns of the Matrix when the elements are column Vectors.
 > ColumnVector1 := <7, 8, 9>;
 ${\mathrm{ColumnVector1}}{≔}\left[\begin{array}{c}{7}\\ {8}\\ {9}\end{array}\right]$ (6)
 > ColumnVector2 := <10, 11, 12>;
 ${\mathrm{ColumnVector2}}{≔}\left[\begin{array}{c}{10}\\ {11}\\ {12}\end{array}\right]$ (7)
 > Matrix4 := ;
 ${\mathrm{Matrix4}}{≔}\left[\begin{array}{cc}{7}& {10}\\ {8}& {11}\\ {9}& {12}\end{array}\right]$ (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 := >;
 ${\mathrm{Matrix5}}{≔}\left[\begin{array}{ccc}{7}& {10}& {13}\\ {8}& {11}& {14}\\ {9}& {12}& {15}\end{array}\right]$ (9)
 > Matrix6 := >;
 ${\mathrm{Matrix6}}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\\ {7}& {8}& {9}\end{array}\right]$ (10)
 > ;
 $\left[\begin{array}{ccc}{7}& {10}& {13}\\ {8}& {11}& {14}\\ {9}& {12}& {15}\\ {1}& {2}& {3}\\ {4}& {5}& {6}\\ {7}& {8}& {9}\end{array}\right]$ (11) 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, integer, integer, integer, integer, and complex.

 • 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);
 ${p}{≔}\left[\begin{array}{cc}{z}& {{z}}^{{2}}\\ {{z}}^{{2}}& {{z}}^{{3}}\end{array}\right]$ (12)
 > z:=3:
 > p;
 $\left[\begin{array}{cc}{z}& {{z}}^{{2}}\\ {{z}}^{{2}}& {{z}}^{{3}}\end{array}\right]$ (13)

as well as other objects like lists and Arrays.

 > M := Matrix([[1, -1, 0], [1, 1, 0], [0, 0, 1]]);
 ${M}{≔}\left[\begin{array}{ccc}{1}& {-1}& {0}\\ {1}& {1}& {0}\\ {0}& {0}& {1}\end{array}\right]$ (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);
 ${M}{≔}\left[\begin{array}{cc}{1}& {2}\\ {3}& {4}\\ {5}& {6}\end{array}\right]$ (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([, [2, 3], [4, 5, 6]], storage=triangular[lower], shape=symmetric );
 ${\mathrm{sym}}{≔}\left[\begin{array}{ccc}{1}& {2}& {4}\\ {2}& {3}& {5}\\ {4}& {5}& {6}\end{array}\right]$ (17)
 > sym[1, 3] := -8:
 > sym;
 $\left[\begin{array}{ccc}{1}& {2}& {-8}\\ {2}& {3}& {5}\\ {-8}& {5}& {6}\end{array}\right]$ (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