CS 45: COPUTER GRAPHICS INTRODUCTION TO ATRICES SPRING 26 DR. ICHAEL J. REALE
hp://www.papeleparee.e c.br/wallpapers/coigoari_2283_2824.jpg ENTER THE ATRIX ari = (p X q) 2D arra of ubers (scalars) p = uber of rows, q = uber of colus Give ari, aoher oaio for a ari is [ ij ] I copuer graphics: os arices will be 22, 33, or 44 We will use arices o perfor rasforaios E.g., ove his poi over here, roae ha poi, ec. 2 2 3 2 2 3 2 2 22 2 2 22 32 3 3 23 33
VECTORS = ATRICES Basicall, a vecor is jus a ari wih eiher oe row or oe colu Cosequel, we will be able o perfor operaios ivolvig arices a vecors v v V v v V
ATRIX ADDITION To a wo arices, jus a he correspoig copoes Sae rules as wih vecors Boh arices us have he sae iesios! Resulig ari sae iesios as origial arices N ij ij ij ij ( ( ) ) ( ( ) )
ULTIPLY A ATRIX BY A SCALAR To uliple a ari b a scalar (sigle uber) a, jus ulipl a b he iiviual copoes Agai, sae as wih vecors No surprisigl, resulig ari sae size as origial T a a a a ij a a
TRANSPOSE OF A ATRIX Traspose of ari = rows becoe colus a colus becoe rows Noaio: T If is (p X q) T is (q p) 6 4 2 5 3 6 5 4 3 2 T
ATRIX ULTIPLICATION
ATRIX-ATRIX ULTIPLICATION As wih vecors, uliplicaio is a lile ore coplicae Whe uliplig wo ari a N like his T = N Size of us be (p X q) Size of N us be (q r) Resul T will be (p r) ORDER ATTERS!!! T N 2 3 3 2 2 2 2 2 2 2
ORDER ATTERS!!! IN GENERAL, wih ari uliplicaio: AB BA (I fac, i a o eve be POSSIBLE o ulipl he i reverse orer, if B s colu cou!= A s row cou)
ATRIX-ATRIX ULTIPLICATION For each value i T ij Ge he o prouc of he row i of a he colu j of N T N 2 2 2 2 2 2
ATRIX-ATRIX ULTIPLICATION 2 2 2 2 2 2 N T
ATRIX-ATRIX ULTIPLICATION 2 2 2 2 2 2 N T
ATRIX-ATRIX ULTIPLICATION 2 2 2 2 2 2 N T
EXAPLE: ATRIX-ATRIX ULTIPLICATION 44 3 2 2 5*6 3*4 *2 2 6 4 8 2 9 7 5 3 N T
EXAPLE: ATRIX-ATRIX ULTIPLICATION 98 6 3 8 5*2 3* *8 2 6 4 8 2 9 7 5 3 44 N T
EXAPLE: ATRIX-ATRIX ULTIPLICATION 6 66 36 4 *6 9*4 7*2 2 6 4 8 2 9 7 5 3 98 44 N T
EXAPLE: ATRIX-ATRIX ULTIPLICATION 278 32 9 56 *2 9* 7*8 2 6 4 8 2 9 7 5 3 6 98 44 N T
EXAPLE: ATRIX-ATRIX ULTIPLICATION T N 44 6 98 278 7 3 9 2 5 4 6 8 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? T N 2 2 2 2 22 2 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? SURE! T N 2 3 3 3 2 3 2 2 2 2 22 2 2 2 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? T N 2 2 2 2 22 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? ABSOLUTELY! This ki of ari * vecor uliplicaio will be use a LOT o rasfor pois! T N 3 3 3 3 2 2 2 22 2 2 2
ULTIPLYING A ATRIX BY A VECTOR We will be usig colu vecors here Colu vecor = (q ) ari uliplig a (q ) vecor b a ari (p q) will give us a ew vecor (p ) For our rasforaios laer, usuall p = q so ha w has he sae size as v w i = o prouc of v wih row i of w v 2 2 2 2 22 v v v 2 w w w 2
EXAPLE: ATRIX-VECTOR ULTIPLICATION This ari will scale a vecor so ha: Is X copoe is ouble Is Y copoe is riple z z z z z v w 3 2 ) * * (* ) * 3* (* ) * * (2* 3 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? T N 2 2 2 2 22 2 2 2 2 22
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? OST ASSUREDLY! We will use his ki of uliplicaio whe we wa o cobie rasforaios (like a raslaio followe b roaio) T N 2 3 3 3 3 3 3 2 2 2 22 2 2 2 2 22 2 2 2 2 22
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? T N 2 2 2 2 22 2 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? NOPE! T N 3 3 2 3 2 2 2 2 22 2 2
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? T N 2 2 2 2 2 22
ATRIX-ATRIX ULTIPLICATION Ca we ulipl hese wo arices? NOT A CHANCE! Reeber: orer aers i ari uliplicaio (i ore was ha oe) 3 3 3 T N 2 2 2 2 2 22
IDENTITY ATRIX Iei ari = square ari wih s o he iagoal a s everwhere else Effecivel he ari equivale of he uber oe uliplig b he iei ari gives ou he sae ari back I I I I I
ATRIX DETERINANT
DETERINANT INTRODUCTION The eeria of a ari Scalar uber Ol efie for square ari (e.g., ari is p p) Deoe as or e() Goig o cocerae here o eerias 22 a 33 arices Copuig eerias for larger square arices is a ki of recursive proceure
DETERINANT FOR 2X2 AND 3X3 Paer: iagoals goig: Upper-LEFT o lower-right a Upper-RIGHT o lower-left subrac 2 2 2 22 2 2 2 22 2 2 22 2 2 2 2
CLOSER LOOK AT 2X2 DETERINANT a b a bc c
2X2 DETERINANT AND AREA Le s sa we have wo vecors A a B We ca for a parallelogra ou of hese wo vecors
2X2 DETERINANT AND AREA If we ake a ari such ha A a B are he colus: he eeria = he sige area of he parallelogra! a b b a b a b a b a b a B A
2X2 DETERINANT AND AREA: PROOF Area of parallelogra = base * heigh Base = legh of A Le s sa we have a vecor C = PERPENDICULAR o A C a, a Heigh = legh of projecio of B oo NORALIZED C Projecio of B oo C BC B C cos ivie b he legh of C B cos
2X2 DETERINANT AND AREA: PROOF Our area is herefore: Bu reeber: legh of C = legh of A SO, our area is: which is: which is he sae as our eeria! C B B C B A cos cos a b b a a b a b c b c b C B ) ( ) ( ) ( ) ( cos B A a b b a b a b a
2X2 DETERINANT = SIGNED AREA Noe ha his is he SIGNED area, so: A B B A You will ge: POSITIVE area if A a B are COUNTER-CLOCKWISE NEGATIVE area if A a B are CLOCKWISE Basicall followig righ-ha rule
3X3 DETERINANT AND CROSS PRODUCT If ou replace: Top row e e e z vecors ile row u u u z 2 2 2 2 22 e u v e u v e u v z z z Boo row v v v z Suel have Sarrus schee for copuig he cross prouc! NOTE: No eacl he sae: Cross prouc gives ou vecor Because e, e, e z are all vecors Deeria gives ou scalar e e 2 ( u ( u z v v z 22 2 ) e ) e ( u ( u z v 2 v z 2 22 ) e ) e z z ( u ( u 2 v v ) 2 ) 2 2
3X3 DETERINANT AND VOLUE Le s sa we have THREE 3D vecors U, V, W If hese vecors = colus of our ari: U V W ( U V) W Deeria = volue of parallelepipe fore b hree vecors!
3X3 DETERINANT AND VOLUE: PROOF Volue = (area of base) * (heigh of volue) Area of base = area of parallelogra fore b U a V (Legh of U) * (Legh of V) * (SINE of agle bewee he) However, we kow ha: U V si U V So our firs sep is o ge he cross prouc of U a V
3X3 DETERINANT AND VOLUE: PROOF Heigh = W projece oo NORALIZED (UV) W projece oo (UV): W ( U V) W U V cos We COULD ivie b he legh of (UV) o oralize i, bu uliael we ee he (heigh*base area) SO: Volue W U V cos ( U V) W
3X3 DETERINANT AND SCALAR TRIPLE PRODUCT This paricular ki of copuaio is calle he scalar riple prouc: Gives ou a scalar value because of fial o prouc Scalar riple prouc = eeria of 33 ari fore b hree vecors W V U ) ( W V U u v v u w v u u v w u v v u w u w v w u v w v u v w u w u v w v u w v u w v u w v u z z z z z z z z z z z z z z ) ( ) ( ) ( ) (
ZERO DETERINANT If eiher: Two rows (or wo colus) have a cross prouc of zero (boh goig eacl he sae wa) OR A row (or a colu) is eirel copose of zeros The = Noe: if =, he - = / so, zero eeria eas ha - oes o eis
ZERO DETERINANT AND VOLUE If he eeria is zero, eiher: Two colus) have a cross prouc of zero = vecors parallel OR Eaple: base area is ZERO A row (or a colu) is eirel copose of zeros Eaple: W = (,,) = heigh is ZERO
ORIENTATION OF A BASIS If each colu of a ari is i fac a basis vecor, he: If eeria is POSITIVE basis is posiivel oriee righ-hae sse If eeria is NEGATIVE basis is egaivel oriee lef-hae sse Eaple: saar basis righ-hae sse e e e z ( e e ) e (,,) e z z
CRAER S RULE
INTRODUCTION Whe we were alkig abou iersecig a ra wih a riagle, we coul solve i usig Craer s Rule The reaso WHY Craer s Rule works because of he wa eerias work (a how he relae o area a volue)
PARALLELOGRA AREA If I have a parallelogra, a I slie he op ege PARALLEL o he boo ege area oes chage If we alk abou he vecors ha ake up he eges of he parallelogra: Boo ege A Top ege B + ka where k = soe value
PARALLELOGRA AREA (Area of shape AB) = (Area of shape A(B+kA)) SO, sice he eeria = area: A( B ka) AB As oe igh epec, his is rue as well: ( A jb) B AB
ANOTHER AREA PROPERTY If ou have TWO parallelogras (ha share he sae vecor A as oe of he sies): AB AC A( B C) (Thik of i like ou are sliig he share ile ege uil he sies are parallel)
RELATION TO OUR PREVIOUS PROPERTY We kow his: AB AC A( B C) If we look ow a he previous proper: A( B ka) AB If we ulipl i ou, we see AkA = (because A is parallel wih ka), so i sill works: A( B ka) AB A( ka) AB
YET ANOTHER AREA PROPERTY If ou scale up oe of he sies b k basicall he sae as uliplig he area b k: ( ka) B k AB
EXAPLE: LINEAR SYSTE WITH 2 UNKNOWNS So, suppose I have wo equaios wih wo ukows (a, b): If: A (3,) B (,2) C (6.5,5.5) The, I ca ur his io a vecor equaio: 6.5 5.5 3a b a 2b C aabb Basicall, how o I scale A a B, a a he ogeher o ge C?
EXAPLE: LINEAR SYSTE WITH 2 UNKNOWNS We kow ha (area of CB) = (area of (aa)b): CB ( aa) B SO, because of his: ( aa) B a AB We ca pull ou he a a solve for i: CB ( aa) B CB a AB a CB AB
WHICH IS CRAER S RULE! Reeber: give a sse: For each cooriae of V (v i ): V N Replace he i h colu of ari wih N Ge he eeria a CB AB Divie b he eeria of he origial ari I his case: A a V b N C B b AC AB
CRAER S RULE IN 3D Basicall, we ow have 33 arices, 3 ukows, a 3D vecors: Noe: A, B, a C are vecors i, he are he colus of he ari, so is 33 A B A C B C a b c DBC a b ABC D ADC ABD c ABC ABC
INVERSE AND ADJOINT OF A ATRIX
INVERSE Iverse of a ari Deoe - ari ies iverse = iei: I Ol eiss for: Square arices Deeria oes equal :
INVERSES AND TRANSFORATIONS Whe we ge o rasforaios, basicall oes he opposie of whaever our rasforaio i Eaple: if U a V are vecors, a is rasforaio ari: V U To ge back U fro V, we uo he rasforaio b applig he iverse: U V
GETTING THE INVERSE Whe we re ealig wih rasforaios for os of he ou ca ge he iverse irecl: Eaple: as +5 o X; he iverse oes he opposie IF, however, we o ee he iverse of soe arbirar ari, here are a couple of was o o i: For a 44 ari or saller ca use he ajoi eho 5 5
BEFORE WE GET TO ADJOINTS Before we ge o ajois, we ee o alk abou soehig calle cofacors These ca be use for: Geig he ajoi ari Copue he eeria
COFACTORS Cofacor ij of row i a colu j Cross ou row i a colu j Take eeria of suff reaiig ulipl b he appropriae sig If (i + j) EVEN posiive Oherwise egaive 9 8 7 6 5 4 3 2 If his is ari: To ge he cofacor for row a colu ( ): Cross ou row a colu 9 8 7 6 5 4 3 2 Copue eeria of wha s lef TIES he appropriae sig: 9 8 6 5
ANOTHER COFACTOR EXAPLE 9 8 7 6 5 4 3 2 Cofacor for row a colu ( ): Cross ou row a colu 9 8 7 6 5 4 3 2 Copue eeria of wha s lef TIES he appropriae sig: 9 7 6 4
COPUTING THE DETERINANT WITH COFACTORS 2 2 2 2 22 You ca acuall ge he eeria usig cofacors Calle Laplace s epasio To ge he eeria: Pick a row or colu (usuall op row) 2 2 2 2 2 22 2 22 2 2 2 2 2 22 2 22 2 2 2 2 2 2 22 2 For each elee i ha row/colu, copue cofacor Su up all cofacors TIES heir correspoig elee 22
ADJOINT Ajoi of a ari = use for: Trasforig surface orals (we ll ge o ha laer) Firs sep i copuig iverse To ge he ajoi ari: Copue cofacors for EVERY elee i ari Use his o buil cofacor ari Each elee i cofacor ari = cofacor for origial elee Ge raspose of cofacor ari cofacor( aj( ) ) 2 2 2 2 cofacor( ) T 2 2 22 2 2 22
GETTING THE INVERSE FRO THE ADJOINT To ge he iverse of a ari : Copue ajoi ari Divie b eeria of origial ari aj( ) 2 2 2 2 22
WHY DOES THIS WORK? Le s ulipl he ari b he ajoi * aj( ) 2 2 2 2 22 2 2 2 2 22 If he oupu er is o he DIAGONAL resul is jus he eeria of! 2....................................... 2..................... Whe we ge he iverse, we ivie b iagoal eries becoe Recall: 22
WHY DOES THIS WORK? * aj( ) 2 2 2 2 22 2 2 2 2 22 If i is NOT o he iagoal:............... 2... 2.......................................... Wh?: Equivale of geig he eeria for THIS ari: Proble: oe of he rows is repeae eas he parallelepipe is fla! volue is zero DETERINANT is zero So, all he o-iagoal eries will be ZERO 2 2 2 2 22
EXAPLE: ADJOINT ETHOD Le s ake our raslaio ari fro before: 5
EXAPLE: ADJOINT ETHOD 5 Firs we ge he cofacors: ( ) ( ) 2 ( ) 5 5 ( ) ( ) 2 ( ) 5 5 2 ( 5) 5 2 ( ) 22 ( )
EXAPLE: ADJOINT ETHOD Cofacor ari: Ajoi ari (raspose of cofacor ari, so swap rows a colus): 5 cofacor( ) 5 aj( )
EXAPLE: ADJOINT ETHOD Ge eeria of : Divie ajoi b eeria of INVERSE: 5 5* * * 5* * * 5 2 5 cofacor( ) 5 5 ) ( aj
RULES FOR THE INVERSE Traspose of iverse = iverse of raspose Iverse of N = (Iverse of N) (Iverse of ) Noe: swap orer! T T N N
DIAGONAL, SYETRIC, AND ORTHOGONAL ATRICES
ATRIX TYPES I urs ou ha he Iei ari acuall has hree iffere properies: Seric Diagoal Orhogoal I I I
SYETRIC ATRIX Seric ari = ari equals is raspose: Eaple: Iei ari is seric T T I I 7 2 3 2 4 3 2 T
DIAGONAL ATRIX Diagoal ari ari ha has zeroes everwhere EXCEPT he iagoal Diagoal values a or a o be zero NOTE: If iagoal also seric I 3 9 5
ORTHOGONAL ATRIX Orhogoal ari I Colus of ari are orhooral vecors: Have legh = Are orhogoal o each oher Eaple: iei, roaio ari arou Z ais R Z cos si si cos
ORTHOGONAL ATRICES AND INVERSES Oe grea hig abou orhogoal arices INVERSE of orhogoal ari = TRANPOSE of orhogoal ari! T Also, if a N are orhogoal N is also orhogoal eas as log as ou are ol uliplig orhogoal arices resul will ALSO be orhogoal
EXAPLE: INVERSE OF ORTHOGONAL ATRIX The iverse of he roaio ari Rz raspose of Rz cos si si cos R Z cos si si cos T R Z R Z ) cos (si ) si cos cos (si ) cos si si (cos ) si (cos cos si si cos cos si si cos 2 2 2 2 T R Z R Z
PROPERTIES OF ORTHOGONAL ATRICES Deeria equals + or - Vecor U will sill have he sae legh afer a rasforaio U U Vecors U a V will sill be perpeicular o each oher afer beig rasfore U V U V
STANDARD BASIS If we use he saar basis as colus of a ari ari is orhogoal osl because we acuall have he iei ari E e e e z I I T I I
ORTHOGONAL ATRIX VS. ORTHOGONAL VECTOR SET (BASIS) Orhogoal basis vecors perpeicular BUT o ecessaril ui legh Use as colus of a ari a o be orhogoal! Orhooral basis vecor perpeicular AND ui legh Use as colus for is orhogoal Yes, i s cofusig.