Can't define custom derivative dependent on model parameters (locally)
codercahol opened this issue · comments
I have a number of symbolic functions, i.e. x(t), y(t), z(t)
and I am trying to define their derivatives with respect to particular model parameters i.e. a, b, c
.
For example, I want
Symbolics.derivative(::typeof(x), args::NTuple{1,Any}, ::Val{1}) = a * y(t)
Ultimately, my goal is to compute a series expansion of f(x(t), y(t), z(t))
I have a function, compute_expansion(params)
where I want to define the derivatives locally just so I can compute the taylor expansion and return a symbolic expression that only contains x(t), y(t), z(t)
and no derivatives (into which I will substitute floats).
However, because Symbolics.derivative
must be defined globally, and I want the parameters to remain local (so I can compute other models) I am stuck.
How can I define the custom derivatives locally?
The system by design wants to have pure functions, so it needs the parameters to be arguments of the function.
meaning, I should also pass in a
explicitly as an argument, in the example I give?
Yes. If a
is not an argument of the function then you cannot differentiate with respect to it. No globals.
Closing but feel free to ask questions if you have more.