JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

Strange `Differential` (+`jacobian`) behavior with arrays #571

Open cooperrc opened 2 years ago

cooperrc commented 2 years ago

The recent Fixes #570 and #568 leaves a strange behavior for derivatives (it sounds like there are some known issues, but I wanted to document a simple case here)

@variables t x[1:2](t) # independent and dependent variables
@parameters k # parameters

Dx1 = Differential(x[1])
Dx2 = Differential(x[2])

V = 1/2*k*(x[2]- x[1])^2
Symbolics.expand_derivatives(Dx1(L))

Result should be -k*(x[2] - x[1])

but instead you receive 0

The problem seems to stem from the Differential

@variables t x[1:2](t) # independent and dependent variables
@parameters k # parameters

Dx1 = Differential(x[1])
Dx2 = Differential(x[2])

V = 1/2*k*x[2]^2 + 1/2*x[1]^2
Symbolics.expand_derivatives(Dx1(L))

returns

k*x_2 + k*x_1

instead of the correct

k*x_1

ChrisRackauckas commented 2 years ago

Seems like one more of these @shashi

cooperrc commented 2 years ago

@shashi if I can help/troubleshoot, let me know. I'm newish to Julia, but I've got a lot of experience in scientific computing.