---
title: "Related Matrices"
canonical: "https://docs.magma-maths.org/v2.30-1/CommutativeAlgebra/DifferentialRings/related-matrix.html"
source: "https://docs.magma-maths.org/v2.30-1/CommutativeAlgebra/DifferentialRings/related-matrix.md"
part: "Commutative Algebra"
chapter: "Differential Rings"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Commutative Algebra", "source": "https://docs.magma-maths.org/v2.30-1/CommutativeAlgebra/index-commutative-algebra.md"}
  - {"title": "Differential Rings", "source": "https://docs.magma-maths.org/v2.30-1/CommutativeAlgebra/DifferentialRings/index-differential-rings.md"}
prev: {"title": "Euclidean Algorithms, GCDs, and LCMs", "source": "https://docs.magma-maths.org/v2.30-1/CommutativeAlgebra/DifferentialRings/euclidean-algorithms.md"}
next: {"title": "Singular Places and Indicial Polynomials", "source": "https://docs.magma-maths.org/v2.30-1/CommutativeAlgebra/DifferentialRings/singularities.md"}
intrinsics:
  - {"name": "CompanionMatrix", "signature": "CompanionMatrix(L): RngDiffOpElt -> AlgMatElt"}
examples:
  - "ex-62793f"
---

# Related Matrices

The *companion matrix* of a monic linear differential operator

$$
D^n+a_{n-1}D^{n-1}+\cdots+a_0 \in F[D]
$$

is defined as the $n\times n$ matrix

$$
 \begin{pmatrix}0&1&0&0&\ldots&0\\ 0&0&1&0&\ldots&0\\ \vdots&\vdots&\vdots&\vdots&\ddots&\vdots\\ 0&0&0&0&\ldots&1\\ -a_0&-a_1&-a_2&-a_3&\ldots&-a_{n-1}\end{pmatrix}
$$

<a id="function-companionmatrix-rngdiffopelt"></a>
## `CompanionMatrix(L): RngDiffOpElt -> AlgMatElt`

Returns the companion matrix of the monic differential operator $L$.

<a id="example-ex-62793f"></a>
## `Example: Companion Matrix of an Operator (ex-62793f)`

```magma
> F<z> := RationalDifferentialField(Rationals());
> R<D> := DifferentialOperatorRing(F);
> L := D^3-z*D^2+2*D+5;
> CompanionMatrix(L);
[0 1 0]
[0 0 1]
[-5 -2 z]
```
