Hi all I have a problem here,
I want to calculate special sum by using
Polynomials.jl, thus it works fine if there is one of degree 4, but if the highest input is of degree 2, the
coeffs(p) would become 3-element vector, and we need to append the last two elements by 0 so we can still make the calculation of
this is the code:
using Symbolics, Polynomials @variables n i a = [1 n*(n+1)/2 n*(n+1)*(2n+1)/6 (1/4)*(n*(n+1))^2 (n*(n+1)*(2n+1)*(3n^2 + 3n - 1))/30] # 1 + 2i -> Polynomial([1,2,0,0], :i) # 3i^2 + i^4 -> Polynomial([0,0,3,0,1], :i) # i^2 - 3i - 10 -> Polynomial([-10,-3,1,0,0], :i) p = Polynomial([-10,-3,1,0,1], :i) # coeffs(p) -> returns the entire coefficient vector # Polynomials.degree(p) -> returns the polynomial degree, length is 1 plus the degree println("The special sum for $p is") a*(coeffs(p))
Anyone know how to append polynomial to 5-element vector with zeroes ? if the input polynomial is less than order of 4?
Thus, if I input this:
p = Polynomial([-10,-3,1,0,0], :i)
it would become still 5-element vector:
[-10; -3; -1; 0; 0] instead of 3-element vector
if-else conditional or any idea?