coeffs
Coefficients of the polynomial.
| Library |
|
Arguments
Input arguments
# p — the polynomial
+
symbolic expression | symbolic function
Details
A polynomial defined as a symbolic expression or function.
# var is a variable of the polynomial
+
character variable
Details
A polynomial variable specified as a symbolic variable.
# vars is a vector of variables of the polynomial
+
vector of symbolic variables
Details
Variables of the polynomial, defined as a vector of symbolic variables.
Output arguments
# C — coefficients of the polynomial
+
character number | character variable | symbolic expression | character vector | character matrix | symbolic N-dimensional array
Details
The coefficients of a polynomial returned as a symbolic number, variable, expression, vector, matrix, or N-dimensional array. If there is only one coefficient and one corresponding term, then C it is returned as a scalar.
# T — terms of the polynomial
+
character number | character variable | symbolic expression | character vector | character matrix | symbolic N-dimensional array
Details
The terms of a polynomial returned as a character number, variable, expression, vector, matrix, or N-dimensional array. If there is only one coefficient and one corresponding term, then T it is returned as a scalar.
Examples
Coefficients of a one-dimensional polynomial
Details
Let’s find the coefficients of the one-dimensional polynomial. The coefficients are ordered from the smallest degree to the largest.
import EngeeDSP.Functions: coeffs
using DynamicPolynomials
@polyvar x
out = coeffs(16*x^2 + 19*x + 11)[1]
3-element Vector{Int64}:
11
19
16
Coefficients of a multidimensional polynomial for a specific variable
Details
Let’s find the coefficients of the polynomial in the variable x:
import EngeeDSP.Functions: coeffs
using DynamicPolynomials
@polyvar x y
out1 = coeffs(x^3 + 2*x^2*y + 3*x*y^2 + 4*y^3, x)[1]
4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:
1
2y
3y²
4y³
and by variable y:
out2 = coeffs(x^3 + 2*x^2*y + 3*x*y^2 + 4*y^3, y)[1]
4-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}}:
4
3x
2x²
x³
Coefficients of a multidimensional polynomial in two variables
Details
Let’s find the coefficients of the polynomial with respect to both variables x and y.
import EngeeDSP.Functions: coeffs
using DynamicPolynomials
@polyvar x y
out = coeffs(x^3 + 2*x^2*y + 3*x*y^2 + 4*y^3, [x, y])[1]
4-element Vector{Int64}:
1
2
3
4
Coefficients and corresponding terms of a one-dimensional polynomial
Details
Let’s find the coefficients and the corresponding terms of the one-dimensional polynomial. When there are two outputs, the coefficients are ordered from the largest to the smallest.
import EngeeDSP.Functions: coeffs
using DynamicPolynomials
@polyvar x y
out1,out2 = coeffs(x^3 + 2*x^2*y + 3*x*y^2 + 4*y^3, x)
println(out1)
println(out2)
out1,out2 = coeffs(x^3 + 2*x^2*y + 3*x*y^2 + 4*y^3, y)
println(out1)
println(out2)
Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}[1, 2y, 3y², 4y³]
Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}[x³, x², x, 1]
Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}[4, 3x, 2x², x³]
Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Int64}[y³, y², y, 1]
All coefficients of the polynomial
Details
Let’s find all coefficients of the polynomial, including coefficients equal to 0 by specifying the option "All". The coefficients returned are ordered from the largest to the smallest.
Let’s find all the coefficients .
import EngeeDSP.Functions: coeffs
using DynamicPolynomials
@polyvar x
out = coeffs(3*x^2, "All")[1]
3-element Vector{Int64}:
3
0
0