Below are the solutions to these exercises on regular sequences.

#################### # # # Exercise 1 # # # #################### #If M=matrix(c(1:10),nrow=5,ncol=2,dimnames=list(c('a','b','c','d','e'),c('A','B'))) #What is the value of: M

## A B ## a 1 6 ## b 2 7 ## c 3 8 ## d 4 9 ## e 5 10

#################### # # # Exercise 2 # # # #################### #Consider the matrix M, #What is the value of: M[1,]

## A B ## 1 6

M[,1]

## a b c d e ## 1 2 3 4 5

M[3,2]

## [1] 8

M['e','A']

## [1] 5

#################### # # # Exercise 3 # # # #################### #Consider the matrix N N=matrix(c(1:9),nrow=3,ncol=3,dimnames=list(c('a','b','c'),c('A','B','C'))) #What is the value of: diag(N)

## [1] 1 5 9

#################### # # # Exercise 4 # # # #################### #What is the value of: diag(4,3,3)

## [,1] [,2] [,3] ## [1,] 4 0 0 ## [2,] 0 4 0 ## [3,] 0 0 4

#Is matrix ? is.matrix(diag(4,3,3))

## [1] TRUE

#################### # # # Exercise 5 # # # #################### #If M=matrix(c(1:9),3,3,byrow=T,dimnames=list(c('a','b','c'),c('d','e','f'))) #What is the value of: rownames(M)

## [1] "a" "b" "c"

colnames(M)

## [1] "d" "e" "f"

#################### # # # Exercise 6 # # # #################### #What is the value of: upper.tri(M)

## [,1] [,2] [,3] ## [1,] FALSE TRUE TRUE ## [2,] FALSE FALSE TRUE ## [3,] FALSE FALSE FALSE

lower.tri(M)

## [,1] [,2] [,3] ## [1,] FALSE FALSE FALSE ## [2,] TRUE FALSE FALSE ## [3,] TRUE TRUE FALSE

lower.tri(M,diag=T)

## [,1] [,2] [,3] ## [1,] TRUE FALSE FALSE ## [2,] TRUE TRUE FALSE ## [3,] TRUE TRUE TRUE

#################### # # # Exercise 7 # # # #################### #Consider two matrix, M,N M=matrix(c(1:9),3,3,byrow=T) N=matrix(c(1:9),3,3) #What is the value of: M*N

## [,1] [,2] [,3] ## [1,] 1 8 21 ## [2,] 8 25 48 ## [3,] 21 48 81

#################### # # # Exercise 8 # # # #################### #Consider two matrix, M,N M=matrix(c(1:9),3,3,byrow=T) N=matrix(c(1:9),3,3) #What is the value of: M%*%N

## [,1] [,2] [,3] ## [1,] 14 32 50 ## [2,] 32 77 122 ## [3,] 50 122 194

#################### # # # Exercise 9 # # # #################### #Consider two matrix,M,N M=matrix(c(1:9),3,3,byrow=T) N=matrix(c(1:9),3,3) #What is the value of: (M+N)^2

## [,1] [,2] [,3] ## [1,] 4 36 100 ## [2,] 36 100 196 ## [3,] 100 196 324

#################### # # # Exercise 10 # # # #################### #Consider two matrix,M,N M=matrix(c(1:9),3,3,byrow=T) N=matrix(c(1:9),3,3) #What is the value of: M/N

## [,1] [,2] [,3] ## [1,] 1.000000 0.500000 0.4285714 ## [2,] 2.000000 1.000000 0.7500000 ## [3,] 2.333333 1.333333 1.0000000

## Leave a Reply