MATLAB:
Do the following with the provided .m file
(a) In the .m file, we have provided three questions. Make sure to answer them.
(b) Now on the MATLAB prompt, let us create any two 3 × 3 matrices and you can do the following:
X=magic(3);
Y=magic(3);
X*Y
matrixMultiplication3by3(X,Y)
(c) Now write a new function in MATLAB called matrixMultiplication that can multiply any two n × n matrix. You can safely assume that we will not test your program with matrices that do not have their inner dimensions matched up
CODE:
function [C] = matrixMultiplicationFor3by3(A,B)
%{
Question: What does b1, b2, and b3 contain?
%}
b1=B(:,1);
b2=B(:,2);
b3=B(:,3);
%{
Question: What does : when used in the
paranthesis do?
%}
a1=A(:,1);
a2=A(:,2);
a3=A(:,3);
%{
Question: The algorithm below to calculate
c1 and c2 and c3, is this the matrix multiplication
involving the column picture or the row picture?
Explain your answer clearly.
%}
c1=a1*b1(1)+a2*b1(2)+a3*b1(3);
c2=a1*b2(1)+a2*b2(2)+a3*b2(3);
c3=a1*b3(1)+a2*b3(2)+a3*b3(3);
C=[c1 c2 c3];
1) here b1 b2 and b3 denote 1st column,2nd column and 3 rd column respectively as the row is not specified it can take any values.
2) : used in the paranthesis means that the particular field of the matrix can take any values,starting from the start of the particular field to the end of the field.Here field can be row or column.
3)The matrix multiplication here is involving the column picture as the matrix a and b are column matrix and c1 c2 and c3 is obtained by multiplying each element of the column a1 with first element of the column matrix b1 and a2 with 2nd element of the column matrix b1 and a3 with the 3rd element of the column matrix b1,similarly for c2 and c3.
and finally C is formed by combining c1 c2 and c3.
Get Answers For Free
Most questions answered within 1 hours.