Register a numeric R function for use in symbolic expressions
Source:R/codegen.R
register_symbolic.Rdregister_symbolic("f", fn) returns a symbolic function f whose
applications f(x) stay unevaluated in expressions and call fn in
generated code, like @register_symbolic in ModelingToolkit. Derivatives
are taken by central differences unless derivatives gives a function for
each argument.
Arguments
- name
Function name.
- fn
An R function of numeric arguments.
- derivatives
Optional list of R functions, the partial derivatives with respect to each argument, taking the same arguments as
fn; or one functionfunction(i, ...)of the argument indexifollowed by the arguments offn(for functions of any number of arguments).
Examples
sq <- register_symbolic("sq", function(x) x^2)
x <- Variable("x", t_nounits)
sq(x)
#> sq(x(t))