0% found this document useful (1 vote)
81 views

Mathcad Matrices

This document provides instruction on working with matrices in Mathcad. It covers how to create, edit, and perform basic operations on matrices including addition, subtraction, multiplication and solving systems of linear equations. Examples are provided for creating matrices using different methods, referencing matrix elements, adding and deleting rows and columns, and performing operations like multiplication, inverse, and determinant. The key points are that matrix operations depend on the dimensions of the matrices and the order of operations matters.

Uploaded by

MartinVidic
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
81 views

Mathcad Matrices

This document provides instruction on working with matrices in Mathcad. It covers how to create, edit, and perform basic operations on matrices including addition, subtraction, multiplication and solving systems of linear equations. Examples are provided for creating matrices using different methods, referencing matrix elements, adding and deleting rows and columns, and performing operations like multiplication, inverse, and determinant. The key points are that matrix operations depend on the dimensions of the matrices and the order of operations matters.

Uploaded by

MartinVidic
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Mathcad Lecture #4 In-class Worksheet

Vectors and Matrices (Basics)


At the end of this lecture, you should be able to:
 create matrices and vectors in Mathcad
 edit matrices
 perform basic matrix math operations
 solve a system of linear equations using matrix math

1. Creating Matrices
There are several ways to create a matrix

A. The "Insert Matrix" Window (<Ctrl>M)

Key Point
 Refer to matrix size by rows x columns
 Use the tab key to move between place holders.

B. Paste a matrix from elsewhere (such as excel or a text file)

 Type variable name in Mathcad


 Open the Excel file called data.xls.
 Select the data
 Copy
 Paste into the placeholder of the variable

Key Point
 You must paste into a placeholder of a variable or the data will
import as text.

C. Insert a table

 Select Insert/Data/Table from the Insert menu


 Click and then right click the upper-left cell
 Select "Import" from the menu
 Use the browser to find the file containing the data (matrix.txt)
 Click OK
 Give the table a variable name

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

Individual elements are referenced with subscripts by typing the [ key.

Demonstration

Key Points
 Mathcad begins counting matrix indices at 0
 You can change the starting index by defining ORIGIN

Demonstration

Demonstration: You can create matrices using index notation

Practice
 2 4
1. Create the following matrix using subscript (index) notation. E 
3 1 

2. What is the value of the 9th row, 3rd column of M?

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

Add 1 row 0 columns

 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.

4. Solving Systems of Linear Equations

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.

5. Operations With Matrices


ORIGIN  1 See Matrix Toolbar (unders Insert-toolbar-matrix) for many matrix operations

Basic Matrix Math Review


Addition and subtraction
 Two matrices can be added and subtracted only if they are the same size.
 Addition and subtraction is done element by element to create a matrix of the same size

 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.

Other Matrix Operations

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

91.25  5w  9  y = 2.5x  0.5z

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. XY, YX, XZ, ZX
ii. AX, XA, AA, A-1A
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

You might also like