  function P2Grade()
% Checks out Best2by2...
n = 100;
noise = .01;
A = randn(n,n);
[Q,T] = schur(A);
X = Q(:,1:2)*randn(2,2)+noise*randn(n,2);

clc
BCVL = Best2by2CVL(A,X)
BYOU = Best2by2(A,X)
err = norm(BCVL-BYOU)


  function B = Best2by2CVL(A,X)
% A is nxn, X is nx2.
% B is a 2x2 matrix that minimizes norm(AQ-QB,'fro').

% norm(AQ-QB,'fro')^2 = 
%                       || A*X(:,1) - B(1,1)*X(:,1) - B(2,1)*X(:,2) ||^2 +
%                       || A*X(:,2) - B(1,2)*X(:,1) - B(2,2)*X(:,2) ||^2 
%                     = || d - Cx ||^2
% where 
[n,m] = size(X);
d = [A*X(:,1) ; A*X(:,2)];
C = [X  zeros(n,2); zeros(n,2) X];
b = C\d;
B = reshape(C\d,2,2);
