3Д БУМ

3Д принтеры и всё что с ними связано

Matrix Multiplication

Okay, on to matrix multiplication! Lots of people get confused when it comes to multiplying matrices. In reality, however, it really isn’t that hard. The first thing you need to do is determine whether the matrices are conformable. Lets say you have two matrices, A and B, that have the dimensions mxn and pxq. The matrices are conformable only if n=p. For instance, a 3×3 matrix and a 3×7 matrix can be multiplied to­gether, but a 3×2 and a 4×5 matrix cannot. If your two matrices satisfy this requirement, you can move to the next step.

The resulting matrix will have the dimensions mxq. That means in the previous example, a 3×3 and a 3×7 matrix multiplied together would produce a 3×7 matrix. The nice thing about 3D graphics is that the matrices you use are usually square. When you multiply two square

matrices together, you guessed it, you get a square matrix of the same size, so a 4×4 matrix multiplied by another 4×4 matrix will give you a final matrix with dimensions 4×4.

But just how do you multiply them together you ask? Well the idea is pretty simple. You take the first row of the first matrix and multiply it by the first column of the second matrix. This results in a single num­ber that goes in the first row and first column of the result. The second element of the result is the first row of the first matrix times the sec­ond column of the second matrix, and so on. Sound confusing? Maybe you need to look at it a little differently.

Consider two 3×3 matrices, A and B, which are multiplied together to form C. You know that the first row of A contains the elements An, A12, and A, D. The first column of B contains Bn, B21, and B31. In order to get

13′

Cn you take (An x B11) + (A12 x B21) + (A13 x B31). You do that a total of nine times to get all the elements for the 3×3 result. Let’s try multiply­ing one in Figure 1.6.

3

5

0

2

5

2

3X2+5X7+0X4

3X5+5X3+0X5

3X2+5X1+0X9

41

30

11

4

4

8

7

3

1

=

4×2+4×7+8×4

4×5+4×3+8×5

4×2+4×1+8×9

=

68

72

CO

9

6

1

4

5

9

9X2+6X7+1X4

9X5+6X3+1×5

9X2+6X1+1X9

64

68

33

Figure 1.6 Multiplying two matrices together. When multiplying matrices, you take the first row of A times the first row of B, the second row of A times the second column of B, and so on.

CAUTION

)

Matrix multiplication is not commutative, meaning that unlike real numbers, the order in which you multiply two matrices does make a difference. If you have two matrices, A and B, multiplying A by B will not give you the same result as multiplying B by A (AB Ф BA). Go ahead and try it with the matrices in Figure 1.6; the result is shown here:

44

42

42

42

53

25

113

94 —1—1—

49

Для любых предложений по сайту: [email protected]