-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.r
37 lines (29 loc) · 897 Bytes
/
Matrix.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#Develop a program to create two 3 X 3 matrices A and B and perform the following
#operations a) Transpose of the matrix b) addition c) subtraction d) multiplication
# Create two 3x3 matrices A and B
A<- matrix(1:9, nrow = 3)
B<- matrix(10:18, nrow = 3)
# Display matrices A and B
cat("Matrix A:\n")
print(A)
cat("\nMatrix B:\n")
print(B)
# a) Transpose of the matrices
cat("\nTranspose of Matrix A:\n")
A_transpose <- t(A)
print(A_transpose)
cat("\nTranspose of Matrix B:\n")
B_transpose <- t(B)
print(B_transpose)
# b) Addition of matrices
cat("\nMatrix A + Matrix B:\n")
addition_result <- A + B
print(addition_result)
# c) Subtraction of matrices
cat("\nMatrix A- Matrix B:\n")
subtraction_result <- A- B
print(subtraction_result)
# d) Multiplication of matrices
cat("\nMatrix A * Matrix B:\n")
multiplication_result <- A %*% B
print(multiplication_result)