Home > OS >  Define a polynomial function in Julia
Define a polynomial function in Julia

Time:06-25

I want to create the function using Polynomials package in Julia, while c is a Vector and n is the length of the Vector. I can make it in JuMP package but not in Polynomials.

Any idea how to create this function?

CodePudding user response:

Just call Polynomial on this vector c.

julia> c = [1, 2, 3, 4]
4-element Vector{Int64}:
 1
 2
 3
 4

julia> p = Polynomial(c)
Polynomial(1   2*x   3*x^2   4*x^3)

julia> c = [2, 4, -8, 0, 0, 1]; 

julia> p = Polynomial(c)
Polynomial(2   4*x - 8*x^2   x^5)

julia> p(2) #evaluate the polynomial at x = 2
10
  • Related