#Write an R program that includes linear algebra operations on vectors and matrices
# Creating a vector
X <- c(2, 5, 1, 7, 8, 2)
Y <- c(7, 9, 1, 5, 2, 1)
# modify a specific element
X[3] <- 11
print('Using subscript operator')
print(X)
# Modify using different logics.
X[X>9] <- 0
print('Logical indexing')
print(X)
# Accessing specific values by passing
# a vector inside another vector.
Y <- c(4, 5, 2, 1, 7)
print('using c function')
print(Y[c(4, 1)])
# Logical indexing
Z <- c(5, 2, 1, 4, 4, 3)
print('Logical indexing')
print(Z[Z>3])
# Deleting a vector
X <- NULL
print('Deleted vector')
print(X)
# MATRIX
# Create a matrix with 3 rows and 2 columns
matrix_data <- c(1, 2, 3, 4, 5, 6)
matrix_example <- matrix(matrix_data, nrow = 3, ncol = 2)
print(matrix_example)
# Using diag() function
diag_matrix <- diag(c(5, 9, 2, 7))
# Using matrix() function
diag_matrix <- matrix(c(5, 0, 0, 0,
0, 9, 0, 0,
0, 0, 2, 0,
0, 0, 0, 7), nrow = 4, byrow = TRUE)
print("C=A+B")
A <- matrix(c(1, 3, 2, 2, 8, 9), ncol = 3, byrow = T)
B <- matrix(c(5, 8, 3, 4, 2, 7), ncol = 3, byrow = T)
C <- A + B
print(C)