Skip to main content
infervour.com

Back to all posts

How to Perform Matrix Multiplication In MATLAB?

Published on
3 min read
How to Perform Matrix Multiplication In MATLAB? image

Best MATLAB Guides to Buy in October 2025

1 MATLAB: A Practical Introduction to Programming and Problem Solving

MATLAB: A Practical Introduction to Programming and Problem Solving

BUY & SAVE
$48.80 $66.95
Save 27%
MATLAB: A Practical Introduction to Programming and Problem Solving
2 MATLAB and Simulink Crash Course for Engineers

MATLAB and Simulink Crash Course for Engineers

BUY & SAVE
$44.99 $59.99
Save 25%
MATLAB and Simulink Crash Course for Engineers
3 MATLAB: A Practical Introduction to Programming and Problem Solving

MATLAB: A Practical Introduction to Programming and Problem Solving

BUY & SAVE
$30.67 $64.95
Save 53%
MATLAB: A Practical Introduction to Programming and Problem Solving
4 MATLAB For Dummies (For Dummies (Computer/Tech))

MATLAB For Dummies (For Dummies (Computer/Tech))

BUY & SAVE
$23.51 $34.99
Save 33%
MATLAB For Dummies (For Dummies (Computer/Tech))
5 ISE MATLAB for Engineering Applications

ISE MATLAB for Engineering Applications

  • COMPREHENSIVE COVERAGE OF MATLAB TOOLS FOR ENGINEERING PROBLEMS.
  • REAL-WORLD EXAMPLES ENHANCE PRACTICAL UNDERSTANDING AND APPLICATION.
  • INTERACTIVE EXERCISES AND TUTORIALS TO BOOST HANDS-ON LEARNING.
BUY & SAVE
$54.00 $150.00
Save 64%
ISE MATLAB for Engineering Applications
6 MATLAB for Engineers

MATLAB for Engineers

BUY & SAVE
$206.27
MATLAB for Engineers
7 MATLAB for Brain and Cognitive Scientists (Mit Press)

MATLAB for Brain and Cognitive Scientists (Mit Press)

BUY & SAVE
$65.00
MATLAB for Brain and Cognitive Scientists (Mit Press)
8 Radar Systems Analysis and Design Using MATLAB

Radar Systems Analysis and Design Using MATLAB

BUY & SAVE
$97.96 $150.00
Save 35%
Radar Systems Analysis and Design Using MATLAB
9 Programming and Engineering Computing with MATLAB 2023

Programming and Engineering Computing with MATLAB 2023

BUY & SAVE
$70.96 $90.00
Save 21%
Programming and Engineering Computing with MATLAB 2023
10 MATLAB for Machine Learning: Unlock the power of deep learning for swift and enhanced results

MATLAB for Machine Learning: Unlock the power of deep learning for swift and enhanced results

BUY & SAVE
$35.77 $49.99
Save 28%
MATLAB for Machine Learning: Unlock the power of deep learning for swift and enhanced results
+
ONE MORE?

To perform matrix multiplication in MATLAB, you can use the built-in command * or the function mtimes(). Matrix multiplication in MATLAB follows the standard mathematical definition.

Here's an example of multiplying two matrices A (m x n) and B (n x p) to obtain the matrix C (m x p):

% Define the matrices A = [1 2; 3 4; 5 6]; % m x n matrix B = [7 8 9; 10 11 12]; % n x p matrix

% Perform matrix multiplication C = A * B; % OR C = mtimes(A, B);

The resulting matrix C will have dimensions m x p. The element C(i, j) is obtained by taking the dot product of the i-th row of matrix A and the j-th column of matrix B.

Make sure that the number of columns in matrix A matches the number of rows in matrix B for matrix multiplication to be valid. Otherwise, you will encounter an error.

Note that if you want to perform element-wise multiplication (corresponding elements multiplied together), you can use the .* operator instead.

How to calculate the trace of a matrix in MATLAB?

The trace of a matrix can be calculated in MATLAB using the trace function. The trace of a square matrix is defined as the sum of the elements on its main diagonal.

Here is an example of how to calculate the trace of a matrix in MATLAB:

% Define a matrix A = [1 2 3; 4 5 6; 7 8 9];

% Calculate the trace of the matrix trA = trace(A);

% Display the result disp('Trace of A: '); disp(trA);

When you run this code, MATLAB will display the following result:

Trace of A: 15

In this example, the trace of the matrix A is 15.

What is the MATLAB function to find the rank of a matrix?

The MATLAB function to find the rank of a matrix is rank(matrix).

What is the syntax to create a matrix in MATLAB?

To create a matrix in MATLAB, you can use the following syntax:

  1. Using square brackets [ ]:
  • For a 2x2 matrix:

matrix = [1 2; 3 4];

  • For a 3x3 matrix:

matrix = [1 2 3; 4 5 6; 7 8 9];

  1. Using the "reshape" function:
  • For a 2x2 matrix:

vector = [1 2 3 4]; matrix = reshape(vector, 2, 2);

  • For a 3x3 matrix:

vector = [1 2 3 4 5 6 7 8 9]; matrix = reshape(vector, 3, 3);

  1. Using the "eye" function for identity matrices:
  • For a 2x2 identity matrix:

matrix = eye(2);

  • For a 3x3 identity matrix:

matrix = eye(3);

  1. Using the "zeros" or "ones" functions:
  • For a 2x2 matrix of zeros:

matrix = zeros(2);

  • For a 3x3 matrix of ones:

matrix = ones(3);

These are some common ways to create matrices in MATLAB, but there are many more possibilities depending on your specific needs and requirements.

What is the MATLAB function for matrix reduction using Gaussian elimination?

The MATLAB function for matrix reduction using Gaussian elimination is rref (Row Reduced Echelon Form).

What is the MATLAB function for matrix exponentiation?

The MATLAB function for matrix exponentiation is expm(matrix).