% Subroutine of IPM_AK.
%
% Jan 12, 2012

function MA = rearrange(A)

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

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

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