amv10 - Matrix Algebra: Orthogonal Vectors and Matrices. EigenValues and Eigenvectors of a Matrix.

preview_player
Показать описание
Help this channel to remain great! Donating to Patreon or Paypal can do this!
Рекомендации по теме
Комментарии
Автор

My new go to channel for Multivariate Analysis

tebellomokgomole
Автор

begin of video 1
# Parentheses around the assignment makes it print.
(A<-matrix(c(23, 29, 18, 3.54, 3.81, 2.75), ncol=2, byrow = FALSE))
A[1, 2] # 1st row, 2nd column
A[3, 1] # 3rd row, 1st column
# R prints vectors as a row vector to save space.
# However, think of this as a column vector.
(a <- c(98, 86, 93, 97))
a[1] # 1st element of vector a
a[4] # 4th element of vector a
plot(2, 3, xlim=c(0, 2), ylim=c(0, 3), xlab="1st Component of Vector", ylab="2nd Component of Vector",
main="Plot of 2D vector (2, 3)")
arrows(0, 0, 2, 3)
k <- 22
print(k)
(A<-matrix(c(3, 1, -2, 3, 4, 7), ncol=3))
(B<-t(A))
(C<-matrix(c(3, 1, -2, 3, 4, 7), ncol=3))
(D<-matrix(c(3, 1, -2, 3, 4, 6), ncol=3))
# Comparing matrices
A==B
A==C
A==D
# Comparing vectors
A[1, ]==D[1, ]
A[2, ]==D[2, ]
end of video 1

begin of video 2
(A<-matrix(c(23, 29, 18, 3.54, 3.81, 2.75), ncol=2, byrow=FALSE))
t(A)
t(t(A))
5 # scalar
t(5)
(A<-matrix(c(3, -2, 4, -2, 10, -7, 4, -7, 9), ncol=3))
all.equal(A, t(A))
diag(c(3, 10, -7))
A
diag(A)
diag(diag(A))
diag(3)
(j<-rep(1, 10))
matrix(rep(1, 10*10), ncol=10)
end of video 2
begin of video 3
(a<-c(2, 6, -4, 1, -2, 7))
A
sum(a)
sum(A)
sum(A[1, ])+sum(A[2, ])
sum(A[1:2, ])
sum(diag(A))
prod(a)
prod(A)
prod(1:5) # not efficient way to calculate 5!
A
(B<-matrix(sample(1:15, 9), ncol=3))
A+B
B+A
t(A)-t(B)
t(A-B)
(A<-matrix(c(2, 7, 3, 4, 6, 9), ncol=3, byrow=TRUE))
2*A
(A<-matrix(c(2, 1, 3, 4, 6, 5), ncol=3, byrow=TRUE))
(B<-matrix(c(1, 4, 2, 6, 3, 8), ncol=2, byrow=TRUE))
A[1, ]%*%B[, 1]
A[1, ]%*%B[, 2]
A[2, ]%*%B[, 1]
A[2, ]%*%B[, 2]
A %*% B
B %*% A
(A<-matrix(c(2, 1, 3, 4, 6, 5), ncol=3, byrow=TRUE))
(B<-matrix(c(1, 4, 2, 6, 3, 8), ncol=2, byrow=TRUE))
(C<-matrix(c(-1, 4, -2, 6, -3, 8), ncol=2, byrow=TRUE))
A%*%(B+C)
A%*%B + A%*%C
(B+C)%*%A
B%*%A + C%*%A
t(A%*%B)
t(B)%*%t(A)
diag(2)%*%A
A%*%diag(3)
end of video 3

begin of video 4

(A<-matrix(c(2, 1, 3, 4, 6, 5), ncol=3, byrow=TRUE))
(b<-c(1, 2, 3))
A%*%b
b[1]*A[, 1] + b[2]*A[, 2] + b[3]*A[, 3, drop=FALSE]
# 'drop' keeps the structure a matrix, otherwise drops it when possible.
# A vector in matrix form is over parameterized.
(A<-matrix(c(3, -2, 4, 1, 3, 5), ncol=3, byrow=TRUE))
(b<-c(2, -5))
t(b)%*%A
b[1]*A[1, ] + b[2]*A[2, ]
b[1]*A[1, ] + b[2]*A[2, , drop=FALSE]
(a<-c(2, -1, 3, 4, -6, 5))
(b<-c(1, 2, 3, 4, 5, 6))
t(a)%*%b
t(b)%*%a
a%*%t(b)
b%*%t(b) # quick way to make a product table

end of video 4

begin of video 5
(j <- rep(1, 10))
t(j)%*%j
j%*%t(j)

(j <- rep(1, 4))
(a <- sample(-5:10, 4, TRUE))
t(j)%*%a
t(a)%*%j

(j <- rep(1, 4))
(A <- matrix(sample(-5:10, 16, TRUE), ncol=4))
t(j)%*%A # column sums
A%*%j # row sums

