How to Append Polynomial to 5-element vector if the highest order is less than 4? Polynomials.jl Package

Does this pad function solve the problem?

julia> pad(v,n) = (L = length(v) ; 
  [i <= L ? v[i] : zero(eltype(v)) for i in 1:n] )
pad (generic function with 1 method)

julia> pad(coeffs(p),5)
5-element Vector{Int64}:
 -10
  -3
   1
   0
   0

pad(v,n) will return vector of length n with elements from v where valid and zero otherwise.
A similar function might exist in some library, or might be added as it sounds useful.

1 Like