FunctionOverSets

Geometry.FunctionOverSets History

Hide minor edits - Show changes to markup

August 06, 2013, at 02:20 PM by Martin Herceg -
Added line 146:
Changed line 171 from:
to:
August 06, 2013, at 02:19 PM by Martin Herceg -
Added line 121:
August 06, 2013, at 02:17 PM by Martin Herceg -
Added line 97:
August 06, 2013, at 02:15 PM by Martin Herceg -
Added line 61:
August 06, 2013, at 02:13 PM by Martin Herceg -
Added line 32:
August 05, 2013, at 11:49 AM by Martin Herceg -
Changed line 22 from:
 S.plot
to:
 S.plot()
Changed line 26 from:
 S.fplot
to:
 S.fplot()
Changed line 106 from:

U.feval(-1,'tiebreak', @(x)0 )

to:

U.feval(-1, 'tiebreak', @(x)0 )

Changed line 116 from:

U.fplot

to:

U.fplot()

Changed line 121 from:

U.feval(-1, 'a','tiebreak','a')

to:

U.feval(-1, 'a', 'tiebreak', 'a')

Changed line 140 from:

U.fplot

to:

U.fplot()

Changed line 164 from:

U.fplot

to:

U.fplot()

August 03, 2013, at 03:49 PM by Martin Herceg -
Changed line 155 from:

To each of the polyhedra a function is assigned under the same name "g", create a PolyUnion object, and plot the function over the union.

to:

To each of the polyhedra a function is assigned under the same name "g", then the PolyUnion object is created and the function over the union is plotted.

August 03, 2013, at 03:47 PM by Martin Herceg -
August 03, 2013, at 03:47 PM by Martin Herceg -
Changed lines 128-129 from:
  • y1 = 0.3*x^2 -1.6*x -1.7 if [-5, -2]
  • y2 = 0.3*x^2 +0.4*x + 2.3 if [-2, 1]
to:
  • y1 = 0.3*x^2 - 1.6*x - 1.7 if [-5, -2]
  • y2 = 0.3*x^2 + 0.4*x + 2.3 if [-2, 1]
Added lines 149-165:

The piecewise function represents any general function defined over polyhedra. Consider the following partition comprising of three regions in two-dimensional space:

(:source lang=MATLAB -getcode:)
P(1) = Polyhedron([0 0; 2 2; 0 4]);
P(2) = Polyhedron([0 0; 4 0; 4 2; 2 2]);
P(3) = Polyhedron([0 4; 4 4; 4 2; 2 2]);

To each of the polyhedra a function is assigned under the same name "g", create a PolyUnion object, and plot the function over the union.

(:source lang=MATLAB -getcode:)
F1 = AffFunction([2.8 3.3]);
P(1).addFunction(F1, 'g');
F2 = QuadFunction(0.2*eye(2), [-3.2, 2.9], 11.2);
P(2).addFunction(F2, 'g');
F3 = Function(@(x) 0.4*x(1)^2 + 0.8*sqrt(x(1)+x(2)) - 1.3*x(1)*x(2) + 14.2 );
P(3).addFunction(F3, 'g');
U = PolyUnion('Set', P, 'Overlaps', false, 'Convex', true)
U.fplot
August 03, 2013, at 03:24 PM by Martin Herceg -
Deleted line 124:
Changed lines 127-128 from:
to:

Piecewise quadratic (PWQ) function can be represented as an union of quadratic functions over polyhedra. Consider the following function y(x) = 0.3*|x-1|^2 + |x+2| over the interval [-5, 5]. The function can be decomposed to three intervals:

  • y1 = 0.3*x^2 -1.6*x -1.7 if [-5, -2]
  • y2 = 0.3*x^2 +0.4*x + 2.3 if [-2, 1]
  • y3 = 0.3*x^2 + 0.4*x + 2.3 if [1, 5]

where the two intervals share the same function value. Such a function can be modeled in MPT with the help of Polyhedron, QuadFunction and PolyUnion objects:

(:source lang=MATLAB -getcode:)
S(1) = Polyhedron('lb', -5, 'ub', -2 );
S(1).addFunction( QuadFunction(0.3, -1.6, -1.7), 'q' );
S(2) = Polyhedron('lb', -2, 'ub', 1);
S(2).addFunction( QuadFunction(0.3, 0.4, 2.3), 'q' );
S(3) = Polyhedron('lb', 1, 'ub', 5);
S(3).addFunction( QuadFunction(0.3, 0.4, 2.3), 'q' );
U = PolyUnion('Set', S, 'Overlaps', false, 'Convex', true, 'FullDim', true, 'Bounded', true)
U.fplot

