Skip to content

Commit 75fe0f0

Browse files
committed
Optionally simplify dummy derivative expressions when changing independent variable
1 parent cbceec4 commit 75fe0f0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/systems/diffeqs/basic_transformations.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function liouville_transform(sys::AbstractODESystem; kwargs...)
5050
ODESystem(neweqs, t, vars, parameters(sys); checks = false, name = nameof(sys), kwargs...)
5151
end
5252

53-
function change_independent_variable(sys::AbstractODESystem, iv, eq = nothing; verbose = false, kwargs...)
53+
function change_independent_variable(sys::AbstractODESystem, iv, eq = nothing; verbose = false, simplify = true, kwargs...)
5454
iv1 = get_iv(sys) # e.g. t
5555
iv2name = nameof(operation(unwrap(iv))) # TODO: handle namespacing?
5656
iv2, = @independent_variables $iv2name # e.g. a
@@ -103,7 +103,11 @@ function change_independent_variable(sys::AbstractODESystem, iv, eq = nothing; v
103103

104104
# 3) Add equations for dummy variables
105105
div1_div2 = 1 / div2_div1
106-
push!(eqs, ddiv2 ~ expand_derivatives(-D2(div1_div2) / div1_div2^3)) # e.g. https://math.stackexchange.com/questions/249253/second-derivative-of-the-inverse-function # TODO: higher orders
106+
ddiv1_ddiv2 = expand_derivatives(-D2(div1_div2) / div1_div2^3)
107+
if simplify
108+
ddiv1_ddiv2 = Symbolics.simplify(ddiv1_ddiv2)
109+
end
110+
push!(eqs, ddiv2 ~ ddiv1_ddiv2) # e.g. https://math.stackexchange.com/questions/249253/second-derivative-of-the-inverse-function # TODO: higher orders
107111

108112
# 4) Recreate system with new equations
109113
sys2 = typeof(sys)(eqs, iv2; name = nameof(sys), description = description(sys), kwargs...)

0 commit comments

Comments
 (0)