3 3 Matrices
3 3 Matrices
input_matrix<-function(rows,cols){
cat("Enter matrix elements row-wise:\n")
matrix_data<-numeric(rows*cols)
for(i in 1:(rows*cols)){
matrix_data[i]<-as.numeric(readline(prompt=""))
}
return(matrix(matrix_data,nrow=rows,ncol=cols,byrow=TRUE))
}
#Display matrices
print_matrix(A)
print_matrix(B)
Output:
Enter matrix elements row-wise:
3
4
5
6
7
8
9
10
11
Enter matrix elements row-wise:
2
1
3
5
6
7
8
9
10
Matrix:
[,1] [,2] [,3]
[1,] 3 4 5
[2,] 6 7 8
[3,] 9 10 11
Matrix:
[,1] [,2] [,3]
[1,] 2 1 3
[2,] 5 6 7
[3,] 8 9 10
a)Transpose of matrix A:
Matrix:
[,1] [,2] [,3]
[1,] 3 6 9
[2,] 4 7 10
[3,] 5 8 11
a)Transpose of matrix B:
Matrix:
[,1] [,2] [,3]
[1,] 2 5 8
[2,] 1 6 9
[3,] 3 7 10