Compute the following using Mathematica Write a function g[A_,B_] that takes as
ID: 3789836 • Letter: C
Question
Compute the following using Mathematica
Write a function g[A_,B_] that takes as input two matrices A and B (not necessarily square) and checks whether the number of columns of A is the same as the number of rows of B. If the dimensions match, then the function returns the product AB, otherwise it returns the message "Error, the matrices cannot be multiplied". Test your function on a couple of matrices.
Generate a square nxn matrix M, whose diagonal elements Subscript[M, ii]are equal to n-1 and the other elements Subscript[M, ij] i!=j are equal to 1. Test it for n=10.
Explanation / Answer
function [product] = g(A_,B_)
[row1 col1] = size(A_);
[row2 col2] = size(B_);
if col1 == row2
product = A_*B_;
else
product = 'Error, the matrices cannot be multiplied';
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.