% Subroutine of IPM_pK 
%
% Jan 12, 2012

function [MA,MB] = rearrange(A)

n = sqrt(size(A,1));

count = 1;
MA = zeros(n*(n+1)/2,size(A,2));
MB = zeros(n^2,n*(n+1)/2);

for j = 1:n
  for i = 1:j
    if i == j
      MA(count,:) = A(n*(i-1) + j,:);
      MB(n*(i-1) + j,count) = 1; 
      count = count + 1;
    end
    if i < j
      MA(count,:) = sqrt(2)*A(n*(i-1) + j,:);
      MB(n*(i-1) + j,count) = 1/sqrt(2);
      MB(n*(j-1) + i,count) = 1/sqrt(2);
      count = count + 1;
    end
  end
end
      