Question 1
x <- 1.1
a <- 2.2
b <- 3.3
1A
z <- x^{a^b}
print(z)
## [1] 3.61714
1B
z <- {x^a}^b
print(z)
## [1] 1.997611
1C
z <- 3*x^3 + 2*x^2 + 1
print(z)
## [1] 7.413
Question 2
2A
line_one <- seq(1,8) # creates 1 to 8 sequence
line_one_repeated <- rep.int(line_one, 2) # repeats the 1 to 8 sequence twice
print(line_one_repeated)
## [1] 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
2B
line_two <- rep(1:5, c(1,2,3,4,5)) # to get each number to repeat that same number of times
print(line_two)
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
2C
line_three <- rep(5:1, c(1,2,3,4,5))
print(line_three)
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Question 3
random_vector <- runif(2)
x <- random_vector[1] # grabs first element in random_vector
y <- random_vector[2] # grabs second
radius_squared <- x + y
radius <- radius_squared^{1/2} # square root of r^2
theta <- atan(y/x) #arc tangent function
print(radius, theta) # polar coordinate
## [1] 1
Question 4
queue <- c("sheep", "fox", "owl", "ant")
4A
queue <- append(queue, "serpent", after = length(queue))
4B ?rm
queue <- queue[-1] # indexing
4C
queue <- c("donkey", queue)
4D
queue <- queue[-5]
4E
queue <- queue[-3]
4F
queue <- append(queue, "aphid", after = 2)
4G
aphid_position <- which(queue == "aphid")
print(aphid_position)
## [1] 3
Question 5
hundred_vector <- seq(1, 100)
not_div_vector <- which((hundred_vector %% 2 != 0) & (hundred_vector %% 3 != 0) & (hundred_vector %% 7 != 0))
print(not_div_vector)
## [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