Matrix Multiplication By now you should understand the rules
Matrix Multiplication
By now, you should understand the rules for matrix multiplication in linear algebra and how MATLAB makes this easy. To fully appreciate how MATLAB does this, you will “manually” write code to replicate what MATLAB’s matrix multiplication operator (*) does “behind the scenes.” Using the matrices A and B shown below, write a nested for loop in MATLAB to “manually” multiply them according to the rules of linear algebra. Your result should agree with the product AB shown below. Note: In your code, you are allowed to use the MATLAB matrix multiplication operator (*) only with scalar operands.
Solution
% matlab code multiply two matrix
A = [1 2; 3 4];
 B = [2 3; 4 5];
[rowA,columnA] = size(A);
 [rowB,columnB] = size(B);
% Initialise the matrix C with zeros
 C = zeros(columnA,rowB);
 for i = 1:rowA
 for j = 1:columnA
 for k = 1:rowA
 C(i,j) = C(i,j) + A(i,k)*B(k,j);
 end
 end
 end
disp(\'A= \');
 disp(A);
 disp(\'B= \');
 disp(B);
 disp(\'C= \');
 disp(C);
%{
 output:
A=
 1 2
 3 4
 B=
 2 3
 4 5
 C=
 10 13
 22 29
 
 %}

