Calculate the eigenvalues and eigenvectors of the matrix below.
\[A = \begin{bmatrix} -5 & 17 & -20 \\ 17 & -3 & -2 \\ -20 & -2 & 12 \end{bmatrix}\]
# Define matrix A
A <- matrix(data = c(-5,17,-20,17,-3,-2,-20,-2,12),nrow = 3,ncol = 3,byrow = T)
# Determine eigenvalues
eigenvalues <- eigen(A)$values
for (x in seq_along(eigenvalues)) {
cat("Eigenvalue",x,":",eigenvalues[x],"\n")
}
## Eigenvalue 1 : 29.45844
## Eigenvalue 2 : 0.9114139
## Eigenvalue 3 : -26.36986
# Determine eigenvectors
eigenvectors <- eigen(A)$vectors
for (y in 1:ncol(eigenvectors)) {
cat("Eigenvector",y,":",eigenvectors[, y],"\n")
}
## Eigenvector 1 : -0.5941837 -0.355654 0.7214264
## Eigenvector 2 : 0.2466314 0.7731612 0.58429
## Eigenvector 3 : 0.7655839 -0.5251019 0.3716843
Write 2,970,430 in words.
# install.packages("english")
library(english)
## Warning: package 'english' was built under R version 4.5.2
Words(x = 2970430)
## [1] "Two million nine hundred seventy thousand four hundred thirty"
A coin is tossed four times. Use a Monte Carlo simulation to estimate the probability of getting two heads and two tails.
set.seed(123) # for reproducibility
coin <- c("Heads","Tails")
counter <- 0
N <- 100000
for (i in 1:N) {
tosses <- sample(x = coin,size = 4,replace = T)
if (sum(tosses == "Heads") == 2) {
counter <- counter + 1
}
}
probability <- counter / N
cat("The estimated probability of obtaining two heads and two tails is:",probability,"\n")
## The estimated probability of obtaining two heads and two tails is: 0.37515
If \(y = \frac{5x^5 - 3x^3}{x^2}\), what is \(\frac{dy}{dx}\)?
# install.packages("Deriv")
library(Deriv)
y <- function(x) {
(5 * x^5 - 3 * x^3) / (x^2)
}
y_prime <- Deriv(y)
y_prime
## function (x)
## 15 * x^2 - 3