Section 12 Class Examples
12.1 Day 3: Wed Sep 8
Remember that to use RREF we must include the pracma
package.
Our goal is to solve the following system of equations: \[ \left\{\begin{array}{rrrrrrrrrr} x_1 &+& 2 x_2 &+&x_3 &+& x_4 & = & 4 \\ x_1 &+& 2x_2 &+& -x_3 &+& -3x_4& =& 6 \\ && x_2 &+& x_3 &+& x_4& =& 0 \\ -x_1&+& x_2 &+& -x_3&+& -4x_4& = &-1\\ \end{array} \right\} \]
We enter the augmented matrix (and echo it back):
= cbind(c(1,1,0,-1),c(2,2,1,1),c(1,-1,1,-1),c(1,-3,1,-4),c(4,6,0,-1))
A A
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 2 1 1 4
## [2,] 1 2 -1 -3 6
## [3,] 0 1 1 1 0
## [4,] -1 1 -1 -4 -1
And then we row reduce it using rref
:
rref(A)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 1 3
## [2,] 0 1 0 -1 1
## [3,] 0 0 1 2 -1
## [4,] 0 0 0 0 0
The corresponding reduced set of equations is \[ \left\{\begin{array}{rrrrrrrrrr} x_1 && && &+& x_4 & = & 3 \\ && x_2 && &-& x_4& =& 1 \\ && &+& x_3 &+& 2x_4& =& -1 \\ \end{array} \right\} \]
The general solution to this system of equations is \[ \begin{align} x_1 &= 3 - x_4 \\ x_2 &= 1 - x_5 \\ x_3 &= -1 - 2 x_4 \\ x_4 &= free \end{align} \]
12.2 Day 4: Fri Sep 10
Question Solve the following matrix equation using R: \[ \begin{bmatrix} 1 & -2 & 1 \\ 1 & 0 & 1 \\ -1 & 1 & ~0~ \\ 2 & 1 & 1 \\ \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 13 \\ 7 \\ -5 \\ 6 \end{bmatrix} \]
Here we enter A and b separately to illustrate (below) how to augment a matrix with a vector.
= cbind(c(1,1,-1,2),c(-2,0,1,1),c(1,1,0,1))
A = c(13,7,-5,6) # notice that b is a vector and not a matrix. b
Let’s echo them back to see what they look like
## [,1] [,2] [,3]
## [1,] 1 -2 1
## [2,] 1 0 1
## [3,] -1 1 0
## [4,] 2 1 1
## [1] 13 7 -5 6
Now I will augment A with b and call it Ab. The syntax is nice:
= cbind(A,b)
Ab Ab
## b
## [1,] 1 -2 1 13
## [2,] 1 0 1 7
## [3,] -1 1 0 -5
## [4,] 2 1 1 6
And then row reduce.
rref(Ab)
## b
## [1,] 1 0 0 2
## [2,] 0 1 0 -3
## [3,] 0 0 1 5
## [4,] 0 0 0 0
This tells me that there is a unique solution to Ax = b, and it is \[ \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 2 \\ -3 \\ 5 \end{bmatrix}. \] Question 2 Can we find a vector d for which A x = d has no solution?
= cbind(c(1,1,-1,2),c(-2,0,1,1),c(1,1,0,1))
A = c(1,1,-1,2) # notice that b is a vector and not a matrix.
d = cbind(A,d)
Ad rref(Ad)
## d
## [1,] 1 0 0 1
## [2,] 0 1 0 0
## [3,] 0 0 1 0
## [4,] 0 0 0 0