feval

Purpose

Evaluates a function defined over a convex set or an array thereof.

Syntax

[fval, feasible] = Set.feval(x)
[fval, feasible] = Set.feval(x,function_name)
[fval, feasible] = feval(Set,x,function_name)

Description

Evaluates function for given value of the point x over the convex Set characterized by the the string function_name. The dimension of the vector x must be the same as the dimension of the Set. If the Set is an array of convex sets, the function values are returned in an array. For a point that lies outside of the Set, the output is NaN.

Input Arguments

Set

Convex set or an array thereof, i.e. any object derived from the ConvexSet class, e.g. Polyhedron, YSet, ...

Class: ConvexSet

x

A point at which the function should be evaluated. The point must be given as column and must be in the same dimension as the set.

Class: double

function_name

String name of the function to evaluate. It must refer to a single function. If omitted, S.feval(x) only works if the set has a single function.

Class: char

Output Arguments

fval

An ../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval1.png matrix of function values at x, where ../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval2.png is the number of sets. If x is not contained in the ../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval3.png-th set, then the ../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval4.png-th column of fval is a vector of NaN.

Class: double

feasible

An ../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval5.png vector of logicals. feasible(j)=true if the ../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval6.png-th element of the array contains x.

Class: double

Example(s)

Example 1

Evaluate a function over a simple polytope. Construct the polytope in H-representation
 P = Polyhedron('lb',[-1;-2],'ub',[1;2]); 
 Assign a quadratic function to it 
 Q = QuadFunction([1 2;-2 3],[0 -5],0.6) 
Quadratic Function: R^2 -> R^1
 P.addFunction(Q,'q'); 
 Obtain the value of the function for the point [-1;-1.5] 
 x = [-1; -1.5];

 y = P.feval(x)
y =

                     15.85

We can plot the function over the set with the point [x,y]
 P.fplot; hold on;  text(x(1),x(2),y,'\bf{x}','FontSize',14); 

../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval_img_1.png

Example 2

We have three linear functions "a", "b", and "c" over unbounded polyhedron P.
 P = Polyhedron([1 2;-0.6 8; 0 0.4; 5 -1],[1;2;0.7;0.01]) 
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : none
 F1 = AffFunction([1 2]) 
Affine Function: R^2 -> R^1
 F2 = AffFunction([3 4; -1 0]) 
Affine Function: R^2 -> R^2
 F3 = AffFunction([5 6; 7 8; 9 -1]) 
Affine Function: R^2 -> R^3
Add functions to a polyhedron with corresponding names in a cell array.
 P.addFunction(F1, 'a') 
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 1 attached "a"
 P.addFunction(F2, 'b') 
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 2 attached "a", "b"
 P.addFunction(F3, 'c') 
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 3 attached "a", "b", "c"
Evaluate function "a" for the point [-1;-1]
 P.feval([-1;-1],'a') 
ans =

    -3

Evaluate functions "b" and "c" for the point [-1;-1]
 y1 = P.feval([-1;-1],'b') 
y1 =

    -7
     1

 y2 = P.feval([-1;-1],'c') 
y2 =

   -11
   -15
    -8

See Also

fplot, function


© 2010-2013 Martin Herceg: ETH Zurich, herceg@control.ee.ethz.ch

© 2003-2013 Michal Kvasnica: STU Bratislava, michal.kvasnica@stuba.sk