clear
echo on
%This script gives the solution to
%problem 2.  Part e uses the function
%matmult(a,b).
%
%a.
a=[1 2 3 4;3 4 5 6;5 6 7 8]
b=[1 2;2 3;3 4;4 5]
%
%b.
atrans=a'
c=a*b
%
%c.
diff=c'-b'*a'
%Since the result is zero, the equivalence
%is demonstrated.
%
%d. The computer gives an error that the
%inner matrix dimensions must agree.  You
%can't perform this operation.
%
%e. This answer uses the function matmult(a,b)
%which must be saved separately in the same
%directory.
difference=c-matmult(a,b)
%Since the difference is zero, the two matrix
%multiplication methods are equivalent.
echo off


______________________________________________


function c=matmult(a,b)
%This function demonstrates how to use
%loops to multiply two matrices a and
%b.

[n,m]=size(a);
[p,q]=size(b);

if m ~= p
 disp('you made a boo boo')
else

c=zeros(n,q);
for i=1:n
 for j=1:q
  for k=1:m
   c(i,j)=c(i,j)+a(i,k)*b(k,j);
  end;
 end;
end;

end;