DOC PREVIEW
OSU CS 419 - Matrices

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1mjb – October 2, 2007Oregon State UniversityComputer GraphicsMatricesMike BaileyOregon State Universitymjb – October 2, 2007Oregon State UniversityComputer GraphicsMatricesA matrix is a 2D array of numbers, arranged in rows that go across and columns that go down:123456 7 89101112⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦4 columns3 rowsMatrix sizes are termed “#rows x #columns”, so this is a 3x4 matrix2mjb – October 2, 2007Oregon State UniversityComputer GraphicsMatrix TransposeA matrix transpose is formed by interchanging the rows and columns:⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡128411731062951121110987654321TThis is a 3x4 matrix This is a 4x3 matrixmjb – October 2, 2007Oregon State UniversityComputer GraphicsSquare MatricesA square matrix has the same number of rows and columns123456789⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦3 columns3 rowsThis is a 3x3 matrix3mjb – October 2, 2007Oregon State UniversityComputer GraphicsRow and Column MatricesA matrix can have a single row (a “row matrix”) or just a single column (a “column matrix”)”[]123This is a 3x1 matrix123⎧⎫⎪⎪⎨⎬⎪⎪⎩⎭This is a 1x3 matrixSometimes these are called row and column vectors, but that overloads the word “vector” and we won’t do it…mjb – October 2, 2007Oregon State UniversityComputer GraphicsMatrix MultiplicationTwo matrices, A and B, can be multiplied if the number of columns in A equals the number of rows in B. The result is a matrix that has the same number of rows as A and the same number of columns as B.*⎡⎤⎡⎤ ⎡ ⎤⎢⎥⎢⎥ ⎢ ⎥⎢⎥⇒⎢⎥ ⎢ ⎥⎢⎥⎢⎥ ⎢ ⎥⎢⎥⎣⎦ ⎣ ⎦⎣⎦I x KABCK x JI x J4mjb – October 2, 2007Oregon State UniversityComputer GraphicsMatrix Multiplication in SoftwareHere’s how to remember how to do it:1. C = A * B2. [ I x J ] = [ I x K ] * [ K x J ]*⎡⎤⎡⎤⎡⎤⎢⎥⎢⎥⎢⎥⎢⎥=⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦⎣⎦ABCI x K K x JI x J=C[ i ][ j ] = A[ i ][ k ] * B[ k ][ j ] ;mjb – October 2, 2007Oregon State UniversityComputer GraphicsMatrix Multiplication in Softwarefor( int i = 0; i < numArows; i++ ){for( int j = 0; j < numBcols; j++ ){C[ i ][ j ] = 0.;for( int k = 0; k < numAcols; k++ ){C[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];}}}Note: numAcols must == numBrows !5mjb – October 2, 2007Oregon State UniversityComputer GraphicsMatrix Multiplication where B and C are Column Matricesfor( int i = 0; i < numArows; i++ ){C[ i ] = 0.;for( int k = 0; k < numAcols; k++ ){C[ i ] += A[ i ][ k ] * B[ k ];}}To help you remember this, think of the “C[ i ]“ lines as:C[ i ][ 0 ] = 0.;…C[ i ][ 0 ] += A[ i ][ k ] * B[ k ][ 0 ];mjb – October 2, 2007Oregon State UniversityComputer GraphicsA Special MatrixConsider the matrix * column situation below:000xzy xyzxyzyx zCAABCA ABCAA B⎡⎤−⎧⎫ ⎧⎫⎢⎥⎪⎪ ⎪⎪=−⎨⎬ ⎨⎬⎢⎥⎪⎪ ⎪⎪⎢⎥−⎩⎭ ⎩⎭⎣⎦(,,)yz zy zx xz xy yxCABABABABABAB=− − −This gives:Which you hopefully recognize as the Cross Product AxB6mjb – October 2, 2007Oregon State UniversityComputer GraphicsDeterminantsThe determinant is important in graphics applications. It represents sort of a “scale factor”, when the matrix is used to represent a transformation.The determinant of a 2x2 matrix is easy:detABADBCCD⎡⎤=∗−∗⎢⎥⎣⎦mjb – October 2, 2007Oregon State UniversityComputer GraphicsDeterminantsdetABCDEFGH I⎡⎤⎢⎥=⎢⎥⎢⎥⎣⎦det det detEF DF DEABCHIGIGH⎡⎤ ⎡⎤ ⎡⎤∗−∗+∗⎢⎥ ⎢⎥ ⎢⎥⎣⎦ ⎣⎦ ⎣⎦()()( )AEI FH B DI FG C DH EG=∗ − −∗ − +∗ −The determinant of a 3x3 matrix is done in terms of its component 2x2 sub-matrices:7mjb – October 2, 2007Oregon State UniversityComputer GraphicsInversesThe matrix inverse is also important in graphics applications because it represents the undoing of the original transformation matrix. It is also useful in solving systems of simultaneous equations.The inverse of a 2x2 matrix is the transpose of the cofactor matrix divided by the determinant:11ABDBCD C AAD BC−−⎡⎤ ⎡ ⎤=⎢⎥ ⎢ ⎥−∗−∗⎣⎦ ⎣ ⎦mjb – October 2, 2007Oregon State UniversityComputer GraphicsInverses1ABCDEFGH I−⎡⎤⎢⎥=⎢⎥⎢⎥⎣⎦The determinant of a 3x3 matrix is done in terms of its component 2x2 sub-matrices::The determinant of 4x4 and larger matrices can be done in a similar way, but usually isn’t. Gauss Elimination is more efficient.det det detdet det detdet det detdetEF DF DEHI GI GHBC AC ABHI GI GHBC AC ABEF DF DEABCDEFGH I⎡⎤⎡⎤⎡ ⎤⎡ ⎤⎢⎥⎢⎥⎢ ⎥⎢ ⎥⎣⎦⎣ ⎦⎣ ⎦⎢⎥⎢⎥⎡⎤⎡⎤⎡ ⎤⎢⎥⎢⎥⎢⎥⎢ ⎥⎢⎥⎣⎦⎣⎦⎣


View Full Document

OSU CS 419 - Matrices

Download Matrices
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Matrices and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Matrices 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?