JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software

Home Page:https://symbolics.juliasymbolics.org/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Finding Coefficients of Cross Terms

Umut-Can-Physics opened this issue · comments

commented

When I try to run the following code, the print function always returns the integer 0 (zero). However, you can easily see that the coefficient of the z[1] * z[2] term equals -2. The Symbolics.jl module is robust for just single variables, such as coefficients of z[1]^2 and z[2]^2.

using Symbolics

@variables z[1:2]

Ψ = z[1]^2 - 2 * z[1] * z[2] + z[2]^2

# Extract coefficient
coeff_value = Symbolics.coeff(Ψ, z[1]*z[2])

println(coeff_value)

But interestingly Symbolics.coeff(Ψ,z[2]^0*z[1]^2) coefficient is true. The module doesn’t work for Symbolics.coeff(Ψ, z[1]*z[2]) Why?

commented

Anyone who solve this problem?