JuliaAlgebra / StaticPolynomials.jl

Fast evaluation of multivariate polynomials
https://juliaalgebra.github.io/StaticPolynomials.jl/latest/
Other
16 stars 4 forks source link

Evaluating PolynomialSystem at the same point #37

Closed ArjunNarayanan closed 4 years ago

ArjunNarayanan commented 4 years ago

I wish to evaluate an entire polynomial system at the same point. (For example if I am interpolating with a polynomial basis.)

Currently it seems that this requires:

import DynamicPolynomials: @polyvar
using StaticPolynomials
@polyvar x
polys = PolynomialSystem([x^2 + 2x, 3x^3 + 12])
evaluate(polys, 0.5*ones(2))  # Requires unnecessary allocation of array of points

It would be more efficient to be able to do something like,

evaluate(polys, 0.5)

I could work on a pull request for the same if somebody can point out where exactly a change is required!

saschatimme commented 4 years ago

Your example only has one variable, so you would need to only create a 1-element vector. Also you can avoid allocations by using SVector from the StaticArrays package.

evaluate(polys, @SVector [0.5])
ArjunNarayanan commented 4 years ago

Ah, I thought the vector that is passed as input is the point at which each function in the PolynomialSystem is evaluated at. So the vector is actually the value of each variable? Perhaps in this case it would be better to throw an error if the vector of evaluation points has length greater than the number of variables?