fcn2optimexpr
Convert a function to an optimization expression.
📝Syntax
expr = fcn2optimexpr(fcn, in1, ..., inN)
expr = fcn2optimexpr(fcn, in1, ..., inN, name, value)
📥Input Arguments
Parameter Description
fcn function handle to convert into an optimization expression.
in1, ..., inN input arguments passed to fcn: optimization variables, optimization expressions, or numeric constants.
name, value optional name-value arguments: 'OutputSize', 'ReuseEvaluation', 'Analysis'.
📤Output Arguments
Parameter Description
expr optimization expression object.
📄Description

fcn2optimexpr converts a function into an optimization expression, so that functions that cannot be composed from the supported elementary operators can still be used as objectives or constraints in a problem-based model.

When the expression is evaluated, each input argument is evaluated for the current variable values, then fcn is called on the resulting numeric values.

💡Examples
Wrap a scalar function of one variable.
x = optimvar('x');
expr = fcn2optimexpr(@(v) sin(v), x);
value = evaluate(expr, struct('x', pi / 2))
Use a converted function as an objective.
x = optimvar('x');
prob = optimproblem('Objective', fcn2optimexpr(@(v) (v - 3) .^ 2 + 1, x));
[sol, fval] = solve(prob, struct('x', 0))
🔗See Also
optimexproptimvarevaluate
Used Functions
optimvar optimexpr evaluate
📚Bibliography
J. Nocedal and S. J. Wright, Numerical Optimization, Springer, 2006.
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub