Homework 4

Lindsey Carlson

2/9/2022

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
Q2a <- c((seq(from=1, to = 8, by= )),(seq(from=7, to=1, by=-1)))
print(Q2a)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
#2b
Q2b <- c(rep(1,1), rep(2,2), rep(3,3), rep(4,4), rep(5,5))
print(Q2b)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
#2c
Q2c <- c(rep(5,1), rep(4,2), rep(3,3), rep(2,4), rep(1,5))
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
x <- c(runif(1))
y <- c(runif(1))
print(x)
## [1] 0.0523771
print(y)
## [1] 0.08478632
#Conversion of numbers to polar coordinates
r <- c(sqrt((x^2)+(y^2)))
theta <- c(atan(y/x))
print(r)
## [1] 0.09965982
print(theta)
## [1] 1.017425

Question 4

#Starting Sequence
queue <- c("sheep", "fox", "owl", "ant")
queue
## [1] "sheep" "fox"   "owl"   "ant"
#Q4a - serpent joins end of line
queue <- append(queue, "serpent")
queue
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"
#Q4b - sheep enters ark
queue <- queue[-1]
queue
## [1] "fox"     "owl"     "ant"     "serpent"
#Q4c - donkey arrives and goes to front
queue <- append(queue, "donkey", after=0)
queue
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"
#Q4d - serpent leaves
queue <- queue[-5]
queue
## [1] "donkey" "fox"    "owl"    "ant"
#Q4e - owl leaves
queue<- queue[-3]
queue
## [1] "donkey" "fox"    "ant"
#Q4f - aphid goes infront of ant
queue <- append(queue, "aphid", after=2)
queue
## [1] "donkey" "fox"    "aphid"  "ant"
#Q4g
  #The aphid is third in line! 

Question 5

Q5 <- c(1:100)
Q5 <- Q5[Q5 %% 3 != 0 & Q5 %% 7 != 0 & Q5 %% 2 != 0]

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

Home Page