Matrix Operations and Inverse

Matrix Operations

A <- matrix(c(-4,-1,-3,-3,3,2), nrow = 2, ncol = 3)
B <- matrix(c(4,2,-1,-4,1,5), nrow = 2, ncol = 3)
C <- matrix(c(-5,-5,2,5,-4,-1), nrow = 2, ncol = 3)
A+B
     [,1] [,2] [,3]
[1,]    0   -4    4
[2,]    1   -7    7
A+B+C
     [,1] [,2] [,3]
[1,]   -5   -2    0
[2,]   -4   -2    6
B+C
     [,1] [,2] [,3]
[1,]   -1    1   -3
[2,]   -3    1    4
A+B+C
     [,1] [,2] [,3]
[1,]   -5   -2    0
[2,]   -4   -2    6
a=-1
b=2
c=3
(a-b)*C
     [,1] [,2] [,3]
[1,]   15   -6   12
[2,]   15  -15    3
a*C-b*C
     [,1] [,2] [,3]
[1,]   15   -6   12
[2,]   15  -15    3

## Example 69
library(matlib)
A <- matrix(c(1,-2,-1,2,3,2,3,-2,1), nrow = 3, ncol = 3)
inv(A)
            [,1]       [,2]       [,3]
[1,]  0.58333333  0.3333333 -1.0833333
[2,]  0.33333333  0.3333333 -0.3333333
[3,] -0.08333333 -0.3333333  0.5833333
library(MASS)
fractions(inv(A))
     [,1]   [,2]   [,3]  
[1,]   7/12    1/3 -13/12
[2,]    1/3    1/3   -1/3
[3,]  -1/12   -1/3   7/12
## Remark 2.10 
library(matlib)
A <- matrix(c(1,-2,-1,2,3,2,3,-2,1), nrow = 3, ncol = 3)
solve(A)
            [,1]       [,2]       [,3]
[1,]  0.58333333  0.3333333 -1.0833333
[2,]  0.33333333  0.3333333 -0.3333333
[3,] -0.08333333 -0.3333333  0.5833333
b=1:3
solve(A)%*%b
     [,1]
[1,]   -2
[2,]    0
[3,]    1

A <- matrix(c(1,-2,-1,2,3,2,3,-2,1), nrow = 3, ncol = 3)
B <- A+1
t(A+B)
     [,1] [,2] [,3]
[1,]    3   -3   -1
[2,]    5    7    5
[3,]    7   -3    3
t(A)+t(B)
     [,1] [,2] [,3]
[1,]    3   -3   -1
[2,]    5    7    5
[3,]    7   -3    3
inv(t(A))
           [,1]       [,2]        [,3]
[1,]  0.5833333  0.3333333 -0.08333333
[2,]  0.3333333  0.3333333 -0.33333333
[3,] -1.0833333 -0.3333333  0.58333333
t(inv(A))
           [,1]       [,2]        [,3]
[1,]  0.5833333  0.3333333 -0.08333333
[2,]  0.3333333  0.3333333 -0.33333333
[3,] -1.0833333 -0.3333333  0.58333333

Exercise

Is matrix multiplication commutative? Give a counterexample using R. When is it commutative?