Question 1a:
x <- 1.1
a <- 2.2
b <- 3.3
z <- x^(a^b)
print(z)
## [1] 3.61714
Question 1b:
x <- 1.1
a <- 2.2
b <- 3.3
z <- (x^a)^b
print(z)
## [1] 1.997611
Question 1c:
x <- 1.1
a <- 2.2
b <- 3.3
z <- 3*x^3+2*x^2+1
print(z)
## [1] 7.413
Question 2a:
c(seq(1,8),seq(7,1))
## [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
Question 2b:
my_vec <- seq(1,5)
rep(x=my_vec,times=my_vec)
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Question 2c:
my_vec1 <- seq(1,5)
my_vec2 <- seq(5,1)
rep(x=my_vec2,times=my_vec1)
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Question 3:
coord <- runif(2)
polar_coord <- c(sqrt(coord[1]^2+coord[2]^2),atan(coord[2]/coord[1]))
print(polar_coord)
## [1] 0.7866833 0.2120234
Question 4a:
#the serpent arrives and gets in line
queue <- c("sheep", "fox", "owl", "ant")
queue[5] <- "serpent"
print(queue)
## [1] "sheep" "fox" "owl" "ant" "serpent"
Question 4b:
#the sheep enters the ark
queue <- queue[-1]
print(queue)
## [1] "fox" "owl" "ant" "serpent"
Question 4c:
#the donkey arrives and talks his way to the front of the line
queue <- c("donkey",queue)
print(queue)
## [1] "donkey" "fox" "owl" "ant" "serpent"
Question 4d:
#the serpent gets impatient and leaves
queue <- queue[-length(queue)]
print(queue)
## [1] "donkey" "fox" "owl" "ant"
Question 4e:
#the owl gets bored and leaves
queue <- queue[-which(queue == "owl")]
print(queue)
## [1] "donkey" "fox" "ant"
Question 4f:
#the aphid arrives and the ant invites him to cut in line
queue <- c(queue[1:2],"aphid",queue[3])
print(queue)
## [1] "donkey" "fox" "aphid" "ant"
Question 4g:
#Finally, determine the position of the aphid in the line.
which(queue == "aphid")
## [1] 3
Question 5:
temp_vec <- 1:100
final_vec <- which((temp_vec%%2 != 0) & (temp_vec%%3 != 0) & (temp_vec%%7 != 0))
print(final_vec)
## [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