LIS4370: Module # 6 Doing math in R part 2

 Module # 6 Doing math in R part 2


1a) Sum of matrices A and B:

> print(sum_result)

     [,1] [,2]

[1,]    7    5

[2,]    2    2


1b) Difference of matrices A and B:

> print(diff_result)

     [,1] [,2]

[1,]   -3   -3

[2,]   -2    4


2) Source Code: 

diag_matrix <- diag(c(4, 1, 2, 3), nrow = 4, ncol = 4)


Output:




3) Source Code:

matrix <- matrix(c(3, 1, 1, 1, 1,
                   2, 3, 0, 0, 0,
                   2, 0, 3, 0, 0,
                   2, 0, 0, 3, 0,
                   2, 0, 0, 0, 3), 
                 nrow = 5, byrow = TRUE)

print(matrix)

Output:
 
    [,1] [,2] [,3] [,4] [,5]
[1,]    3    1    1    1    1
[2,]    2    3    0    0    0
[3,]    2    0    3    0    0
[4,]    2    0    0    3    0
[5,]    2    0    0    0    3

Comments

Popular posts from this blog

LIS 4370: Module # 10 Building your own R package

LIS 4317 Final Project: Fuel Economy Data from the U.S Dept. of Energy

LIS 4317: Module # 10 assignment