Question 1:

x = 1.1
a = 2.2
b = 3.3

## a
z = x^(a^b)
print(z)
## [1] 3.61714
## b
z = (x^a)^b
print(z)
## [1] 1.997611
## c
z = 3*x^3 + 2*x^2 +1
print(z)
## [1] 7.413

 

Question 2:

## a
a1 = seq(1,8,1)
a2 = seq(7,1,-1)

a3 = c(a1,a2)
print(a3)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
## b
b1 = seq(1,5,1)

b2 = rep(b1, times=b1)
print(b2)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
## c
c1 = seq(5,1,-1)
c2 = rep(c1, times=b1)
print(c2)
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

 

Question 3:

set.seed(77)

q3_cartesian = runif(2, min=0,max=10)
names(q3_cartesian) <- c("x","y")
print(q3_cartesian)
##        x        y 
## 2.912838 7.174690
r = sqrt(sum(q3_cartesian^2))
theta = atan(as.numeric(q3_cartesian["y"] / q3_cartesian["x"]))

q3_polar = c(r, theta)
names(q3_polar) <- c("r", "theta")
print(q3_polar)
##        r    theta 
## 7.743437 1.185139

 

Question 4:

queue <- c("sheep", "fox", "owl", "ant")
print(queue)
## [1] "sheep" "fox"   "owl"   "ant"
##a
queue = c(queue, "serpent")
#print(queue)

## b
queue = queue[-1]
#print(queue)

## c
queue = c("donkey", queue)
#print(queue)

## d
queue = queue[-length(queue)]
#print(queue)

## e
queue = queue[-3]
#print(queue)

## f
queue = c(queue[-length(queue)], "aphid", queue[length(queue)])
#print(queue)

## g
queue[3]
## [1] "aphid"

 

##3 Question 5:

q5 <- seq(1,100)

q5.a = q5[!(q5 %% 2 == 0 | q5 %% 3 == 0 | q5 %% 7 == 0)]
print(q5.a)
##  [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