1. What is the formation of cost function in YALMIP LPV1 example, ?
2. How is absolute value been obtained by max(aa[x;u]+bb), where is the max operator?
In the example, author says no need to do so in the
newest version of YALMIP
, but do what?
3.
is a 12 by 1 vector in my case, while
is a scalar, is it ok to sum them up?
60 % |x| written as max(a[x;u]+b)
61 a = [kron(eye(nx+nu),[1 -1]') zeros(2*(nx+nu),nu)];
62 b = zeros(2*(nx+nu),1);
63 % |u| written as max(c[x;u]+d)
64 c = [zeros(2*nu,(nx+nu)) kron(eye(nu),[1 -1]')];
65 d = zeros(2*nu,1);
67 % |x|+|u| written as max(aa[x;u]+bb)
68 aa = repmat(a,2*nu,1) + kron(c,ones(size(a,1),1));
69 bb = repmat(b,2*nu,1) + kron(d,ones(size(a,1),1));
71 % Final state constraints
72 F = [F, xmin <= xp <= xmax];
74 % Cost function
75 F = [F, aa*[Q*(xp-xref);R*u{k}]+bb + norm(Q*(x{k}-xref),inf) <= w];
main_v0.m
YALMIP LPV1 example
full copy of LPV1 code
1. summarize all kinds of MPC cost function from ppt slider like tutorials and fundamental handbooks.
2. download the
newest version of YALMIP
to search for the answers. Especially syntax of
and
.
3. same as 2.
using and .
1 % first step robustify starts here
1 ***** Starting YALMIP robustification module. *********************
2 - Detected 2 uncertain variables % th{3}(1,1) and th{3}(2,1)
3 - Detected 1 independent group(s) of uncertain variables % due to F.origin #2 equality's exsistence, th{3}(:,1) has only 1 DOF (max possibility of 2), if one of them fixed ,the other is fixed also
4 ***** Derivation of robust counterpart done ***********************
5 % first step robustify ends here, solvemp starts here
6 mpt_plcp: 35 regions
7 -> Generated 1 partition.
8 % first step solvemp ends here, second step robustify starts here
9 ***** Starting YALMIP robustification module. *********************
10 - Detected 2 uncertain variables
11 - Detected 1 independent group(s) of uncertain variables
12 ***** Derivation of robust counterpart done ***********************
13 % second step robustify ends here, second step solvemp starts here
14 regions: 24, unexplored: 7
15 regions: 63, unexplored: 6
16 mpt_plcp: 86 regions
17 -> Generated 1 partition.
18 % second step solvemp ends here, last step robustify starts here
19 ***** Starting YALMIP robustification module. *********************
20 - Detected 2 uncertain variables
21 - Detected 1 independent group(s) of uncertain variables
22 ***** Derivation of robust counterpart done ***********************
23 % last step robustify ends here, last step solvemp starts here
24 regions: 7, unexplored: 4
25 regions: 18, unexplored: 6
26 regions: 29, unexplored: 8
27 regions: 43, unexplored: 7
28 regions: 54, unexplored: 5
29 mpt_plcp: 65 regions
30 -> Generated 1 partition.
function [F,h,failure] = robustify(F,h,ops,w)
shows that it actually has 4th input.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| ID| Constraint|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| #1| Uncertainty declaration| % line 35 uncertain(th{3})
| #2| Equality constraint 1x1| % line 35 sum(th{3}) == 1
| #3| Element-wise inequality 4x1| % line 35 0 <= th{3} <= 1
| #4| Element-wise inequality 2x1| % line 37 0 <= w <= 10000
| #5| Element-wise inequality 4x1| % line 44 repmat(umin,ndyn,1) <= u{3} <= repmat(umax,ndyn,1)
| #6| Element-wise inequality 4x1| % line 46 xmin <= x{3} <= xmax
| #7| Element-wise inequality (polynomial) 4x1| % line 61 xmin <= xp <= xmax, polynomial
| #8| Element-wise inequality (polynomial,derived) 8x1| % line 63 aa*[Q*(xp-xref);R*uth]+bb + norm(Q*(x{k}-xref),inf) <= w, derived is due to norm operator
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++
| ID| Constraint|
+++++++++++++++++++++++++++++++++++++++++++++++++
| #1| Element-wise inequality 4x1| ##########################
| #2| Element-wise inequality 4x1| #7 xmin <= xp <= xmax
| #3| Element-wise inequality 4x1|
| #4| Element-wise inequality 4x1| ##########################
| #5| Element-wise inequality (derived) 4x1| #8 aa*[Q*(xp-xref);R*uth]+bb + norm(Q*(x{k}-xref),inf) <= w
| #6| Element-wise inequality (derived) 4x1|
| #7| Element-wise inequality (derived) 4x1|
| #8| Element-wise inequality (derived) 4x1|
| #9| Element-wise inequality (derived) 4x1|
| #10| Element-wise inequality (derived) 4x1|
| #11| Element-wise inequality (derived) 4x1|
| #12| Element-wise inequality (derived) 4x1|
| #13| Element-wise inequality (derived) 4x1| ########################## This one totally due to norm(Q*(x{k}-xref),inf) in #8, and no need for relaxation
| #14| Element-wise inequality 2x1| #4 0 <= w <= 10000
| #15| Element-wise inequality 4x1| #5 repmat(umin,ndyn,1) <= u{3} <= repmat(umax,ndyn,1)
| #16| Element-wise inequality 4x1| #6 xmin <= x{3} <= xmax, none of them has things to do with th{3}
+++++++++++++++++++++++++++++++++++++++++++++++++
When
F.origin
#2 equality removed, the result after first
is
.
In the final section, the fundamental usage of mpc in yalmip will be explained. However, there is still a long way to go to fully master yalmip and mpt3
[sol{k},diagnost{k},Uz{k},J{k},Optimizer{k}] = solvemp(F,obj,yopts,x{k},u{k});
J{k} is the value function, Optimizer{k} is the decision function to get the optimal control input.