Mathcad Matrices
Mathcad Matrices
1. Creating Matrices
There are several ways to create a matrix
Key Point
Refer to matrix size by rows x columns
Use the tab key to move between place holders.
Key Point
You must paste into a placeholder of a variable or the data will
import as text.
C. Insert a table
Key Points
Do NOT create the variable name first!
Make sure to import the table by right clicking
Nice to use this for big tables (scroll bars)
2. Referencing Arrays
Demonstration
Key Points
Mathcad begins counting matrix indices at 0
You can change the starting index by defining ORIGIN
Demonstration
Practice
2 4
1. Create the following matrix using subscript (index) notation. E
3 1
3. Editing a Matrix
You can add or delete rows and columns to existing matrices.
It is tricky.
To add a row/column:
1. Place cursor above rows and to the left of the rows and columns to be added.
2. Open the Insert Matrix window.
3. Type the number of rows and columns to add and click Insert.
To delete a row/column:
1. Place cursor in the uppermost row and leftmost column of the rows and columns to be removed.
2. Open the Insert Matrix window.
3. Type the number of rows and columns to delete and click Delete.
Demonstration
1 2 5 1 2 5
1 2 5
B B B 8 1 1
3 0 9
3 0 9 3 0 9
Delete 2 columns, 1 row by first 1 column 1 row and then 1 column 0 rows.
1 2 5
2 5 2
B 8 1 1 B B
1 1 1
3 0 9
Key Point
Notice that to add a row in the middle of B, you add 1 row and 0 columns.
Explanation
Recall that matrix math can be used solve systems of linear equations.
A system of linear equations is one in which the variables (x, y, z) appear only to the power of 1.
x y = 6
2x 4 y = 88
A system of linear equations can be written the following matrix form.
A X = B
1 1 x 6
where A= X= B=
2 4 y 88
The system of linear equations written in this form has the following solution.
1 1
A A X = A B
1
I X = A B
1
X=A B
The order of the multiplication matters. The solution is A-1 B not BA-1
To determine if a solution exists to a system a linear equations, take the determinant of the coefficient matrix (A).
If the determinant is non-zero, a solution exits.
Demonstration
Key Points
Mathcad can obtain the answers in two ways, using an inverse or using lsolve
Both are correct.
lsolve uses a faster algorithm which may become important for large matrices.
a b c u v w a u b v c w
d e f x y z d x y e f z
Multiplication
Two matrices can be multiplied if their inner dimensions are the same.
Example: 2x3 * 3x2 not 3x2 * 3x2.
Example: 3x3 * 3x1 not 3x1 * 3x3
The outer dimensions tell the size of the matrix.
Example: 2x3 * 3x2 will produce a 2x2 matrix
Remember that order matters with matrix multiplication!
a b c u v w
d e f x y z Error because inner dimensions don't match
u v
a b c a u b w c y a v b x c z
w x
d e f w e d u f y x e d v f z
y z
u v a b c a u d v v e b u c u f v
w x a w d x x e b w c w f x
d e f
y z a y d z z e b y c y f z
Division
There is not matrix division!
Multiply by the inverse to move matrices across = signs.
Functions Description
rows(A) Returns the number of rows in matrix A
cols(A) Returns the number of columns in matrix A
Creates a new matrix which is a portion of array A. The portion
submatrix(A, ir, jr, ic, jc) consists of the elements in rows ir through jr and in columns ic
through jc.
Creates a single matrix comprised of vectors A, B, C, … all with the
augment(A, B, C,…)
same number of rows, concatenated from left to right.
Creates a single matrix comprised of vectors A, B, C, … all with the
stack(A, B, C,…)
same number of columns, concatenated from top to bottom.
Extracts the nth column of a matrix as a column vector.
Takes the inverse of a matrix.
Takes the determinant of the matrix.
The vector dot and cross product.
a b
c d
s t
a b u v a b r s t a b r s t
stack
s t
c d w x u v augment c d u v w c d u v w
y z w e f x y z e f x y z
x
y z
a b r s t
u v w
submatrix c d u v w 2 3 3 5
2
u v w v
x y z
e f x y z x y z y
5 Practice
1. If it exists, find a solution to the following set of equations.
3x 2 y = 16.5 z
55 w = 3x 20z
2z y = 5 x 2w
2. For the matrices defined below, performed the requested operations (if possible). If a particular operation is not possible,
can you give the reason why?
1 2 3 3 2 4 10 1
6 4 2
A X 4 5 6 Y 2 1 3 Z 13 50
5 3 1
7 8 9 0 1 5 32 3
i. XY, YX, XZ, ZX
ii. AX, XA, AA, A-1A
iii. X+Y, Y+X
iv. AT, XT, ZT
v. Y-Z, Y-X
vi. |A|, |X|, |Y|, |Z|
3.
Use the matrix tool on the palette to define the following 3x3 matrix:
1 2 3
A 4 5 6
7 8 9
Add a row containing the entries [1 4 9] after the second row to form the following
matrix:
1 2 3
A
4 5 6
1 4 9
7
8 9
Add an additional column to the matrix with the entries [1 2 3 4] to form the following
4x4 matrix:
1 2 3 1
A
4 5 6 2
1 4 9 3
7
8 9 4