Question 1
x <- 1
a <- 2.2
b <- 3.3
z = x^a^b
print(z)
## [1] 1
z = (x^a)^b
print(z)
## [1] 1
z = (3*x)^3 + (2*x)^2 + 1
print(z)
## [1] 32
Question 2 a)
c(seq(1,8), seq(7,1))
## [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
rep(x = seq(1:5), times = seq(1:5))
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
rep(x = seq(5,1), times = seq(1,5))
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Question 3
x = runif(1)
y = runif(1)
yx <- y/x
r <- sqrt(x^2 + y^2)
theta <- atan(yx)
Question 4
queue <- c("sheep", "fox", "owl", "ant")
queue <- c(queue, "serpent")
print(queue)
## [1] "sheep" "fox" "owl" "ant" "serpent"
queue <- queue[-1]
print(queue)
## [1] "fox" "owl" "ant" "serpent"
queue <- c("donkey", queue)
print(queue)
## [1] "donkey" "fox" "owl" "ant" "serpent"
queue <- queue[-c(5)]
print(queue)
## [1] "donkey" "fox" "owl" "ant"
queue <- queue[-c(3)]
print(queue)
## [1] "donkey" "fox" "ant"
queue <- c(queue[1:2], "aphid", queue[3])
print(queue)
## [1] "donkey" "fox" "aphid" "ant"
which(queue == "aphid")
## [1] 3
Question 5
sequence <- seq(1:100)
filtered_seq <- sequence[!(sequence %% 2 == 0 | sequence %% 3 == 0 | sequence %% 7 == 0)]
print(filtered_seq)
## [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