## Syntax

y = sdpfun(arg1,arg2,...,argn,'function')

## Examples

General nonlinear functions are supported through the evaluation based nonlinear operator framework. Most functions (exponentials, logarithms, trigonometric, etc.) are defined by default, but the user can use sdpfun to define other (element-wise) functions, without going through the hassle of creating new files (although that is the preferred approach).

The following example shows how we can use a nonlinear solver to find a local optimizer to a small trigonometric problem (sin is actually already overloaded, but we do it here again for illustrative purposes).

sdpvar x
y = sdpfun(10*x,'sin')
solvesdp([-pi <= x <= pi],y+abs(x))

Nonlinear operators defined using the sdpfun command can be used in the global solver bmibnb. Performance is poor though, since the bounding procedures have to be done ad-hoc.

sdpvar x
y = sdpfun(10*x,'sin')
solvesdp([-pi <= x <= pi],y+abs(x),sdpsettings('solver','bmibnb'))

By using function handles, we can redefine functions (they will still work correctly on doubles)

sdpvar x
sin = @(x) sdpfun(x,'sin');
solvesdp([-pi <= x <= pi],sin(10*x)+abs(sin(x))+x,sdpsettings('solver','bmibnb'));
double(x)

t = (-pi:0.01:pi);
plot(t,sin(10*t)+abs(sin(t))+t)
hold on;
plot(double(x),double(sin(10*x)+abs(sin(x))+x),'r+')

Anonymous functions can be also in the function definition.

clear sin % To avoid aby problems from code above
sdpvar x
strange = @(x) sdpfun(x,'@(x) sin(10*x)+abs(sin(x))+x');
solvesdp([-pi <= x <= pi],strange(x),sdpsettings('solver','bmibnb'));
double(x)

Notice that there is an important difference between this model, and the model where only sin was defined. When only sin is defined, the solver will work with 3 variables to describe the objective; callback variables to evaluate sin(x) and sin(10*x), and a third variable to model absolute values. When the anonymous functions is used, there will only be one callback variable in the objective. In other words, the sin and absolute value operator will never be applied on a symbolic sdpvar variable, but only on numerical values of x along the solution process.

The command can be useful for redefining how some functions are implemented. As an example, if abs is used in a nonconvex way in YALMIP, it is modeled using a mixed-integer representation. If you instead want to solve the nonconvex problem by simply treating abs as a general (non-smooth) nonlinear function, simply redefine it as a anonymous function.

The following problem will be solved as a mixed-integer linear program since YALMIP detects that the absolute value is used in a nonconvex way and thus implements a mixed integer description.

sdpvar y
constraints = [-5 <= y <= 5, abs(y-2)>=1];
solvesdp(constraints,y)

The following alternative will be solved as a general nonlinear program since YALMIPs implementation of the abs operator will be avoided.

sdpvar y
abs = @(x) sdpfun(x,'@(x) abs(x)');
constraints = [-5 <= y <= 5, abs(y-2)>=1];
solvesdp(constraints,y)
clear abs