Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate the tridiagonal companion matrix of a univariate polynomial
| ResourceFunction["TridiagonalCompanionMatrix"][poly,x] gives a tridiagonal companion matrix of poly, treated as a polynomial in x. | 
Generate a tridiagonal companion matrix:
| In[1]:= | ![ResourceFunction["TridiagonalCompanionMatrix"][
  5 + 4 x + 3 x^2 + 2 x^3 + x^4 + x^5, x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/1a433529aea703a9.png) | 
| Out[1]= |  | 
The characteristic polynomial of this matrix is a constant multiple of the original polynomial:
| In[2]:= | ![CharacteristicPolynomial[%, x]](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/66ea9d00446887ff.png) | 
| Out[2]= |  | 
Tridiagonal companion matrix of a polynomial with complex coefficients:
| In[3]:= | ![ResourceFunction[
  "TridiagonalCompanionMatrix"][(x - 1 - I)^2 (x + I) (x + 1), x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/14de985937b2af0f.png) | 
| Out[3]= |  | 
Tridiagonal companion matrix of a polynomial with symbolic coefficients:
| In[4]:= | ![ResourceFunction["TridiagonalCompanionMatrix"][x^4 + b x^3 + c, x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/6ea14cd2d7d4f65f.png) | 
| Out[4]= |  | 
Numerically find the roots of a polynomial by computing the eigenvalues of its tridiagonal companion matrix:
| In[5]:= | ![Eigenvalues[
 N[ResourceFunction["TridiagonalCompanionMatrix"][
   1 + 2 x + 3 x^2 + 4 x^3, x]]]](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/013ea1cdeb37d675.png) | 
| Out[5]= |  | 
Compare with the result of NSolve:
| In[6]:= | ![x /. NSolve[1 + 2 x + 3 x^2 + 4 x^3 == 0, x]](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/340685a65b915c07.png) | 
| Out[6]= |  | 
A polynomial with real coefficients whose roots are all real has a symmetric tridiagonal companion matrix:
| In[7]:= | ![ResourceFunction["TridiagonalCompanionMatrix"][
  24 - 96 x + 72 x^2 - 16 x^3 + x^4, x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/18a70abec80959ff.png) | 
| Out[7]= |  | 
| In[8]:= | ![{SymmetricMatrixQ[%], Eigenvalues[%]}](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/0825f31134d0988c.png) | 
| Out[8]= |  | 
If the polynomial has repeated roots, then the companion matrix is symmetric and block diagonal:
| In[9]:= | ![ResourceFunction["TridiagonalCompanionMatrix"][(x^2 - x - 1)^2, x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/647b1d2a460a786c.png) | 
| Out[9]= |  | 
| In[10]:= | ![{SymmetricMatrixQ[%], Eigenvalues[%]}](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/2ac6db3fbcf8fb22.png) | 
| Out[10]= |  | 
A polynomial with real coefficients and complex roots will have a tridiagonal companion matrix with negative entries in its superdiagonal:
| In[11]:= | ![ResourceFunction[
  "TridiagonalCompanionMatrix"][(x^2 - 6 x + 25) (x^2 + x + 1), x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/753c3b5f541e1876.png) | 
| Out[11]= |  | 
| In[12]:= | ![Eigenvalues[%]](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/726a22a3e35688ba.png) | 
| Out[12]= |  | 
If the polynomial has repeated roots, the superdiagonal will also have zero entries:
| In[13]:= | ![ResourceFunction["TridiagonalCompanionMatrix"][(x^2 - 6 x + 25)^2, x] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/7270782426bf6353.png) | 
| Out[13]= |  | 
| In[14]:= | ![Eigenvalues[%]](https://www.wolframcloud.com/obj/resourcesystem/images/20b/20b7118e-cbfa-482d-8b1e-0b455b890337/6c02fd8dcb290c3c.png) | 
| Out[14]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License