function nulla(A)
% NULLA(A) is a matrix whose columns form a basis
% for the null space of A. The basis is obtained from
% the reduced row echelon form of A.
[R,jp] = rref(A);
[m,n] = size(A);
r = length(jp);
nmr = n - r;
N = zeros(n,nmr);
kp = other(jp,n);
    % Construct N, the matrix of basis vectors
for q = 1:nmr
    N(kp(q),q) = 1;
    N(jp,q) = -R(1:r,kp(q));
end
disp(['Basis for Null(A):'])
disp(N)
end

function kp = other(jp,n)
% OTHER(jp,n) contains the indices remaining in 1,2,...,n
% when the indices in jp are removed.
x = 1:n;
x(jp) = zeros(1,length(jp));
kp = x(find(x));
end
