Julia extract Polynomial coefficients as Vector

51 Views Asked by At

How do I extract the coefficients of a Julia Polynomial?

In Julia we can create a Polynomial:

using Polynomials
p = Polynomial([23,34,23,135])

Which gives:

Polynomial(23 + 34*x + 23*x^2 + 135*x^3)

How do I extract the coefficients and store them in a Vector?

1

There are 1 best solutions below

1
Bastiaan Quast On BEST ANSWER

In Julia, this is done using the coeffs() function.

For the above Polynomial called p, this is done as such:

coeffs(p)

Which gives:

4-element Vector{Int64}:
  23
  34
  23
 135