Assignment3 L9-L12
Assignment3 L9-L12
July 2024
Assignment 3
c(6,4,2,1)*c(1,2,3,4)**c(4,2,2,1)+c(4,4,10,10)/c(2,2)?
a. 7 0 7 2
b. 5.000000 7.000000 53.000000 7.333333
c. 5 -7 -5 -7
d. None of these
Solution: Again, in this problem, we can use basic arithmetic and BODMAS rule to arrive
at option a.
1
3. Which one of the following commands will give a result without a warning?
a. c(111,123,215,17)^c(16,27,8) + c(23,19,17,35)**c(12,3,14,15)-
c(240,30,76,98)*c(8,3)
b. c(111,123,215,17)^c(16,28) + c(23,19,17,35)**c(12,3,14,15)-
c(240,30,76,98)*c(8,3)
c. c(11,13,15,17)^c(5,7) + c(12,13,14,15)**c(12,3,15)- c(240,30,
76,98)*c(8,3)
d. c(11,13,15,17)**c(8,9,4,7) + c(12,13,14,15)*c(12,3,14,15)-
c(240,30,76,98)/c(8,3,7)
Solution: Second options have all the vector operations that are compatible with each
other. In first option, c(111,123,215,17)^c(16,27,8) is not of compatible length.
Similarly, c(23,19,17,35)**c(12,3,15) and c(240,30, 76,98)/c(8,3,7) are not of
compatible length in option c and d respectively.
max(c(12,6,7,8)*c(3,6,7,2))+ sqrt(c(12,14,12,14)*c(12,12)+
c(11,21,14,4)**c(2,2,3,1)) ?
Solution: In this problem again, the R uses basic arithmetic and BODMAS to arrive at
option a.
2
5. Which one of the following is the correct outcome of the command
c(12,3,2,1)**c(1,2,-1,-2)*c(-2,-3,2,3)*c(-3,2,-2,-3)?
a. 72 52 2 9
b. 72 -54 -2 -9
c. -1 1 33 73
d. Error
c(115,206,157,138)%/%4 + c(124,244,222,334)%/%c(4,5,4,6) +
c(343,36,67, 88)%%c(21, 33) ?
a. 102 111 98 66
b. 66 111 98 102
c. 66 102 98 111
d. 111 98 66 102
3
7. Which one of the following is the correct outcome of the command
min(c(88,98,144,176)**c(-1/2,1/2))/min(c(81,144,22,38)^c(1/2,-3
)) -prod(c(3,2,3,2)^c(2,3))/max(c(81,24,44,99,26)*min(c(4,3,8
,6)))- max(c(12,24,24,12)^c(2,3))-1/2 ?
a. 23490
b. -234990
c. 234990
d. None of these
Solution: In this problem, the R uses simple arithmetic and BODMAS rule on vectors to
arrive at the option c.
4
9. Which one of the following is the correct outcome of the command
floor(c(5,1,7,8)^c(3,2))-ceiling(c(1,6,1,8)^c(2,2)) +
ceiling(c(2,3,4,5)^c(-1,-2)) + round(c(5,6,7,8)^c(3,2)) +
floor(c(5,6,7,8)^c(3,2)) ?
10. Which one of the following is the correct outcome of the command
ceiling(c(4,8,4,5)^c(-3,-9) - sqrt(c(3,6,8,6)**c(3,2))*sqrt(c(2
,3,4,5)^c(3,2)) - round(c(4,7,8,9)*round(c(7,9)))) ?
a. -42 -80 -237 -110
b. -80 -110 -237 -36
c. 42 80 237 110
d. None of these
11. Which one of the following is the correct outcome of the command
ceiling(prod(c(1,5,2,6))+ sum(c(21,22,23,24,25))) -
floor(prod(c(1,5,2,6))- round(c(21,22,23,24,25))) ?
a. 36 37 38 39 40
b. 236 237 238 239 240
c. 136 137 138 139 140
d. None of these
5
12. Which one of the following is the value of X2 when the following commands are
executed over the R console?
X1 = c(12,16,8,14)
X2 = sqrt(X1^2)-X1*2/X1^2+X1**(1/2)+abs(X1)
Solution: In this problem, X1**(1/2) is calculated first, then 2/X1^2. After which, the rest of
calculations are done according to the BODMAS rule.
13. Which one of the following is the correct outcome of the command
c(2,2,4,4)^c(-3,-2,2,3)/c(4,3,2,1) +
c(2,4,1,6)%/%c(3,4)*c(2,5,3,6)+
max(c(20,10,14,15)^c(1,2))/min(c(6,2,7,15)^c(2,2))?
6
14. Which one of the following is the correct command to obtain the following matrix?
11 14 17
𝑥 = (12 15 18)
13 16 19
a. x=matrix(11:19,3,3,byrow=T)
b. x=mat(11:19,3,3, byrow=T)
c. x=matrix(11:19,3,3,byrow=F)
d. x=mat(11:19,3,3,byrow=F)
Solution: Valid command to form a matrix is matrix(). The data is entered columnwise, so
byrow = F.
15. Which one of the following is the correct command to obtain the following matrix? 𝑧 =
15 8
(11 19)
17 12
Solution: The matrix has three rows and 2 columns, and the data vector in the command
must be contained in c().
7
16. Which one of the following is the correct command to obtain the third column and
second row of a matrix x defined in R?
Solution: x[ ,ncol] and x[nrow, ] are the standard commands for ncol-th column and nrow-
th row of the matrix x.
17. Which one of the following is the correct outcome of the command X[2,1] for the
matrix constituted by the command X=matrix(45:54,3,3,byrow=F)?
a. 45
b. 46
c. 47
d. 48
Solution: X[2,1] represents the element in the second row and first column, which is 46.
18. Which one of the following is the correct outcome of the commands dim(x) and
dim(y) for the matrices obtained by x=matrix(1:40,4,10,byrow=T) and
y=matrix(41:80,10,4,byrow=F) ?
a. 10 4 and 4 10 respectively.
b. 4 10 and 10 4 respectively.
c. 4 10 and 4 10 respectively.
d. 10 4 and 10 4 respectively.
Solution: The dimensions of the matrix is already given in the commands to be executed,
which are 2 * 25 and 25 * 2 respectively.
8
19. Which one of the following is the correct command to obtain the following matrix? 𝑧 =
5 1 7
( )
8 9 2
20. Which one of the following is the correct outcome of the command
3 7
a. 𝑥 = ( )
0 7
0 3
b. 𝑥 = ( )
7 0
3 7
c. 𝑥=( )
3 7
3 0
d. 𝑥=( )
0 7
Solution: The command diag() creates a diagonal matrix in R with diagonal entries given
by data.
9
MOOC Course - Foundations of R Software
Answers of Assignment 3
1. b
2. a
3. b
4. a
5. b
6. c
7. c
8. b
9. b
10. a
11. c
12. a
13. c
14. c
15. b
16. c
17. b
18. b
19. a
20. d
10