Question 1

For \(f(x) = 4 - x\) on \([-1,3]\), what is the average value of \(f(x)\) on the interval?

\[f_{average} = \frac{1}{b - a} \int_{a}^{b} f(x) \space dx\]

# 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) {
  4 - x
}
average_value <- (1 / (3 - (-1))) * integrate(f = f,lower = -1,upper = 3)$value
x_values <- seq(-1,3,length.out = 500)
y_values <- f(x_values)
q1_data <- data.frame(x = x_values,y = y_values)
ggplot(q1_data,aes(x = x,y = y)) +
  geom_line(col = "blue",lwd = 1.5) +
  labs(title = "Graph of f(x) = 4 - x",
       caption = paste("Average value:",average_value),
       x = "x",
       y = "y") +
  theme_gray()

Question 2

Use integration by substitution to find \(\int \frac{x^2}{x^3 + 1} \space dx\).

# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: scales
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
## Loading required package: ggiraph
## Warning: package 'ggiraph' was built under R version 4.5.2
## Loading required package: ggridges
## Warning: package 'ggridges' was built under R version 4.5.2
## 
## New to ggformula?  Try the tutorials: 
##  learnr::run_tutorial("introduction", package = "ggformula")
##  learnr::run_tutorial("refining", package = "ggformula")
library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.5.2
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
g <- makeFun(x^2 / (x^3 + 1) ~ x)
anti_g <- antiD(g(x) ~ x)
anti_g
## function (x, C = 0) 
## {
##     F <- makeF(x^2/(x^3 + 1))
##     evalFun(F, x = x, .const = C)
## }
## <environment: 0x000001446415f238>

Question 3

Write 180 in words.

# install.packages("english")
library(english)
## Warning: package 'english' was built under R version 4.5.2
## 
## Attaching package: 'english'
## The following object is masked from 'package:scales':
## 
##     ordinal
words(180)
## [1] "one hundred eighty"

Question 4

Create the corresponding polygon given the \((x,y)\) data below.

# install.packages("tidyverse")
library(tidyverse)
q4_data <- data.frame(X = c(-2,-2,2,7,7,4),
                      Y = c(3,9,12,9,3,-2))
ggplot(q4_data,aes(x = X,y = Y)) +
  geom_polygon(fill = "steelblue",col = "black",lwd = 2) +
  geom_point(size = 3) +
  coord_equal() +
  theme_gray()

Question 5

The ages of 50 people taking a driving test were grouped and recorded as follows. Use the midpoints of the groups to estimate the mean age of the people taking the test.

  1. Construct a bar graph for the data. This helps me visualize the data and approximate the mean.
# install.packages("tidyverse")
library(tidyverse)
q5_data <- data.frame(Age = c("10-19","20-29","30-39","40-49","50-59","60-69","70-79","80-89"),
                      Number = c(11,25,6,2,3,2,0,1))
ggplot(q5_data,aes(x = factor(Age),y = Number)) +
  geom_col() +
  labs(title = "Driving Test Data",
       x = "Age",
       y = "Number") +
  theme_gray()

B. Compute the mean using the midpoints.

# install.packages("tidyverse")
library(tidyverse)
q5_data <- q5_data %>%
  separate(Age,into = c("Upper","Lower"),sep = "-",convert = T) %>%
  mutate(Midpoint = (Lower + Upper) / 2)
expanded_q5_data <- rep(q5_data$Midpoint,q5_data$Number)
cat("The estimated mean using the midpoints is:",mean(expanded_q5_data),"\n")
## The estimated mean using the midpoints is: 28.9