(A <- matrix(sample(-5:10, 8, TRUE), ncol=2))
t(A)%*%A
t(A[, 1])%*%A[, 1]
t(A[, 1])%*%A[, 2]
t(A[, 2])%*%A[, 1]
t(A[, 2])%*%A[, 2]
A%*%t(A)
t(A[1, ])%*%A[1, ]
t(A[1, ])%*%A[2, ]
t(A[1, ])%*%A[3, ]
t(A[3, ])%*%A[2, ]

(A <- matrix(sample(-5:10, 8, TRUE), ncol=2))
(D <- diag(1:4))
D%*%A
A
(D <- diag(1:2))
A%*%D

end of video 5



begin of video 6

(A <- matrix(c(2, -3, 4, 1, 4, 8, 8, 2, 1), ncol=3))
(B <- matrix(1:9, ncol=3))
(A11 <- A[1:2, 1:2])
(A12 <- A[1:2, 3, drop=FALSE])
(A21 <- A[3, 1:2, drop=FALSE])
(A22 <- A[3, 3, drop=FALSE])
(B11 <- B[1:2, 1:2])
(B12 <- B[1:2, 3, drop=FALSE])
(B21 <- B[3, 1:2, drop=FALSE])
(B22 <- B[3, 3, drop=FALSE])

A%*%B
A11%*%B11 + A12%*%B21
A11%*%B12 + A12%*%B22
A21%*%B11 + A22%*%B21
A21%*%B12 + A22%*%B22

end of video 6


begin of video 7

(A <- matrix(c(3, 1, 2, 6, 2, 4), ncol=2))
(B <- matrix(c(1, 5, -2, 2, 3, 4), ncol=3))
qr(A)$rank # qr is from the QR Decomposition
qr(B)$rank

(A <- matrix(c(2, -3, 4, 1, 4, 8, 8, 2, 1), ncol=3))
(B <- matrix(c(1, 2, 4, 1, -5, 8, 8, 2, 1), ncol=3))
qr(A)$rank # qr is from the QR Decomposition
qr(B)$rank
(A1 <- solve(A))
(B1 <- solve(B))
A1%*%A
zapsmall(A1%*%A)
zapsmall(A%*%A1)
all.equal(solve(solve(A)), A) # property 1
all.equal(solve(t(A)), t(solve(A))) # property 3
all.equal(solve(A%*%B), solve(B)%*%solve(A)) # property 4

end of video 7

begin of video 8

(A <- matrix(c(3, 0, -3, 0, 6, 3, -3, 3, 6), ncol=3))
(T <- chol(A))
sqrt(3)
sqrt(6)
sqrt(1.5)
t(T)%*%T
all.equal(A, t(T)%*%T)

(A <- matrix(c(3, 0, -3, 0, 6, 3, -3, 3, 6), ncol=3))
det(A)
det(A) == det(t(A))
det(solve(A)) == 1/det(A)
det(2*A) == 2^3 * det(A) # example why "==" has problems
all.equal(det(2*A), 2^3 * det(A))
all.equal(det(t(A)%*%A), det(A)^2)

(A <- matrix(c(3, 0, -3, 0, 6, 3, -3, 3, 6), ncol=3))
(B <- matrix(c(1, 2, -3, -1, 6, 3, 4, 3, 1), ncol=3))
sum(diag(A))
all.equal(sum(diag(A+B)), sum(diag(A))+sum(diag(B)))
all.equal(sum(diag(2*A)), 2*sum(diag(A)))
all.equal(sum(diag(A%*%B)), sum(diag(B%*%A)))
@
\LARGE

end of video 8


begin of video 9

(A <- matrix(c(1, -1, 2, 4), ncol=2))
eigen(A)
(A.val <- eigen(A)$values)
(A.vec <- eigen(A)$vectors)
A%*%A.vec[, 1]
A.val[1]*A.vec[, 1, drop=FALSE]
all.equal(A%*%A.vec[, 2], A.val[2]*A.vec[, 2, drop=FALSE])

crossprod(A.vec[, 1]) # dot product with itself
t(A.vec[, 2])%*%A.vec[, 2] # both vectors are normalized
t(A.vec[, 1])%*%A.vec[, 2] # not orthogonal to each other

A <- matrix(c(1, -1, 2, 4), ncol=2)
A.val <- eigen(A)$values
det(A)
prod(A.val)
sum(diag(A))
sum(A.val)

A <- matrix(c(13, -4, 2, -4, 13, -2, 2, -2, 10), ncol=3)
A.val <- eigen(A)$values
A.vec <- eigen(A)$vectors
zapsmall(A.vec %*% t(A.vec))
zapsmall(t(A.vec) %*% A.vec)
eigen(A)$values
qr(A)$rank

end of video 9

statisticsmatt