Part 5: Working with Matrices - Maple Help

Home : Support : Online Help : Getting Started : Tutorials : MaplePortal/Tutorial5

Part 5: Working with Matrices

 Introduction Maple Tutorials are designed to help you get started with Maple, learn about the key tools available in Maple, and lead you through a series of problems.   In Part 5: Working with Matrices, you will create matrices and vectors, perform linear algebra calculations, and extract entries.   To try this material on your own, start with an empty Maple document. Perform the steps described in the left column of each table below.  The results of the steps are displayed in the right column for reference.   Refer to Help>Quick Reference for basic getting started tips.   Note for non-Windows users: The keystrokes given in this document are for Windows.  There will be differences for other platforms. If you are using a different platform, see Help>Quick Help for the list of the most common keystrokes.

Creating Matrices and Vectors

Enter matrices using the palettes or using the matrix notation.

Steps

Result

Creating a Matrix

Example: Use the Matrix palette to create a 3 x 3 matrix.  Tab between the placeholders and fill in the values.

To assign this matrix to a name, type "A:=" and then use an equation label to refer to the matrix.  To get an equation label, type [Ctrl][L].  In the Insert Label box, type 2.1.

Example: Create a matrix using Maple's matrix notation.  Use <> brackets to enclose a sequence of the entries in each column, and | to separate the columns.  Enclose the entire matrix in more brackets <>.

Forming a New Matrix from Two Matrices

To form a new matrix, simply adjoin these matrices.

Example: Use the matrix notation to form a new matrix from the columns of A and the columns of B.



$[\begin{array}{ccc}1& 2& 4\\ 3& 4& 2\\ 4& 5& 3\end{array}]$

 $\left[\begin{array}{rrr}{1}& {2}& {4}\\ {3}& {4}& {2}\\ {4}& {5}& {3}\end{array}\right]$ (2.1)

$A≔$

 $\left[\begin{array}{rrr}{1}& {2}& {4}\\ {3}& {4}& {2}\\ {4}& {5}& {3}\end{array}\right]$ (2.2)

$B≔⟨⟨1,4,2⟩|⟨0,9,2⟩⟩$

 $\left[\begin{array}{rr}{1}& {0}\\ {4}& {9}\\ {2}& {2}\end{array}\right]$ (2.3)



$⟨A|B⟩$

 $\left[\begin{array}{rrrrr}{1}& {2}& {4}& {1}& {0}\\ {3}& {4}& {2}& {4}& {9}\\ {4}& {5}& {3}& {2}& {2}\end{array}\right]$ (2.4)





Creating a Vector

Vectors are created in a similar way.

Example: Use the Matrix palette to create a 3 element column vector (with 3 rows and 1 column).  Tab between the placeholders and fill in the values.

Example: Create a vector using vector notation. Use <> brackets to enclose the entire vector. Use a comma to separate the elements in a column vector,and | to separate elements in a row vector.

$\left[\begin{array}{c}a\\ b\\ c\end{array}\right]$









 $\left[\begin{array}{c}{a}\\ {b}\\ {c}\end{array}\right]$ (2.5)

 $\left[\begin{array}{ccc}{a}& {b}& {c}\end{array}\right]$ (2.6)



Working with Matrices and Vectors

Maple has extensive support for linear algebra.

Steps

Result

Matrix Calculations with the Context Menu

Use the context menu to perform matrix calculations.

Example:
Select Standard Operations>Inverse to find the inverse.

Select Standard Operations>Determinant to find the determinant.



$[\begin{array}{ccc}1& 2& 4\\ 3& 4& 2\\ 4& 5& 3\end{array}]$$\stackrel{\text{inverse}}{\to }$$\left[\begin{array}{ccc}{-}\frac{{1}}{{2}}& {-}\frac{{7}}{{2}}& {3}\\ \frac{{1}}{{4}}& \frac{{13}}{{4}}& {-}\frac{{5}}{{2}}\\ \frac{{1}}{{4}}& {-}\frac{{3}}{{4}}& \frac{{1}}{{2}}\end{array}\right]$

$\left[\begin{array}{ccc}1& 2& 4\\ 3& 4& 2\\ 4& 5& 3\end{array}\right]$$\stackrel{\text{determinant}}{\to }$${-}{4}$

Matrix Calculations

Multiplying Matrices

Example:  To multiply two matrices or to multiply a matrix by a vector, use a period (.) as the matrix multiplication symbol.

Multiplying By a Scalar

Example: To multiply a matrix by a scalar, use the multiplication symbol * (displayed as $\cdot$).

Extracting Entries

To extract entries from a matrix, use the command M[i, j], where $M$ is the name of the matrix, and $i$ and $j$ are the row and column.

To extract a submatrix, give a range instead for each index.

Example: Extract the 2 x 2 matrix from the bottom left corner of the matrix A.

Tip:  Negative indices can be used: -1 selects the last row (or column) entry, -2 selects the second-to-last row (or column) entry, and so on.  Thus, you could obtain the same submatrix using A[-2..-1, 1..2].

This selects the submatrix located in the last two rows and first two columns of A.

To extract entries from a vector, use the command V[i], where i is a number or a range.



$A.B$

$A.\mathrm{colvec}$

 $\left[\begin{array}{c}{a}{+}{2}{}{b}{+}{4}{}{c}\\ {3}{}{a}{+}{4}{}{b}{+}{2}{}{c}\\ {4}{}{a}{+}{5}{}{b}{+}{3}{}{c}\end{array}\right]$ (3.1)



$c\cdot \left[\begin{array}{cc}-93& -72\\ -76& -2\end{array}\right]$

 $\left[\begin{array}{cc}{-}{93}{}{c}& {-}{72}{}{c}\\ {-}{76}{}{c}& {-}{2}{}{c}\end{array}\right]$ (3.2)









$A\left[2,3\right]$

 ${2}$ (3.3)









$A\left[2..3,1..2\right]$

 $\left[\begin{array}{rr}{3}& {4}\\ {4}& {5}\end{array}\right]$ (3.4)















$\mathrm{rowvec}\left[2..3\right]$

 $\left[\begin{array}{cc}{b}& {c}\end{array}\right]$ (3.5)



Viewing Large Matrices

Only small matrices are shown inline.  For instance, consider the matrix created here.  To browse this matrix, double-click on the summary.

You can export to Excel from this dialog.  For more information on importing and exporting, see MaplePortal/Tutorial7.

$\mathrm{LinearAlgebra}\left[\mathrm{RandomMatrix}\right]\left(500,500\right)$

 $\left[\begin{array}{c}{\mathrm{500 x 500}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{\mathrm{anything}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (3.6)





Tip: The LinearAlgebra package contains many commands for creating and manipulating matrices and vectors and for solving linear algebra problems.