Lab On C 1
Lab On C 1
Analysis:
Matrix operation – Multiplication: Matrix multiplication, also known as matrix
product and the multiplication of two matrices, produces a single matrix. It is a type
of binary operation.
If A and B are the two matrices, then the product of the two matrices A and B are
denoted by:
X = AB
Hence, the product of two matrices is the dot product of the two matrices.
If A is a m×n matrix and B is a p×q matrix, then the matrix product of A and B is
represented by:
X = AB
Where X is the resulting matrix of m×q dimension.
Matrix multiplication Rules
a. The product of two matrices A and B is defined if the number of columns of A
is equal to the number of rows of B.
b. If AB is defined, then BA need not be defined
c. If both A and B are square matrices of the same order, then both AB and BA
are defined.
d. If AB and BA are both defined, it is not necessary that AB = BA.
e. If the product of two matrices is a zero matrix, it is not necessary that one of
the matrices is a zero matrix.
Algorithm:
Matrix operation – Multiplication:
Input: matrices A and B
Let C be a new matrix of the appropriate size
For i from 1 to n:
For j from 1 to p:
Let sum = 0
For k from 1 to m:
Set sum ← sum + Aik × Bkj
Set Cij ← sum
Return C
Source Code:
[P.T.O]
Input Output
Matrix Multiplication
Input Output
Matrix Addition
Input Output
Matrix Subtraction
Remarks
Here only Addition, Subtraction & Multiplication are implemented. Technically, there
is no such thing as matrix division. Dividing a matrix by another matrix is an
undefined function. The closest equivalent is multiplying by the inverse of another
matrix. In other words, while [A] ÷ [B] is undefined, you can solve the problem [A]
* [B]-1.