Question 1

For \(f(x) = \sqrt{x}\) and \(g(x) = x^2\) on \([0,1]\), find the area between both functions and graph them.

# 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(x) {
  sqrt(x)
}
g <- function(x) {
  x^2
}
difference <- function(x) {
  f(x) - g(x) # difference between each function for integral calculation
}
area <- integrate(f = difference,lower = 0,upper = 1)$value
x_values <- seq(0,1.001,length.out = 500)
f_values <- f(x_values)
g_values <- g(x_values)
differences <- difference(x_values)
q1_data <- data.frame(x = x_values,f = f_values,g = g_values,difference = differences)
ggplot(q1_data,aes(x = x)) +
  geom_line(aes(y = f),col = "red",lwd = 2) +
  geom_line(aes(y = g),col = "blue",lwd = 2) +
  geom_ribbon(data = subset(q1_data,x >= 0 & x <= 1),
              aes(ymin = g,ymax = f),
              fill = "lightblue") +
  labs(title = "Graph of f(x) = sqrt(x) and g(x) = x^2",
       caption = paste("Area between the functions:",round(area,4)),
       x = "x",
       y = "y") +
  theme_gray()

Question 2

Plot the corresponding polygon to the points below.

\[A(6,7) \space B(7,6) \space C(3,-2)\]

# install.packages("tidyverse")
library(tidyverse)
q2_data <- data.frame(x = c(6,7,3),
                      y = c(7,6,-2))
ggplot(q2_data,aes(x = x,y = y)) +
  geom_polygon(fill = "yellow",color = "black",lwd = 1.25) +
  geom_point(size = 3) +
  coord_equal() +
  theme_gray()

Question 3

Beatrice has the following tops and skirts in her closet. She is going to a party and can choose any one of the tops and any one of the skirts. Answer the following questions.

A. What is the probability Beatrice chooses a top and a skirt of exactly the same color?

Shirts1 <- c("Black","Red","Yellow","Blue","Purple","Orange","White","Light Green","Light Blue")
Skirts1 <- c("Black","White","Brown","Green","Orange","Red")
counter1 <- 0
N1 <- 1e5
for (i in 1:N1) {
  shirt1 <- sample(x = Shirts1,size = 1,replace = T)
  skirt1 <- sample(x = Skirts1,size = 1,replace = T)
  if (shirt1 == skirt1) {
    counter1 <- counter1 + 1
  }
}
probability1 <- counter1 / N1
cat("The probability Beatrice chooses a top and a skirt of exactly the same color is:",probability1,"\n")
## The probability Beatrice chooses a top and a skirt of exactly the same color is: 0.07331

B. What is the probability Beatrice chooses a top and a skirt that are not exactly the same color?

Shirts2 <- c("Black","Red","Yellow","Blue","Purple","Orange","White","Light Green","Light Blue")
Skirts2 <- c("Black","White","Brown","Green","Orange","Red")
counter2 <- 0
N2 <- 1e5
for (j in 1:N2) {
  shirt2 <- sample(x = Shirts2,size = 1,replace = T)
  skirt2 <- sample(x = Skirts2,size = 1,replace = T)
  if (shirt2 != skirt2) {
    counter2 <- counter2 + 1
  }
}
probability2 <- counter2 / N2
cat("The probability Beatrice chooses a top and a skirt that are not exactly the same color is:",probability2,"\n")
## The probability Beatrice chooses a top and a skirt that are not exactly the same color is: 0.92605