Construct the polygon with the following coordinates.
\[A(2,-3), B(5,5), C(-1,7)\]
# 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
q1_data <- data.frame(X = c(2,5,-1),
Y = c(-3,5,7))
ggplot(q1_data,aes(x = X,y = Y)) +
geom_polygon(fill = "lightblue",alpha = 0.5,color = "black",lwd = 1.25) +
geom_point(size = 3) +
coord_equal() +
theme_gray()
The diagram shows a special die in the shape of an octagonal prism. It has eight rectangular faces, each with a number 1 to 8, and two octagonal faces at the ends. Abe rolls the die on a flat surface until it settles with a number on the top face. Because the die is rolled, it cannot land on either of the octagonal faces. Answer the following questions below.
A. What is the probability Abe scores a factor of 6?
Spinner <- 1:8 # our spinner
Counter <- 0 # number of times the spinner lands on a factor of 6
N <- 1e6 # 1 million trials
for (i in 1:N) { # iterating through the number of trials
Spin <- sample(x = Spinner,size = 1,replace = T) # spinning the spinner
if (6 %% Spin == 0) { # checking if the score is a factor of 6
Counter <- Counter + 1 # incrementing the counter up by 1 if the statement is true
}
}
probability <- Counter / N # finding the probability of scoring a factor of 6
cat("The probability Abe scores a factor of 6 is:",probability,"\n")
## The probability Abe scores a factor of 6 is: 0.500736
B. What is the probability Abe does not score a factor of 6?
Spinner2 <- 1:8 # our spinner
Counter2 <- 0 # number of times the spinner does not land on a factor of 6
N2 <- 1e6 # 1 million trials
for (j in 1:N2) { # iterating through the number of trials
Spin2 <- sample(x = Spinner2,size = 1,replace = T) # spinning the spinner
if (6 %% Spin2 != 0) { # checking if the score is not a factor of 6
Counter2 <- Counter2 + 1 # incrementing the counter up by 1 if the statement is true
}
}
probability2 <- Counter2 / N2 # finding the probability of not scoring a factor of 6
cat("The probability Abe does not score a factor of 6 is:",probability2,"\n")
## The probability Abe does not score a factor of 6 is: 0.500454
What is the area between the curve \(f(x) = x^2 - 4\) and the x-axis from \(x = -2\) to \(x = 2\)?
# install.packages("tidyverse")
library(tidyverse)
f <- function(x) {
x^2 - 4
}
area <- integrate(f = f,lower = -2,upper = 2)$value
x_values <- seq(-2.01,2.01,length.out = 500)
y_values <- f(x_values)
q3_data <- data.frame(x = x_values,y = y_values)
ggplot(q3_data,aes(x = x,y = y)) +
geom_line(col = "black",lwd = 1.5) +
geom_ribbon(data = subset(q3_data,x >= -2 & x <= 2),
aes(ymin = 0,ymax = y),
fill = "red") +
labs(title = "Graph of f(x) = x^2 - 4",
caption = paste("Area:",round(area,4)),
x = "x",
y = "y") +
theme_gray(base_size = 14)