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)
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