%% Null Space of Matrix
% Use the null function to calculate orthonormal and rational basis vectors for the null space of a matrix. The null space of a matrix contains vectors x that satisfy \textrm{Ax}=0.
%
% Create a 4-by-4 magic square matrix. This matrix is rank deficient, with one of the singular values being equal to zero.

A = magic(4)

%
% Calculate an orthonormal basis for the null space of A. Confirm that Ax_1 =0, within roundoff error.

x1 = null(A)

%

norm(A*x1)

%
% Now calculate a rational basis for the null space. Confirm that Ax_2 =0.

x2 = null(A,'r')
norm(A*x2)

% x1 and x2 are similar, but are normalized differently.
%
% Copyright 2018 The MathWorks, Inc.