Recall that to multiply two matrices the inner dimensions must be the same: ...
ID: 3680917 • Letter: R
Question
Recall that to multiply two matrices the inner dimensions must be the same: ...
Therefore, your code should check this condition, and raise an error if the condition is not met. For this you are to use MATLAB's built in error function, refer to MATLABs built in help for more information regarding error. The elements of [C] mx p are obtain via ...
Refer to photo...
Therefore your code will require three nested loops. You are to write this code as a function called matmul that accepts the two matrices as arguments. In this question you will write your own custom code to perform matrix multiplication. Before we continue to describe this question, we need some notation. We let [Alnxm denote a matrix A with n rows and m columns. Given such a matrix A we denote the element in the ith row and jth column by aij Recall that to multiply two matrices the inner dimensions must be the same: Therefore, your code should check this condition, and raise an error if the cono d raise an error if the condition is not met. or this you are to use MATLAB's built-in error function, refer to MATLAB's built-in help for more information regarding error. The elements of [Clmxp are obtained via TI Therefore, your cod will nquire tre neted lop Therefore, your code will require three nested loops. You are to write this code as a function called matmul that accepts the two matrices as argu- ments.
Explanation / Answer
%function for multiplication and returns the resulting mat
function [ Cp ]= product(A,B)
[n,m] = size(A);
[p,q] = size(B);
Cp = zeros(n,p);
if p~=m
error('In compatable multiplication.');
end
for k = 1:n
for j = 1:q
temp=0;
for i = 1:p
temp = temp+(A(k,i)*B(i,j));
end
Cp(k,j) = temp;
end
end
end
----------------Example execution here------------------------------
A=[1]
B=[4]
C=product(A,B)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.