Demonstration of functions associated to sets
mpt_demo_functions1
F1 = Function(@(x)x)
Function: @(x)xCreate Function object
F2 = Function(@(x) x_(1)-x_(2)^3)
Function: @(x)x_(1)-x_(2)^3Create Function with parameter
F3 = Function([],struct('K',eye(2)))
Empty FunctionOnce the object has been created, we can assign the handle and refer to already stored parameter
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)
L1 = AffFunction(6,1)
Affine Function: R^1 -> R^1Affine map
L2 = AffFunction([-1,1],1)
Affine Function: R^2 -> R^1Vector function
L3 = AffFunction(eye(2),[1;2])
Affine Function: R^2 -> R^2Linear function
L4 = AffFunction(eye(5))
Affine Function: R^5 -> R^5
Q1 = QuadFunction(1,1)
Quadratic Function: R^1 -> R^1Quadratic map
Q2 = QuadFunction(2,-4)
Quadratic Function: R^1 -> R^1Quadratic map
Q3 = QuadFunction(eye(2),[0,0],1)
Quadratic Function: R^2 -> R^1
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 : noneAssign 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 : noneAssign 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"
P3.fplot('gain')
P3.fplot('power')
P4.fplot('a','position',1,'color','y')
P4.fplot('b','position',2,'color','m')
P3.feval([1;0],'power')
ans = 0.482747657739079 0.373550607694242Evaluate the function "gain"
P3.feval([-1;0],'gain')
ans = 3 1
◀ | mpt | mpt_demo_deployment_onlinempc | ▶ |
© 2010-2013 Martin Herceg: ETH Zurich, herceg@control.ee.ethz.ch