  Search    Advertiser Disclosure
 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      Author Feedback Print Article Comment on this Article # SQL Techniques for Performing Operations on Matrices : Page 2

## 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 11, 2008
 Page 2 of 4 Simple Operations on Matrices
Here are some simple operations you can implement on matrices:

Matrices A and B can be added, if they are the same size (e.g., m x n). The matrix sum C = A + B also will be a m x n matrix, where for each element cij = aij + bij and 1 ≤ i ≤ m and 1 ≤ j ≤ n. You would use this solution: Matrix addition is commutative (e.g., A + B = B + A) and associative (e.g., C + (D + E) = (C + D) + E).

2) Matrix Subtraction
Two matrices (A and B) can be subtracted if they are the same size (e.g., k x l). The matrix difference D = A – B will also be a k x l matrix with the element dij = aij – bij, where 1 ≤ i ≤ k and 1 ≤ j ≤ l.

To subtract matrix B from matrix A: You would use this solution: Matrix subtraction is neither commutative nor associative.

3) Matrix Scalar Multiplication
If A is an m x n matrix and the constant k is a number, then the scalar product of k and A is a new matrix B = kA, where bij = kaij and 1 ≤ i ≤ m and 1 ≤ j ≤ n.

To find B = 5∙A, where: You would use this solution: Scalar multiplication is commutative and associative:

``````
k(AB) = (kA)B = A(kB) = (AB)k
`````` Author Feedback Email Article Print Article Comment on this Article  