Main Content


Null space of matrix



Z = null(A) returns an orthonormal basis for the null space of A.


Z = null(A,'r') returns a "rational" basis for the null space of A that is typically not orthonormal. If A is a small matrix with small integer elements, then the elements of Z are ratios of small integers. This method is numerically less accurate than null(A).


collapse all

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 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)
A = 4×4

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

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

x1 = null(A)
x1 = 4×1


ans = 2.8952e-15

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

x2 = null(A,'r')
x2 = 4×1


ans = 0

x1 and x2 are similar, but are normalized differently.

Find one particular solution to an underdetermined system, and then obtain the general form for all solutions.

Underdetermined linear systems Ax=b involve more unknowns than equations. An underdetermined system can have infinitely many solutions or no solution. When the system has infinitely many solutions, they all lie on a line. The points on the line are all obtained with linear combinations of the null space vectors.

Create a 2-by-4 coefficient matrix and use backslash to solve the equation Ax0=b, where b is a vector of ones. Backslash calculates a least-squares solution to the problem.

A = [1 8 15 67; 7 14 16 3]
A = 2×4

     1     8    15    67
     7    14    16     3

b = ones(2,1);
x0 = A\b
x0 = 4×1


The complete general solution to the underdetermined system has the form x=x0+Ny, where:

  • N is the null space of A.

  • y is any vector of proper length.

  • x0 is the solution computed by backslash.

Calculate the null space of A, and then use the result to construct another solution to the system of equations. Check that the new solution satisfies Ax=b, up to roundoff error.

N = null(A)
N = 4×2

   -0.2977   -0.8970
   -0.6397    0.4397
    0.7044    0.0157
   -0.0769   -0.0426

x = x0 + N*[1; -2]
x = 4×1


ans = 2.8908e-14

Input Arguments

collapse all

Input matrix.

Data Types: single | double
Complex Number Support: Yes

Output Arguments

collapse all

Null space basis vectors, returned in the columns of a matrix. Z satisfies the properties:

  • A*Z has negligible elements.

  • size(Z,2) is an estimate of the nullity of A.

If rank(A) is equal to size(A,2), then Z is empty.


null(A) calculates the singular value decomposition of the matrix, A = U*S*V'. The columns of V that do not correspond to nonzero singular values form a set of orthonormal basis vectors for the null space.

The "rational" basis for the null space null(A,'r') is obtained from the reduced row echelon form of A, as calculated by rref.

Extended Capabilities

See Also

| | |

Introduced before R2006a