The cost function is \(C(x) = 12x^4 - 5x^3 + 2x + 11\). What is \(C'(x)\)?
# install.packages("Deriv")
library(Deriv)
C <- function(x) {
12 * x^4 - 5 * x^3 + 2 * x + 11
}
C_prime <- Deriv(C)
C_prime
## function (x)
## 2 + x^2 * (2 * (12 * x - 5) + 24 * x - 5)
Solve the system of equations below.
\[2x - 3y = 7 \\ 4x + 5y = 1\]
q2_data <- data.frame(X = c(2,4),
Y = c(-3,5),
Constants = c(7,1))
q2_model <- lm(Constants ~ . - 1,data = q2_data) # ".": all other variables except response variable, -1 excludes intercept
coef(q2_model)
## X Y
## 1.727273 -1.181818
Calculate the eigenvalues and eigenvectors of \(E = \begin{pmatrix} 2 & -1 & 1 \\ 0 & 1 & -1 \\ 0 & 0 & 1 \end{pmatrix}\).
E <- matrix(data = c(2,-1,1,0,1,-1,0,0,1),nrow = 3,ncol = 3,byrow = T)
eigen(E)
## eigen() decomposition
## $values
## [1] 2 1 1
##
## $vectors
## [,1] [,2] [,3]
## [1,] 1 0.7071068 7.071068e-01
## [2,] 0 0.7071068 7.071068e-01
## [3,] 0 0.0000000 1.570092e-16
Use the data frame below to construct a bar graph.
First, define the data frame.
q4_data <- data.frame(Color = c("Red","Yellow","Blue","Green","Gray","Purple","Orange"),
Frequency = c(8,5,6,3,5,2,1))
q4_data
## Color Frequency
## 1 Red 8
## 2 Yellow 5
## 3 Blue 6
## 4 Green 3
## 5 Gray 5
## 6 Purple 2
## 7 Orange 1
# 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
ggplot(q4_data,aes(x = factor(Color),y = Frequency)) +
geom_col() +
labs(title = "Colors of Cars Passing the School Gate During a Ten-Minute Period",
x = "Color",
y = "Frequency") +
theme_gray()
Write the fractions below in order from largest to smallest.
\[\text{Fractions} = [\frac{1}{4},\frac{1}{10},\frac{1}{8},\frac{1}{6}]\]
# install.packages("tidyverse")
library(tidyverse)
q5_data <- data.frame(Fractions = c(1/4,1/10,1/8,1/6))
q5_data %>%
arrange(desc(Fractions))
## Fractions
## 1 0.2500000
## 2 0.1666667
## 3 0.1250000
## 4 0.1000000
What is the least common multiple of 9 and 24?
# install.packages("pracma")
library(pracma)
##
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
##
## cross
Lcm(a = 9,b = 24)
## [1] 72