Skip to contents

register_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.

Usage

register_symbolic(name, fn, derivatives = NULL)

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 function function(i, ...) of the argument index i followed by the arguments of fn (for functions of any number of arguments).

Value

A symbolic function.

Examples

sq <- register_symbolic("sq", function(x) x^2)
x <- Variable("x", t_nounits)
sq(x)
#> sq(x(t))