Matrix Multiplication in C | Matrix Chain Multiplication Program in C

# Matrix Multiplication in C

A is the same as the number of rows in B.

The general definition of matrix multiplication is as follows: If A is a n×m matrix and B is a m×p matrix, their product C will be a n×p matrix such that the general element cij of C is given by

cij=∑k=1maikbkj.

Note that in general AB is not equal to BA (matrix multiplication is not commutative).

Example:

×[560−1]=

Since a vector is simply a one-dimensional matrix, the definition of matrix multiplication given above also applies when a vector is multiplied by an appropriate matrix, e.g.,

×=.

The operator * is used for matrix multiplication, as you may have guessed. For example, if

a =

1 2

3 4

and

b =

5 6

0 -1

the statement

c = a * b

results in

c =

5 4

15 14

Note the important difference between the array operation a .* b (evaluate by hand and check with MATLAB) and the matrix operation a * b.

To multiply a matrix by a vector in that order, the vector must be a column vector. So if

b = [2 3]'

the statement