Null space of matrix
Z = null(A)
Z = null(A,'r')
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
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
ans = 0
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
ans = 1.8291e-14
A— Input matrix
Complex Number Support: Yes
Z— Null space basis vectors
Null space basis vectors, returned in the columns of a matrix.
satisfies the properties:
A*Z has negligible elements.
size(Z,2) is an estimate of the nullity of
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
The "rational" basis for the null space
null(A,'r') is obtained from
the reduced row echelon form of
A, as calculated by
Usage notes and limitations:
Generated code might return a different basis than MATLAB®
Code generation does not support the rational basis option (second input).
Code generation does not support sparse matrix inputs for this function.
Usage notes and limitations:
Z = null(A, 'r') is not supported.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).