Convert \(\frac{26 \pi}{5}\) radians into degrees.
# install.packages("pracma")
library(pracma)
answer <- rad2deg(rad = 26 * pi / 5)
cat("26 pi / 5 radians =",answer,"degrees","\n")
## 26 pi / 5 radians = 936 degrees
What is the area between the curve \(f(x) = 4x^3\) and the \(x\)-axis from \(x = 0\) to \(x = 1\)?
# install.packages("tidyverse")
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ purrr::cross() masks pracma::cross()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
f <- function(x) {
4 * x^3
}
area <- integrate(f,lower = 0,upper = 1)$value
x_values <- seq(0,1.05,length.out = 500)
y_values <- f(x_values)
q2_data <- data.frame(x = x_values,y = y_values)
ggplot(q2_data,aes(x = x,y = y)) +
geom_line(col = "black",lwd = 1.25) +
geom_ribbon(data = subset(q2_data,x >= 0 & x <= 1),
aes(ymin = 0,ymax = y),
fill = "red") +
labs(title = "Graph of f(x) = 4x^3",
caption = paste("The area under the curve between x = 0 and x = 1 is:",area),
x = "x",
y = "y") +
theme_gray(base_size = 14)
Ben takes an ordinary deck of 52 playing cards and removes all the picture cards - all the Jacks, Queens, and Kings. Ben then shuffles the remaining cards and selects a card at random. Ben wins if the number on the card is a prime number. Use a Monte Carlo simulation to estimate the probability of winning.
# install.packages("pracma")
library(pracma) # for the isprime() function
Cards <- 1:10 # 1 represents the Ace, 2 - 10 are normal
counter <- 0 # number of prime number cards
N <- 100000 # number of trials
for (x in 1:N) {
pick <- sample(x = Cards,size = 1,replace = T)
if (isprime(pick) == TRUE) {
counter <- counter + 1
}
}
probability <- counter / N
cat("The probability of winning is:",probability,"\n")
## The probability of winning is: 0.40209
You are given some data about products and prices. Answer the following parts.
Part 1: Define the data frame.
q4_data <- data.frame(Product = c("Salt","Bread","Flour","Toothbrush","Soap","Lollipop","Cake","Tissues"),
Price = c(0.50,0.93,0.90,0.75,0.30,0.25,0.48,0.79))
q4_data
## Product Price
## 1 Salt 0.50
## 2 Bread 0.93
## 3 Flour 0.90
## 4 Toothbrush 0.75
## 5 Soap 0.30
## 6 Lollipop 0.25
## 7 Cake 0.48
## 8 Tissues 0.79
A. Arrange the data in order from least price to greatest price.
# install.packages("tidyverse")
library(tidyverse)
q4_data %>%
arrange(Price)
## Product Price
## 1 Lollipop 0.25
## 2 Soap 0.30
## 3 Cake 0.48
## 4 Salt 0.50
## 5 Toothbrush 0.75
## 6 Tissues 0.79
## 7 Flour 0.90
## 8 Bread 0.93
B. Arrange these in order from greatest price to least price.
# install.packages("tidyverse")
library(tidyverse)
q4_data %>%
arrange(desc(Price))
## Product Price
## 1 Bread 0.93
## 2 Flour 0.90
## 3 Tissues 0.79
## 4 Toothbrush 0.75
## 5 Salt 0.50
## 6 Cake 0.48
## 7 Soap 0.30
## 8 Lollipop 0.25
C. Arrange this data in alphabetical order.
# install.packages("tidyverse")
library(tidyverse)
q4_data %>%
slice(str_order(Product))
## Product Price
## 1 Bread 0.93
## 2 Cake 0.48
## 3 Flour 0.90
## 4 Lollipop 0.25
## 5 Salt 0.50
## 6 Soap 0.30
## 7 Tissues 0.79
## 8 Toothbrush 0.75