# 26 ax a 1 x 1 a 2 x 2 a m x m a 1 2 1 090 0077 2 076

• Notes
• 130

This preview shows pages 26–39. Sign up to view the full content.

26 Ax = A [ , 1] * x [1] + A [ , 2] * x [2] + · · · + A [ , m ] * x [ m ]

This preview has intentionally blurred sections. Sign up to view the full version.

> a [,1] [,2] [1,] 0.90 0.077 [2,] -0.76 -0.922 [3,] 0.37 -1.115 [4,] -0.17 0.450 [5,] -0.70 1.063 > b<-1:2 > a%*%b [,1] [1,] 1.05 [2,] -2.60 [3,] -1.86 [4,] 0.73 [5,] 1.43 > drop(a%*%b) [1] 1.05 -2.60 -1.86 0.73 1.43 27
Observe that the result is a matrix. If you use the %*% symbol, for matrix multiplication, then R first makes the vector into an m x 1 matrix. In the same way (remember b is c (1,2) ) > b%*%b [,1] [1,] 5 The drop() function, applied to an array, drops all dimensions of the array with value equal to one, so it makes a vector from an m x 1 matrix. You could also use as.vector() . 28

This preview has intentionally blurred sections. Sign up to view the full version.

Matrix-Matrix Multiplication If A is a matrix with dim(A)=c(n,m) and B is a matrix with dim(B)=c(m,r) , then C=A %*% B is a matrix with dim(C)=c(n,r) . Thus the number of columns of A has to be equal to the number of rows of B (the matrices must conform ). The columns are the vectors being combined in the weighted sum, the rows are the coefficients (weights). 29
Matrix multiplication AB creates r weighted sums of the m columns of A (or n weighted sums of the rows of B ). In summation notation C=AB can be written out as In terms of inner products the matrix multiplication C=AB can be written as C[i,j]= sum (A[i,]*B[,j]) . 30 c ij = m =1 a i b j

This preview has intentionally blurred sections. Sign up to view the full version.

More generally 31 C = AB c ij = m =1 a i b j , C = AB c ij = m =1 a i b j , C = A B c ij = m =1 a i b j , C = A B c ij = m =1 a i b j .
Observe that t(A %*% B)=t(B) %*% t(A) , or because In general, if A and B are matrices, then crossprod (A,B) is t(A) %*% B , while tcrossprod (A,B) is A %*%t (B) . Thus for vectors tcrossprod (x,y) is outer (x,y) . If crossprod () or tcrossprod () only have a single argument, they compute their own cross products, so crossprod (X) is t (X)%*% X , and tcrossprod (X) is X %*%t (X) . 32 [( AB ) ] ij = ( AB ) ji = m =1 a j b i = ( B A ) ij ( AB ) = B A

This preview has intentionally blurred sections. Sign up to view the full version.

It is important to realize that matrix multiplication is distributive because A(B+C) =AB+AC and (B+C)A=BA+CA , but not necessarily commutative . In general AB BA . In fact if AB is defined, BA may not even be defined because the matrices do not conform. But even for square matrices of the same order, which always conform, we generally have AB BA . 33
Trace The trace of a square matrix A is the sum of its diagonal elements. Of course for any matrix X both crossprod (X) and tcrossprod (X) are square, and thus we can enquire about the trace of crossprod (X) and tcrossprod (X) . Turns out that 34 tr X X = tr XX = n i =1 m j =1 x 2 ij

This preview has intentionally blurred sections. Sign up to view the full version.

More generally Also very useful later on 35 tr ABC = tr BCA = tr CAB. tr A B = m j =1 ( A B ) jj = m j =1 n i =1 ( A ) ji b ij = m j =1 n i =1 a ij b ij
3. Patterned Matrices 36

This preview has intentionally blurred sections. Sign up to view the full version.

A matrix A is square if the number of rows is equal to the number of columns. A rectangular matrix is not (necessarily) square. A n x m matrix is tall if n m and broad if n m . square tall broad 37
A square matrix A is symmetric if A[i,j]=A[j,i] for all i and j . Equivalently: if A=t(A) . A square matrix is asymmetric if it is not symmetric. A square matrix A is anti - symmetric if A[i,j]=-A[j,i] for all i and j . Equivalently: if t(A)=-A .

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern