library(kableExtra)
library(knitr)

Problem

  • In Exercises C30-C33 determine if the matrix is nonsingular or singular. Give reasons for your answer.

Matrix row operations

r1=c(-3,1,2,8)
r2=c(2,0,3,4)
r3=c(1,2,7,-4)
r4=c(5,-1,2,0)

starting_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(starting_matrix))
V1 V2 V3 V4
r1 -3 1 2 8
r2 2 0 3 4
r3 1 2 7 -4
r4 5 -1 2 0

Row 1<—>3 (swap rows)

r3=c(-3,1,2,8)
r1=c(1,2,7,-4)

new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 2 7 -4
r2 2 0 3 4
r3 -3 1 2 8
r4 5 -1 2 0

R2=-2R1+ R2

r2=-2*(r1)+r2
r2
## [1]   0  -4 -11  12
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 2 7 -4
r2 0 -4 -11 12
r3 -3 1 2 8
r4 5 -1 2 0

R3=3*r1+r3

r3=3*(r1)+r3
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 2 7 -4
r2 0 -4 -11 12
r3 0 7 23 -4
r4 5 -1 2 0

R4=-5*r1+r4

r4=-5*(r1)+r4
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 2 7 -4
r2 0 -4 -11 12
r3 0 7 23 -4
r4 0 -11 -33 20

R2=r2/-4

r2=-(r2)/4
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 2 7.00 -4
r2 0 1 2.75 -3
r3 0 7 23.00 -4
r4 0 -11 -33.00 20

R1=r1-2r2

r1=(r1)-2*r2
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 1.50 2
r2 0 1 2.75 -3
r3 0 7 23.00 -4
r4 0 -11 -33.00 20

R3=r2*-7 + r3

r3=(r2)*-7+r3
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 1.50 2
r2 0 1 2.75 -3
r3 0 0 3.75 17
r4 0 -11 -33.00 20

R4=11*r2 +r4

r4=11*r2+r4
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 1.50 2
r2 0 1 2.75 -3
r3 0 0 3.75 17
r4 0 0 -2.75 -13

R3=r3/3.75

r3=r3/3.75
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 1.50 2
r2 0 1 2.75 -3
r3 0 0 3.75 17
r4 0 0 -2.75 -13
## R1 =r4+r 2*6/1 1
r1=r1+r4*(6/11)
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 0.00 -5.090909
r2 0 1 2.75 -3.000000
r3 0 0 1.00 4.533333
r4 0 0 -2.75 -13.000000

R2=r2 + r4

r2=r2+r4
new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 0.00 -5.090909
r2 0 1 0.00 -16.000000
r3 0 0 1.00 4.533333
r4 0 0 -2.75 -13.000000

R4=r3*2.75+ r4

r4=r3*2.75+ r4
new_matrix <- rbind(r1,r2,r3,r4)
kable(new_matrix)
r1 1 0 0 -5.0909091
r2 0 1 0 -16.0000000
r3 0 0 1 4.5333333
r4 0 0 0 -0.5333333

r4/-.53333

 r4=r4/-.53333333
 new_matrix <- rbind(r1,r2,r3,r4)
 kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 0 -5.090909
r2 0 1 0 -16.000000
r3 0 0 1 4.533333
r4 0 0 0 1.000000

R(1,4),R(2,4),R(3,4)==0

r1=round(r1+r4*5.0909090909,2)
r2=round(r2+r4*16,2)
r3=round(r3+r4*-4.5333333333,2)
new_matrix <- rbind(r1,r2,r3,r4)
kable(as.data.frame(new_matrix))
V1 V2 V3 V4
r1 1 0 0 0
r2 0 1 0 0
r3 0 0 1 0
r4 0 0 0 1

Compare with RREF from pracma

library(pracma)
my_mat <- matrix(c(-3,1,2,8,2,0,3,4,1,2,7,-4,5,-1,2,0), ncol=4)
rref(my_mat)
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1

Describe Matrix

  • The reduced form of the original matrix is an identity matrix and therefore the matrix is nonsingular

Code to create knitting style

  • toc_float is what keeps the toc on the side. As a warning I had issues with this in the past when I printed to pdf I believe
# output:
#   html_document:
#     theme: "simplex"
#     highlight: 'pygments'
#     toc: true
#     toc_float: true