# NOT RUN {
# construct a diagonal 2x2 matrix
diag(2)
# construct a diagonal 2x2x2 tensor
diag(2, dim = 3)
# construct a diagonal 2x2x2 tensor with values 3 and 4
diag(2, dim = 3, value = c(3,4))
# construct a diagonal 3x3 matrix with values 1,2,3
diag(1:3)
# extract diagonals
x <- diag(1:4, dim = 3)
diag(x)
# replace diagonals
x <- diag(1:4, dim = 3)
diag(x) <- c(5,6,7,8)
x
# }
Run the code above in your browser using DataLab