DOC PREVIEW
OSU CS 419 - Matrices

This preview shows page 1 out of 3 pages.

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

Unformatted text preview:

1MatricesMike [email protected] – September 5, 2014Oregon State UniversityComputer GraphicsOregon State UniversityMatricesA matrix is a 2D array of numbers, arranged in rows that go across and columns that go down:12344 columnsA column:mjb – September 5, 2014Oregon State UniversityComputer Graphics56 7 891011123 rowsMatrix sizes are termed “#rows x #columns”, so this is a 3x4 matrixMatrix TransposeA matrix transpose is formed by interchanging the rows and columns:106295187654321Tmjb – September 5, 2014Oregon State UniversityComputer Graphics1284117312111098765This is a 3x4 matrix This is a 4x3 matrixSquare MatricesA square matrix has the same number of rows and columns1233 columnsmjb – September 5, 2014Oregon State UniversityComputer Graphics34567893 rowsThis is a 3x3 matrixRow and Column MatricesA matrix can have a single row (a “row matrix”) or just a single column (a “column matrix”)”12345mjb – September 5, 2014Oregon State UniversityComputer Graphics123This is a 3x1 matrix56This is a 1x3 matrixSometimes these are called row and column vectors, but that overloads the word “vector” and we won’t do it…Matrix MultiplicationThe basic operation of matrix multiplication is to pair-wise multiply a single row by a single column1234****mjb – September 5, 2014Oregon State UniversityComputer GraphicsABC12356*→32→4*1 + 5*2 + 6*31x3 3x1 1x12Matrix 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.*          Amjb – September 5, 2014Oregon State UniversityComputer Graphics    I x KABCK x JI x JMatrix Multiplication in SoftwareHere’s how to remember how to do it:1. C = A * B2. [ I x J ] = [ I x K ] * [ K x J ]mjb – September 5, 2014Oregon State UniversityComputer GraphicsI x K K x JI x J=C[ i ][ j ] = A[ i ][ k ] * B[ k ][ j ] ;Matrix Multiplication in Softwarefor( int i = 0; i < numArows; i++ ){for( int j = 0; j < numBcols; j++ ){mjb – September 5, 2014Oregon State UniversityComputer GraphicsC[ i ][ j ] = 0.;for( int k = 0; k < numAcols; k++ ){C[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];}}}Note: numAcols must == numBrows !Matrix Multiplication in SoftwareNote that:C[ i ][ j ] = 0.;mjb – September 5, 2014Oregon State UniversityComputer Graphicsfor( int k = 0; k < numAcols; k++ ){C[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];}Is like saying:C[ i ][ j ] = A[i][0] * B[0][j] + A[i][1] * B[1][j] + A[i][2] * B[2][j] + A[i][3] * B[3][j] ;Matrix 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 ];mjb – September 5, 2014Oregon State UniversityComputer GraphicsC[ 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 ];A Special MatrixConsider the matrix * column situation below:000xzy xyz xyzyx zCAABCA ABCAA B mjb – September 5, 2014Oregon State UniversityComputer Graphicszyx z (,, )yzzyzxxzxyyxCABABABABABABThis gives:Which you hopefully recognize as the Cross Product AxB3DeterminantsThe 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:mjb – September 5, 2014Oregon State UniversityComputer GraphicsdetABADBCCDDeterminantsdetABCDEFGH IEF DF DE  The determinant of a 3x3 matrix is done in terms of its component 2x2 sub-matrices:mjb – September 5, 2014Oregon State UniversityComputer Graphicsdet det detEF DF DEABCHIGIGH   ()()( )AEI FH B DI FG C DH EG   InversesThe 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:mjb – September 5, 2014Oregon State UniversityComputer Graphics11ABDBCD C AAD BC      Inverses1ABCDEFGH IThe determinant of a 3x3 matrix is done in terms of its component 2x2 sub-matrices:det det detdet det detEF DF DEHI GI GHBC AC ABHI GI GHBC AC AB         mjb – September 5, 2014Oregon State UniversityComputer GraphicsThe determinant of 4x4 and larger matrices can be done in a similar way, but usually isn’t. Gauss Elimination is more efficient.det det detdetBC AC ABEF DF DEABCDEFGH


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?