Write a MATLAB nested function, MyTransposeProduct INPUT to the function is any
ID: 3554621 • Letter: W
Question
Write a MATLAB nested function, MyTransposeProduct
INPUT to the function is any matrix, A
OUTPUT is the product of the matrix with its transpose. This of course can be done two ways, AA' and A'A, so there will be two output arguments (in the order shown)
Use previous assignments MyTranspose and mymatmult . Function mymatmult should be a subfunction in MyTransposeProduct. Just like in those assignments, the transpose and multiplications should be done with for-loops.
Example
SOLUTION:
function [A1, A2] = MyTransposeProduct(A)
A1 = A; %replace with your code to compute A'A and AA'
%place your nested function here
function [C]=mymatmult(A,B)
% mymatmult - multiplies two matrices, traditional looping
end
end
Explanation / Answer
function [A1, A2] = MyTransposeProduct(A)
sizeA=size(A);
transpA=zeros(sizeA(2),sizeA(1));
for i=1:sizeA(2)
for j=1:sizeA(1)
transpA(i,j)=A(j,i);
end
end
function [C]=mymatmult(A,B)
sizeA=size(A);
sizeB=size(B);
temp=zeros(sizeA(1),sizeB(2));
if (sizeA(2)==sizeB(1))
for i=1:sizeA(1)
for j=1:sizeB(2)
temp(i,j)=0;
for k=1:sizeA(2)
temp(i,j)=temp(i,j)+A(i,k)*B(k,j);
end
end
end
C=temp;
else
disp('Cannot multiply matrices');
end
end
A1=mymatmult(A,transpA);
A2=mymatmult(transpA,A);
end
% Type [A1 A2]=MyTransposeProduct(A) in the command window to get the result
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.