diff --git a/Project.toml b/Project.toml index 1aeb164ae9..8e8a22db62 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ModelingToolkit" uuid = "961ee093-0014-501f-94e3-6117800e7a78" authors = ["Chris Rackauckas "] -version = "1.2.9" +version = "1.2.10" [deps] DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" diff --git a/src/differentials.jl b/src/differentials.jl index 4ec39ee81a..7418f19593 100644 --- a/src/differentials.jl +++ b/src/differentials.jl @@ -113,6 +113,7 @@ end derivative(::typeof(+), args::NTuple{N,Any}, ::Val) where {N} = 1 derivative(::typeof(*), args::NTuple{N,Any}, ::Val{i}) where {N,i} = Operation(*, deleteat!(collect(args), i)) +derivative(::typeof(one), args::Tuple{<:Any}, ::Val) = 0 function count_order(x) @assert !(x isa Symbol) "The variable $x must have an order of differentiation that is greater or equal to 1!" diff --git a/test/derivatives.jl b/test/derivatives.jl index 6938412188..515bc6ebb8 100644 --- a/test/derivatives.jl +++ b/test/derivatives.jl @@ -72,3 +72,13 @@ isequal(ModelingToolkit.derivative(Operation(+, [x*y, y, z]), 1), 1) Expression[ModelingToolkit.Constant(1) ModelingToolkit.Constant(0) Differential(t)(x) ModelingToolkit.Constant(1) ModelingToolkit.Constant(0) ModelingToolkit.Constant(0)]) + +# issue 252 +@variables beta, alpha, delta +@variables x1, x2, x3 + +# expression +tmp = beta * (alpha * exp(x1) * x2 ^ (alpha - 1) + 1 - delta) / x3 +# derivative w.r.t. x1 and x2 +t1 = ModelingToolkit.gradient(tmp, [x1, x2]) +@test_nowarn ModelingToolkit.gradient(t1[1], [beta])