Function Repository Resource:

SubspaceBasis

Source Notebook

Find a basis for the subspace spanned by a list of vectors

Contributed by: Dennis M Schneider

ResourceFunction["SubspaceBasis"][vecs]

returns a basis for the subspace spanned by vecs.

ResourceFunction["SubspaceBasis"][polys,x,"Polynomial"]

returns a basis for the subspace spanned by a list of polynomials in x.

ResourceFunction["SubspaceBasis"][funcs,x]

returns a basis for the subspace spanned by a list of functions of x.

Details and Options

The vecs argument should be a list of vectors in n or n, or a list of matrices whose elements are in n or n.
ResourceFunction["SubspaceBasis"][list] can be used to determine if the vectors in the list are independent when compared with the resource function LinearlyIndependent.
ResourceFunction["SubspaceBasis"][vecs,x] attempts to find a basis for the functions in the list by expressing the zero function as a linear combination of the functions and then generating a list of homogeneous equations obtained by substituting k = Length[vecs] random real numbers into the equation, thereby obtaining a square matrix. Then the members of the list corresponding to the pivot columns of the reduced echelon form of the matrix are selected to obtain the independent functions in the list.
When the input is a set of functions, ResourceFunction["SubspaceBasis"] returns a set that may be ill-conditioned.

Examples

Basic Examples (5) 

A basis for the subspace spanned by a dependent list of vectors in 4:

In[1]:=
ResourceFunction[
 "SubspaceBasis"][{{2, 0, 3, 0}, {0, 1, 1, 3}, {2, 1, 4, 3}, {1, 2, 3,
    4}}]
Out[1]=

If the vectors in the list are independent, then SubspaceBasis[list] returns a list:

In[2]:=
ResourceFunction["SubspaceBasis"][{{1, 2}, {3, 4}}]
Out[2]=

Test whether a list of vectors is independent (compare with ResourceFunction["LinearlyIndependent"]):

In[3]:=
list = {{1, 2}, {3, 4}};
{ResourceFunction["SubspaceBasis"][list] === list, ResourceFunction["LinearlyIndependent"][list]}
Out[4]=

A basis for the subspace spanned by a dependent list of three 2×2 matrices:

In[5]:=
ResourceFunction[
 "SubspaceBasis"][{{{2, 0}, {3, 0}}, {{0, 1}, {1, 3}}, {{2, 1}, {4, 3}}, {{1, 1}, {2, 2}}}]
Out[5]=

The 2×2 symmetric matrices together with the 2×2 trace zero matrices do not form an independent list of matrices:

In[6]:=
list = Join[ResourceFunction["CanonicalBasis"]["SymmetricMatrices", 2],
  ResourceFunction["CanonicalBasis"]["TraceZeroMatrices", 2]]
Out[6]=
In[7]:=
ResourceFunction["SubspaceBasis"][list] === list
Out[7]=

A basis for the span of this list of matrices:

In[8]:=
MatrixForm /@ ResourceFunction["SubspaceBasis"][list]
Out[8]=

A basis for the subspace spanned by a dependent list of polynomials in x:

In[9]:=
ResourceFunction[
 "SubspaceBasis"][{1, x, 1 + x^2, x^2, 1 + x + x^2, 1 + x + x^2 + x^3}, x, "Polynomial"]
Out[9]=

A basis for the subspace spanned by a dependent list of trig functions:

In[10]:=
ResourceFunction[
 "SubspaceBasis"][{1, Sin[x]^2, 0, Cos[2 x], Cos[1 + x^2], Cos[x]^2},
  x]
Out[10]=

Test that a list of trigonometric polynomials is linearly independent:

In[11]:=
list = {1, Cos[t], Cos[2 t], Cos[3 t]};
ResourceFunction["SubspaceBasis"][list, t] === list
Out[12]=

Possible Issues (2) 

When the input is a set of functions, SubspaceBasis uses a method that may be ill-conditioned:

In[13]:=
poly = JacobiP[4, 2, 8, x]
Out[13]=
In[14]:=
ResourceFunction["SubspaceBasis"][{1, x, x^2, x^3, x^4, poly}, x]
Out[14]=

Specifying polynomial inputs gives a better result:

In[15]:=
ResourceFunction[
 "SubspaceBasis"][{1, x, x^2, x^3, x^4, JacobiP[4, 2, 8, x]}, x, "Polynomial"]
Out[15]=

Publisher

Dennis M Schneider

Version History

  • 1.0.0 – 18 September 2020

Related Resources

License Information