Evaluation of PWQ function is achieved using the overloaded feval method as for PWA functions:

(:source lang=MATLAB -getcode:)
U.feval(0.6)
August 03, 2013, at 02:59 PM by Martin Herceg -
Changed line 118 from:

Note that evaluation of such a function could return two different values for a point that is shared in two intervals:

to:

Note that evaluation of such a function could return two different values for a point that is shared in two intervals. This case can be resolved by a tie-breaking function which in this example takes the minimum of the same function 'a'

Changed lines 120-121 from:

U.feval(1)

to:

U.feval(-1, 'a') U.feval(-1, 'a','tiebreak','a')

August 03, 2013, at 02:49 PM by Martin Herceg -
Added lines 107-120:

@]

Consider a PWA function that is defined over two regions which are overlapping.

(:source lang=MATLAB -getcode:)
P(1) = Polyhedron('lb', -3, 'ub', 2 );
P(1).addFunction( AffFunction(-0.8, 1), 'a' );
P(2) = Polyhedron('lb', -2, 'ub', 3);
P(2).addFunction( AffFunction(0.8, 1), 'a' );
U = PolyUnion('Set', P, 'Overlaps', true)
U.fplot

Note that evaluation of such a function could return two different values for a point that is shared in two intervals: (:source lang=MATLAB -getcode:) [@ U.feval(1)

August 03, 2013, at 01:55 PM by Martin Herceg -
Changed line 37 from:

Multiple functions can be attached to a set. In the following example two functions are attached to an interval [0, 1]

to:

Multiple functions can be attached to a set. In the following example two functions are attached to an interval [0, 2]

Changed lines 40-43 from:
 f2 = AffFunction(0.3)
 P = Polyhedron('lb', 0, 'ub', 1);
 P.addFunction(f1, 'nonlinear')
 P.addFunction(f2, 'linear')
to:
 f2 = AffFunction(0.3,1)
 P = Polyhedron('lb', 0, 'ub', 2);
 P.addFunction(f1, 'a')
 P.addFunction(f2, 'b')
Changed line 46 from:

The stored function objects are accessible by index using the Func property or can be extracted via the getFunction method

to:

The stored function objects are accessible by index using the Func property or can be extracted via the getFunction method by pointing to their names

Changed lines 48-49 from:
 P.getFunction('nonlinear')
 P.getFunction('linear')
to:
 P.getFunction('a')
 P.getFunction('b')
Changed lines 52-53 from:
to:

Referencing to the function name is useful for plotting the specific function over the set

(:source lang=MATLAB -getcode:)
 P.fplot('a','color','green','linewidth', 2); 
 hold on
 P.fplot('b','color','blue', 'linewidth', 2, 'linestyle', '--');
 P.plot('color', 'red', 'linewidth', 2)
 legend(2,'a', 'b')

The evaluation of the function for a particular point is achieved via feval method and the function must be referenced by its name. For instance, to evaluate the function "a" for a point 0.5 can be done as follows

(:source lang=MATLAB -getcode:)
 P.feval(0.5, 'a')
Added lines 69-107:

Piecewise affine (PWA) function can be represented as union of sets that have attached an affine function. In the previous section you can learn how to construct single function over a set. Merging multiple affine functions over sets to a compact form of the PolyUnion object represents a piecewise affine function over polyhedra. As an example, consider a saturated controller u(x) = 1 if -5 <= x<= -1, u(x) = -x if -1 <= x <= 1, u(x) = -1 if 1 <= x <= 5 . To create PWA function the corresponding intervals are defined as Polyhedron objects:

(:source lang=MATLAB -getcode:)
 R(1) = Polyhedron('lb', -5, 'ub', -1);
 R(2) = Polyhedron('lb', -1, 'ub', 1);
 R(3) = Polyhedron('lb', 1, 'ub', 5);

Secondly, the function objects are created and attached to the intervals under the same name

(:source lang=MATLAB -getcode:)
 f(1) = AffFunction(0, 1);
 f(2) = AffFunction(-1);
 f(3) = AffFunction(0, -1);
 R(1).addFunction(f(1), 'u');
 R(2).addFunction(f(2), 'u');
 R(3).addFunction(f(3), 'u');

Thirdly, the functions over sets are merged to a single PolyUnion object. If some properties of the union are known at the time of constructing the PolyUnion object, one can associate them directly to the constructor:

(:source lang=MATLAB -getcode:)
U = PolyUnion('Set', R, 'Convex', true, 'Overlaps', false, 'Bounded', true, 'FullDim', true, 'Connected', true)

The PWA function can be plotted using overloaded fplot function that applies for PolyUnion objects:

(:source lang=MATLAB -getcode:)
U.fplot('u', 'linewidth', 2)
axis([-8 8 -2 2])
xlabel('x')
ylabel('u')

Evaluation of PWA functions proceeds via overloaded feval function. If there is only one function attached to a set, one does not have to refer to the name

(:source lang=MATLAB -getcode:)
U.feval(3)

Note that for two points -1,1 there exist two functions values because these points lie at the connection of the intervals. When evaluation of PWA function is invoked for such a point, two values are returned

(:source lang=MATLAB -getcode:)
U.feval(-1)
U.feval(1)

To get rid of multiple values, it is always recommended to use the extended evaluation syntax that considers the tie-break criterion to decide which value to use. For instance, if an anonymous function @(x)0 is used as a tie-breaking function, it takes always the first choice

(:source lang=MATLAB -getcode:)
U.feval(-1,'tiebreak', @(x)0 )
August 02, 2013, at 03:34 PM by Martin Herceg -
Deleted line 45:
Added lines 47-51:
(:source lang=MATLAB -getcode:)
 P.getFunction('nonlinear')
 P.getFunction('linear')
August 02, 2013, at 02:05 PM by Martin Herceg -
Changed lines 14-47 from:
to:

Function over the set can be constructed by attaching the Function object to an object derived from the ConvexSet class. Consider a quadratic function y = x^2 - 2*x +1 defined over the interval -1 <= x <= 2 . To represent such a function over the set in MPT, it is required to construct corresponding Function object and ConvexSet object and then add the function to the set using addFunction method:

(:source lang=MATLAB -getcode:)
 F = QuadFunction(1, -2, 1);
 S = Polyhedron('lb', -1, 'ub', 2);
 S.addFunction(F,'alpha')

When adding the Function object to the ConvexSet object, it is required to provide the name of the function to be used for referencing. In the above example the quadratic function will be stored under the name "alpha". The name of the function is obligatory in order to distinguish multiple functions over the set. When the function has been attached, the object still behaves as a convex set and all methods applicable for ConvexSet class can be used, including additional methods for functions over sets. For instance, to plot the set one can use the plot method

(:source lang=MATLAB -getcode:)
 S.plot

that applies for objects derived from the ConvexSet class. To plot the function over the set, the specific method fplot applies

(:source lang=MATLAB -getcode:)
 S.fplot

To plot both, the set and the function over the set, it is required to provide some arguments for the fplot method:

(:source lang=MATLAB -getcode:)
 S.fplot('show_set', true, 'color', 'blue', 'linewidth', 2, 'linestyle', '--')

For more help on plotting functions over sets, type

(:source lang=MATLAB -getcode:)
 help ConvexSet/fplot

Multiple functions can be attached to a set. In the following example two functions are attached to an interval [0, 1]

(:source lang=MATLAB -getcode:)
 f1 = Function( @(x)exp(0.3*x) )
 f2 = AffFunction(0.3)
 P = Polyhedron('lb', 0, 'ub', 1);
 P.addFunction(f1, 'nonlinear')
 P.addFunction(f2, 'linear')

The stored function objects are accessible by index using the Func property or can be extracted via the getFunction method

July 31, 2013, at 02:22 PM by Martin Herceg -
Changed line 3 from:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets, constrution of unions of sets, unions of polyhedra?, and construction of functions.

to:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets, constrution of unions of sets, and construction of functions.

July 31, 2013, at 01:45 PM by Martin Herceg -
Changed line 3 from:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets, constrution of unions of sets, and construction of functions.

to:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets, constrution of unions of sets, unions of polyhedra?, and construction of functions.

July 31, 2013, at 01:43 PM by Martin Herceg -
Changed lines 3-4 from:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets and construction of functions.

to:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets, constrution of unions of sets, and construction of functions.

Added lines 11-14:

Single function over the set

July 31, 2013, at 01:36 PM by Martin Herceg -
Added lines 2-3:

This part explains construction of piecewise functions, i.e. functions defined over sets. To understand the basic concepts, you should be familiar with the construction of sets and construction of functions.

July 31, 2013, at 01:31 PM by Martin Herceg -
Changed lines 1-26 from:

Construction of functions over sets

to:

Construction of functions over sets


Piecewise Affine Function

Piecewise Quadratic Function

Piecewise Function

Back to computational geometry overview.

July 31, 2013, at 01:25 PM by Martin Herceg -
Added line 1:

Construction of functions over sets