JuliaPy / SymPy.jl

Julia interface to SymPy via PyCall
http://juliapy.github.io/SymPy.jl/
MIT License
268 stars 62 forks source link

Symply.jl for getting coefficients for ALL combination of the variables of a multivariable polynomial #482

Closed xiang-yu closed 1 year ago

xiang-yu commented 1 year ago

How to get coefficients for ALL combination of the variables of a multivariable polynomial using sympy.jl or other Julia package for symbolic computation?

Here is an example from MATLAB,

syms a b y [cxy, txy] = coeffs(ax^2 + by, [y x], ‘All’) cxy = [ 0, 0, b] [ a, 0, 0] txy = [ x^2y, xy, y] [ x^2, x, 1]

As you can see it returns all combination of the variables with 0 coefficients. The SymPy.jl returns julia> @syms x, y, a, b julia> ff = sympy.Poly(ax^2 + by, (x,y)) Poly(a*x*2 + by, x, y, domain='ZZ[a,b]') julia> [prod(ff.gens.^i) for i in ff.monoms()] 2-element Vector{Sym}: x^2 y

My goals is to get [ x^2y, xy, y] [ x^2, x, 1]

I asked the same question at https://discourse.julialang.org/t/symply-jl-for-getting-coefficients-for-all-combination-of-the-variables-of-a-multivariable-polynomial/89091 but I think this is more related to SymPy.jl.

jverzani commented 1 year ago

CLosing, I think this got answered.