Question 1

Consider the matrix \(D\) below. Find its eigenvalues and eigenvectors.

\[D = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 8 & -12 & 6 \end{bmatrix}\]

# Constructing matrix D
D <- matrix(data = c(0,1,0,0,0,1,8,-12,6),nrow = 3,ncol = 3,byrow = T)

# Obtaining eigenvalues and eigenvectors
eigenvalues <- eigen(D)$values # eigenvalues
eigenvectors <- eigen(D)$vectors # eigenvectors

# Display eigenvalues
for (x in seq_along(eigenvalues)) {
  cat("Eigenvalue",x,":",eigenvalues[x],"\n")
}
## Eigenvalue 1 : 2.000009+1.555313e-05i 
## Eigenvalue 2 : 2.000009-1.555313e-05i 
## Eigenvalue 3 : 1.999982+0i
# Display eigenvectors
for (y in 1:ncol(eigenvectors)) {
  cat("Eigenvector",y,":",eigenvectors[, y],"\n")
}
## Eigenvector 1 : 0.2182162-3.393929e-06i 0.4364344-3.393944e-06i 0.8728727+0i 
## Eigenvector 2 : 0.2182162+3.393929e-06i 0.4364344+3.393944e-06i 0.8728727+0i 
## Eigenvector 3 : 0.2182212+0i 0.4364386+0i 0.8728693+0i

Question 2

Write 3,708,152 in words.

# install.packages("english")
library(english)
## Warning: package 'english' was built under R version 4.5.2
words(3708152)
## [1] "three million seven hundred eight thousand one hundred fifty-two"

Question 3

A bag contains 3 white balls, 4 green balls, and 5 red balls. Use a Monte Carlo simulation to determine the probabilities of picking each color ball.

set.seed(123) # for reproducibility
bag_of_balls <- c(rep("White",3),rep("Green",4),rep("Red",5))
N <- 1e6 # 1 million trials
simulation <- sample(x = bag_of_balls,size = N,replace = T)
probabilities <- prop.table(table(simulation))
probabilities
## simulation
##    Green      Red    White 
## 0.333513 0.416864 0.249623

Question 4

Find the roots and graph them for the function \(f(x) = 4x^3 + 8x^2 - 25x - 50\).

# install.packages(c("rootSolve","tidyverse"))
library(rootSolve)
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^3 + 8 * x^2 - 25 * x - 50
}
roots <- uniroot.all(f,c(-5,5))
for (r in seq_along(roots)) {
  cat("Root",r,":",roots[r],"\n")
}
## Root 1 : -2.5 
## Root 2 : -2 
## Root 3 : 2.5
x_values <- seq(-3,3,length.out = 500)
y_values <- f(x_values)
q4_data <- data.frame(x = x_values,y = y_values)
ggplot(q4_data,aes(x = x,y = y)) +
  geom_line(col = "black",lwd = 1.25) +
  annotate("point",x = roots[1],y = f(roots[1]),col = "blue",size = 5) +
  annotate("point",x = roots[2],y = f(roots[2]),col = "blue",size = 5) +
  annotate("point",x = roots[3],y = f(roots[3]),col = "blue",size = 5) +
  labs(title = "Graph of f(x) = 4x^3 + 8x^2 - 25x - 50",
       caption = paste("Roots:",roots[1],roots[2],"and",roots[3]),
       x = "x",
       y = "y") +
  theme_gray(base_size = 14)