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
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.