C10 In Example TMP the first table lists the cost (per kilogram) to manufacture each of the three varieties of trail mix (bulk, standard, fancy). For example, it costs $3.69 to make one kilogram of the bulk variety. Re-compute each of these three costs and notice that the computations are linear in character.

Computations are linear because we have not changed the values in the matrix to have any other computations such as square roots, cubes, etc., If plotted, they would all be straight lines.

A = matrix( 
    c(7, 6, 2, 6, 4, 5, 2, 5, 8), 
    nrow=3, 
    ncol=3) 
batches = A/15
cost = matrix( 
    c(3.69, 3.86, 4.45), 
    nrow=3, 
    ncol=1) 

solve(batches, cost)
##      [,1]
## [1,] 2.55
## [2,] 4.65
## [3,] 4.80

M45 You keep a number of lizards, mice and peacocks as pets. There are a total of 108 legs and 30 tails in your menagerie. You have twice as many mice as lizards. How many of each creature do you have?

Did not find the right values here..

4l + 4m + 4p = 108 l + m + p = 30 2l - m = 0

A = matrix( 
    c(4, 1, 2, 4, 1, -1, 4, 1, 0, 108, 30, 1), 
    nrow=3, 
    ncol=4) 

# R1 = R1 + 3(R3)
A[1,] = A[1,] + (4*(A[3,]))
# R1 = R1 + 3(R3)
A[1,] = A[1,] * (A[3,])
# R1 = R1 / 24*R2
A[1,] = A[1,] / (24*(A[2,]))
# R2 = R2 - R1
A[2,] = A[2,] - A[1,]
# R3 = R2 + R3
A[3,] = A[2,] + A[3,]
# R3 = R2 * R3
A[3,] = A[2,] * A[3,]
# R2 = R2 - R3
A[2,] = A[2,] - A[3,]
A
##      [,1] [,2] [,3]         [,4]
## [1,]    1    0    0    0.1555556
## [2,]    0    1    0 -890.6908642
## [3,]    0    0    1  920.5353086

C21 Compute the product AB of the two matrices below using both the definition of the matrix-vector product

A = matrix( 
    c(1, -1, 0, 3, 2, 1, 2, 1, 0), 
    nrow=3, 
    ncol=3) 
A
##      [,1] [,2] [,3]
## [1,]    1    3    2
## [2,]   -1    2    1
## [3,]    0    1    0
B = matrix( 
    c(4, 1, 3, 1, 0, 1, 2, 1, 5), 
    nrow=3, 
    ncol=3) 
B
##      [,1] [,2] [,3]
## [1,]    4    1    2
## [2,]    1    0    1
## [3,]    3    1    5
A %*% B
##      [,1] [,2] [,3]
## [1,]   13    3   15
## [2,]    1    0    5
## [3,]    1    0    1

by “hand”…

C1 = A[1,] %*% B[,1]
C2 = A[1,] %*% B[,2]
C3 = A[1,] %*% B[,3]
C4 = A[2,] %*% B[,1]
C5 = A[2,] %*% B[,2]
C6 = A[2,] %*% B[,3]
C7 = A[3,] %*% B[,1]
C8 = A[3,] %*% B[,2]
C9 = A[3,] %*% B[,3]

C = matrix( 
    c(C1, C4, C7, C2, C5, C8, C3, C6, C9), 
    nrow=3, 
    ncol=3) 
C
##      [,1] [,2] [,3]
## [1,]   13    3   15
## [2,]    1    0    5
## [3,]    1    0    1

C24 If it exists, find the inverse of the 2 × 2 matrix

No inverse exists for this matrix

A = matrix( 
    c(6, 4, 3, 2), 
    nrow=2, 
    ncol=2) 
A
##      [,1] [,2]
## [1,]    6    3
## [2,]    4    2
det = 1/((A[1,1]*A[2,2])-(A[1,2]*A[2,1]))
det
## [1] Inf