fronts.D.from_expr
- fronts.D.from_expr(expr, vectorized=True, max_derivatives=2)
Create a D function from a SymPy-compatible expression.
- Parameters:
expr (sympy.Expression or str or float) – SymPy-compatible expression containing up to one free symbol.
vectorized (bool, optional) –
Whether the returned D must be compatible with a solver that uses vectorized calls.
If True (default), the first argument passed to D may always be either a float or a NumPy array. However, if False, calls as
D(theta, 1)
orD(theta, 2)
will assume thattheta
is a single float, which may allow for optimizations that speed up the evaluations required by a solver that does not use vectorized calls.Note that, regardless of this setting, calls to D that do not ask for any derivatives (i.e., calls as
D(theta)
) will always take floats and arrays interchangeably. This behavior ensures that D is always compatible with the solution classes.max_derivatives (int, optional) – Highest-order derivative of D that may be required. Can be 0, 1 or 2. The default is 2.
- Returns:
D –
Function to evaluate \(D\) and its derivatives:
D(theta)
evaluates and returns \(D\) attheta
If max_derivatives >= 1,
D(theta, 1)
returns both the value of \(D\) and its first derivative attheta
If max_derivatives is 2,
D(theta, 2)
returns the value of \(D\), its first derivative, and its second derivative attheta
If vectorized is True, the argument
theta
may be a single float or a NumPy array in all cases. If vectorized is False,theta
may be either a float or an array when D is called asD(theta)
, but it must be a float otherwise.- Return type:
callable
Notes
Users will rarely need to call this function, as all built-in solver functions already do so themselves when they receive an expression as D.