Different Operations on Matrices

For introduction on matrices, you can refer the following article: Matrix Introduction
In this article, we will discuss various operations on matrices and their properties:

Matrices Addition –
The addition of two matrices A m*n and Bm*n gives a matrix Cm*n. The elements of C are sum of corresponding elements in A and B which can be shown as:

The algorithm for addition of matrices can be written as:

for i in 1 to m
   for j in 1 to n
      cij = aij + bij

Key points:



Matrices Subtraction –
The subtraction of two matrices Am*n and Bm*n gives a matrix Cm*n. The elements of C are difference of corresponding elements in A and B which can be represented as:

The algorithm for subtraction of matrices can be written as:

for i in 1 to m
   for j in 1 to n
      cij = aij-bij

Key points:

Matrices Multiplication –
The multiplication of two matrices Am*n and Bn*p gives a matrix Cm*p. It means number of columns in A must be equal to number of rows in B to calculate C=A*B. To calculate element c11, multiply elements of 1st row of A with 1st column of B and add them (5*1+6*4) which can be shown as:

The algorithm for multiplication of matrices A with order m*n and B with order n*p can be written as:

for i in 1 to m
   for j in 1 to p
      cij = 0
      for k in 1 to n
         cij += aik*bkj

Key points:

Read next – Determinant of a Matrix, Adjoint and Inverse of a Matrix

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

This article is contributed by Sonal Tuteja. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : RahulWankhede, Shoaibahmed, Ankk98

Article Tags :
Practice Tags :