x <- 1.1
a <- 2.2
b <- 3.3
y <- (x^a^b)
w <- ((x^a)^b)
m <- (3*x^3 + 2*x^2 + 1)
z <- c(y,w,m)
rep(z)
## [1] 3.617140 1.997611 7.413000
We have our variables x, a, and b, being assigned various
numbers.
Next we have y,w, and m being assigned equations.
Finally z has all the previous expression stored in it.
prob <- c(seq(1:8), seq(from=7, to=1))
rep(prob)
## [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
test <- c(1:5)
rep(x=test,times=test)
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
new <- seq(from=5, to=1)
test2 <- c(5:1)
rep(x=new,times=test)
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Code for part A,B,C work to produce the expected outputs for the Second part of the assignment in Homework 4
numberx <- runif(1)
numbery <- runif(1)
r <- sqrt(numberx^2 + numbery^2)
zero <- atan(numberx/numbery)
final <- c(r, zero)
rep(final)
## [1] 0.2588429 1.1470282
For problem three this program generates two random numbers for the x and y coordinates respectively. Then the r and the zero are calculated to properly use the polar coordinates.
queue <- c("Sheep", "fox", "owl", "ant")
queue <- append(queue,"Serpent") #A
queue <- (queue[! queue%in% c("Sheep")]) #B
queue <- append(queue, "Donkey", 0) #C
queue <- (queue[! queue%in% c("Serpent")]) #D
queue <- (queue[! queue%in% c("owl")]) #E
queue <- append(queue, "Aphid", after = which(queue == "ant")) #F
ap <- which(queue == "Aphid") #G.
rep(queue)
## [1] "Donkey" "fox" "ant" "Aphid"
The queue contains our original animal line while each step from A-G has its own queue line. Each line at the end has the # letter that corresponds with the step its solving.
Rnumbers <- c(1:100)
Rvect <- which(Rnumbers %%2 !=0 & Rnumbers %%3 !=0 & Rnumbers%%7 !=0)
rep(Rvect)
## [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
Rnumbers is used to call the 1-100 list of numbers. It is then called into Rvect which checks to make sure that only numbers not divisible by 2,3, and 7 can be added to Rvect.