Matrix Algebra
Matrix Algebra
Topic:
MATRIX ALGEBRA
Session - 31
To familiarize students with the basic concept of Necessity of Matrix Algebra Functions using Arrays
INSTRUCTIONAL OBJECTIVES
This Session is designed to:
• Utilize a 2-D Array to implement the addition of two 2-D Matrices.
• Implement the multiplication of two 2-D Matrices.
• Calculate the trace of a 2-D Matrix.
• Gain a comprehension of Matrix algebra using functions.
• Implement the Transpose of a 2-D Matrix.
LEARNING OUTCOMES
At the end of this session, you should be able to:
Successfully implement the addition of two 2-D Matrices using a 2-D Array.
Effectively perform the multiplication of two 2-D Matrices.
Calculate the trace of a given 2-D Matrix accurately.
Demonstrate a clear understanding of Matrix algebra, incorporating functions.
Implement the Transpose operation on a 2-D Matrix, producing the desired result.
Multiplicati
on
Matrix Transpose
Identity
Matrix
CREATED BY K. VICTOR BABU
INTRODUCTION
Matrices
Matrix is a rectangular array of numbers, symbols, points, or
characters each belonging to a specific row and column. A matrix is
identified by its order which is given in the form of rows ⨯ and
columns.
The numbers, symbols, points, or characters present inside a matrix
are called the elements of a matrix.
The location of each element is given by the row and column it
belongs to.
• Order of Matrix
Order of the Matrix tells about the number of rows and columns
present in a matrix. Order of a matrix is represented as the number of
rows times the number of columns. Let’s say if a matrix has 4 rows
and 5 columns then the order of the matrix will be 4⨯5.
Examples of matrices are mentioned below:
Matrix Multiplication:
1.Start.
2.Enter the value of m and n (or) order of the first matrix.
3.Enter the value of p and q (or) order of the second matrix.
4.Create a matrix of size a[m][n] and b[p][q].
5.Enter the element of matrices row-wise using loops.
6.If the number of columns of the first matrix is not equal to the number of rows of the second
matrix, print matrix multiplication is not possible and exit. If not, proceed to the next step.
7.Create a third matrix, c of size m x q, to store the product.
8.Set a loop from i=0 to i=m.
9.Set an inner loop for the above loop from j=0 to j=q.
10.Initialise the value of the element (i, j) of the new matrix to 0.
11.Set an inner loop inside the above loop from k=0 to k=p.
12.Using the add and assign operator (+=) store the value of a[i][k] * b[k][j] in the third matrix, c[i][j].
13.Print the third matrix.
14.Stop.
Mathematical Explanation:
Mathematical Explanation:
Task 1:
Matrix Multiplication of two Matrices using two 2-D Array.
Task 2:
create a C program that utilizes a 2-D array to take runtime input for a
source matrix mat[3][3], and completes the following tasks?
(i) Computes the transpose of matrix mat[3][3] and stores the output in a
new matrix named transpose[3][3].
(ii) Verifies whether the diagonal elements of mat[3][3] and transpose[3]
[3] are in the same positions.
CREATED BY K. VICTOR BABU
EXAMPLES
1. How would you implement the addition of two 2-D Matrices using a
2-D Array?
2. Can you explain the steps involved in performing the multiplication
of two 2-D Matrices?
3. How do you calculate the trace of a given 2-D Matrix? Provide an
example.
4. Describe the process of implementing the Transpose operation on a
2-D Matrix using suitable code or algorithm.
Reference Books:
1. Brian W. Kernighan, Dennis M. Ritchie, “The C Programming Language:
ANSI C Version”, 2/e, Prentice-Hall/Pearson Education-2005.
2. E. Balagurusamy, “Programming in ANSI C” 4thed.,Tata McGraw-Hill
Education, 2008.
3. Mark Allen weiss, Data Structures and Algorithm Analysis in C, 2008,
Third Edition, Pearson Education.