function showimage(A)
    % Show the matrix A as a grayscale image.
    % Elements should lie between 0 and 1, or will be truncated to
    % this range.

    k = rank(A);

    % restrict elements to interval [0,1]:
    A = min(A, 1);
    A = max(A, 0);

    % Put in as components of RGB map:
    % All three components equal ==> gray scale
    [m,n] = size(A);
    C = zeros(m,n,3);
    C(:,:,1) = A;
    C(:,:,2) = A;
    C(:,:,3) = A;

    image(C)
    title(sprintf('Rank %i matrix', k))
