Problem #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

1d

(z %% 1)
## [1] 0.413
floor((z %% 1)*10)
## [1] 4

Problem #2

2a

x <- seq(from = 1, to=8)
y <- seq(from = 7, to = 1)
c(x,y)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1

2b

rep(1:5, c(1,2,3,4,5))
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

2c

rep(5:1, c(1,2,3,4,5))
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

Problem 3

v <- runif(2)
r <- sqrt(v[1]^2 + v[2]^2)
theta <- atan(v[2]/v[1])
print(r)
## [1] 0.4308105
print(theta)
## [1] 1.491462

Problem 4

queue <- c("sheep", "fox", "owl", "ant")

a

queue <- c(queue, "serpent")

b

queue <- queue[-1]

c

queue <- c("donkey",queue)

d

queue <- queue[-5]

e

queue <- queue[-3]

f

queue <- append(queue, "aphid", after = 2)

g

which(queue == "aphid")
## [1] 3

Problem 5

v <- rep(1:100, by=1)
v[v%%2 != 0 & v%%3 !=0 & v%%7 !=0]
##  [1]  1  5 11 13 17 19 23 25 29 31 37 41 43 47 53 55 59 61 65 67 71 73 79
## [24] 83 85 89 95 97

Problem 6

z <- runif(1000)

a

y<-c(mean(z<0.1),mean(z>0.9),mean(z>.45 & z<.55))
print(y)
## [1] 0.094 0.093 0.109

b

x1 <- log10(z)
x2 <- z^2
x3 <- exp(z)
x4 <- sqrt(z)

c

w1 <- c(mean(x1<0.1),mean(x1>0.9),mean(x1>.45 & x<.55))
print(w1)
## [1] 1 0 0
w2 <- c(mean(x2<0.1),mean(x2>0.9),mean(x2>.45 & x<.55))
print(w2)
## [1] 0.287 0.051 0.000
w3 <- c(mean(x3<0.1),mean(x3>0.9),mean(x3>.45 & x3< .55))
print(w3)
## [1] 0 1 0
w4 <- c(mean(x3<0.1),mean(x3>0.9),mean(x3>.45 & x3< .55))
print(w4)
## [1] 0 1 0