Question 1

What is the antiderivative of \(f(x) = \frac{1}{1 - \sin^2(x)}\)?

# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: ggplot2
## Loading required package: scales
## 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
f <- makeFun(1 / (1 - (sin(x))^2) ~ x)
anti_f <- antiD(f(x) ~ x)
anti_f
## function (x, C = 0) 
## {
##     F <- makeF(1/(1 - (sin(x))^2))
##     evalFun(F, x = x, .const = C)
## }
## <environment: 0x000001f3356503f0>

Question 2

Evaluate the following summation.

\[\sum_{n = 1}^{\infty} \frac{1}{(2n)^2}\]

total <- 0
series <- function(n) {
  1 / ((2 * n)^2)
}
for (x in 1:1000000) {
  total <- total + series(x)
}
total
## [1] 0.4112333

Question 3

Mat recorded the numbers of sweets he ate each day for a week. Construct a bar graph for the data frame below.

  1. Define the data frame.
q3_data <- data.frame(Weekday = c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"),
                      Frequency = c(4,5,7,8,6,3,2))
q3_data
##     Weekday Frequency
## 1    Monday         4
## 2   Tuesday         5
## 3 Wednesday         7
## 4  Thursday         8
## 5    Friday         6
## 6  Saturday         3
## 7    Sunday         2
  1. Construct the bar graph.
# install.packages("tidyverse")
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ lubridate 1.9.4     ✔ tibble    3.3.0
## ✔ purrr     1.1.0     ✔ tidyr     1.3.1
## ✔ readr     2.1.5     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ readr::col_factor() masks scales::col_factor()
## ✖ purrr::discard()    masks scales::discard()
## ✖ tidyr::expand()     masks Matrix::expand()
## ✖ dplyr::filter()     masks stats::filter()
## ✖ dplyr::lag()        masks stats::lag()
## ✖ tidyr::pack()       masks Matrix::pack()
## ✖ tidyr::unpack()     masks Matrix::unpack()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
ggplot(q3_data,aes(x = factor(Weekday,levels = Weekday),y = Frequency)) +
  geom_col() +
  labs(title = "Number of Sweets Mat Ate Each Day",
       x = "Weekday",
       y = "Frequency") +
  theme_gray()

Question 4

Order \(\lbrace \frac{4}{6}, \frac{5}{6}, \frac{3}{6}, \frac{1}{6} \rbrace\) from smallest to largest.

# install.packages("tidyverse")
library(tidyverse)
q4_data <- data.frame(Fraction = c(4/6,5/6,3/6,1/6))
q4_data %>%
  arrange(Fraction) # arrange(): ascending order
##    Fraction
## 1 0.1666667
## 2 0.5000000
## 3 0.6666667
## 4 0.8333333

Question 5

What is the least common multiple of 9 and 15?

# install.packages("pracma")
library(pracma)
## 
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
## 
##     cross
## The following objects are masked from 'package:Matrix':
## 
##     expm, lu, tril, triu
answer <- Lcm(a = 9,b = 15)
cat("The least common multiple of 9 and 15 is:",answer,"\n")
## The least common multiple of 9 and 15 is: 45

Question 6

A box contains 3 red pencils, 5 green pencils, and 7 yellow pencils. Xena chooses 3 pencils at random from the box without replacement. What is the probability they are all the same color?

box <- c(rep("Red",3),rep("Green",5),rep("Yellow",7))
counter <- 0
N <- 1e6
for (i in 1:N) {
  picks <- sample(x = box,size = 3,replace = F)
  if (length(unique(picks)) == 1) {
    counter <- counter + 1
  }
}
probability <- counter / N
cat("The probability is:",probability,"\n")
## The probability is: 0.100976