# Functions

## Construction of Function objects

### The Function object - general functions

The Function object is the top-level class for representation of functions. It stores a function handle and the data corresponding to the function. The function handle is a Matlab concept for representing functions (see  help function_handle) which has been adopted in the Function object. As an example, consider a function y = 2*x that can be represented as anonymous function y = @(x) 2*x in Matlab. The Function object can be created as follows

y = @(x) 2*x
F = Function(y)

which accepts the function handle as an argument. Arbitrary user data can be stored with the function which are provided as a second argument. For instance,

z = @(x) sum(x)
d.name = 'summation method';
d.date = date;
F = Function(z, d)

The user data can be employed for parametrization of the function. Consider a function y=p(1)*x(1)^2 + p(2)*x(2) + p(3) that is parametrized in the variable "p" that can be modified. The Function object can be constructed by pointing to the parameters in the user data. Note that the object must be constructed first in order to refer to the stored data as shown here:

d.p = [1, -0.5, 0.3];
F = Function([], d)
F.setHandle(@(x) F.Data.p(1)*x(1)^2 + F.Data.p(2)*x(2) + F.Data.p(3))

To evaluate the function stored in the Function for a particular value of the point x=[1;1], one can use an overloaded feval method

F.feval( [1; 1] )

By changing the parameters, the function value changes as well

F.Data.p(3) = 0.5;
F.feval( [1; 1] )

### The AffFunction object - affine function

The AffFunction object represents an affine function in the form y = F*x + g. It stores data of the matrices F, and g as properties of the object. To create an affine function one has to provide the corresponding matrices, e.g.

F = [1, 0];
g = 2;
F1 = AffFunction(F, g)

The stored matrices are accessible in the appropriate fields:

F1.F
F1.g

After construction of the object, the function can be evaluated using feval method inherited from Function class. For instance, the value of the function for the point x=[1;1] can be obtained as

F1.feval( [1; 1] )

Based on the dimensions of the input matrices F, and g, the domain and range of the affine function can be determined. The dimension of the domain space can be retrieved by referring to D property

F1.D

and the range by referring to R property

F1.R

If no matrix g is provided as input, it is considered as zero-value, e.g.

F1 = AffFunction( -1 )
F1.feval( 1 )

The QuadFunction object represents quadratic functions in the form y = x'*H*x + F*x + g. It stores data of the matrices H, F, and g as properties of the object. To create a quadratic function one has to provide the corresponding matrices, e.g.

H = eye(2);
F = [-2, 3];
g = 1;

The matrices can be accessed by referring to the properties with the same name:

F2.H
F2.F
F2.g

Evaluation of the function is achieved by feval method for a particular value of a point, e.g.

F2.feval( [0; -1] )

The dimensions of the domain and range are accessible from D and R property:

F2.D
F2.R

Object can be constructed without providing the matrices F, and g. In this case the values for the matrices F, and g are considered as zeros:

F2.H
F2.F
F2.g

### The InfNormFunction object - infinity norm function

The InfNormFunction object represents a function y = max( abs(Q*x) ) that returns always positive values. The object can be constructed by providing the matrix Q as an argument

F3 = InfNormFunction( diag([1, 2]) )

and is useful for representing a performance criterion. The evaluation of the function is achieved via feval method, i.e.

F3.feval( [-1; 1] )

### The OneNormFunction object - one norm function

The OneNormFunction object represents a function y = sum( abs(Q*x) ) that returns always positive values. The object can be constructed by providing the matrix Q as an argument

F4 = OneNormFunction( diag([2, 3]) )

and is useful for representing a performance criterion. Function evaluation proceeds via overloaded feval method that applies for all objects derived from Function class.

Back to Computational geometry overview.