Question 1

Set up and solve the definite integral for the region bounded by \(x = \sqrt{y}\) and the y-axis for \(0 \leq y \leq 4\) revolved about the y-axis.

  1. Set up the integral.

Formula: \(V = \pi \int_{a}^{b} g(y) dy\)

We get the following definite integral through substituting in our known parameters.

\[V = \pi \int_{0}^{4} y \space dy\]

Note: It is \(g(y) = y\) since we are working in the y-direction.

  1. Solve the integral and graph it.
# 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() ──
## ✖ 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(y) {
  y
}
result <- pi * integrate(f,lower = 0,upper = 4)$value
y_values <- seq(0,4,length.out = 500)
q1_data <- data.frame(x = sqrt(y_values),
                      y = y_values)
ggplot(q1_data,aes(x = x,y = y)) +
  geom_area(fill = "skyblue",alpha = 0.4) +
  geom_line(size = 1.25,color = "steelblue") +
  labs(title = "Region Bounded by x = sqrt(y) and the y-axis",
       caption = paste("Answer:",round(result,4)),
       x = "x",
       y = "y") +
  theme_minimal(base_size = 16)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Question 2

You are given some data on food and beverages along with their prices. Perform the following.

First, I will define the data frame.

q2_data <- data.frame(Product = c("Burger","Hotdog","Fries","Soda","Drumstick","Onion Ring","Coffee","Nuggets"),
                      Price = c(.89,.72,.65,.68,.95,.24,.99,.20))
q2_data
##      Product Price
## 1     Burger  0.89
## 2     Hotdog  0.72
## 3      Fries  0.65
## 4       Soda  0.68
## 5  Drumstick  0.95
## 6 Onion Ring  0.24
## 7     Coffee  0.99
## 8    Nuggets  0.20

A. Sort in ascending order by Price.

# install.packages("tidyverse")
library(tidyverse)
q2_data %>%
  arrange(Price)
##      Product Price
## 1    Nuggets  0.20
## 2 Onion Ring  0.24
## 3      Fries  0.65
## 4       Soda  0.68
## 5     Hotdog  0.72
## 6     Burger  0.89
## 7  Drumstick  0.95
## 8     Coffee  0.99

B. Sort in descending order by Price.

# install.packages("tidyverse")
library(tidyverse)
q2_data %>%
  arrange(desc(Price))
##      Product Price
## 1     Coffee  0.99
## 2  Drumstick  0.95
## 3     Burger  0.89
## 4     Hotdog  0.72
## 5       Soda  0.68
## 6      Fries  0.65
## 7 Onion Ring  0.24
## 8    Nuggets  0.20

Question 3

Dan tossed a die twenty times and recorded the results. Use a Monte Carlo simulation to record the results in a frequency table and a bar graph.

# Preparation
# install.packages("tidyverse")
library(tidyverse)
set.seed(123)
N <- 20 # number of tosses
die <- 1:6 # fair die

# Simulation
simulation <- sample(x = die,size = N,replace = T)

# Frequency Table
freq_table <- table(simulation)
q3_data <- as.data.frame(freq_table)
colnames(q3_data) <- c("Score","Frequency")
q3_data
##   Score Frequency
## 1     1         3
## 2     2         3
## 3     3         6
## 4     4         2
## 5     5         2
## 6     6         4
# Bar Graph
ggplot(q3_data,aes(x = factor(Score),y = Frequency)) +
  geom_col(color = "black") +
  labs(title = "Simulated Die Tosses",
       x = "Die Face",
       y = "Frequency") +
  theme_gray(base_size = 14)

Question 4

Carl spins the spinner twice and adds the two scores together. Use a Monte Carlo simulation to answer the following questions.

\[\text{Spinner} = [1,5,1,5,2,1,5,3]\]

A. What is the probability Carl gets a total score of 9 or greater?

Spinner <- c(1,5,1,5,2,1,5,3)
Counter <- 0
num_trials <- 1e6 # 1 million trials
for (i in 1:num_trials) {
  spin1 <- sample(x = Spinner,size = 1,replace = T)
  spin2 <- sample(x = Spinner,size = 1,replace = T)
  if (spin1 + spin2 >= 9) {
    Counter <- Counter + 1
  }
}
probability1 <- Counter / num_trials
cat("The probability of getting a total score of 9 or greater is:",probability1,"\n")
## The probability of getting a total score of 9 or greater is: 0.140687

B. What is the probability Carl does not get a total score 9 or greater?

Spinner <- c(1,5,1,5,2,1,5,3)
Counter2 <- 0
num_trials <- 1e6 # 1 million trials
for (i in 1:num_trials) {
  spin3 <- sample(x = Spinner,size = 1,replace = T)
  spin4 <- sample(x = Spinner,size = 1,replace = T)
  if (spin3 + spin4 < 9) {
    Counter2 <- Counter2 + 1
  }
}
probability2 <- Counter2 / num_trials
cat("The probability of not getting a total score of 9 or greater is:",probability2,"\n")
## The probability of not getting a total score of 9 or greater is: 0.859948