- Matlab Matrix - Discussion
- Matlab Matrix - Useful Resources
- Matlab Matrix - Quick Guide
- Matlab-Matrix - Deletion Row & Coloumn
- Matlab-Matrix - Transpose
- Matlab-Matrix - Rank
- Matlab-Matrix - Trace
- Matlab-Matrix - Inverse
- Matlab-Matrix - Matrix Determinant
- Matlab-Matrix - Subtraction
- Matlab-Matrix - Addition
- Matlab-Matrix - Multiplication
- Matlab-Matrix - Working with Matrices
- Matlab-Matrix - Create Matrix
- Matlab-Matrix - Environment Setup
- Matlab-Matrix - Introduction
- Matlab-Matrix - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Matlab-Matrix - Multippcation
Consider two matrices A and B. If A is an m x n matrix and B is an n x p matrix, they could be multipped together to produce an m x n matrix C. Matrix multippcation is possible only if the number of columns n in A is equal to the number of rows n in B.
In matrix multippcation, the elements of the rows in the first matrix are multipped with the corresponding columns in the second matrix.
Each element in the (i, j)thposition, in the resulting matrix C, is the summation of the products of elements in ith row of the first matrix with the corresponding element in the jth column of the second matrix.
Matrix multippcation in MATLAB is performed by using the * operator.
Example
Consider following example in MATLAB
a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; prod = a * b
Output
The execution in MATLAB will display the following result −
>> a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; prod = a * b prod = 18 10 -4 27 14 -4 22 16 -6 >>
The mtimes function
You can also make use of the function mtimes to multiply two given matrices. It is a builtin function available in MATLAB.
Example
Consider following example −
a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; test= mtimes(a,b)
Output
On execution in MATLAB the output is as follows −
>> a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; test= mtimes(a,b) test = 18 10 -4 27 14 -4 22 16 -6 >>Advertisements