Paper3 simulation

I. Cost function

problems:

1. What is the formation of cost function in YALMIP LPV1 example, Δx+u+Δxinf?
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. Δx+u is a 12 by 1 vector in my case, while Δxinf is a scalar, is it ok to sum them up?

codes in main_v0.m:

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];

source files:

main_v0.m
YALMIP LPV1 example
full copy of LPV1 code

hints to problems:

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.

hints to hints to problems:

1. references list
2. run test code in syntax of and YALMIP robust model

full copy of YALMIP LPV1 codes:


source file: YALMIP_LPV1.m

result and conclusion to all hints:

1. the formation in YALMIP LPV1 example is a standard cost function like as is shown in page 30 of Model Predictive Control - Basic Concepts.pdf , which is written as

J=k=0N-1[xT(k)Qx(k)+uT(k)Ru(k)]+xT(N)Px(N)

using and .
2. is not used by YALMIP LPV1 example but . so we are not about to investigate because there are two parametric variables - th{k} and x{k}, plus decision variable u{k} in YALMIP LPV1 example , which is solved by involving function and .

pre analysis of YALMIP LPV1 example :

1. run full code of it, see
a) how gets 4th input.
b) what is the running cost and final cost.
c) read comments carefully.

2. compare cost function and cost-to-go in YALMIP LPV1 example and page 30 of Model Predictive Control - Basic Concepts.pdf and , find out what is the structure of iteration cost function in YALMIP LPV1 example by excluding the interference of .
3. learn MPT3 by .
4. find clues (especially function of robustify and solvemp) in YALMIP newest release .

post analysis of YALMIP LPV1 example :

1. output and result of run code fully and segmentedly, commented by @trancemania:
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.
a) there are two .m file in YALMIP newest release , one should be a dummy function under /extras/@optproblem directory, another under /modules/robust should be the real function, the syntax

function [F,h,failure] = robustify(F,h,ops,w)

shows that it actually has 4th input.
Original constraint variable F (F.origin) is
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|   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
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

after first step , constraint variable F become F.first
+++++++++++++++++++++++++++++++++++++++++++++++++
|    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 .
When F.origin sdpsettings robust.polya set to NaN (yopts = sdpsettings('robust.polya',NaN);), the result after first is .
When F.origin sdpsettings robust.polya set to 2 (yopts = sdpsettings('robust.polya',2);), the result after first is . When relaxation order rises, number of LMI unchanged, #1~#12 LMI order rise following relaxation order except #13.
When F.origin #8 LMI with norm(Q*(x{k}-xref),inf) exempted, the result after first is . Plus polya set to 2, result is . The order unchanged #13 LMI after first robustify missed, and all of "derived" description gone.
When F.origin with #8 LMI exempted, the result after first is , while with #7 LMI exempted, the result after first is

CONCLUSION:

1. robustify
a) the order of robustify is to eliminate uncertainty, purely uncertain LMI will be used to generate all possible case, in YALMIP LPV1 example , th{3} has 4 possible combination, therefore, #1~4 in robustified F.first are corresponding to #7 in F.origin . #5~13 in robustified F.first are corresponding to #8 in F.origin , note #13 are totolly corresponeding to norm.
b) second order of robustify is to decouple polynomials.
c) the procedure of robustify is firstly go through uncertainty, then certainty.
d) binvar's bound 0~1 mustn't be omitted.
e) the 8 variables in #8 LMI of F.origin are th{3}(1,1),th{3}(2,1),x{3}(1,1),x{3}(2,1),u{3}(1,1),u{3}(2,1),norm(),w.

II. CLOTURE

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

1. unsolved
a)
b) usage of .
c) usage of , structure of sol, region, unexplored, partition, solver of plcp
2. guideline of how to use yalmip
a) basic syntax

[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.
usage:
i. draw decision function and value function
value function: figure;plot(J{1})
decision function: figure;plot(Optimizer{1})
ii. optimal control input and cost
control input:
assign(x{1},[-1;1]);
value(Optimizer{1})
cost: value(J{1})
3. further
a) probability affects result
b) continuous uncertainty
c) how to get the most optimal result
d) LPV2