You are on page 1of 23

Name: K.V.

MRUNALINI REDDY
Reg.no: 20MID0116

Slot: L43+L
Course code: CSI3005
Course title: Advance data visualization techniques
Digital assignment: 02

Aim – To write code for the given exercises using a programming language
R programming is used to solve the given exercises
1.create a vector of the values of e^x cos(x) at x=3,3.1,3.2,...6.

#1.create a vector of the values of e^x cos(x) at x=3,3.1,3.2,...6.

v=seq(3,6,by=0.1)

print(exp(v)*cos(v))

2. Consider five cylinders lengths: 2.1, 3.4, 2.5, 2.7, 2.9 and the diameters are:
0.3, 0.5, 0.6, 0.9, 1.1. Read these data into two vectors. Calculate the
correlation between lengths and diameters. Calculate the volumes so that
their units are in cubic millimetres. Calculate the mean, standard deviation,
and coefficient of variation of these new volumes.
#2. Consider five cylinders lengths: 2.1, 3.4, 2.5, 2.7, 2.9 and the

#diameters are: 0.3, 0.5, 0.6, 0.9, 1.1. Read these data into

#two vectors. Calculate the correlation between lengths and diameters.

#Calculate the volumes so that their units are in cubic

#millimetres. Calculate the mean, standard deviation, and

#coefficient of variation of these new volumes.

l=c(2.1,3.4,2.5,2.7,2.9)

d=c(0.3,0.5,0.6,0.9,1.1)

r=d/2

#correlation b/w lengths and diamteres

print('correlation b/w two vectors')


cor(l,d)

#volumes in cubic meters

print('volume')

m=(pi*r*r*l)

#mean

print('mean')

mean(m)

#standard deviation

print('standard deviation')

sd(m)

#coeffecient of variation

print('coefficient of variation')

cp=sd(m)/mean(m)*100

cp
3. Create an empty matrix 5*5 and do the following operations
a. Perform element-wise matrix multiplication
b. Find the power of a matrix.
c. Modify any two elements in the matrix.
d. Rotate the matrix to 90 degrees clockwise.
e. Access the matrix elements using character index
#5x5 matrix
n= matrix(nrow=5,ncol=5)
print(n)
#a. perform matrix-wise matrix multiplication
mymatrix=n*n
mymatrix
#b. find the power of a matrix
library(expm)
x=mymatrix%^%2

x
mymatrix %*% mymatrix
#c. Modify any two elements in the matrix.
print("The Original Matrix...")
print(mymatrix)
n[1,2]=1
mymatrix[2,1]=1
print("modifing the matrix....")
print(mymatrix)
#d. Rotate the matrix to 90 degrees clockwise.
print("The Original Matrix....")
print(mymatrix)
rmatrix=t(apply(mymatrix,2,rev))
print("rotating the matrix 90 degress clockwise...")
print(rmatrix)
#e. Access the matrix elements using character index.
print(rmatrix[2,4])
print(rmatrix[4,4])
4.Write a R program to create a list of random numbers in normal

#4.Write a R program to create a list of random numbers in normal

#distribution and count occurrences of each value.

x <- rnorm(50)

count=table(x)

print(count)
5. Write a R program to create three vectors numeric data, character data and
logical data. Display the content of the vectors and their type.
#5.Write a R program to create three vectors numeric data,

#character data and logical data. Display the content of the

#vectors and their type.

n1=c(2:10)

print(n1)

print(typeof(n1))

c2=c('a','k','l')

print(c2)

print(typeof(c2))

l2=c(TRUE,FALSE,FALSE)

print(l2)
print(typeof(l2))

6. Write a R program to create bell curve of a random normal distribution.


#6. Write a R program to create bell curve of a random normal distribution
library(rcompanion)
x= c(rnorm(1000))
plotNormalHistogram( x, prob = FALSE,
main = "bell curve ",
length = 1000 )
7. Write a R program to create a list containing strings, numbers, vectors and
a logical value.
#7. Write a R program to create a list containing strings,
#numbers, vectors and a logical values.
mylist=list('20MID0116','app',23,45,c(1,8,90,87),TRUE,
FALSE,FALSE,TRUE)
print(mylist)
8. Write a R program to compute the Armstrong number and Fibonacci series.
#8.write a R program to compute the Amstrong number
#and fibonacci series.
#amstrong number
n = as.integer(readline(prompt="enter a number :"))

t=n
t1=n
c=0
sum=0
while (t > 0) {
t=floor(t/10)
c=c+1
}
print(c)
while(t1>0) {
d=t1 %% 10
sum=sum+(d^c)
t1=floor(t1/10)
}
print(sum)
if(n==sum) {
print(paste(n,"is an amstrong number"))
}
else {
print(paste(n,"is not an amstrong number"))
}
#Fibonacci series.
n = readline(prompt = "Enter a number: ")

n = as.integer(n)
a=0
b=1
ct = 2
if(n <= 0) {
print("Plese enter a positive integer")
} else {
if(n == 1) {
print("Fibonacci sequence is...")
print(0)
} else {
print("Fibonacci sequence is...")
print(0)
print(1)
while(ct < n) {
c=a+b
print(c)
a=b
b=c
ct =ct+1
}
}
}
9. Write a R program to create a two-dimensional 5x3 array of sequence of even integers
greater than 50.
#9. Write a R program to create a two-dimensional 5x3
#array of sequence of even integers greater than 50.
twodarray = array(seq(from=50,length.out = 15,by = 2),c(5, 3))
print("array of sequence of even integers greater than 50....")

print(twodarray)
10. Write a R program to add two vectors of integers type and length 3
#10.write a R program to add two vectors of integers type and length 3
#type and length 3
p=c(1L,2L,3L)
typeof(p)
q=c(30L,29L,89L)
typeof(q)
v=p+q
print(v)

You might also like