Question 1
<- 1.1
x <- 2.2
a <- 3.3
b
#1a
<- x^(a^b)
z print(z)
## [1] 3.61714
#1b
<- (x^a)^b
z print(z)
## [1] 1.997611
#1c
<- 3*(x^3) + 2*(x^2) + 1
z print(z)
## [1] 7.413
Question 2
#2a
<- c((seq(from=1, to = 8, by= )),(seq(from=7, to=1, by=-1)))
Q2a print(Q2a)
## [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
#2b
<- c(rep(1,1), rep(2,2), rep(3,3), rep(4,4), rep(5,5))
Q2b print(Q2b)
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
#2c
<- c(rep(5,1), rep(4,2), rep(3,3), rep(2,4), rep(1,5))
Q2c print(Q2c)
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Question 3
#Creating vector of two random uniform numbers
<- c(runif(1))
x <- c(runif(1))
y print(x)
## [1] 0.0523771
print(y)
## [1] 0.08478632
#Conversion of numbers to polar coordinates
<- c(sqrt((x^2)+(y^2)))
r <- c(atan(y/x))
theta print(r)
## [1] 0.09965982
print(theta)
## [1] 1.017425
Question 4
#Starting Sequence
<- c("sheep", "fox", "owl", "ant")
queue queue
## [1] "sheep" "fox" "owl" "ant"
#Q4a - serpent joins end of line
<- append(queue, "serpent")
queue queue
## [1] "sheep" "fox" "owl" "ant" "serpent"
#Q4b - sheep enters ark
<- queue[-1]
queue queue
## [1] "fox" "owl" "ant" "serpent"
#Q4c - donkey arrives and goes to front
<- append(queue, "donkey", after=0)
queue queue
## [1] "donkey" "fox" "owl" "ant" "serpent"
#Q4d - serpent leaves
<- queue[-5]
queue queue
## [1] "donkey" "fox" "owl" "ant"
#Q4e - owl leaves
<- queue[-3]
queue queue
## [1] "donkey" "fox" "ant"
#Q4f - aphid goes infront of ant
<- append(queue, "aphid", after=2)
queue queue
## [1] "donkey" "fox" "aphid" "ant"
#Q4g
#The aphid is third in line!
Question 5
<- c(1:100)
Q5 <- Q5[Q5 %% 3 != 0 & Q5 %% 7 != 0 & Q5 %% 2 != 0]
Q5
Q5
## [1] 1 5 11 13 17 19 23 25 29 31 37 41 43 47 53 55 59 61 65 67 71 73 79 83 85
## [26] 89 95 97