This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

null

Null space of matrix

Syntax

Z = null(A)
Z = null(A,'r')

Description

example

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

example

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).

Examples

collapse all

The null space of a matrix contains vectors that satisfy . Use the null function to calculate orthonormal and rational basis vectors for the null space of a matrix.

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 , within roundoff error.

x1 = null(A)
x1 = 4×1

   -0.2236
   -0.6708
    0.6708
    0.2236

norm(A*x1)
ans = 2.4738e-15

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

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

    -1
    -3
     3
     1

norm(A*x2)
ans = 0

x1 and x2 are similar, but are normalized differently.

Underdetermined linear systems 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. This example finds one particular solution to an underdetermined system and then obtains the general form for all solutions.

Create a 2-by-4 coefficient matrix and use backslash to solve the equation , where 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

         0
         0
    0.0623
    0.0010

The complete general solution to the underdetermined system has the form , where:

  • is the null space of

  • is any vector of proper length

  • 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 , 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

    1.4963
   -1.5192
    0.7354
    0.0093

norm(A*x-b)
ans = 1.8291e-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.

Algorithms

null(A) calculates the singular value decomposition of the matrix, [U,S,V] = svd(A,0). 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