Write 15,236,044 in words.
# install.packages("english")
library(english)
## Warning: package 'english' was built under R version 4.5.2
words(15236044)
## [1] "fifteen million two hundred thirty-six thousand forty-four"
Solve the system of equations below.
\[x + 2y = 5 \\ 3x - y = 1\]
q2_data <- data.frame(x = c(1,3),
y = c(2,-1),
constants = c(5,1))
q2_model <- lm(constants ~ . - 1,data = q2_data)
coef(q2_model)
## x y
## 1 2
On average, Adam is late for school one day in every five. During a particular week (Monday - Friday), what is the probability that Adam is on time every day?
set.seed(123) # for reproducibility
N <- 1e5 # 100,000 trials
probability_on_time <- 4 / 5
results <- replicate(N,{
week <- rbinom(5,size = 1,prob = probability_on_time)
all(week == 1) # 1: on time, 0: late
})
answer <- mean(results)
cat("The probability that Adam is on time every day is:",answer,"\n")
## The probability that Adam is on time every day is: 0.32674
Find the roots and graph \(f(x) = x^2 - 5x - 6\).
# 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) {
x^2 - 5 * x - 6
}
roots <- uniroot.all(f,c(-10,10))
for (x in seq_along(roots)) {
cat("Root",x,":",roots[x],"\n")
}
## Root 1 : -1
## Root 2 : 6
x_values <- seq(-2,7,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 = 4) +
annotate("point",x = roots[2],y = f(roots[2]),col = "blue",size = 4) +
labs(title = "Graph of f(x) = x^2 - 5x - 6",
caption = paste("Roots:",roots[1],"and",roots[2]),
x = "x",
y = "y") +
theme_gray()
If \(g(x) = (4x + 2) \sqrt{x}\), what is \(g'(x)\)?
# install.packages("Deriv")
library(Deriv)
g <- function(x) {
(4 * x + 2) * sqrt(x)
}
g_prime <- Deriv(g)
g_prime
## function (x)
## {
## .e1 <- sqrt(x)
## 0.5 * ((2 + 4 * x)/.e1) + 4 * .e1
## }