# Convert polynomials

Dear all,

I cannot overcome just the simpliest example from Julia notes on how to convert special polynomials into a polynomial-type value. Below is the program and the Error. Where is the problem?

julia> using Polynomials

julia> c = ChebyshevT([1, 0, 3, 4])

ChebyshevT(1⋅T_0(x) + 3⋅T_2(x) + 4⋅T_3(x))

julia> p = convert(Polynomial, c)

ERROR: UndefVarError: Polynomial not defined

Stacktrace:

[1] top-level scope

@ REPL[6]:1

By the way, is there a simple way of using a variable of a certain method in the program (say, Cosmo) with some commands from Polynomial pkg (like monomials, where I want a variable of monomials in a vector to be the variable of a method of optimization problem)?

Works perfectly fine for me:

``````julia> c = ChebyshevT([1, 0, 3, 4])
ChebyshevT(1⋅T_0(x) + 3⋅T_2(x) + 4⋅T_3(x))

julia> p = convert(Polynomial, c)
Polynomial(-2 - 12*x + 6*x^2 + 16*x^3)
``````

Try restarting the Julia REPL and run the code one more time.

1 Like

Great! I have removed and the installed back Polynomials pkg, but this didn’t change the situation. But restarting the Julia REPL removed the problem! Oh, this seems to me that new tasks make lot of problems for new users.

By the way, if there is a nice way to use a certain variable of a model (say,

model = Model(COSMO.Optimizer)
@variable(model, u)
@variable(model, t)

)
to get a vector of monomials of [u,t] up to certain degree (say, 10) with some nice command like
monomials([u,t], 0:10)?

By now I cannot do it since I can’t name by “u” a variable of a model and by the same sign “u” a polyvar argument which is needed to monomials command, if I am not mistaken.

It would be nice to have such a short command and not writing a vector of monomials by hand (since I have more than 2 variables in monomial vector).