How to find a null space vector in Julia

A matrix’s null space is the set of vectors that, when multiplied with the original matrix, result in the zero vectorA vector with a zero magnitude.. It is the set of solutions to the equation Ax=0Ax = 0, where AA is a matrix of size m×nm \times n and xx is a vector.

It is an important concept in linear algebra and has many applications in physics, engineering, and computer science fields.

Note: The null space can also be considered the set of all vectors perpendicular to the row space of matrix AA. This is because if a vector is perpendicular to all the rows of AA, then it will be orthogonal to any linear combination of those rows, which means it will be in the null space of AA.

Example

Let matrix AA be

A=(A01A0nAm0Amn)A=\left(\begin{array}{ccc} A_{01} & \ldots & A_{0 n} \\ \ldots & \ldots & \ldots \\ \ldots & \ldots & \ldots \\ A_{m 0} & \ldots & A_{m n} \end{array}\right)

and the vector xx be

x=(x0xn).x=\left(\begin{array}{c} x_0 \\ \cdot \\ \cdot \\ x_n \end{array}\right).

For xx to be the null space vector, the following equations should be satisfied:

A00x0+A01x1++A0nxn=0Am0x0+Am1x1++Amnxn=0A_{0 0} x_0+A_{0 1} x_1+\ldots \ldots + A_{0 n} x_n=0 \\ \cdot \\ \cdot \\ A_{m 0} x_0+A_{m 1} x_1+\ldots \ldots + A_{m n} x_n=0

Code example

Let’s see an example of finding the null space vector:

using LinearAlgebra
# Defing a matrix
A = [1 0 0; 0 1 0; 0 0 0]
# Finding null space vector
x = nullspace(A)
println("x: ", x)
# Checking if it satisfies the equation
println("Result of Ax: ", A*x)

Code explanation

Here is a line-by-line explanation of the code above:

  • Line 1: We import the LinearAlgebra module.

  • Lines 3: We define a matrix AA.

  • Line 5: We find the nullspace vector of matrix AA using the nullspace function from the LinearAlgebra module.

  • Line 6: We print the nullspace vector xx returned by the function.

  • Line 8: We check if the vector xx satisfies the equation Ax=0Ax=0.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved