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
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 . This is because if a vector is perpendicular to all the rows of , then it will be orthogonal to any linear combination of those rows, which means it will be in the null space of .
Example
Let matrix be
and the vector be
For to be the null space vector, the following equations should be satisfied:
Code example
Let’s see an example of finding the null space vector:
using LinearAlgebra# Defing a matrixA = [1 0 0; 0 1 0; 0 0 0]# Finding null space vectorx = nullspace(A)println("x: ", x)# Checking if it satisfies the equationprintln("Result of Ax: ", A*x)
Code explanation
Here is a line-by-line explanation of the code above:
-
Line 1: We import the
LinearAlgebramodule. -
Lines 3: We define a matrix .
-
Line 5: We find the nullspace vector of matrix using the
nullspacefunction from theLinearAlgebramodule. -
Line 6: We print the nullspace vector returned by the function.
-
Line 8: We check if the vector satisfies the equation .
Free Resources