Find the slope of the line tangent to \(f(x) = x^3 - 3x^2 + 2x + 4\) at the point \((1,4)\).
# install.packages("Deriv")
library(Deriv)
f <- function(x) {
x^3 - 2 * x^2 + 2 * x + 4
}
f_prime <- Deriv(f)
slope <- f_prime(x = 1)
cat("The slope at the point (1,4) is:",slope,"\n")
## The slope at the point (1,4) is: 1
If \(g(t) = \frac{t}{\ln(t)}\), find \(g'(e^2)\).
# install.packages("Deriv")
library(Deriv)
g <- function(t) {
t / log(t)
}
g_prime <- Deriv(g)
answer <- g_prime(t = exp(1)^2)
cat("g'(e^2) =",answer,"\n")
## g'(e^2) = 0.25
Find the product of these two matrices, if it exists.
\[\begin{pmatrix} 6 & 4 & -2 \\ 7 & 2 & 0 \\ 9 & -6 & 2 \end{pmatrix} \cdot \begin{pmatrix} 5 & 2 & 9 \\ 3 & -5 & 1 \end{pmatrix}\]
A <- matrix(data = c(6,4,-2,7,2,0,9,-6,2),nrow = 3,ncol = 3,byrow = T)
B <- matrix(data = c(5,2,9,3,-5,1),nrow = 2,ncol = 3,byrow = T)
if (nrow(B) == ncol(A)) {
A %*% B
} else {
cat("The product of these matrices does not exist due to insufficient dimensions.")
}
## The product of these matrices does not exist due to insufficient dimensions.
Alex took a test in physics and scored a 35. The class average was 27 and the standard deviation was 5. Noah took a chemistry test and scored an 82. The class average was 70 and the standard deviation was 8. Show that Alex had the better performance by calculating Alex’s standard normal percentile and Noah’s standard normal percentile.
alex_zscore <- scale(x = 35,center = 27,scale = 5)
noah_zscore <- scale(x = 82,center = 70,scale = 8)
alex_percentile <- pnorm(alex_zscore)
noah_percentile <- pnorm(noah_zscore)
cat("Alex's Percentile:",round(alex_percentile * 100,2),"%\n")
## Alex's Percentile: 94.52 %
cat("Noah's Percentile:",round(noah_percentile * 100,2),"%\n")
## Noah's Percentile: 93.32 %
# 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
x_values <- seq(
min(27 - 4 * 5,70 - 4 * 8),
max(27 + 4 * 5,70 + 4 * 8),
length.out = 1000
)
physics <- dnorm(x_values,mean = 27,sd = 5)
chemistry <- dnorm(x_values,mean = 70,sd = 8)
q4_data <- data.frame(x = x_values,Physics = physics,Chemistry = chemistry) %>%
pivot_longer(cols = c("Physics","Chemistry"),
names_to = "Class",
values_to = "Density")
ggplot(q4_data,aes(x = x,y = Density,color = Class)) +
geom_line(lwd = 1.25) +
# Alex's Score
geom_vline(xintercept = 35,
col = "blue",linetype = "dashed",lwd = 1) +
annotate("text",x = 35,y = max(physics) * 0.9,label = "Alex (Score: 35)",col = "blue",hjust = -0.1) +
# Noah's Score
geom_vline(xintercept = 82,
col = "red",linetype = "dashed",lwd = 1) +
annotate("text",x = 82,y = max(chemistry) * 0.9,label = "Noah (Score: 82)",col = "red",hjust = -0.1) +
# Labels
labs(title = "Comparison of Physics and Chemistry Score Distributions",
x = "Score",
y = "Density",
color = "Class") +
# Themes
theme_minimal() +
# Colors
scale_color_manual(values = c("Physics" = "steelblue","Chemistry" = "darkred"))
We find that Alex’s percentile was around 94.52% while Noah’s percentile was 93.32%. This means that Alex’s performance was better than Noah’s performance.