fcn2optimexpr
Algorithm Description
fcn2optimexpr
converts a standard MATLAB® function handle, as applied to optimization variables, to an equivalent
optimization expression. The function attempts to create an expression that is efficient
to evaluate. Without details, fcn2optimexpr
takes the following
steps.
The steps in words:
If the
Analysis
argument is"off"
, wrap the function as a black box function and exit.Otherwise, check whether the function has
for
loops expressed as separate functions.If so, attempt to analyze the function using static analysis. If this succeeds, then exit. Otherwise, proceed to the next case.
If not, attempt to evaluate the function using overloads, meaning check whether all operations are from the list of Supported Operations for Optimization Variables and Expressions. If they are, then use the supported operators and exit; if they are not, wrap the function as a black box and exit.
When the returned expression is a "black box," automatic differentiation does not apply. This means if the solver uses derivative information, the solver must estimate the derivatives using finite difference steps.
For information about static analysis, see Static Analysis of Optimization Expressions.