-
Notifications
You must be signed in to change notification settings - Fork 5
/
PWAAnalNon.m
278 lines (275 loc) · 10.2 KB
/
PWAAnalNon.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
clear model pwasys
echo on;
clc
% *************************************************************************
% ANALYZING A NONLINEAR MODEL FOR STABILITY (GLOBAL LYAPUNOV APPROACH)
% *************************************************************************
%
% PWATOOL can analyze a nonlinear model, approximated with PWADIs, to
% check if it is stable at a given point xcl.
%
% Please hit number 1 and 3 in the main menu of PWATOOL to learn about
% PWADIs.
%
% A nonlinear model which is bounded within a lower and upper envelope is
% stable at a given point xcl if both of the envelopes are stable at that
% given point xcl.
%
% Reference: B. Samadi and L. Rodrigues. Extension of local linear
% controllers to global piecewise affine controllers for uncertain
% non-linear systems. International Journal of Systems Science,
% 39(9):867-879, 2008.
%
% We explain how a nonlinear system is analyzed for stability.
%
pause; %strike any key to continue
clc
% STABILITY ANALYSIS: A GLOBAL LYAPUNOV APPROACH
%
%
% Let a nonlinear model be approximated by PWADIs as follows
%
% sigma_j: dx/dt=A{i,j} x+ a{i,j}+ B{i,j} u j=1,2 and x is in region R_i (*)
%
% where regions R_i are defined to be
%
% R_i={x | E{i} x + e{i} >= 0 }. i=1,2,...,NR
%
pause; %strike any key to continue
%
% (OPTIONAL) Also, let the controller output in each region R_i be
%
% u=K{i} x +k{i} if x is in R_i.
%
% NOTE: If controller gains K{i} and k{i} are not defined, the system is
% considered open-loop and controller gains K{i} and k{i} will be zero.
%
pause; %strike any key to continue
clc
% PWATOOL analyzes the system by searching for a global quadratic Lyapunov
% function for the system; PWATOOL searches for a positive definite matrix
% 'Q' that satisfies the following conditions for a constant positive
% scalar 'alpha'.
%
%
% 1) V(x) = x' Q x >0 for x defined by sigma_j
% 2) dV/dt = d(x' Q x)/dt <-alpha * V(x) for x defined by sigma_j
%
% Conditions (1) and (2) amount to the following LMIs
%
pause; %strike any key to continue
clc
% Let Z{i} be matrices of proper size with non-negative elements which are
% to be found. Then, the following LMIs are obtained for i=1,2,...,NR and
% j=1,2.
%
%
% (1) Q>0, Z{i}(:) >0
%
% (2) In regions R_i which contain the equilibrium point xcl
%
% Q*(A{i,j}+B{i,j}*K{i})+(A{i,j}+B{i,j}*K{i})'*Q+alpha*Q <0
%
%
% (3) In regions R_i which do NOT contain the equilibrium point xcl
%
% [Q*(A{i,j}+B{i,j}*K{i})+(A{i,j}+B{i,j}*K{i})'*Q+alpha*Q+E{i}'*Z{i}*E{i} (Q*a{i,j}+B{i,j}*k{i})+E{i}'*Z{i}*e{i};
% (Q*(a{i,j}+B{i,j}*k{i})+E{i}'*Z{i}*e{i})' e{i}'*Z{i}*e{i}] < 0
%
pause; %strike any key to continue
clc
% NOTE 1: PWATOOL uses Yalmip to solve above LMIs. A solution, then, may or
% may not be found by the solver. Since the previous LMIs are
% sufficient conditions for stability, we can conclude the system is
% stable only if we find a Q>0 that satisfies above LMIs. In case a
% matrix Q>0 is not found we may not be able to comment on the
% stability of the system.
%
pause; %strike any key to continue
clc
% NOTE 2: The regions can also be approximated with ellipsoids which in the
% case of slab regions they will be degenerate ellipsoids. This
% yields to a different set of LMIs which again are sufficient
% conditions for stability:
%
% References: (1) L. Rodrigues and S. Boyd. Piecewise-affine state feedback
% for piecewise-affine slab systems using convex optimization.
% Systems and Control Letters, 54:835-853, 200
%
% (2) A. Hassibi and S. Boyd. Quadratic stabilization and
% control of piecewise-linear systems. Proceedings of the
% American Control Conference, 6:3659-3664, 1998
%
% (3) L. Vandenberghe, S. Boyd, and S.-P. Wu. Determinant
% maximization with linear matrix inequality constraints. SIAM
% Journal on Matrix Analysis and Applications,9(2):499-533,1998
%
pause; %strike any key to continue
clc
% To obtain LMIs with ellipsoidal approximation, let 'Elip_i' be the
% ellipsoid that approximates region R_i and is described as follows:
%
% Elip_i={x | || EL{i} x + eL{i}|| < 1}
%
% Also let miu{i} be the negative scalars which are to be found. Then, we
% should satisfy the following LMis.
%
pause; %strike any key to continue
%
% For i=1,2,...,NR and j=1,2
%
% (1) Q>0 , miu{i} <0
%
% (2) In regions R_i which contain the equilibrium point xcl
%
% Q*(A{i,j}+B{i,j}*K{i})+(A{i,j}+B{i,j}*K{i})'*Q+alpha*Q <0
%
%
% (3) In regions R_i which do NOT contain the equilibrium point xcl
%
% [Q*(A{i,j}+B{i,j}*K{i})+(A{i,j}+B{i,j}*K{i})'*Q+alpha*Q+miu{i}*EL{i}'*EL{i} Q*(a{i,j}+B{i,j}*k{i})+miu{i}*EL{i}'*eL{i};
% (Q*(a{i,j}+B{i,j}*k{i})+miu{i}*EL{i}'*eL{i})' -miu{i}*(1-eL{i}'*eL{i});]<0
%
%
pause; %strike any key to continue
clc
%
% STABILITY ANALYSIS OF A NONLINEAR MODEL USING PWATOOL
%
% We use the inverted pendulum example (L. Rodrigues and J.P. How, 2002)
% to show how PWATOOL analyzes a nonlinear model.
%
% |-----------------------------------------------------------------------|
% | STEP 0: APPROXIMATING THE NONLINEAR MODEL WITH PWADI
% |-----------------------------------------------------------------------|
%
% Please hit number 3 in the main menu of PWATOOL for "CREATING A PWADI
% MODEL"
%
% For the inverted pendulum example we load the variable 'inv_pend_pwadi'
%
load inv_pend_pwadi
%
% by doing so, a variable called 'pwainc' will contain the PWADI
% approximation of the inverted pendulum.
%
pause; %strike any key to continue
clc
% |-----------------------------------------------------------------------|
% | STEP 1: CHECKING THE STABILITY OF A PWADI model
% |-----------------------------------------------------------------------|
%
% To check the stability of the the PWADI model 'pwainc' at the equilibrium
% point 'xcl', type
%
% pwaanalysis(pwainc, setting);
%
% where setting is a structured variable with the following fields:
%
pause; %strike any key to continue
%
% setting.Lyapunov: shows whether 'global' or 'pwq' (piecewise quadratic)
% Lyapunov function should be used in the analysis
%
% For the inverted pendulum example we set
%
setting.Lyapunov='global';
%
% This means that PWATOOL uses only global Lyapunov function in analysis.
%
pause; %strike any key to continue
clc
% setting.ApxMeth: shows whether 'ellipsoidal' or 'quadratic' curve
% method should be used to approximate the regions.
%
% For the inverted pendulum example we don't set this field so that it
% takes the default value {'quadratic', 'ellipsoidal'}.
%
pause; %strike any key to continue
%
% setting.alpha : specifies the decay rate in finding the Lyapunov function.
% Generally, bigger values of alpha make the convergence
% harder.
%
% For the inverted pendulum example, we set
%
setting.alpha=.1;
%
pause; %strike any key to continue
%
% setting.xcl : shows the desired equilibrium point which user sets.
% If it is not set by the user, PWATOOL uses the
% pwainc.xcl (if exists) as the equilibrium point.
% PWATOOL issues an error and stops running if xcl is not
% defined or if at xcl we cannot satisfy the equilibrium
% point equations analytically.
%
% For the inverted pendulum example, we set
%
setting.xcl=[0 pi 0 0]';
%
pause; %strike any key to continue
clc
% We call 'pwaanalysis' to analyze the stability of the model at xcl
%
pause; %strike any key to continue
%
pwaanalysis(pwainc, setting);
pause; %strike any key to continue
clc
% |-----------------------------------------------------------------------|
% | STEP 2: RESULTS AND DUISCUSSIONS
% |-----------------------------------------------------------------------|
%
% We can only say the system is stable if a positive definite matrix Q is
% found; otherwise we cannot comment on the stability of the nonlinear
% system.
%
pause; %strike any key to continue
%
% In the inverted pendulum example the message
% "I could not verify if the open-loop nonlinear system is stable at xcl."
% implies that LMIs have not been able to find a matrix Q>0 that solves
% the LMIs. Therefore, xcl may or may not be an equilibrium point for the
% system.
%
pause; %strike any key to continue
clc
% |-----------------------------------------------------------------------|
% | STEP 2: FORMATS OF CALLING PWAANALYSIS
% |-----------------------------------------------------------------------|
%
% pwaanalysis can also be called by three inputs as follows.
%
% pwaanalysis(pwainc, setting, gain);
%
% In this format, 'gain' should be the control gain Kbar (please hit
% number 1 in the main menu of PWATOOL to learn about Kbar).
%
% We use a stabilizing gain Kbar to check this option.
%
pause; %strike any key to continue
%
load Kbar_pendul
%
% Now, let's analyze the inverted pendulum around xcl one more time; this
% time the loop is closed through the gain Kbar
%
pause; %strike any key to continue
%
pwaanalysis(pwainc, setting, Kbar_pendul);
% The message "The closed-loop PWA system is stable at xcl." shows PWATOOL
% has been successful in finding a matrix Q>0 for solving the LIMs and
% hance the closed-loop system is stable around xcl.
%
pause; %strike any key to continue
clc
% 'pwanalysis' also produces an output which is 1, whenever it has verified
% the stability of the system at a given point xcl. Therefore, the
% following formats in calling pwaanalysis are valid:
%
% Y = pwaanalysis(pwainc, setting);
% Y = pwaanalysis(pwainc, setting, gain);
%
pause; %strike any key to return to the main menu
echo off