Compute the eigenvalues and eigenvectors for \(A = \begin{pmatrix} 4 & -1 \\ 2 & 1 \end{pmatrix}\).
A <- matrix(data = c(4,-1,2,1),nrow = 2,ncol = 2,byrow = T)
eigenvalues <- eigen(A)$values
eigenvectors <- eigen(A)$vectors
for (x in seq_along(eigenvalues)) {
cat("Eigenvalue",x,":",eigenvalues[x],"\n")
}
## Eigenvalue 1 : 3
## Eigenvalue 2 : 2
cat("Eigenvectors:","\n")
## Eigenvectors:
print(eigenvectors)
## [,1] [,2]
## [1,] 0.7071068 0.4472136
## [2,] 0.7071068 0.8944272
Estimate how many whole numbers from 1 to 900 are divisible by 3.
# install.packages("comprehenr")
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
result <- to_vec(for (i in 1:900) if (i %% 3 == 0) i)
cat("There are",length(result),"whole numbers from 1 to 900 that are divisible by 3.","\n")
## There are 300 whole numbers from 1 to 900 that are divisible by 3.
Determine which one of the following numbers is divisible by 8.
A. 5236
B. 6232
C. 7238
D. 8234
# 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
q3_data <- data.frame(Choice = LETTERS[1:4],
Number = c(5236,6232,7238,8234))
correct_answer <- q3_data %>%
mutate(Div.by.8 = Number %% 8 == 0) %>%
filter(Div.by.8 == TRUE) %>%
pull(Choice)
cat("The correct answer is:",correct_answer,"\n")
## The correct answer is: B
There are two octagonal dice labeled 1 to 8. Ulysses makes a two digit nuber from the numbers on the top faces. Use a Monte Carlo simulation to estimate the probability of the two-digit number being divisible by 11.
set.seed(123)
die1 <- 1:8
die2 <- 1:8
N <- 1e5
counter <- 0
for (z in 1:N) {
roll1 <- sample(x = die1,size = 1,replace = T)
roll2 <- sample(x = die2,size = 1,replace = T)
two_digit_number <- roll1 * 10 + roll2
if (two_digit_number %% 11 == 0) {
counter <- counter + 1
}
}
probability <- counter / N
cat("The probability of thw two-digit number being divisible by 11 is:",probability,"\n")
## The probability of thw two-digit number being divisible by 11 is: 0.12482