This laid of exercises volition assistance y'all to larn in addition to exam your science inward matrix operations, starting alongside basic ones similar scalar multiplication all the means through eigenvalue in addition to eigenvectors. Before proceeding, it mightiness move helpful to await over the assistance pages for the
diag
, t
, eigen
, and crossprod
functions. If y'all desire farther documentation too regard chapter 5.7 from “An Introduction to R”. Answers to the exercises are available here.
If y'all obtained a dissimilar (correct) answer than those listed on the solutions page, delight experience gratis to postal service your answer equally a comment.
Exercise 1
Consider
a) Find A + B
b) Find A – B
A=matrix(c(2,0,1,3), ncol=2)
and B=matrix(c(5,2,4,-1), ncol=2).
a) Find A + B
b) Find A – B
Exercise 2
Scalar multiplication. Find the solution for aA where
a=3
and A is the same equally inward the previous question. Exercise 3
Using the the
diag
function educate a diagonal matrix of size four alongside the next values inward the diagonal 4,1,2,3. Exercise 4
Find the solution for Ab, where A is the same equally inward the previous inquiry and
b=c(7,4).
Exercise 5
Find the solution for AB, where B is the same equally inward inquiry 1.
Exercise 6
Find the transpose matrix of A.
Exercise 7
Find the inverse matrix of A.
Exercise 8
Find the value of x on Ax=b.
Exercise 9
Using the function
eigen
find the eigenvalue for A. Exercise 10
Find the eigenvalues in addition to eigenvectors of A’A . Hint: Use
crossprod
to compute A’A . ______________________________________
Below are the solutions to these exercises on Matrix operations.
#################### # # # Exercise 1 # # # #################### A <- matrix(c(2,0,1,3), ncol=2) B <- matrix(c(5,2,4,-1),ncol=2) A+B
## [,1] [,2] ## [1,] vii five ## [2,] ii ii
A-B
## [,1] [,2] ## [1,] -3 -3 ## [2,] -2 four
#################### # # # Exercise ii # # # #################### a <- iii a*A
## [,1] [,2] ## [1,] half dozen iii ## [2,] 0 nine
#################### # # # Exercise iii # # # #################### diag(4)*c(4,1,2,3)
## [,1] [,2] [,3] [,4] ## [1,] four 0 0 0 ## [2,] 0 1 0 0 ## [3,] 0 0 ii 0 ## [4,] 0 0 0 iii
#################### # # # Exercise four # # # #################### b <- c(7,4) b%*%A
## [,1] [,2] ## [1,] fourteen nineteen
#################### # # # Exercise five # # # #################### A%*%B
## [,1] [,2] ## [1,] 12 vii ## [2,] half dozen -3
#################### # # # Exercise half dozen # # # #################### t(A)
## [,1] [,2] ## [1,] ii 0 ## [2,] 1 iii
#################### # # # Exercise vii # # # #################### solve(A)
## [,1] [,2] ## [1,] 0.5 -0.1666667 ## [2,] 0.0 0.3333333
#################### # # # Exercise 8 # # # #################### solve(A,b)
## [1] 2.833333 1.333333
#################### # # # Exercise nine # # # #################### eigen(A)$values
## [1] iii ii
#################### # # # Exercise ten # # # #################### eigen(crossprod(A))
## $values ## [1] 10.605551 3.394449 ## ## $vectors ## [,1] [,2] ## [1,] 0.2897841 -0.9570920 ## [2,] 0.9570920 0.2897841
Sources:
http://www.r-exercises.com/2016/08/22/matrix-operations/
http://www.r-exercises.com/2016/08/22/matrix-operations-solutions/