We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c0f774 commit 779d04cCopy full SHA for 779d04c
src/matrices/companion.jl
@@ -1,3 +1,5 @@
1
+using Polynomials: Polynomial
2
+
3
"""
4
Companion Matrix
5
================
@@ -11,6 +13,8 @@ The companion matrix to a monic polynomial
11
13
+ vec: `vec` is a vector of coefficients.
12
14
15
+ dim: `vec = [1:dim;]`. `dim` is the dimension of the matrix.
16
17
++ polynomial: `polynomial` is a polynomial. vector will be appropriate values from coefficients.
18
19
struct Companion{T<:Number} <: AbstractMatrix{T}
20
n::Integer
@@ -23,6 +27,7 @@ end
23
27
24
28
# constructors
25
29
Companion(n::T) where {T<:Integer} = Companion(T[1:n;])
30
+Companion(polynomial::Polynomial) = Companion(-polynomial.coeffs[end-1:-1:begin] ./ polynomial.coeffs[end])
26
31
32
# properties
33
size(A::Companion) = (A.n, A.n)
0 commit comments