Example 2.1

x <- as.matrix(c(1,3,2))

x
##      [,1]
## [1,]    1
## [2,]    3
## [3,]    2
y <- as.matrix(c(-2,1,1))

y
##      [,1]
## [1,]   -2
## [2,]    1
## [3,]    1
z <- 3*x

z
##      [,1]
## [1,]    3
## [2,]    9
## [3,]    6
w <- x + y

w
##      [,1]
## [1,]   -1
## [2,]    4
## [3,]    3
norm(x, type="F")
## [1] 3.741657
norm(z, type="F")
## [1] 11.22497

Example 2.2

x1 <-as.matrix(c(1,2,1))

x1
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    1
x2 <-as.matrix(c(1,0,-1))

x2
##      [,1]
## [1,]    1
## [2,]    0
## [3,]   -1
x3 <-as.matrix(c(1,-2,1))

x3
##      [,1]
## [1,]    1
## [2,]   -2
## [3,]    1
X <-cbind(x1,x2,x3)

X
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    2    0   -2
## [3,]    1   -1    1
det(X)
## [1] -8
det(X)==0
## [1] FALSE

False, hence x1, x2, x3 is linearly independent

Example 2.4

A <-rbind(c(0,3,1), c(1,-1,1))

A
##      [,1] [,2] [,3]
## [1,]    0    3    1
## [2,]    1   -1    1
B <- rbind(c(1,-2,-3), c(2,5,1))

B
##      [,1] [,2] [,3]
## [1,]    1   -2   -3
## [2,]    2    5    1
4*A
##      [,1] [,2] [,3]
## [1,]    0   12    4
## [2,]    4   -4    4
A+B
##      [,1] [,2] [,3]
## [1,]    1    1   -2
## [2,]    3    4    2

Example 2.5

A <-rbind(c(3,-1,2), c(1,5,4))

A
##      [,1] [,2] [,3]
## [1,]    3   -1    2
## [2,]    1    5    4
B <- as.matrix(c(-2,7,9))

B
##      [,1]
## [1,]   -2
## [2,]    7
## [3,]    9
C <-rbind(c(2,0), c(1,-1))

C
##      [,1] [,2]
## [1,]    2    0
## [2,]    1   -1
A%*%B 
##      [,1]
## [1,]    5
## [2,]   69
C%*%A 
##      [,1] [,2] [,3]
## [1,]    6   -2    4
## [2,]    2   -6   -2

Example 2.6

A <- rbind(c(1,-2,3), c(2,4,-1))

A
##      [,1] [,2] [,3]
## [1,]    1   -2    3
## [2,]    2    4   -1
b <- as.matrix(c(7,-3, 6))

b
##      [,1]
## [1,]    7
## [2,]   -3
## [3,]    6
c <- as.matrix(c(5,8,-4))

c
##      [,1]
## [1,]    5
## [2,]    8
## [3,]   -4
d <-as.matrix(c(2,9))

A%*%b
##      [,1]
## [1,]   31
## [2,]   -4
b%*%t(c)
##      [,1] [,2] [,3]
## [1,]   35   56  -28
## [2,]  -15  -24   12
## [3,]   30   48  -24
t(b)%*%c
##      [,1]
## [1,]  -13
t(d)%*%A%*%d 
## Error in t(d) %*% A %*% d: non-conformable arguments

Example 2.7

A=rbind(c(3,2), c(4,1))

A
##      [,1] [,2]
## [1,]    3    2
## [2,]    4    1
B <- solve(A)

A%*%B
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
B%*%A 
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1

Example 2.8

A <-rbind(c(1,-5), c(-5,1))

A
##      [,1] [,2]
## [1,]    1   -5
## [2,]   -5    1
eigen(A)
## eigen() decomposition
## $values
## [1]  6 -4
## 
## $vectors
##            [,1]       [,2]
## [1,] -0.7071068 -0.7071068
## [2,]  0.7071068 -0.7071068

Example 2.9

A =rbind(c(13, -4,2), c(-4,13,-2),c(2,-2,10))

A
##      [,1] [,2] [,3]
## [1,]   13   -4    2
## [2,]   -4   13   -2
## [3,]    2   -2   10
Eigen_A<-eigen(A)

Eigen_A$values
## [1] 18  9  9
Eigen_A$vectors
##            [,1]       [,2]      [,3]
## [1,]  0.6666667 -0.7453560 0.0000000
## [2,] -0.6666667 -0.5962848 0.4472136
## [3,]  0.3333333  0.2981424 0.8944272
A%*%Eigen_A$vectors[,1]
##      [,1]
## [1,]   12
## [2,]  -12
## [3,]    6
A%*%Eigen_A$vectors[,2]
##           [,1]
## [1,] -6.708204
## [2,] -5.366563
## [3,]  2.683282
A%*%Eigen_A$vectors[,3]
##          [,1]
## [1,] 0.000000
## [2,] 4.024922
## [3,] 8.049845
Eigen_A$vectors%*%t(Eigen_A$vectors)
##               [,1]          [,2]         [,3]
## [1,]  1.000000e+00 -2.220446e-16 5.551115e-17
## [2,] -2.220446e-16  1.000000e+00 5.551115e-17
## [3,]  5.551115e-17  5.551115e-17 1.000000e+00
t(Eigen_A$vectors)%*%Eigen_A$vectors
##               [,1]          [,2] [,3]
## [1,]  1.000000e+00 -2.359224e-16    0
## [2,] -2.359224e-16  1.000000e+00    0
## [3,]  0.000000e+00  0.000000e+00    1

Example 2.10

A <- rbind(c(3, -sqrt(2)), c(-sqrt(2), 2))

A           
##           [,1]      [,2]
## [1,]  3.000000 -1.414214
## [2,] -1.414214  2.000000

\[ (x_1, x_2) \times A \times \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) = = 3 x_1^2+2x_2^2-2\sqrt{2}x_1x_2\]

eigen(A)
## eigen() decomposition
## $values
## [1] 4 1
## 
## $vectors
##            [,1]       [,2]
## [1,] -0.8164966 -0.5773503
## [2,]  0.5773503 -0.8164966

\[ (x_1, x_2) \times A \times \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) = 4(x_1, x_2) \times e_1 e_1' \times \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) + (x_1, x_2) \times e_2 e_2' \times \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) = 4 ((x_1, x_2) e_1)^2 + ((x_1, x_2) e_2)^2 >0,\] if \((x_1,x_2) \ne (0,0).\)