0
0
R Programmingprogramming~20 mins

Transpose and inverse in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of transpose on a matrix
What is the output of the following R code that transposes a matrix?
R Programming
mat <- matrix(1:6, nrow=2, ncol=3)
transposed <- t(mat)
print(transposed)
A
[,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6
B
[,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
C
[1,] 1 2 3
[2,] 4 5 6
D
[,1] [,2]
[1,]    4    1
[2,]    5    2
[3,]    6    3
Attempts:
2 left
💡 Hint
Remember that transpose flips rows and columns.
Predict Output
intermediate
2:00remaining
Output of inverse of a matrix
What is the output of this R code that calculates the inverse of a matrix?
R Programming
mat <- matrix(c(4,7,2,6), nrow=2)
inv_mat <- solve(mat)
print(round(inv_mat, 2))
AError in solve(mat) : system is computationally singular: reciprocal condition number = 0
B
     [,1] [,2]
[1,]  6.00  7.00
[2,]  2.00  4.00
C
     [,1] [,2]
[1,]  0.60 -0.20
[2,] -0.70  0.40
D
     [,1] [,2]
[1,]  0.40 -0.20
[2,] -0.70  0.60
Attempts:
2 left
💡 Hint
The inverse of a 2x2 matrix [[a,b],[c,d]] is (1/(ad-bc))*[[d,-b],[-c,a]].
🔧 Debug
advanced
2:00remaining
Identify the error in matrix inversion code
What error will this R code produce when trying to invert a matrix?
R Programming
mat <- matrix(c(1,2,2,4), nrow=2)
inv_mat <- solve(mat)
print(inv_mat)
AError in solve(mat) : system is computationally singular: reciprocal condition number = 0
BError in solve(mat) : 'a' must be a square matrix
CError in solve(mat) : non-numeric argument to mathematical function
DNo error, prints inverse matrix
Attempts:
2 left
💡 Hint
Check if the matrix is invertible by its determinant.
🧠 Conceptual
advanced
2:00remaining
Effect of transpose on matrix multiplication
Given two matrices A and B, which of the following is true about the transpose of their product (A %*% B)?
At(A %*% B) equals A %*% t(B)
Bt(A %*% B) equals t(A) %*% t(B)
Ct(A %*% B) equals B %*% A
Dt(A %*% B) equals t(B) %*% t(A)
Attempts:
2 left
💡 Hint
Transpose reverses the order of multiplication.
Predict Output
expert
3:00remaining
Output of combined transpose and inverse operations
What is the output of this R code that combines transpose and inverse operations?
R Programming
mat <- matrix(c(2,1,1,2), nrow=2)
result <- solve(t(mat))
print(round(result, 2))
AError in solve(t(mat)) : system is computationally singular: reciprocal condition number = 0
B
     [,1] [,2]
[1,]  0.67 -0.33
[2,] -0.33  0.67
C
     [,1] [,2]
[1,]  2.00  1.00
[2,]  1.00  2.00
D
     [,1] [,2]
[1,]  0.40 -0.20
[2,] -0.70  0.60
Attempts:
2 left
💡 Hint
Transpose of a symmetric matrix is the same matrix.