Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note 1: Ensure that you follow MATLAB naming rules for variables and filenames N

ID: 3811827 • Letter: N

Question

Note 1: Ensure that you follow MATLAB naming rules for variables and filenames
Note 2: Insert comments wherever appropriate for clarity of your program
Note 3: Your script must have no syntax errors; if it fails to run or if errors (with red messages on the Command Window) are generated then no points will be given
Note 4: Each problem should have a comments section that describes what that script does
Note 5: Each part should start with clc,clear as the first instruction of that section

3. (40 Points Using MATLAB loops and the size(0 function, create a MATLAB script that will multiply 2 matrices. Note that sizeCA) will return a row vector containing the dimensions of a matrix A. Thus you need to code a statement such as Trowsize, colsizel size(A) You may not multiply matrices A and Bjust using A *B, you MUST use matrix indexing to compute the matrix product as ifyou were multiplying the matrices using pencil and paper

Explanation / Answer

clc %clc for first section
%A = [1 2 3; 4 5 6; 7 8 10] % matrix A
%B = [5 6 3; 4 1 2; 8 9 7] %matrix B
A=input("Enter matrix A values");
B=input("Enter matrix B values");
clc%clc for next section
[rowsA, colsA] = size(A);
[rowsB, colsB] = size(B);
if(colsA !=rowsB) %check if matrix multipicatn is possible
disp("Matrix multiplication not possible");
disp("Try again!Exiting the program");
else
theMatrixProduct = zeros(rowsA, colsA);%iniialise the product atrix to zzeros
for row = 1 : rowsA %loop to get the values and perform multiplictn of elements
   for col = 1 : colsB
       theSum = 0;
       for k = 1 : colsA
           theSum = theSum + A(row, k) * B(k, col);
       end
       theMatrixProduct(row, col) = theSum;
   end
end
clc%clc after for loop section
disp( theMatrixProduct);
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote