Function Repository Resource:

LinearCombination

Source Notebook

Decompose a vector into a linear combination of a set of vectors

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["LinearCombination"][{u},{vi}]

returns a list of coefficients that express u as a linear combination of the basis vectors vi.

ResourceFunction["LinearCombination"][{u}, {vi}, type]

returns the given representation type that express u as a linear combination of the vi.

Details and Options

The input type can be "Association", "Coefficients" or "FullDecomposition" and defaults to "Coefficients".
The basis set need not be linearly independent.

Examples

Basic Examples (1) 

Express a vector as a combination of two vectors:

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

Scope (3) 

Express the output as an Association:

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

Display the linear combination as an Inactive expression:

In[3]:=
v = {10, 2, 2};
ResourceFunction[
 "LinearCombination"][v, {{4, 2, 5}, {3, 1, 2}}, "FullDecomposition"]
Out[4]=

Verify the decomposition is correct:

In[5]:=
v === Activate[%]
Out[5]=

Express a matrix in terms of a set of matrices:

In[6]:=
m = {{2, 3}, {4, -5}}; 
ResourceFunction["LinearCombination"][
  m, {{{1, 0}, {0, 1}}, {{0, 1}, {0, 0}}, {{0, 0}, {1, 0}}, {{0, 0}, {0, 1}}}, "FullDecomposition"] // TraditionalForm
Out[6]=

Verify the decomposition is correct:

In[7]:=
m === Activate[%]
Out[7]=

Possible Issues (2) 

If no linear combination is found, LinearCombination returns unevaluated:

In[8]:=
ResourceFunction["LinearCombination"][{1, 0}, {{4, 2}, {2, 1}}]
Out[8]=

If the basis set is not linearly independent, LinearCombination will return one combination from the infinite set of possibilities:

In[9]:=
ResourceFunction[
 "LinearCombination"][{1, 1}, {{4, 2}, {2, 3}, {-7, 2}}]
Out[9]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 01 April 2020

Related Resources

License Information