TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

SQL Techniques for Performing Operations on Matrices : Page 3

SQL does not support direct operations on matrices, but it does allow easy manipulations with matrices. Learn a few SQL techniques for performing some basic operations on matrices.

 by Alex Kozak
 Dec 10, 2008
 Page 3 of 4
4) Matrices Multiplication
Two matrices (A and B) can be multiplied if they are compatible, meaning that the first (left) matrix has as many columns as the second (right) matrix has rows. If matrices A and B meet this condition, you can multiply them. The result of such a multiplication will be matrix C, which has as many rows as matrix A and as many columns as matrix B:
``````

Amxn ∙Bnxp  = Cmxp
``````

The rules for matrices multiplication are not as trivial as for scalar matrix multiplication. To calculate the ij-element of the product matrix, you need to multiply the ith row vector of the first matrix by the jth column vector of the second matrix. The multiplication of a row vector by a column vector goes as follows:

1. Multiply the first elements of the row and column vectors to get product 1.
2. Multiply the second elements of the row and column vectors to get product 2.
. . . . . . . . . . . . .
N. Multiply the Ns elements of the row and column vectors to get product N.
Lastly, sum up all the products.

The result of such a calculation will be a scalar.

Figure 2 shows the algorithm in math notation for Amxn ∙Bnxp = Cmxp (where i = 1, 2, . . m, and j =1, 2, . . p.).

 Figure 2. Calculating ij-element of Product Matrix C: Here is the algorithm in math notation for Amxn ∙Bnxp = Cmxp.

To find product C = A ∙ B, where:

You would use this solution:

Matrices multiplication is not commutative (i.e., A∙B ≠ B∙A). Indeed, in Example 4, the multiplication A3x2 ∙ B2x4 is allowed, because matrices A3x2 and B2x4 are compatible. However, the multiplication B2x4 ∙ A3x2 would be illegal, because the number of columns in the left matrix is not equal to the number of rows in the right matrix. But even if both A∙B and B∙A are compatible, that doesn’t guarantee the same result.

Consider two square matrices:

However, matrices multiplication is associative and distributive:

• associative - A∙(B∙C) = (A∙B)∙C
• distributive - A∙(B + C) = A∙B + A∙C
• distributive - (A + B)C = A∙C + B∙C

5) Matrix Transpose
The transposing of a matrix simply means an exchange between the rows and the columns. Suppose you have an m x n matrix, Amxn. If you transpose that matrix, you will get an n x m matrix, Bnxm, with the following correspondence between the elements of A and B:

``````
aixj   = bjxi, for all i and j.
``````

The most common notation for the transposing of matrix A is AT.

Find the transpose of a matrix A as follows:

Comment and Contribute

(Maximum characters: 1200). You have 1200 characters left.

Thanks for your registration, follow us on our social networks to keep up-to-date