function Apr28()

% Note that if Q is orthogonal then norm(AZ-B,'fro') = norm(Q'AZ - Q'B,'fro')
% In other words, the solution does not change if we premultiply A and B
% by the same othogonal matrix. So compute {Q,R] = qr(A,B) and notice
% that if A1 = Q'*A and A2 = Q'B then 
%    norm(Q'AZ - Q'B,'fro')^2 = norm(A1*Z - B1,'fro')^2 
%                             = norm(A1(1:6,:)*Z - B1(1:6,:),'fro')^2
%     = norm(A1(1:3,:)*Z - B1(1:3),'fro')^2 + norm(B1(4:6,:))^2
% So compute RA = Q(:,1:3)'*A and RB = Q(:,1:3)'*B once and for all
% and then hand this over to lsqnonlin:
    function y = F(theta,RA,RB)
 c1 = cos(theta(1); s1 = cos(theta(1);
 c2 = cos(theta(2); s2 = cos(theta(2);
 c3 = cos(theta(3); s3 = cos(theta(3);
 
 Y = RA*[1 0 0; 0 c1 s1;; 0 -s1 c1]*...
       [c2 s2 0; -s2 c2 0; 0 0 1]*...
       [1 0 0; 0 c3 s3; 0 -s3 c3] - RB;
 y = reshape(9,1)


% For a given Z, the best v is given by (AZ-B)'*e/n where e = ones(n,1).
% Thus, to find the best Z we must minimize
%          norm(AZ - e((AZ-B)'*e/n)' - B,'fro') = norm(Atilde*Z - Btilde)
% where Atilde = A - e*(e'*A)/n and Btilde = B - e*(e'*B)/n. Describe a
      function F that could be passed to lsqnonlin to solve this problem
          
          

     
fu