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 A = r×t = rt. In general, matrix can be displayed as,

A = a11a12a1ja21a22a2jai1ai2aij

Matrix A is a square (or) rectangular matrix based on their order. The ithrow elements are ai1, ai2....ait while the jthcolumn elements are aj1,aj2, ......ait . In general, is an element of matrix which is lying in the ithrow and jth 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.

M=m00 m01 m02 m10 m11 m12 m20 m21m22KM=km00 km01 km02 km10 km11 km12 km20 km21km22Where K is a scalarKM= 37634251064     = 2118912615301812

Properties of scalar multiplication

Let A=aijr×tand B=bijr×tand α,βR  then

(i) α(A+B)=αA+αB

(ii) (α+β)A=αA+βA

Example

If A=5213, B=-100-1then find the matrix such that X such that 2A-X=B .

Solution:

Given:2A-X=B .

Adding on both sides, we get,

2A+X-X=B+X2A+0=B+X2A=B+X

Subtract matrix from both sides, we get,

2A-B=B-B+X2A-B=0+X2A-B=XX=2A-B

X=25213--100-1X=10426+1001X=11427

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=aijr×t, B=bijt×sbe r×tmatrix and t×s matrix respectively then the product of the matrix is C of order r×s. Therefore, the product matrix C=cijr×s=AB where to get i,kth element cik of matrix C we multiply ith row of the matrix A with the k th column of matrix B and then summing up their product to obtain cik.

Example

Let A=12112×2 and B=322×1

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

AB=121132     =1×3+2×21×3+1×2     =3+43+2AB=752×1

Notice that BA=322×112112×2is not defined because the number of columns of B is not equal to the number of rows of A.

 

AB=1001 abcd= abcdBA= abcd1001=abcdAB=BA

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,bR, if ab=0 then either a=0 (or) b=0

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

Let A=0102, B=1300 then,AB=01021300=0000

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

Answer: Option a is correct.

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

Answer: Option b is correct

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

Answer: Option c is correct.

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

Answer: Option b is correct.

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

Answer: Option d is correct.

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

Algorithms

Matrix

Matrix multiplication

Matrix Multiplication Homework Questions from Fellow Students

Browse our recently answered Matrix Multiplication homework questions.

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

Algorithms

Matrix

Matrix multiplication