Skip to content

Commit 779d04c

Browse files
committed
feat(matrices): add constructor of polynomial
accept a polynomial as argument vector will come from coefficients of the polynomial See-Also: https://nhigham.com/2021/03/23/what-is-a-companion-matrix/
1 parent 5c0f774 commit 779d04c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: src/matrices/companion.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Polynomials: Polynomial
2+
13
"""
24
Companion Matrix
35
================
@@ -11,6 +13,8 @@ The companion matrix to a monic polynomial
1113
+ vec: `vec` is a vector of coefficients.
1214
1315
+ 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.
1418
"""
1519
struct Companion{T<:Number} <: AbstractMatrix{T}
1620
n::Integer
@@ -23,6 +27,7 @@ end
2327

2428
# constructors
2529
Companion(n::T) where {T<:Integer} = Companion(T[1:n;])
30+
Companion(polynomial::Polynomial) = Companion(-polynomial.coeffs[end-1:-1:begin] ./ polynomial.coeffs[end])
2631

2732
# properties
2833
size(A::Companion) = (A.n, A.n)

0 commit comments

Comments
 (0)