MATRIX MULTIPLICATION PROGRAM

MATRIX MULTIPLICATION PROGRAM

In this “MATRIX MULTIPLICATION PROGRAM” article, You can learn about matrix multiplication programs, matrix multiplication basics, dimensions, types of matrices, scalar multiplication, dot product, rule of multiplying matrices, algorithm, c and python program, and matrix multiplication program using python numpy.

MATRIX MULTIPLICATION BASICS

A matrix is a rectangular arrangement of numbers into rows and columns. it is also known as a 2-D array. Each cell contains a number and each number in a matrix is referred to as a matrix element or entry.

The dimensions of the matrix tell its size: the number of rows and columns of the matrix, in that order. For example,

MULTIPLYING MATRICES
MULTIPLYING MATRICES

Since Matrix A has one row and three columns, so it’s dimension is 1 × 3, pronounced as “1 by 3”. Similarly, Matrix B has three rows and two columns, so its dimensions are 3 × 2.

No of rows comes first then no of columns. (Dimension)

Row is treated as row i and column is treated as column j of Matrix A is denoted as Ai,j.

There are different types of matrices,

  • Square Matrix.
  • Symmetric Matrix.
  • Triangular Matrix.
  • Diagonal Matrix.
  • Identity Matrix.
  • Orthogonal Matrix.

SCALAR MULTIPLICATION

The term “SCALAR” means (of a quantity) having only magnitude, not direction. Like, 2, 1, 10 etc real numbers.

The term scalar multiplication refers to the product of a real number and a matrix. In scalar multiplication, each entry in the matrix is multiplied by the given scalar. For example,

Scalar multiplication
Scalar multiplication

Since, A is multiplied with a real number i.e. 3 thus each entry in the matrix is multiplied by 3.

In many cases, the repeated addition of a matrix is done as A+ A+ A = 3 ( A ).

DOT PRODUCT

We are familiar with ordered pairs, for example (2,5), and perhaps even ordered triples, for example (3,1,8).

We can find the dot product of two n-tuples of equal length by summing the products of corresponding entries.

For example, to find the dot product of two ordered pairs, we multiply the first coordinates and the second coordinates and add the results.

DOT PRODUCT
DOT PRODUCT

Ordered n-tuples are often indicated by a variable with an arrow on top. For example, we can let a⃗=(3,1,8) and b⃗=(4,2,3). The expression a⃗⋅b⃗ indicates the dot product of these two ordered triples and can be found as follows:

a⃗⋅b⃗=(3,1,8)⋅(4,2,3)

=3⋅4+1⋅2+8⋅3

=12+2+24

=38

Notice that the dot product of two n-tuples of equal length is always a single real number.

To perform matrix multiplication, at least 2 matrices are required. Thus there are different types of matrices, there are some rules given below, which are used to perform matrix multiplication.

RULE OF MULTIPLYING MATRICES

For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The result matrix has the number of rows of the first and the number of columns of the second matrix.

We can add, subtract, multiply, and divide 2 matrices. To do so, we are taking input from the user for row number, column number, first matrix elements, and second matrix elements. Then we are performing multiplication on the matrices entered by the user.

In matrix multiplication, the first matrix one-row element is multiplied by the second matrix all column elements.

The resulting matrix dimension is First matrix row size and second matrix column size.

Matrix Multipllcation
Matrix Multipllcation

ALGORITHM:

C PROGRAM

PYTHON PROGRAM:

INPUT OUTPUT:

NUMPY IN PYTHON

A Very simple program using numpy in python.

This program is common in many examinations. Do practice with these programs.

Matrix multiplication program has a simple trick to remember the code, read it as,

The given above short note is helpful to you.

YOU MIGHT LIKE:

https://www.shoutcoders.com/divide-and-conquer-quick-sort/

https://www.shoutcoders.com/activity-selection-problem/

https://www.shoutcoders.com/fifo-page-replacement-algorithm/

https://www.shoutcoders.com/memory-management-note/

If you feel any question regarding this, feel free to comment below, and Hope that you can learn something new today. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami