## What is a matrix?

A matrix is an entity composed of components arranged in rows and columns. The rows and columns of a matrix determine the dimension of a matrix. A matrix containing 3 rows and 4 columns is of dimension 3x4. Dimensions in matrix arithmetic are very important since some operations are not possible unless matrices have identical dimensions.

The matrices are frequently used in computer graphics and the matrix transformations are one of the important mechanics of any 3D graphics, the chain of matrix transformations allows rendering a 3D object on a 2D monitor

## What is the order of a matrix?

In a matrix, the vertical and horizontal arrangements are called the columns and rows of the matrices respectively. The order of a matrix denotes the arrangement of elements as number of rows and columns in a matrix. So, it is known as dimension of a matrix. So, if a matrix has r rows and t columns then the matrix is said to be of order  read as r cross/by t. The dimension of the matrix tells the total number of elements of the matrix and it can be obtained by multiplying the rows by columns.

The order of a matrix is useful to find the number of elements in any type of matrix. For example, the total number of elements in matrix . In general, matrix can be displayed as,

Matrix $A$ is a square (or) rectangular matrix based on their order. The ${i}^{th}$row elements are  while the ${j}^{th}$column elements are  . In general, is an element of matrix which is lying in the ${i}^{th}$row and ${j}^{th}$ column of a matrix.

## Multiplication of matrix:

### Scalar matrix multiplication:

Multiplying a vector by a scalar is perhaps one of the easiest operations we can perform using vectors. The process is called scalar multiplication but is sometimes simply called scaling because it simply either increases or decreases the magnitude of the vector, it does not alter the vector's direction. Scalar multiplication is performed by multiplying a scalar with each corresponding component in the matrix.

## Properties of scalar multiplication

Let $A={\left[{a}_{ij}\right]}_{r×t}$and $B={\left[{b}_{ij}\right]}_{r×t}$and $\alpha ,\beta \in \mathfrak{R}$  then

(i) $\alpha \left(A+B\right)=\alpha A+\alpha B$

(ii) $\left(\alpha +\beta \right)A=\alpha A+\beta A$

Example

If then find the matrix such that X such that

Solution:

Given:

Adding on both sides, we get,

$2A+X-X=B+X\phantom{\rule{0ex}{0ex}}2A+0=B+X\phantom{\rule{0ex}{0ex}}2A=B+X$

Subtract matrix from both sides, we get,

$2A-B=B-B+X\phantom{\rule{0ex}{0ex}}2A-B=0+X\phantom{\rule{0ex}{0ex}}2A-B=X\phantom{\rule{0ex}{0ex}}X=2A-B$

$X=2\left[\begin{array}{cc}5& 2\\ 1& 3\end{array}\right]-\left[\begin{array}{cc}-1& 0\\ 0& -1\end{array}\right]\phantom{\rule{0ex}{0ex}}X=\left[\begin{array}{cc}10& 4\\ 2& 6\end{array}\right]+\left[\begin{array}{cc}1& 0\\ 0& 1\end{array}\right]\phantom{\rule{0ex}{0ex}}X=\left[\begin{array}{cc}11& 4\\ 2& 7\end{array}\right]$

## Multiplication of matrices

Let A,B be any matrices and matrix multiplication is defined only when the number of columns of matrix A is equal to the number of rows of matrix B. That is if $A={\left[{a}_{ij}\right]}_{r×t}$, $B={\left[{b}_{ij}\right]}_{t×s}$be $r×t$matrix and $t×s$ matrix respectively then the product of the matrix is C of order $r×s$. Therefore, the product matrix $C={\left[{c}_{ij}\right]}_{r×s}=AB$ where to get $\left(i,k\right)$th element ${c}_{ik}$ of matrix C we multiply $i$th row of the matrix A with the k th column of matrix B and then summing up their product to obtain ${c}_{ik}$.

Example

Let

Here, $2×2×2×1=2×1$

Notice that $BA={\left[\begin{array}{c}3\\ 2\end{array}\right]}_{2×1}{\left[\begin{array}{cc}1& 2\\ 1& 1\end{array}\right]}_{2×2}$is not defined because the number of columns of B is not equal to the number of rows of A.

In general, product of two multiplication is defined but their commutativity fails.

Special case

The product of two non-zero matrices can be a zero matrix but not necessarily.

Example: We know that in real number system for all $a,b\in \mathfrak{R}$, if ab=0 then either a=0 (or) b=0

But this is not necessarily enough to show the case in matrices.

## Properties of matrix multiplication

• Associative property: The changes in the surrounding matrix multiplication will not affect the output. Associative property can be written as, A1(A2A3)=(A1A2)A3.
• Intersecting property: When the matrix M X N is multiplied by the N X N matrix, then the output will be the M X N matrix, and this property is known as multiplicative identity.
• Distributive property: The matrices can be distributed as we distribute the real numbers, the distributed property can be written as, A1(A2+A3) = A1A2+A1A3.

