A rate function is \(r(x) = \csc(2x + 3)\). What is \(r'(x)\)?
Note: \(\csc(x) = \frac{1}{\sin(x)}\)
# install.packages("Deriv")
library(Deriv)
r <- function(x) {
1 / sin(2 * x + 3) # csc(x) = 1 / sin(x)
}
r_prime <- Deriv(r)
r_prime
## function (x)
## {
## .e2 <- 2 * x + 3
## -(2 * (cos(.e2)/sin(.e2)^2))
## }
How many composite numbers are there between 20 and 29 inclusive?
# install.packages(c("pracma","comprehenr"))
library(pracma)
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
composites <- to_vec(for (x in 20:29) if (!isprime(x)) x)
cat("There are",length(composites),"composite numbers between 20 and 29 inclusive.","\n")
## There are 8 composite numbers between 20 and 29 inclusive.
There are 4 yellow, 3 gray, 2 red, and 1 blue marbles in a bag. You mix them up and choose one marble from the bag without looking and note its color. You put the marble back, mix them up, and then choose a second marble without looking. What is the probability both marbles are yellow?
bag <- c(rep("Yellow",4),rep("Gray",3),rep("Red",2),"Blue")
counter <- 0
N <- 1e5 # 100,000 trials
for (i in 1:N) {
picks <- sample(x = bag,size = 2,replace = T)
if (all(picks == "Yellow")) {
counter <- counter + 1
}
}
probability <- counter / N
cat("The probability both marbles are yellow is:",probability,"\n")
## The probability both marbles are yellow is: 0.15906