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

Numerical Methods for Engineers, ME 325, Fall 2017 4. Write a user-defined funct

ID: 3594046 • Letter: N

Question

Numerical Methods for Engineers, ME 325, Fall 2017 4. Write a user-defined function, i.e., matrix_ mult_IYOUR WSU IDJ.m, calculating a matrix multiplication (4 pt). Requirement matrix mult_Al11B222.m: 1- The students MUST NOT use the built-in Octave (or Matlab) syntax to execute the matrix multiplication, i.e., A B, for the multiplication for matrices A and B. If the matrix multiplication is calculated using Octave (or Matlab) syntax, i.c., A B, no credit will be given. 2. Instead, the students need to follow the principle of the matrix multiplication (see below) 3. It requires two input arguments, one for the first matrix and the other for the second matrix, 4· The function should include a script for error message when the matrix multiplication 5. The student needs to turn in the following: (a) The Octave (or Matlab) script for user and use "for" loop (or "while" loop) to accomplish the matrix multiplication. (2 pt) and one output matrix (result of the multiplication of two matrices). cannot be calculated, due to the size mismatch for the matrices A and B. (I pt) defined function, "matrix mult_A111B222.m" and the screen capture of the Octave (or Matlab) command window, showing the function run (see the example execution above) (I pt). Given a mxn matrix A and a nxp matrix B, the multiplication of matrices of A and B, i.e. AB is defined to be a mxp matrix C, whose elements, i.e., Cy, are computed from the elements of A and B, i.e., aa and by, according to In command window, if the matrices of A and B are given as 20 3 4 The outcome of matrix mult_A111B222(A,B) should be in the following 14 17 AB =C In other words, if the student type the C command window, it should return as matrix mult Al11B222(A,B) in the Octave (or Matlab) You need to turn in Octave (or Matlab) output by running the developed script, matrix mult A111B222.m in the command window as given below >>A-142 B-[21:34 enter> C matrix mult Al11B222(A,B) Center> 14 17

Explanation / Answer

Please the below Matlab function for matrix multiplication without using standard multplication operator:


function C = matrix_mult_A111B222(A,B)

[r1,c1] = size(A)
[r2,c2] = size(B)

%Asign zero to initial output
C = zeros(r1,c2)

%Check for correct matrix size
if c1 != r2
disp "Matrices with entered orders can't be multiplied with each other"
else
%Matrix multiplication Logic
for i = 1:r1
for j = 1:c2
for k = 1:c1
C(i,j) = C(i,j) + (A(i,k)*B(k,j))
end
end
end
end   

end