Function Repository Resource:

CoordinateVector

Source Notebook

Find the coordinate vector of a vector with respect to a basis

Contributed by: Dennis M Schneider

ResourceFunction["CoordinateVector"][vec,basis]

finds the coordinates of the vector vec with respect to the basis basis.

ResourceFunction["CoordinateVector"][vec,basis,var]

finds the coordinates of a vector when the vector and the basis vectors are members of a function space consisting of functions of var.

Details and Options

The input vector is given in terms of the standard basis.
The input vector may be a list of vectors.

Examples

Basic Examples (1) 

Get the coordinates of a given vector in a given basis:

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

Scope (15) 

Vectors in n

When 1 is viewed as a vector space, its elements are singletons, i.e. (α). The standard basis for 1 is {(1)}, so to find the coordinates of the vector (5) with respect to the basis {(1)}, proceed as follows:

In[2]:=
ResourceFunction["CoordinateVector"][{5}, {{1}}]
Out[2]=

Find the coordinates of a vector in 4 with respect to a basis of 4:

In[3]:=
basis = {{1, 1, 1, 1}, {0, 2, 2, 2}, {0, 0, 3, 3}, {0, 0, 0, 4}};
coords = ResourceFunction["CoordinateVector"][{1, 2, 3, 4}, basis]
Out[4]=

Verify the result:

In[5]:=
coords.basis
Out[5]=

Find the coordinates of a vector in 4 with respect to a basis for a three-dimensional subspace of 4:

In[6]:=
basis = {{1, 1, 0, 1}, {0, 2, 0, 2}, {5, 5, 0, 4}};
coords = ResourceFunction["CoordinateVector"][{1, 2, 0, 4}, basis]
Out[7]=

Verify the result:

In[8]:=
coords.basis
Out[8]=

Find the coordinates of a list of vectors with respect to a basis:

In[9]:=
basis = {{1, 1, 1, 1}, {0, 2, 2, 2}, {0, 0, 3, 3}, {0, 0, 0, 4}};
coords = ResourceFunction[
  "CoordinateVector"][{{1, 2, 3, 4}, {2, 1, 0, 1}}, basis]
Out[10]=

Verify the result:

In[11]:=
coords.basis
Out[11]=

Find the coordinate vector of a vector with symbolic entries:

In[12]:=
coords = ResourceFunction[
  "CoordinateVector"][{a, b}, {{2, 4}, {3, 4}}]
Out[12]=

Verify the result:

In[13]:=
coords.{{2, 4}, {3, 4}} // Simplify
Out[13]=

If the vectors listed as the basis vectors are not independent, an error message is returned:

In[14]:=
ResourceFunction[
 "CoordinateVector"][{{1, 2, 3}, {4, 5, 6}}, {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
Out[14]=

Check that the given list of vectors is not independent:

In[15]:=
MatrixRank[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
Out[15]=

If a vector is not in the span of the given list of vectors, an error message is returned:

In[16]:=
ResourceFunction[
 "CoordinateVector"][{{5, 7, 9}, {1, 0, 1}}, {{1, 2, 3}, {4, 5, 6}}]
Out[16]=

Check that at least one of the given vectors is not in the span:

In[17]:=
RowReduce[
  Transpose[
   Join[{{1, 2, 3}, {4, 5, 6}}, {{5, 7, 9}, {1, 0, 1}}]]] // MatrixForm
Out[17]=

Spaces of matrices (2) 

The standard basis for the space of 2×4 matrices is:

In[18]:=
basis = Map[Partition[#, 4] &, IdentityMatrix[8]]
Out[18]=

Find the coordinate vector of the 2×4 matrix with respect to this basis:

In[19]:=
coords = ResourceFunction[
  "CoordinateVector"][{{1, 2, 3, 4}, {2, 1, 0, 1}}, basis]
Out[19]=

Verify the result:

In[20]:=
coords.basis
Out[20]=

Find the coordinates of a matrix with symbolic entries:

In[21]:=
basis = {{{1, 1}, {1, 1}}, {{1, 0}, {1, 1}}, {{1, -1}, {0, 1}}, {{1, 2}, {-2, 2}}};
coords = ResourceFunction["CoordinateVector"][{{{a, b}, {c, d}}}, basis]
Out[19]=

Check that the result is correct:

In[22]:=
coords.basis // Simplify
Out[22]=

Function spaces (6) 

Find the coordinates of a list of two vectors (functions) with respect to the standard basis {1,x,x2,x3} of the space of polynomials of degree at most 3:

In[23]:=
basis = {1, x, x^2, x^3};
coords = ResourceFunction[
  "CoordinateVector"][{1 - 2 x + 3 x^2, 2 x - x^2 + x^3}, basis, x]
Out[19]=

Verify the result:

In[24]:=
coords.basis
Out[24]=

Find the coordinates of two vectors (functions) with respect to a basis for a two-dimensional subspace of the space of polynomials of degree at most 4:

In[25]:=
basis = {-x + x^3, -x^2 + x^4};
coords = ResourceFunction[
  "CoordinateVector"][{2 (-x + x^3) + 3 (-x^2 + x^4), x (x^2 - 1) (x + 3)}, basis, x]
Out[19]=

Verify the result:

In[26]:=
coords.basis == {2 (-x + x^3) + 3 (-x^2 + x^4), x (x^2 - 1) (x + 3)} // Simplify
Out[26]=

This example exploits trigonometric identities to find the vector's coordinates:

In[27]:=
basis = {1, Cos[2 t]};
coords = ResourceFunction["CoordinateVector"][{Cos[t]^2, Sin[t]^2}, basis, t]
Out[19]=

Verify the result:

In[28]:=
coords.basis // FullSimplify
Out[28]=

Example involving exponential and hyperbolic functions:

In[29]:=
basis = {1, Cos[x], Cos[x]^2, Exp[x], Exp[-x]};
coords = ResourceFunction[
  "CoordinateVector"][{1, Cos[x], Cos[2 x], Sinh[x]}, basis, x]
Out[19]=

Verify the result:

In[30]:=
coords.basis // FullSimplify
Out[30]=

A more complicated function:

In[31]:=
basis = {Exp[2 x], x Exp[2 x], x^2 Exp[2 x]}; coords = ResourceFunction["CoordinateVector"][
  D[5 Exp[2 x] + 2 x Exp[2 x] - x^2 Exp[2 x], x], {Exp[2 x], x Exp[2 x], x^2 Exp[2 x]}, x]
Out[31]=

Verify the result:

In[32]:=
First[coords.basis] == D[5 Exp[2 x] + 2 x Exp[2 x] - x^2 Exp[2 x], x] // Simplify
Out[32]=

The following example involves a dependent list of exponential and hyperbolic functions. The given list of vectors is dependent because the vector cos2(x) is a linear combination of 1 and cos(2x):

In[33]:=
basis = {1, Cos[x], Cos[2 x], Sinh[x], Cosh[x], Cos[x]^2};
coords = ResourceFunction["CoordinateVector"][{Exp[x], Exp[-x]}, basis, x]
Out[32]=

Publisher

Dennis M Schneider

Version History

  • 3.0.0 – 31 August 2020
  • 2.0.0 – 23 September 2019
  • 1.0.0 – 12 September 2019

Related Resources

License Information