Documentation

# 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

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 $\mathit{x}$ that satisfy $\mathrm{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 $\mathit{A}{\mathit{x}}_{1}=0$, within roundoff error.

`x1 = null(A)`
```x1 = 4×1 0.2236 0.6708 -0.6708 -0.2236 ```
`norm(A*x1)`
```ans = 4.4019e-15 ```

Now calculate a rational basis for the null space. Confirm that $\mathit{A}{\mathit{x}}_{2}=0$.

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

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

Underdetermined linear systems $\mathrm{Ax}=\mathit{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 $\mathit{A}{\mathit{x}}_{0}=\mathit{b}$, where $\mathit{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 0 0 0.0623 0.0010 ```

The complete general solution to the underdetermined system has the form $\mathit{x}={\mathit{x}}_{0}+\mathrm{Ny}$, where:

• $\mathit{N}$ is the null space of $\mathit{A}$.

• $\mathit{y}$ is any vector of proper length.

• ${\mathit{x}}_{0}$ 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 $\mathrm{Ax}=\mathit{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 1.4963 -1.5192 0.7354 0.0093 ```
`norm(A*x-b)`
```ans = 2.9513e-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`.