mpt_demo_functions1

Purpose

Demonstration of functions associated to sets

Syntax

mpt_demo_functions1

Description

Demonstration of functions associated to sets.

Example(s)

Example 1

Constructing general functions Create Function object ../../../fig/mpt/demos/mpt_demo_functions11.png.
 F1 = Function(@(x)x) 
Function: @(x)x
Create Function object ../../../fig/mpt/demos/mpt_demo_functions12.png.
 F2 = Function(@(x) x_(1)-x_(2)^3) 
Function: @(x)x_(1)-x_(2)^3
Create Function with parameter ../../../fig/mpt/demos/mpt_demo_functions13.png, ../../../fig/mpt/demos/mpt_demo_functions14.png. Since the parameter value may change, we first create the object with the parameter ../../../fig/mpt/demos/mpt_demo_functions15.png.
 F3 = Function([],struct('K',eye(2))) 
Empty Function
Once the object has been created, we can assign the handle and refer to already stored parameter ../../../fig/mpt/demos/mpt_demo_functions16.png.
 F3.setHandle(@(x) -log(F3.Data.K*x)) 
Function: @(x)-log(F3.Data.K*x)
We can change the value of the parameter any time later.
 F3.Data.K = 2*eye(2) 
Function: @(x)-log(F3.Data.K*x)

Example 2

Constructing linear and affine functions Affine map ../../../fig/mpt/demos/mpt_demo_functions17.png
 L1 = AffFunction(6,1) 
Affine Function: R^1 -> R^1
Affine map ../../../fig/mpt/demos/mpt_demo_functions18.png
 L2 = AffFunction([-1,1],1) 
Affine Function: R^2 -> R^1
Vector function ../../../fig/mpt/demos/mpt_demo_functions19.png.
 L3 = AffFunction(eye(2),[1;2]) 
Affine Function: R^2 -> R^2
Linear function ../../../fig/mpt/demos/mpt_demo_functions110.png
 L4 = AffFunction(eye(5)) 
Affine Function: R^5 -> R^5

Example 3

Constructing quadratic functions Quadratic map ../../../fig/mpt/demos/mpt_demo_functions111.png.
 Q1 = QuadFunction(1,1) 
Quadratic Function: R^1 -> R^1
Quadratic map ../../../fig/mpt/demos/mpt_demo_functions112.png.
 Q2 = QuadFunction(2,-4) 
Quadratic Function: R^1 -> R^1
Quadratic map ../../../fig/mpt/demos/mpt_demo_functions113.png
 Q3 = QuadFunction(eye(2),[0,0],1) 
Quadratic Function: R^2 -> R^1

Example 4

Assign function to a set Construct the polyhedron first.
 P1 = Polyhedron('lb',-1,'ub',1)
Polyhedron in R^1 with representations:
    H-rep (redundant)   : Inequalities   2 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : none
Assign the function to a set under under the name "a".
 P1.addFunction(QuadFunction(4,-1),'a') 
Polyhedron in R^1 with representations:
    H-rep (redundant)   : Inequalities   2 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 1 attached "a"
Another polyhedron
 P2 = Polyhedron('V',[-1 1;1 1; -1 -1]) 
Polyhedron in R^2 with representations:
    H-rep               : Unknown (call computeHRep() to compute)
    V-rep (redundant)   : Vertices   3 | Rays   0
Functions : none
Assign the function under the name "b".
 P2.addFunction(AffFunction(-eye(2),[-1;2]),'b') 
Polyhedron in R^2 with representations:
    H-rep               : Unknown (call computeHRep() to compute)
    V-rep (redundant)   : Vertices   3 | Rays   0
Functions : 1 attached "b"
You can assign names to functions handles.
P3 = Polyhedron('lb',[-1;-1],'ub',[1;1])
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : none
P3.addFunction(Function(@(x)x.^2-x.^3+1),'gain') 
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 1 attached "gain"
P3.addFunction(AffFunction(randn(2)),'power') 
Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 2 attached "gain", "power"
Multiple functions can be assign only at separate calls.
 P4 = Polyhedron('V',randn(6,2)); 

 L(1) = AffFunction(randn(2),randn(2,1)); 

 L(2) = AffFunction(randn(2),randn(2,1)); 

 P4.addFunction(L(1),'a') 
Polyhedron in R^2 with representations:
    H-rep               : Unknown (call computeHRep() to compute)
    V-rep (redundant)   : Vertices   6 | Rays   0
Functions : 1 attached "a"
 P4.addFunction(L(2),'b') 
Polyhedron in R^2 with representations:
    H-rep               : Unknown (call computeHRep() to compute)
    V-rep (redundant)   : Vertices   6 | Rays   0
Functions : 2 attached "a", "b"

Example 5

Plotting of functions Plot the function over the set based on the name
 P3.fplot('gain') 

../../../fig/mpt/demos/mpt_demo_functions1_img_1.png

 P3.fplot('power') 

../../../fig/mpt/demos/mpt_demo_functions1_img_2.png

Plot the first element of the vector valued function "a"
 P4.fplot('a','position',1,'color','y') 

../../../fig/mpt/demos/mpt_demo_functions1_img_3.png

Plot the second element of the vector valued function "b" based on the index.
 P4.fplot('b','position',2,'color','m') 

../../../fig/mpt/demos/mpt_demo_functions1_img_4.png

Example 6

Evaluation of functions Evaluate the function based on the name
 P3.feval([1;0],'power') 
ans =

         0.482747657739079
         0.373550607694242

Evaluate the function "gain"
 P3.feval([-1;0],'gain') 
ans =

     3
     1

See Also

mpt_demo_functions2


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