X is a matrix of size 4 x 2 (4 rows by 2 columns)
X is a matrix of size 2 x 3 (2 rows by 3 columns) Note the order how the matrix is filled The data vector with entries c(1,2,0,0,0,3) x 1,1 x 1,2 x 1,3 x 1,2 x 2,2 x 2, , 2, 0, 0, 0, 3
X is a matrix of size 4 x 2 (4 rows by 2 columns) A matrix is a 2-dimensional array of data. We can plot 2-dimensional data arrays in R with the image() function using different colors for the entries in the matrix. image(X) Problems: (1)rows are ordered along x- axis, columns ordered along y-axis y x
X is a matrix of size 4 x 2 (4 rows by 2 columns) A matrix is a 2-dimensional array of data. We can plot 2-dimensional data arrays in R with the image() function using different colors for the entries in the matrix. image(t(X)) Problems: (2) The transpose function t(X) yields an up-side-down image of the matrix y x
To solve the problem and plot an image that orders the rows and columns exactly as defined in our matrix X: (1)Flip the transposed matrix such that rows are ‘up-side-down’: see updated scripts/myfunctions.R : matrix_flip_v(X) (2)And then use the transpose of the returned (‘up-side-down’) matrix in the image() plot function t(matrix_flip_v(X))
(1)In myfunctions.R there is a supporting function matrix_image() (2)Call res<-matrix_image(X) (Note: the function returns the transformed matrix)
demo_matrix_image.R Download the updated scripts myfunctions.R demo_matrix_image.R (data/labrador.ppm
Vectors in R: y<-c(x1,x2,x3,…xn)
R-Code: Another common notation for vector dot products Mathemathics: ‘magnitude’ or ‘length’ of a vector
Download the updated scripts demo_linear_trans.R demo_eigenvectors.R