
Last chance! 50% off unlimited learning
Sale ends in
Function polynomialIndex
provides matrix which allows to iterate through the elements
of multivariate polynomial being aware of these elements powers.
So (i, j)-th element of the matrix is power of j-th variable in i-th
multivariate polynomial element.
Function printPolynomial
prints multivariate polynomial
given its degrees (pol_degrees
) and coefficients
(pol_coefficients
) vectors.
polynomialIndex(pol_degrees = numeric(0), is_validation = TRUE)printPolynomial(pol_degrees, pol_coefficients, is_validation = TRUE)
Function polynomialIndex
returns matrix which rows are
responsible for variables while columns are related to powers.
So
Function printPolynomial
returns the string which
contains polynomial symbolic representation.
non-negative integer vector of polynomial degrees (orders).
logical value indicating whether function input
arguments should be validated. Set it to FALSE
for slight
performance boost (default value is TRUE
).
numeric vector of polynomial coefficients.
Multivariate polynomial of degrees
pol_degrees
) has the form:
Function printPolynomial
removes polynomial elements
which coefficients are zero and variables which powers are zero. Output may
contain long coefficients representation as they are not rounded.
## Get polynomial indexes matrix for the polynomial
## which degrees are (1, 3, 5)
polynomialIndex(c(1, 3, 5))
# \donttest{
## Consider multivariate polynomial of degrees (2, 1) such that coefficients
## for elements which powers sum is even are 2 and for those which powers sum
## is odd are 5. So the polynomial is 2+5x2+5x1+2x1x2+2x1^2+5x1^2x2 where
## x1 and x2 are polynomial variables.
# Create variable to store polynomial degrees
pol_degrees <- c(2, 1)
# Let's represent its powers (not coefficients) in a matrix form
pol_matrix <- polynomialIndex(pol_degrees)
# Calculate polynomial elements' powers sums
pol_powers_sum <- pol_matrix[1, ] + pol_matrix[2, ]
# Let's create polynomial coefficients vector filling it
# with NA values
pol_coefficients <- rep(NA, (pol_degrees[1] + 1) * (pol_degrees[2] + 1))
# Now let's fill coefficients vector with correct values
pol_coefficients[pol_powers_sum %% 2 == 0] <- 2
pol_coefficients[pol_powers_sum %% 2 != 0] <- 5
# Finally, let's check that correspondence is correct
printPolynomial(pol_degrees, pol_coefficients)
# }
## Let's represent polynomial 0.3+0.5x2-x2^2+2x1+1.5x1x2+x1x2^2
pol_degrees <- c(1, 2)
pol_coefficients <- c(0.3, 0.5, -1, 2, 1.5, 1)
printPolynomial(pol_degrees, pol_coefficients)
Run the code above in your browser using DataLab