## The Naive matrix multiplication

### Pseudocode

Data: S[a][b], P[g][h]

Result: Q[][]

If B == G, then

For i=0; i<a; i++ do

For j=0; j<h; j++ do

Q[i][j] = 0;

For k =0; k<g; K++ do

Q[i][j]+= S[i][k] * p[k][j];

End

End

End

End

The above algorithm loops through P and S entities, and the resultant matrix Q is filled using the outermost loop. It uses an exhaustive approach.

### Time complexity

There are three nested loops in the naive matrix multiplication algorithm. For every outer loop iteration, the number of runs in the inner loops will be equivalent to the matrix length. O(1) is the time taken to perform an integer operation. The length of a matrix is N, then the time complexity is O(N*N*N) = O(N3).

## Stassen algorithm

This algorithm uses the divide-and-conquer method along with some matrix tricks to solve the problems with low computation. Generally, the input matrix dimension will be N X N. Consider the two input matrices (S and P) with 2 X 2 order. The input matrix is divided into four submatrices with the order N/2 X N/2. Perform 10 subtraction/addition operation. calculate seven multiplication operations recursively using former results. R[m], m ϵ {1,2,…,7} with the size N/2 X N/2. Finally, the desired submatrix of the Q resultant matrix is calculated by subtracting and adding a different combination of R[m] submatrices.

### Time complexity

The solution of the Stassen algorithm is based on the recursion. O(1) is the time to perform the first step (dividing the input matrices into submatrices with N/2 X N/2 size.) to calculate 10 subtraction/addition takes O(N2) time. R1 to R7 is calculated, the output loop of the step, where there will be 7 matrices with size N X 2 and it tales 7T(N/2) time. Finally, finding the Q matrix takes O(N2) time. The time complexity is,

T(N) = 7T(N/2) + O(N2)  = O(Nlog2 7)= O(N2..8074) time

## Use of matrices

• Square matrices can represent the linear transformation of objects. They are used to project 3-D images into 2-D planes in graphics.
• In computer graphics, digital images are treated as a matrix where the columns and rows of matrices correspond to the columns and rows of the pixels. The numerical entries are the color values of the pixel.
• Matrix is used to manipulate the point, which is a common mathematical approach used in video game graphics. Graphs can be represented in a matrix, where columns and rows of the matrix is the node and value of their intersection.
• In computer graphics, the matrix operations like rotation and translation will be used.

## Context and Applications

This topic is significant in all the competitive exams, at school levels, both graduate and post-graduate levels especially for

• Bachelors in Computer Science or Mathematics
• Masters in Computer Science or Mathematics

## Practice Problems

Q1 What is the time complexity of navie algorithm?

a) O(N3)

b) O(N2.8074)

c) O(N)

d) None of the above

Explanation: O(1) is the time taken to perform an integer operation. The length of a matrix is N, then the time complexity is O(N*N*N) = O(N3).

Q2 Divide-and-conquer approach is used by ______.

a) Navie algorithm

b) Strassen algorithm

c) Both a and b

d) None of the above

Explanation: Solvay Strassen algorithm uses the divide-and-conquer method along with some matrix tricks to solve the problems with low computation.

Q3 The associative property is written as____.

a) A1(A2+A3) = A1A2+A1A3

b) A1(A2A3)=(A1A2)A2.

c) A1(A2A3)=(A1A2)A3.

d) None of the above

Explanation: The changes in the surrounding matrix multiplication will not affect the output. Associative property can be written as, A1(A2A3)=(A1A2)A3.

Q4 The Solvay Strassen algorithm is suitable for  ___ matrices.

1. Non-square
2. Square
3. Neither a nor b
4. None of the above

Explanation: The Solvay Strassen algorithm use divide and conquer method with the maths tricks to solve matrix multiplication with low computation and this works only on the square matrices with the same dimensions.

Q5 In which property, the matrices can be distributed as we distribute the real numbers?

1. Associative
2. Distributive
3. Interesting
4. All of the above

Explanation: The matrices can be distributed as we distribute the real numbers, the distributed property can be written as, A1(A2+A3) = A1A2+A1A3.

### Want more help with your computer science homework?

We've got you covered with step-by-step solutions to millions of textbook problems, subject matter experts on standby 24/7 when you're stumped, and more.
Check out a sample computer science Q&A solution here!

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

### Search. Solve. Succeed!

Study smarter access to millions of step-by step textbook solutions, our Q&A library, and AI powered Math Solver. Plus, you get 30 questions to ask an expert each month.

Tagged in
EngineeringComputer Science

### Matrix multiplication

• Copyright, Community Guidelines, DSA & other Legal Resources: Learneo Legal Center
• bartleby, a Learneo, Inc. business