Civil Engineering (CE) Exam  >  Civil Engineering (CE) Notes  >  Engineering Mathematics  >  Different Operations on Matrices

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE) PDF Download

Matrices Addition

The addition of two matrices Am * 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: 

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE)

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
// C++ Program for matrix addition
#include <iostream>
using namespace std;
int main()
{
int n = 2, m = 2;
int a[n][m] = { { 2, 5 }, { 1, 7 } };
int b[n][m] = { { 3, 7 }, { 2, 9 } };
int c[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
c[i][j] = a[i][j] + b[i][j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << c[i][j] << " ";
cout << endl;
}
}

Output:
5 12
3 16

Time Complexity: O(n * m)

Auxiliary Space: O(n * m)

Key points:

  • Addition of matrices is commutative which means A + B = B + A
  • Addition of matrices is associative which means A + (B + C) = (A + B) + C
  • The order of matrices A, B and A + B is always same
  • If order of A and B is different, A + B can’t be computed
  • The complexity of addition operation is O(m * n) where m * n is order of matrices

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: 

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE)

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
// C++ Program for matrix substraction
#include <iostream>
using namespace std;
int main()
{
int n = 2, m = 2;
int a[n][m] = { { 2, 5 }, { 1, 7 } };
int b[n][m] = { { 3, 7 }, { 2, 9 } };
int c[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
c[i][j] = a[i][j] - b[i][j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << c[i][j] << " ";
cout << endl;
}
}

Output:
-1 -2
-1 -2

Key points:

  • Subtraction of matrices is non-commutative which means A - B ≠ B - A
  • Subtraction of matrices is non-associative which means A - (B - C) ≠ (A - B) - C
  • The order of matrices A, B and A - B is always same
  • If order of A and B is different, A - B can’t be computed
  • The complexity of subtraction operation is O(m * n) where m * n is order of matrices

Question for Different Operations on Matrices
Try yourself:
What is the key point to remember about the subtraction of matrices?
View Solution

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: 

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE)

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
// C++ Program for matrix Multiplication
#include <iostream>
using namespace std;
int main()
{
int n = 2, m = 2;
int a[n][m] = { { 2, 5 }, { 1, 7 } };
int b[n][m] = { { 3, 7 }, { 2, 9 } };
int c[n][m];
int i, j, k;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
c[i][j] = 0;
for (k = 0; k < n; k++)
c[i][j] += a[i][k] * b[k][j];
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << c[i][j] << " ";
cout << endl;
}
}

Output:
16 59
17 70

Key Points

  • Multiplication of matrices is non-commutative which means A * B ≠ B * A
  • Multiplication of matrices is associative which means A * (B * C) = (A * B) * C
  • For computing A * B, the number of columns in A must be equal to number of rows in B
  • Existence of A * B does not imply existence of B * A
  • The complexity of multiplication operation (A * B) is O(m * n * p) where m*n and n*p are order of A and B respectively
  • The order of matrix C computed as A * B is m * p where m * n and n * p are order of A and B respectively.
The document Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE) is a part of the Civil Engineering (CE) Course Engineering Mathematics.
All you need of Civil Engineering (CE) at this link: Civil Engineering (CE)
65 videos|120 docs|94 tests

Top Courses for Civil Engineering (CE)

FAQs on Different Operations on Matrices - Engineering Mathematics - Civil Engineering (CE)

1. What are the different operations that can be performed on matrices?
Ans. Matrices can be added, subtracted, and multiplied by following certain rules and conditions.
2. How is matrix addition performed?
Ans. Matrix addition is performed by adding the corresponding elements of two matrices of the same size.
3. What is the process of matrix subtraction?
Ans. Matrix subtraction involves subtracting the corresponding elements of two matrices of the same size.
4. How is matrix multiplication carried out?
Ans. Matrix multiplication is done by multiplying the rows of the first matrix with the columns of the second matrix and adding the products.
5. What are the key points to remember while performing operations on matrices?
Ans. It is important to ensure that the matrices being operated on are compatible in size and follow the rules specific to each operation.
65 videos|120 docs|94 tests
Download as PDF
Explore Courses for Civil Engineering (CE) exam

Top Courses for Civil Engineering (CE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE)

,

Summary

,

Sample Paper

,

Exam

,

practice quizzes

,

Free

,

study material

,

past year papers

,

Important questions

,

Previous Year Questions with Solutions

,

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE)

,

video lectures

,

pdf

,

MCQs

,

Different Operations on Matrices | Engineering Mathematics - Civil Engineering (CE)

,

Objective type Questions

,

Viva Questions

,

Semester Notes

,

Extra Questions

,

mock tests for examination

,

shortcuts and tricks

,

ppt

;