Linear Algebra Options
In the sections below are several commented examples using options that are common to many of the LinearAlgebra package functions. They illustrate how you can exercise greater control over Maple behavior.
The inplace option determines whether a function creates a new object or uses one of its inputs to store the output. Most functions default to returning a new object. The exceptions to this are LinearAlgebra[Map] and LinearAlgebra[Zip].
By default, when we swap the rows of A, we get a new Matrix, and A is unchanged:
If we want A to be updated, we indicate that by using "inplace" or "inplace=true":
Performing an operation in place saves memory, and can also save having to create new variable names for intermediate results. In the following example, a 3x3 Matrix is augmented with a 3x3 identity Matrix, and then the inverse is found manually.
Matrix Inverse Example
Create the Matrix.
Augment the Matrix with an identity Matrix of the same size.
Use elementary row operations to get zeroes below the main diagonal.
Use elementary row operations to get zeros above the main diagonal
Extract the inverse Matrix.
Multiply the original Matrix by its inverse to verify that it is, indeed, the inverse.
Most LinearAlgebra functions that return a Matrix allow you some control over the form of the output Matrix. This control is gained by using the outputoptions parameter. What follows is an example of why you might use outputoptions with the IdentityMatrix function.
Suppose that you want to create a Matrix that is almost an identity Matrix: just two of its rows are swapped. You could use the IdentityMatrix function as a starting point to create your Matrix, and then swap two rows:
That worked, but now you have two Matrices: M1 and M2. You really do not require the original identity Matrix. It would have been better to perform the operation in place, but when you try that, you get an error:
Error, (in LinearAlgebra:-RowOperation) invalid assignment to identity diagonal
The error arises because the default Matrix returned by the IdentityMatrix function uses no storage, just a mathematical shape of 'identity'. Take a closer look:
The 'empty' storage means that no space is allocated for entries, and the 'identity' index function means that only 1's are permitted on the main diagonal and only 0's off the diagonal.
To create an identity Matrix that can be updated, use outputoptions to specify rectangular shape (so that the values that can go in each location are unrestricted, and that rectangular storage is used).
Now you can swap the rows inplace:
Some functions allow you to specify the method (algorithm) to be used to carry out the function. For example, the Determinant function lets you choose from many methods, including 'float', 'minor', and 'rational'. If you know your Matrix has particular characteristics, you can specify an appropriate algorithm, making the computation faster.
M is an upper triangular Matrix, and this information is readily available to the Determinant function.
M:= 99 x 99 MatrixData Type: anythingStorage: triangularupperOrder: Fortran_order
N is also an upper triangular Matrix, but this information is not readily available to the Determinant function because its shape is 'rectangular'.
N:= 99 x 99 MatrixData Type: anythingStorage: rectangularOrder: Fortran_order
The Determinant function uses the fact that M is upper triangular to select an appropriate algorithm and returns an answer in a negligible amount of time:
With no information about N, the Determinant function does not necessarily make the most efficient algorithm choice, and takes longer:
When the user specifies the method, the Determinant function can work as quickly on N as it did on M. (The minor expansion is done along the first column, and since the first column of an upper triangular Matrix is mostly zeros, the computation is very fast for upper triangular Matrices.)
For more information, see the Determinant help page.
Return to Index for Example Worksheets
Download Help Document
What kind of issue would you like to report? (Optional)