50% found this document useful (2 votes)
11K views5 pages

Algorithm For Matrix Addition-1

The document describes algorithms for matrix addition, subtraction, and multiplication. For matrix addition, it explains that the matrices must be the same order (dimensions) and the algorithm iterates through each element, adding the values at the corresponding indices of the two matrices to populate the result matrix. Matrix subtraction is similar, but subtracts the corresponding element values instead of adding them. Matrix multiplication is only defined if the number of columns in the first matrix equals the rows of the second. The algorithm initializes the result matrix to zero and iterates through, multiplying each element of the first row/column with the corresponding element of the second column/row and accumulating the results.

Uploaded by

m azfar tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
11K views5 pages

Algorithm For Matrix Addition-1

The document describes algorithms for matrix addition, subtraction, and multiplication. For matrix addition, it explains that the matrices must be the same order (dimensions) and the algorithm iterates through each element, adding the values at the corresponding indices of the two matrices to populate the result matrix. Matrix subtraction is similar, but subtracts the corresponding element values instead of adding them. Matrix multiplication is only defined if the number of columns in the first matrix equals the rows of the second. The algorithm initializes the result matrix to zero and iterates through, multiplying each element of the first row/column with the corresponding element of the second column/row and accumulating the results.

Uploaded by

m azfar tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ALGORITHM FOR MATRIX ADDITION

If A and B are two matrices of same order m x n (to be read as m by n matrix) then their
addition is defined by A + B. For example if A is a matrix of order 2×3 and B is a matrix
of same order 2×3 then addition is possible and the resultant matrix will be of order
2×3. If a matrix A has its order 2×3 and another matrix B has its order 3×2 then addition
is not possible. So before adding any number of matrices we must check that whether
each of the matrices are of same order or not then we need to proceed further.
ALGORITHM:
(Matrix addition Algorithm) Suppose A and B are two matrix arrays of order m x n,
and C is another matrix array to store the addition result. i, j are counters.
Step1: Start
Step2: Read: m and n
Step3: Read: Take inputs for Matrix A[1:m, 1:n] and Matrix B[1:m, 1:n]
Step4: Repeat for i := 1 to m by 1:
                        Repeat for j := 1 to n by 1:
                                    C[i, j] := A[i, j] + B[i, j]
                        [End of inner for loop]
            [End of outer for loop]
Step5: Print: Matrix C
Step6: Exit.

Also See:

C PROGRAM FOR MATRIX ADDITION, SUBTRACTION, MULTIPLICATION AND


TRANSPOSE, DETERMINANT, INVERSE AND OTHER PROPERTISE OF 3
DIMENSIONAL ARRAYS
FLOWCHART FOR MATRIX ADDITION

ALGORITHM TO FIND MATRIX SUBTRACTION


If A and B are two matrices having same order m x n and C be the resultant Matrix then
we can write C = A – B. The order of Matrix C will also be m x n. To perform subtraction,
order of each matrix should be same otherwise subtraction is not possible as it stated
above in the case of Matrix Addition.

ALGORITHM:
(Matrix Subtraction Algorithm) Suppose A and B are two matrix arrays of order m x n,
and C is another matrix array to store the addition result. i, j are counters.

Step1: Start
Step2: Read: m and n
Step3: Read: Take inputs for Matrix A[1:m, 1:n] and Matrix B[1:m, 1:n]
Step4: Repeat for i := 1 to m by 1:
Repeat for j := 1 to n by 1:
C[i, j] := A[i, j] – B[i, j]
[End of inner for loop]
[End of outer for loop]
Step5: Print: Matrix C[1:m, 1:n]
Step6: Exit.

FLOWCHART FOR MATRIX SUBTRACTION:


ALGORITHM TO FIND MATRIX MULTIPLICATION
If A and B are two matrices of order m x n and p x q then their multiplication possible
only if the number of columns in first matrix is equal to the number of rows in second
matrix. Suppose C a matrix where the result of A x B will be stored then the order of C is
m x p.

(Matrix Multiplication Algorithm) Suppose A and B are two matrices and their order
are respectively m x n and p x q. i, j and k are counters. And C to store result.

Step1: Start.
Step2: Read: m, n, p and q
Step3: Read: Inputs for Matrices A[1:m, 1:n] and B[1:p, 1:q].
Step4: If n ≠ p then:
Print: Multiplication is not possible.
Else:
Repeat for i := 1 to m by 1:
Repeat for j := 1 to q by 1:
C[i, j] := 0 [Initializing]
Repeat k := 1 to n by 1
C[i, j] := C[i, j] + A[i, k] x B[k, j]
[End of for loop]
[End of for loop]
[End of for loop]
[End of If structure]
Step5: Print: C[1:m, 1:q]
Step6: Exit.

FLOWCHART FOR MATRIX MULTIPLICATION

You might also like