Presentation is loading. Please wait.

Presentation is loading. Please wait.

GG313 Lecture 12 Matrix Operations Sept 29, 2005.

Similar presentations


Presentation on theme: "GG313 Lecture 12 Matrix Operations Sept 29, 2005."— Presentation transcript:

1 GG313 Lecture 12 Matrix Operations Sept 29, 2005

2 Matrix Addition Requirement: same order Characteristic: element-by-element addition Notation: A+B=C 1 1 A = 1 1 1 1 2 1 B = -1 3 0 -2 3 2 C=A+B = 0 4 1 -1 Eqn 3.20

3 You can add a scalar to a matrix: 1 1 A = 1 1 B = A + 4 = 1 1 5 5 Commutative: A+B=B+A Associative: A+B+C= A+(B+C) You can also multiply a scalar by a matrix: 2 4 A = 4 6 B = A * 2 = 1 3 4 8 8 12 2 6

4 Dot Product Also known as: scalar product or inner product Requirements: row vector and column vector of the same order (dimensions) Characteristics: Result is a scalar Uses: Big in physics. The dot product between a force and a velocity yields the power being given to a body Notation: a b = d Eqn. 3.25

5 In physics, we multiply the projection of one vector onto the other vector by the length of the second vector: ab=u a u b +v a v b +w a w b =|a||b|cos(  ) |a|=sqrt(u a 2 +v a 2 +w a 2 )=length of a If a and b are orthogonal to eachother, then cos(  ) =0 and ab=0 If a and b are parallel to eachother, then cos(  ) =1 and ab= |a||b|= product of the lengths of the vectors

6 Squaring a vector is simply taking the dot product of the vector and its transpose: For a row vector: a 2 = a a T For a column vector: a 2 = a T a Matrix Multiplication We can extend the idea of the dot product to matrices: Requirement: There must be the same number of columns in the first matrix as rows in the second. Characteristics: The resulting matrix has the same number of rows as the first matrix and same number of columns as the second.

7 Notation: C (m,n) =A (m,p) B (p,n) elements of C are: In Matlab, matrix multiplication is: C = A*B

8

9 The order of multiplication is important: On the previous page, we have an order A (5,3) matrix times a B (3,4) matrix. BA is not even possible. If the matrices are square, or if A T has the same order as B, or B T the same order as A, then both products, AB and BA can be formed. The transpose of a matrix product is equal to the product of the transpose of the matrices in reverse order: A B C = C T B T A T NOT Commutative: A B ≠ B A Associative: (A B) C= A (B C)

10 Multiplication by the identity matrix (Matlab: eye(p,p) ) leaves the original matrix unchanged - just as multiplying any regular number by “1” leaves that number unchanged. A(n,p) I(p,p) = I A = A For example:

11 Scaling: We can scale a coordinate system by multiplying by a diagonal matrix of scale weights:

12 On the previous slide we pre-multiplied by the scaling matrix. If we post-multiply instead,then each column gets multiplied by the same scaling factor: Note that we had to use a diagonal order 5x5 matrix.

13 Efficiency considerations: When dealing with large matrices, it is possible to save a considerable amount of calculating by being careful how multiplies are arranged. While there may be no difference in the result mathematically, if the number of calculations can be significantly reduced, time can be reduced and precision can be improved.

14 Note that while (AB)C = A(BC), these two expressions can have very different numbers of multiplications. D (m,n) = A (m,p) B (p,n) has m*n*p multiplications E (m,q) = D (m,n) C (n,q) has m*n*q multiplications So E=(AB)C requires m*n(p+q) multiplications Similarly, F (p,q) =B (p,n) C (n,q) has n*p*q multiplications E (m,q) = A (m,p) F (p,q) has m*p*q multiplications So E=A(BC) requires p*q*(m+n) multiplications. If p*q >> m*n, then A(BC) will require far more multiplications than (AB)C.

15 Fore example, say m=5, n=2, p=25, and q=100. Then one way requires 25*100*(5+2)=17,500 multiplications, and the other requires 5*2*(25+100)=1,250. As execution time and “digital noise”, or round off error, increase with every multiplication, it makes sense to perform the calculation in a particular way. In class exercises. 1) We have three vectors A, B, and C with one end at the origin and the other at x i,y i, z i. A(x,y,z)=(22,7,100), B=(-32,1,48), and C=(3,-11,33). Using Matlab matrices, transform the vectors into another coordinate system where r=3x and s=5y, t=2.5z.

16 We set up a matrix with the x-values in the first row, y in the second, and z in the third: >> A=[22 -32 3;7 1 -11;100 48 33] A = 22 -32 3 7 1 -11 100 48 33 Now set up a diagonal matrix containing the transformations: >> D=[3 0 0;0 5 0; 0 0 2.5] D = 3.0 0 0 0 5.0 0 0 0 2.5

17 Now multiply: >> D*A ans = 66.0 -96.0 9.0 35.0 5.0 -55.0 250.0 120.0 82.5 This is a simple transformation; others, like changing from rectangular to spherical coordinates utilize more terms in the transformation matrix.

18 DETERMINANT: A property of a matrix very useful in the solution of simultaneous equations. Requirement: Square matrices only Notation: det A, |A|, or ||A|| Calculation: As the matrix size grows, Matlab comes in handy, det(A).

19 Determinant Characteristics: Switching two rows or columns changes the sign. Scalars can be factored out of rows and columns. Multiplication of a row or column by a scalar multiplies the determinant by that scalar. The determinant of a diagonal matrix equals its trace.

20 Consider the determinant of a 3x3 matrix. It can be re- written: And the determinant can be written: |A|=a 11 (a 22 a 33 -a 23 a 32 )-a 12 (a 21 a 33 -a 23 a 31 )+a 13 (a 21 a 32 -a 22 a 31 ) A singular matrix is a square matrix with determinant equal to 0. This happens when 1)any row or column is equal to zero or 2)Any row or column is a linear combination of any other rows or columns

21 The degree of clustering about the principal diagonal is a property of a matrix that affects the determinant. If clustering is high, then the determinant is larger. The rank of a matrix is the number of linearly independent vectors (row or column) that it contains. The rank of a product of two matrices must be less than or equal to the smallest rank of the two matrices being multiplied. Linear independence here means that the two vectors being considered are NOT scalar multiples of each other.

22 Matrix division (Matrix inverse) In normal math, we can easily solve the equation below for c. y= cx, c = y/x = yx -1. Xx -1 =1 We can generate inverse matrices to do the same operation in matrix algebra. In matrix algebra the inverse matrix is A -1, where AA -1 =I, the identity matrix. The inverse of a matrix exists only if its determinant is non-zero.

23 The inverse of a matrix is easy to calculate for 2x2 matrices, but anything larger is difficult to even explain. For a 2x2 matrix: Eqn. 3.63 For example, To check:

24 Using matrices to calculate normal scores - as in Chapter 2. We can use matrix notation to calculate the mean and z- values of vectors. An important concept is the unit vector that consists of ones in a row (unit row vector) or column (unit column vector). Consider the data matrix A consisting of three columns of data samples: We can calculate the mean of each column in A simply by multiplying A by J 3 T and dividing by 3:

25 In our example: We now have the mean values, but we want the normal scores (z-values),

26 We do the subtraction in the numerator by: D= - (1/n) JA where J is the nxm unit matrix (all entries=1). The standard deviation is not linear, and needs to be calculated separately, then entered into a diagonal matrix: The normal scores are then:


Download ppt "GG313 Lecture 12 Matrix Operations Sept 29, 2005."

Similar presentations


Ads by Google