Tuesday, October 31, 2023

R Programming Lab - Bsc CS DA and BSC ML And AI -Bharathiar University - Program 2- Manipulation of Vectors and matrix

 B.Sc Computer Science  

R Programming - Lab  

Bharathiar University 

Program 2

Manipulation of vectors and matrix 

Program 2 {a}- Write a R program to perform manipulation in vectors


SOURCE CODE:

# Manipulation of Vectors
# Create  two numeric vectors
v1 <- c(1, 2, 3, 4, 5)
v2 <- c(1, 1, 1, 1, 1)

# Print the original vector
print("Original Numeric Vectors:")
print(v1) 
print(v2)

print("Manipulation of Vectors")
print("Adding 1 to each element of the 1st vector")
m <- v1 + 1
print(m)

print("Adding 1st and 2 nd vectors")
print(v1+v2)

print("Subtract 2nd vector from 1st vector")
print(v1-v2)

print(" Multiplying two vectors")
print(v1*v2)


OUPUT


Program 2 {b}- Write a R program to perform manipulations in matrix 


SOURCE CODE:


# Manipulation of Matrix

# Create two matrices
m1 <- matrix(1:9, nrow = 3, ncol = 3)
m2 <- matrix(1:9, nrow = 3, ncol = 3)

# Print the original matrix
print("Original Matrices:")
print("Matrix 1:")
print(m1)
print("Matrix 2:")
print(m2)


print("Addition of two matrices")
print(m1+m2)

print("Subtraction of two matrices")
print(m1-m2)

print("Multiplication of two matrices")
print(m1*m2)

print("Division of two matrices")
print(m1/m2)


OUTPUT:

No comments:

Post a Comment

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...