You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I was looking for a way to symbolically integrate a MultiVariate polynomial, or at least to find a primitive. I ended up writing the below code to find it. Would you be interested by a PR? If yes, I could add a little bit of documentation, write unit tests etc. Note : as primitive is already a specific julia language word, I opted out for antidifferentiate.
using TypedPolynomials
using MultivariatePolynomials
antidifferentiate(p::Polynomial, v::Variable) =Polynomial(antidifferentiate.(terms(p), v))
antidifferentiate(t::Term, v::Variable) =coefficient(t) *antidifferentiate(monomial(t), v)
functionantidifferentiate(m::Monomial{Vars,N}, v::V) where {Vars,N,V<:Variable}
if TypedPolynomials.inmonomial(v, Vars...)
return_antidiff(m, exponents(m), v)
else# Insert `v` in the monomialreturn m * v
endendfunction_antidiff(::Monomial{Vars}, exponents::NTuple{N,Integer}, v::Variable) where {Vars,N}
vi = TypedPolynomials.find_variable_index(v, Vars)
new_m =Monomial{Vars,N}(
ntuple(i ->beginif i == vi
(exponents[i] ==0) ?1: exponents[i] +1else
exponents[i]
endend,
Val{N}()
)
)
return1/ (exponents[vi] +1) * new_m
end@polyvar x y # assigns x (resp. y) to a variable of name x (resp. y)
p =2x +3.0x * y^2+ y +1.5@show p
@showantidifferentiate(p, x)
@showantidifferentiate(p, y)
p =2y +3@show p
@showantidifferentiate(p, x)
@showantidifferentiate(p, y)
The text was updated successfully, but these errors were encountered:
Yes, I would be interested by a PR. Could you define the part for polynomial and terms in https://github.com/JuliaAlgebra/MultivariatePolynomials.jl like it's done for differentiate ? Also, the function antidifferentiate should be defined by MultivariatePolynomials so that it's part of the API
Hi,
I was looking for a way to symbolically integrate a MultiVariate polynomial, or at least to find a primitive. I ended up writing the below code to find it. Would you be interested by a PR? If yes, I could add a little bit of documentation, write unit tests etc. Note : as
primitive
is already a specific julia language word, I opted out forantidifferentiate
.The text was updated successfully, but these errors were encountered: