Let \(I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\) and \(\quad J = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix}\). What is \((I + J)^2\)?
# install.packages("matrixcalc")
library(matrixcalc)
## Warning: package 'matrixcalc' was built under R version 4.5.2
I <- diag(2) # identity matrix of 2x2
J <- matrix(data = c(0,1,-1,0),nrow = 2,ncol = 2,byrow = T)
answer <- matrix.power(x = I + J,k = 2) # x = I + J (our value), k = 2 (square it)
answer
## [,1] [,2]
## [1,] 0 2
## [2,] -2 0
Use the sort() method and the tidyverse package to order the values \([0.35,0.035,3.05,0.305]\) from least to greatest.
A. Use the sort() function.
values <- c(0.35,0.035,3.05,0.305)
sort(values,decreasing = F) # decreasing = F (least to greatest)
## [1] 0.035 0.305 0.350 3.050
B. Use the tidyverse package.
# 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
q2_data <- data.frame(Values = c(0.35,0.035,3.05,0.305))
q2_data %>%
arrange(Values) # arrange(): least to greatest values
## Values
## 1 0.035
## 2 0.305
## 3 0.350
## 4 3.050
Solve the system of equations below.
\[3x + 5y = 9 \\ x - y = -5\]
q3_data <- data.frame(X = c(3,1),
Y = c(5,-1),
Constants = c(9,-5))
q3_model <- lm(Constants ~ . - 1,data = q3_data) # "." means all other variables in the dataset, -1 to exclude intercept
coef(q3_model)
## X Y
## -2 3
Differentiate \(f(x) = \tan(2x)\).
# install.packages("Deriv")
library(Deriv)
f <- function(x) {
tan(2 * x)
}
f_prime <- Deriv(f)
f_prime
## function (x)
## 2/cos(2 * x)^2