1 | function pmsm_ildp2
|
---|
2 | %verze ildp algoritmu s uvazovanim P (v logaritmu) pro PMSM motor
|
---|
3 | %rozsirena verze o diag P v pi aproximaci u
|
---|
4 | tic
|
---|
5 |
|
---|
6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
7 | %pocatecni konstanty
|
---|
8 |
|
---|
9 | Iterace = 2; %iterace
|
---|
10 | K = 20; %casy
|
---|
11 | N = 50; %vzorky
|
---|
12 |
|
---|
13 | %konstanty motoru
|
---|
14 | %Rs = 0.28;
|
---|
15 | %Ls = 0.003465;
|
---|
16 | %PSIpm = 0.1989;
|
---|
17 | %kp = 1.5;
|
---|
18 | %p = 4.0;
|
---|
19 | %J = 0.04;
|
---|
20 | DELTAt = 0.000125;
|
---|
21 |
|
---|
22 | %upravene konstanty
|
---|
23 | Ca = 0.9898;
|
---|
24 | Cb = 0.0072;
|
---|
25 | Cc = 0.0361;
|
---|
26 | Cd = 1.0;
|
---|
27 | Ce = 0.0149;
|
---|
28 |
|
---|
29 | %omezeni rizeni
|
---|
30 | cC1 = 100*100;
|
---|
31 | cLb = -50;
|
---|
32 | cUb = 50;
|
---|
33 |
|
---|
34 | %matice
|
---|
35 | %kovariancni matice Q a R
|
---|
36 | mQ = diag([0.0013 0.0013 5.0e-6 1.0e-10]);
|
---|
37 | mR = diag([0.0006 0.0006]);
|
---|
38 |
|
---|
39 | mSigma = mR*mR';
|
---|
40 |
|
---|
41 | %matice pro vypocet
|
---|
42 | %matice A zavisla na parametrech
|
---|
43 | mA = zeros(4);
|
---|
44 | mA(1,1) = Ca;
|
---|
45 | mA(2,2) = Ca;
|
---|
46 | mA(3,3) = Cd;
|
---|
47 | mA(4,4) = 1;
|
---|
48 | mA(4,3) = DELTAt;
|
---|
49 |
|
---|
50 | %macite C konstantni
|
---|
51 | mC = [ 1 0 0 0; 0 1 0 0];
|
---|
52 |
|
---|
53 | %pozadovana hodnota otacek
|
---|
54 | omega_t_stripe = 1.0015;
|
---|
55 |
|
---|
56 | %pocatecni hodnoty
|
---|
57 | X0 = [0; 0; 1; pi/2];
|
---|
58 | Y0 = [0; 0];
|
---|
59 | P0 = diag([0.01 0.01 0.01 0.01]);
|
---|
60 |
|
---|
61 | h_bel = 0;
|
---|
62 | h_beldx = [0; 0; 0; 0; 0; 0; 0; 0];
|
---|
63 |
|
---|
64 | %velikost okoli pro lokalni metodu
|
---|
65 | rho = 0.01;
|
---|
66 |
|
---|
67 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
68 | %globalni promenne
|
---|
69 |
|
---|
70 | % Kpi_alfa = ones(12, K); %konstanty aproximace slozky rizeni u_alfa
|
---|
71 | Kpi_alfa = ones(11, K); %konstanty aproximace slozky rizeni u_alfa
|
---|
72 | Kpi_alfa(1, :) = (Cd - Cb*Ce)*ones(1, K);
|
---|
73 | Kpi_alfa(2, :) = Ca*Ce*ones(1, K);
|
---|
74 | Kpi_alfa(3, :) = Ca*Ce*ones(1, K);
|
---|
75 | Kpi_alfa(4, :) = Cc*Ce*ones(1, K);
|
---|
76 | % Kpi_alfa(5, :) = zeros(1, K);
|
---|
77 | % Kpi_beta = ones(12, K); %konstanty aproximace slozky rizeni u_beta
|
---|
78 | Kpi_beta = ones(11, K); %konstanty aproximace slozky rizeni u_beta
|
---|
79 | Kpi_beta(1, :) = (Cd - Cb*Ce)*ones(1, K);
|
---|
80 | Kpi_beta(2, :) = Ca*Ce*ones(1, K);
|
---|
81 | Kpi_beta(3, :) = Ca*Ce*ones(1, K);
|
---|
82 | Kpi_beta(4, :) = Cc*Ce*ones(1, K);
|
---|
83 | % Kpi_beta(5, :) = zeros(1, K);
|
---|
84 |
|
---|
85 | Wv = zeros(35, K); %konstanty aproximace Bellmanovy fce
|
---|
86 |
|
---|
87 | Xkn = zeros(4, K, N); % X = [i_alfa, i_beta, omega, theta]
|
---|
88 | Ykn = zeros(2, K, N); % Y = [i_alfa, i_beta]
|
---|
89 | Pkn = zeros(4, 4, K, N); % P = N vzorku posloupnosti K matic 4x4
|
---|
90 |
|
---|
91 | mKy = zeros(4, 2); % K = pomocna matice pro vypocet
|
---|
92 | mRy = zeros(2, 2); % R = pomocna matice pro vypocet
|
---|
93 |
|
---|
94 | Xstripe = zeros(4, K);
|
---|
95 | Ystripe = zeros(4, K);
|
---|
96 | Pstripe = zeros(4, 4, K);
|
---|
97 |
|
---|
98 | Epsilon = zeros(20, N); %globalni promena pro vypocet Bellmanovy fce z odchylek (X - Xprum)
|
---|
99 |
|
---|
100 | gka = 0; %globalni promenna pro prenos casu k
|
---|
101 | gnu = 0; %globalni promenna pro prenos vzorku n
|
---|
102 |
|
---|
103 | Uopt2 = zeros(2, N);
|
---|
104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
105 | %hlavni iteracni smycka
|
---|
106 | for i = 1:Iterace,
|
---|
107 |
|
---|
108 | %generovani stavu
|
---|
109 | for n = 1:N,
|
---|
110 | Xkn(:, 1, n) = X0;
|
---|
111 | Ykn(:, 1, n) = Y0 + mR * [randn(); randn()];
|
---|
112 | Pkn(:, :, 1, n) = P0;
|
---|
113 |
|
---|
114 | for k = 1:K-1,
|
---|
115 | Uk = uPi(k, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
116 |
|
---|
117 | mRy = mC * Pkn(:, :, k, n) * mC' + mR;
|
---|
118 | mKy = Pkn(:, :, k, n) * mC' / mRy;
|
---|
119 | Xkn(:, k+1, n) = fceG(Xkn(:, k, n), Uk) - mKy * (Ykn(:, k, n) - fceH(Xkn(:, k, n)));
|
---|
120 | Ykn(:, k+1, n) = Xkn(1:2, k+1, n) + mR * [randn(); randn()]; %X kopie do Y + sum
|
---|
121 | mA(1, 3) = Cb * sin(Xkn(4, k, n));
|
---|
122 | mA(1, 4) = Cb * Xkn(3, k, n) * cos(Xkn(4, k, n));
|
---|
123 | mA(2, 3) = - Cb * cos(Xkn(4, k, n));
|
---|
124 | mA(2, 4) = Cb * Xkn(3, k, n) * sin(Xkn(4, k, n));
|
---|
125 | mA(3, 1) = - Ce * sin(Xkn(4, k, n));
|
---|
126 | mA(3, 2) = Ce * cos(Xkn(4, k, n));
|
---|
127 | mA(3, 4) = - Ce * (Xkn(2, k, n) * sin(Xkn(4, k, n)) + Xkn(1, k, n) * cos(Xkn(4, k, n)));
|
---|
128 | Pkn(:, :, k+1, n) = mA * (Pkn(:, :, k, n) - Pkn(:, :, k, n) * mC' * inv(mRy) * mC * Pkn(:, :, k, n)) * mA + mQ;
|
---|
129 | end
|
---|
130 | end
|
---|
131 | Xstripe = mean(Xkn, 3);
|
---|
132 | Ystripe = mean(Ykn, 3);
|
---|
133 | Pstripe = mean(Pkn, 4);
|
---|
134 |
|
---|
135 | for k = K-1:-1:1,
|
---|
136 | gka = k;
|
---|
137 |
|
---|
138 | % 1]
|
---|
139 | for n = 1:N,
|
---|
140 | %krive okoli
|
---|
141 | Ykn(1, k, n) = Ykn(1, k, n) - Xkn(1, k, n);
|
---|
142 | Ykn(2, k, n) = Ykn(2, k, n) - Xkn(2, k, n);
|
---|
143 |
|
---|
144 | Xkn(1, k, n) = Xstripe(1, k) + rho*randn();
|
---|
145 | Xkn(2, k, n) = Xstripe(2, k) + rho*randn();
|
---|
146 | Xkn(3, k, n) = Xstripe(3, k) + rho*randn();
|
---|
147 | Xkn(4, k, n) = Xstripe(4, k) + rho*randn();
|
---|
148 |
|
---|
149 | Ykn(1, k, n) = Ykn(1, k, n) + Xkn(1, k, n);
|
---|
150 | Ykn(2, k, n) = Ykn(2, k, n) + Xkn(2, k, n);
|
---|
151 |
|
---|
152 | Pkn(:, :, k, n) = Pstripe(:, :, k) .* exp(rho*randn(4));
|
---|
153 | end
|
---|
154 |
|
---|
155 | % 2]
|
---|
156 | for n = 1:N,
|
---|
157 | gnu = n;
|
---|
158 | [Uopt2(:, n), Hmin(n)] = fmincon(@Hamilt, uPi(k, Xkn(:, k, n),Pkn(:, :, k, n)), [], [], [], [], cLb, cUb, @Cond2, optimset('GradConstr','on','Display','notify','Algorithm','active-set'));
|
---|
159 | end
|
---|
160 |
|
---|
161 | % 3]
|
---|
162 | for n = 1:N,
|
---|
163 | Vn(n) = DELTAt*Hmin(n) + Vtilde(k+1, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
164 | end
|
---|
165 |
|
---|
166 | % 4]
|
---|
167 | Epsilon = zeros(8, N);
|
---|
168 | for n = 1:N,
|
---|
169 | Epsilon(1:4, n) = Xkn(1:4, k, n) - Xstripe(1:4, k);
|
---|
170 | Epsilon(5:8, n) = diag(Pkn(:, :, k, n) ./ Pstripe(:, :, k));
|
---|
171 | end
|
---|
172 | mFi = matrixFi(Epsilon);
|
---|
173 | FiFiTInvFi = (mFi*mFi')\mFi;
|
---|
174 | Wv(:,k) = FiFiTInvFi * Vn';
|
---|
175 |
|
---|
176 | for n = 1:N,
|
---|
177 | tialfa(n) = Xkn(1, k, n);
|
---|
178 | tibeta(n) = Xkn(2, k, n);
|
---|
179 | tomega(n) = Xkn(3, k, n);
|
---|
180 | ttheta(n) = Xkn(4, k, n);
|
---|
181 | tp1(n) = Pkn(1, 1, k, n);
|
---|
182 | tp2(n) = Pkn(2, 2, k, n);
|
---|
183 | tp3(n) = Pkn(3, 3, k, n);
|
---|
184 | tp4(n) = Pkn(4, 4, k, n);
|
---|
185 | end
|
---|
186 | % mPsi = [tomega',...1
|
---|
187 | % -tialfa'.*sin(ttheta)',...2
|
---|
188 | % tibeta'.*cos(ttheta)',...3
|
---|
189 | % -Uopt2(1,:)'.*sin(ttheta)',...4
|
---|
190 | % ones(N,1),...5
|
---|
191 | % log(tp3)',...6
|
---|
192 | % -tialfa'.*log(tp4)',...7
|
---|
193 | % -log(tp1)'.*sin(ttheta)',...8
|
---|
194 | % tibeta'.*log(tp4)',...9
|
---|
195 | % log(tp2)'.*cos(ttheta)',...10
|
---|
196 | % -Uopt2(1,:)'.*log(tp4)',...11
|
---|
197 | % -Uopt2(1,:)'];%12
|
---|
198 | mPsi = [tomega',...1
|
---|
199 | -tialfa'.*sin(ttheta)',...2
|
---|
200 | tibeta'.*cos(ttheta)',...3
|
---|
201 | -Uopt2(1,:)'.*sin(ttheta)',...4
|
---|
202 | log(tp3)',...6
|
---|
203 | -tialfa'.*log(tp4)',...7
|
---|
204 | -log(tp1)'.*sin(ttheta)',...8
|
---|
205 | tibeta'.*log(tp4)',...9
|
---|
206 | log(tp2)'.*cos(ttheta)',...10
|
---|
207 | -Uopt2(1,:)'.*log(tp4)',...11
|
---|
208 | -Uopt2(1,:)'];%12
|
---|
209 | PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
210 | Kpi_alfa(:, k) = PsiPsiTInvPsi * (omega_t_stripe * ones(N, 1));
|
---|
211 |
|
---|
212 | % mPsi = [tomega',...1
|
---|
213 | % -tialfa'.*sin(ttheta)',...2
|
---|
214 | % tibeta'.*cos(ttheta)',...3
|
---|
215 | % Uopt2(2,:)'.*cos(ttheta)',...4
|
---|
216 | % ones(N,1),...5
|
---|
217 | % -log(tp3)',...6
|
---|
218 | % tialfa'.*log(tp4)',...7
|
---|
219 | % log(tp1)'.*sin(ttheta)',...8
|
---|
220 | % -tibeta'.*log(tp4)',...9
|
---|
221 | % -log(tp2)'.*cos(ttheta)',...10
|
---|
222 | % Uopt2(2,:)'.*log(tp4)',...11
|
---|
223 | % Uopt2(2,:)'];%12
|
---|
224 | mPsi = [tomega',...1
|
---|
225 | -tialfa'.*sin(ttheta)',...2
|
---|
226 | tibeta'.*cos(ttheta)',...3
|
---|
227 | Uopt2(2,:)'.*cos(ttheta)',...4
|
---|
228 | -log(tp3)',...6
|
---|
229 | tialfa'.*log(tp4)',...7
|
---|
230 | log(tp1)'.*sin(ttheta)',...8
|
---|
231 | -tibeta'.*log(tp4)',...9
|
---|
232 | -log(tp2)'.*cos(ttheta)',...10
|
---|
233 | Uopt2(2,:)'.*log(tp4)',...11
|
---|
234 | Uopt2(2,:)'];%12
|
---|
235 | PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
236 | Kpi_beta(:, k) = PsiPsiTInvPsi * (omega_t_stripe * ones(N, 1));
|
---|
237 | end
|
---|
238 | end
|
---|
239 |
|
---|
240 | %%%%%%%%%%%
|
---|
241 | toc
|
---|
242 | % keyboard
|
---|
243 | Kpi_alfa
|
---|
244 | Kpi_beta
|
---|
245 | %vykresleni grafu
|
---|
246 | clf
|
---|
247 | subplot(3,4,3);
|
---|
248 | plot(1:K,omega_t_stripe*ones(1,K));
|
---|
249 |
|
---|
250 | Ukn = zeros(2, K, N);
|
---|
251 | for n = 1:N,
|
---|
252 | Xkn(:, 1, n) = X0;
|
---|
253 | Ykn(:, 1, n) = Y0 + mR * [randn(); randn()];
|
---|
254 | Pkn(:, :, 1, n) = P0;
|
---|
255 | for k = 1:K-1,
|
---|
256 | Ukn(:, k, n) = uPi(k, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
257 | mRy = mC * Pkn(:, :, k, n) * mC' + mR;
|
---|
258 | mKy = Pkn(:, :, k, n) * mC' / mRy;
|
---|
259 | Xkn(:, k+1, n) = fceG(Xkn(:, k, n), Ukn(:, k, n)) - mKy * (Ykn(:, k, n) - fceH(Xkn(:, k, n)));
|
---|
260 | Ykn(:, k+1, n) = Xkn(1:2, k+1, n) + mR * [randn(); randn()]; %X kopie do Y + sum
|
---|
261 | mA(1, 3) = Cb * sin(Xkn(4, k, n));
|
---|
262 | mA(1, 4) = Cb * Xkn(3, k, n) * cos(Xkn(4, k, n));
|
---|
263 | mA(2, 3) = - Cb * cos(Xkn(4, k, n));
|
---|
264 | mA(2, 4) = Cb * Xkn(3, k, n) * sin(Xkn(4, k, n));
|
---|
265 | mA(3, 1) = - Ce * sin(Xkn(4, k, n));
|
---|
266 | mA(3, 2) = Ce * cos(Xkn(4, k, n));
|
---|
267 | mA(3, 4) = - Ce * (Xkn(2, k, n) * sin(Xkn(4, k, n)) + Xkn(1, k, n) * cos(Xkn(4, k, n)));
|
---|
268 | Pkn(:, :, k+1, n) = mA * (Pkn(:, :, k, n) - Pkn(:, :, k, n) * mC' * inv(mRy) * mC * Pkn(:, :, k, n)) * mA + mQ;
|
---|
269 | end
|
---|
270 |
|
---|
271 | hold all
|
---|
272 | subplot(3,4,1);
|
---|
273 | title('X:i_{\alpha}')
|
---|
274 | plot(1:K,Xkn(1,:,n))
|
---|
275 |
|
---|
276 | hold all
|
---|
277 | subplot(3,4,2);
|
---|
278 | title('X:i_{\beta}')
|
---|
279 | plot(1:K,Xkn(2,:,n))
|
---|
280 |
|
---|
281 | hold all
|
---|
282 | subplot(3,4,3);
|
---|
283 | title('X:\omega')
|
---|
284 | plot(1:K,Xkn(3,:,n))
|
---|
285 |
|
---|
286 | hold all
|
---|
287 | subplot(3,4,4);
|
---|
288 | title('X:\theta')
|
---|
289 | plot(1:K,Xkn(4,:,n))
|
---|
290 |
|
---|
291 | hold all
|
---|
292 | subplot(3,4,5);
|
---|
293 | title('Y:i_{\alpha}')
|
---|
294 | plot(1:K,Ykn(1,:,n))
|
---|
295 |
|
---|
296 | hold all
|
---|
297 | subplot(3,4,6);
|
---|
298 | title('Y:i_{\beta}')
|
---|
299 | plot(1:K,Ykn(2,:,n))
|
---|
300 |
|
---|
301 | hold all
|
---|
302 | subplot(3,4,7);
|
---|
303 | title('u_{\alpha}')
|
---|
304 | plot(1:K,Ukn(1,:,n))
|
---|
305 |
|
---|
306 | hold all
|
---|
307 | subplot(3,4,8);
|
---|
308 | title('u_{\beta}')
|
---|
309 | plot(1:K,Ukn(2,:,n))
|
---|
310 |
|
---|
311 | hold all
|
---|
312 | subplot(3,4,9);
|
---|
313 | title('P(1, 1)')
|
---|
314 | plot(1:K,squeeze(Pkn(1, 1, :, n)))
|
---|
315 |
|
---|
316 | hold all
|
---|
317 | subplot(3,4,10);
|
---|
318 | title('P(2, 2)')
|
---|
319 | plot(1:K,squeeze(Pkn(2, 2, :, n)))
|
---|
320 |
|
---|
321 | hold all
|
---|
322 | subplot(3,4,11);
|
---|
323 | title('P(3, 3)')
|
---|
324 | plot(1:K,squeeze(Pkn(3, 3, :, n)))
|
---|
325 |
|
---|
326 | hold all
|
---|
327 | subplot(3,4,12);
|
---|
328 | title('P(4, 4)')
|
---|
329 | plot(1:K,squeeze(Pkn(4, 4, :, n)))
|
---|
330 | end
|
---|
331 |
|
---|
332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
333 | %pomocne funkce
|
---|
334 |
|
---|
335 | function [val_uPi] = uPi(k_uPi, x_uPi, p_uPi)
|
---|
336 | val_uPi = zeros(2, 1);
|
---|
337 | % val_uPi(1) = (-omega_t_stripe + Kpi_alfa(1, k_uPi)*x_uPi(3)+Kpi_alfa(6, k_uPi)*log(p_uPi(3,3)) - Kpi_alfa(2, k_uPi)*x_uPi(1)*sin(x_uPi(4))-Kpi_alfa(7, k_uPi)*x_uPi(1)*log(p_uPi(4,4))-Kpi_alfa(8, k_uPi)*log(p_uPi(1,1))*sin(x_uPi(4)) + Kpi_alfa(3, k_uPi)*x_uPi(2)*cos(x_uPi(4))+Kpi_alfa(9, k_uPi)*x_uPi(2)*log(p_uPi(4,4))+Kpi_alfa(10, k_uPi)*log(p_uPi(2,2))*cos(x_uPi(4)) + Kpi_alfa(5)) / (Kpi_alfa(4)*sin(x_uPi(4))+Kpi_alfa(11)*log(p_uPi(4,4))+Kpi_alfa(12));
|
---|
338 | % val_uPi(2) = ( omega_t_stripe - Kpi_beta(1, k_uPi)*x_uPi(3)-Kpi_beta(6, k_uPi)*log(p_uPi(3,3)) + Kpi_beta(2, k_uPi)*x_uPi(1)*sin(x_uPi(4))+Kpi_beta(7, k_uPi)*x_uPi(1)*log(p_uPi(4,4))+Kpi_beta(8, k_uPi)*log(p_uPi(1,1))*sin(x_uPi(4)) - Kpi_beta(3, k_uPi)*x_uPi(2)*cos(x_uPi(4))-Kpi_beta(9, k_uPi)*x_uPi(2)*log(p_uPi(4,4))-Kpi_beta(10, k_uPi)*log(p_uPi(2,2))*cos(x_uPi(4)) - Kpi_beta(5)) / (Kpi_beta(4)*cos(x_uPi(4))+Kpi_beta(11)*log(p_uPi(4,4))+Kpi_beta(12));
|
---|
339 | val_uPi(1) = (-omega_t_stripe + Kpi_alfa(1, k_uPi)*x_uPi(3)+Kpi_alfa(5, k_uPi)*log(p_uPi(3,3)) - Kpi_alfa(2, k_uPi)*x_uPi(1)*sin(x_uPi(4))-Kpi_alfa(6, k_uPi)*x_uPi(1)*log(p_uPi(4,4))-Kpi_alfa(7, k_uPi)*log(p_uPi(1,1))*sin(x_uPi(4)) + Kpi_alfa(3, k_uPi)*x_uPi(2)*cos(x_uPi(4))+Kpi_alfa(8, k_uPi)*x_uPi(2)*log(p_uPi(4,4))+Kpi_alfa(9, k_uPi)*log(p_uPi(2,2))*cos(x_uPi(4)) + Kpi_alfa(5)) / (Kpi_alfa(4)*sin(x_uPi(4))+Kpi_alfa(10)*log(p_uPi(4,4))+Kpi_alfa(11));
|
---|
340 | val_uPi(2) = ( omega_t_stripe - Kpi_beta(1, k_uPi)*x_uPi(3)-Kpi_beta(5, k_uPi)*log(p_uPi(3,3)) + Kpi_beta(2, k_uPi)*x_uPi(1)*sin(x_uPi(4))+Kpi_beta(6, k_uPi)*x_uPi(1)*log(p_uPi(4,4))+Kpi_beta(7, k_uPi)*log(p_uPi(1,1))*sin(x_uPi(4)) - Kpi_beta(3, k_uPi)*x_uPi(2)*cos(x_uPi(4))-Kpi_beta(8, k_uPi)*x_uPi(2)*log(p_uPi(4,4))-Kpi_beta(9, k_uPi)*log(p_uPi(2,2))*cos(x_uPi(4)) - Kpi_beta(5)) / (Kpi_beta(4)*cos(x_uPi(4))+Kpi_beta(10)*log(p_uPi(4,4))+Kpi_beta(11));
|
---|
341 |
|
---|
342 | if (val_uPi(1)<cLb)
|
---|
343 | val_uPi(1) = cLb;
|
---|
344 | end
|
---|
345 | if (val_uPi(1)>cUb)
|
---|
346 | val_uPi(1) = cUb;
|
---|
347 | end
|
---|
348 | if (val_uPi(2)<cLb)
|
---|
349 | val_uPi(2) = cLb;
|
---|
350 | end
|
---|
351 | if (val_uPi(2)>cUb)
|
---|
352 | val_uPi(2) = cUb;
|
---|
353 | end
|
---|
354 | end
|
---|
355 |
|
---|
356 | function [val_ham] = Hamilt(u_ham)
|
---|
357 | mRy = mC * Pkn(:, :, gka, gnu) * mC' + mR;
|
---|
358 | mKy = Pkn(:, :, gka, gnu) * mC' / mRy;
|
---|
359 | tXkn = fceG(Xkn(:, gka, gnu), u_ham) - mKy * (Ykn(:, gka, gnu) - fceH(Xkn(:, gka, gnu)));
|
---|
360 | mA(1, 3) = Cb * sin(Xkn(4, gka, gnu));
|
---|
361 | mA(1, 4) = Cb * Xkn(3, gka, gnu) * cos(Xkn(4, gka, gnu));
|
---|
362 | mA(2, 3) = - Cb * cos(Xkn(4, gka, gnu));
|
---|
363 | mA(2, 4) = Cb * Xkn(3, gka, gnu) * sin(Xkn(4, gka, gnu));
|
---|
364 | mA(3, 1) = - Ce * sin(Xkn(4, gka, gnu));
|
---|
365 | mA(3, 2) = Ce * cos(Xkn(4, gka, gnu));
|
---|
366 | mA(3, 4) = - Ce * (Xkn(2, gka, gnu) * sin(Xkn(4, gka, gnu)) + Xkn(1, gka, gnu) * cos(Xkn(4, gka, gnu)));
|
---|
367 | tPkn = mA * (Pkn(:, :, gka, gnu) - Pkn(:, :, gka, gnu) * mC' * inv(mRy) * mC * Pkn(:, :, gka, gnu)) * mA + mQ;
|
---|
368 | tf = zeros(8,1);
|
---|
369 | tf(1:4) = tXkn;
|
---|
370 | tf(5:8) = diag(tPkn);
|
---|
371 |
|
---|
372 | loss = (tXkn(3) - omega_t_stripe)^2;
|
---|
373 |
|
---|
374 | val_ham = loss + tf' * Vtilde_dx(gka+1, Xkn(:, gka, gnu), Pkn(:, :, gka, gnu)) + 1/2 * trace(mSigma * ( Wv(10, gka+1)*[2 0; 0 0] + Wv(18, gka+1)*[0 0; 0 2] ));
|
---|
375 |
|
---|
376 | end
|
---|
377 |
|
---|
378 | function [val_Vt] = Vtilde(k_Vt, x_Vt, p_Vt)
|
---|
379 | if(k_Vt == K)
|
---|
380 | val_Vt = h_bel;
|
---|
381 | else
|
---|
382 | Epsl = zeros(8, 1);
|
---|
383 | Epsl(1:4) = x_Vt(1:4) - Xstripe(1:4, k_Vt);
|
---|
384 | Epsl(5:8) = diag(p_Vt ./ Pstripe(:, :, k));
|
---|
385 |
|
---|
386 | val_Vt = vectFi(Epsl)' * Wv(:,k_Vt);
|
---|
387 | end
|
---|
388 | end
|
---|
389 |
|
---|
390 | function [val_Vt] = Vtilde_dx(k_Vt, x_Vt, p_Vt)
|
---|
391 | if(k_Vt == K)
|
---|
392 | val_Vt = h_beldx;
|
---|
393 | else
|
---|
394 | Epsl = zeros(8, 1);
|
---|
395 | Epsl(1:4) = x_Vt(1:4) - Xstripe(1:4, k_Vt);
|
---|
396 | Epsl(5:8) = diag(p_Vt ./ Pstripe(:, :, k));
|
---|
397 |
|
---|
398 | val_Vt = difFi(Epsl)' * Wv(:,k_Vt);
|
---|
399 | end
|
---|
400 | end
|
---|
401 |
|
---|
402 | function [val_Fi] = vectFi(x_Fi)
|
---|
403 | val_Fi = [ ...
|
---|
404 | 1; ... %1
|
---|
405 | x_Fi(1); ... %Xi pro 1-4
|
---|
406 | x_Fi(2); ...
|
---|
407 | x_Fi(3); ...
|
---|
408 | x_Fi(4); ...
|
---|
409 | log(x_Fi(5)); ... %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
410 | log(x_Fi(6)); ...
|
---|
411 | log(x_Fi(7)); ...
|
---|
412 | log(x_Fi(8)); ...
|
---|
413 | x_Fi(1)^2; ... %kvadraticke cleny jen v Xi 1-4 a kombinovane
|
---|
414 | x_Fi(1)*x_Fi(2); ...
|
---|
415 | x_Fi(1)*x_Fi(3); ...
|
---|
416 | x_Fi(1)*x_Fi(4); ...
|
---|
417 | x_Fi(1)*log(x_Fi(5)); ...
|
---|
418 | x_Fi(1)*log(x_Fi(6)); ...
|
---|
419 | x_Fi(1)*log(x_Fi(7)); ...
|
---|
420 | x_Fi(1)*log(x_Fi(8)); ...
|
---|
421 | x_Fi(2)^2; ...
|
---|
422 | x_Fi(2)*x_Fi(3); ...
|
---|
423 | x_Fi(2)*x_Fi(4); ...
|
---|
424 | x_Fi(2)*log(x_Fi(5)); ...
|
---|
425 | x_Fi(2)*log(x_Fi(6)); ...
|
---|
426 | x_Fi(2)*log(x_Fi(7)); ...
|
---|
427 | x_Fi(2)*log(x_Fi(8)); ...
|
---|
428 | x_Fi(3)^2; ...
|
---|
429 | x_Fi(3)*x_Fi(4); ...
|
---|
430 | x_Fi(3)*log(x_Fi(5)); ...
|
---|
431 | x_Fi(3)*log(x_Fi(6)); ...
|
---|
432 | x_Fi(3)*log(x_Fi(7)); ...
|
---|
433 | x_Fi(3)*log(x_Fi(8)); ...
|
---|
434 | x_Fi(4)^2; ...
|
---|
435 | x_Fi(4)*log(x_Fi(5)); ...
|
---|
436 | x_Fi(4)*log(x_Fi(6)); ...
|
---|
437 | x_Fi(4)*log(x_Fi(7)); ...
|
---|
438 | x_Fi(4)*log(x_Fi(8)); ...
|
---|
439 | ];
|
---|
440 | end
|
---|
441 |
|
---|
442 | function [val_Fi] = matrixFi(x_Fi)
|
---|
443 | val_Fi = [ ...
|
---|
444 | ones(1, N); ... %1
|
---|
445 | x_Fi(1, :); ... %Xi pro 1-4
|
---|
446 | x_Fi(2, :); ...
|
---|
447 | x_Fi(3, :); ...
|
---|
448 | x_Fi(4, :); ...
|
---|
449 | log(x_Fi(5, :)); ... %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
450 | log(x_Fi(6, :)); ...
|
---|
451 | log(x_Fi(7, :)); ...
|
---|
452 | log(x_Fi(8, :)); ...
|
---|
453 | x_Fi(1, :).^2; ... %kvadraticke cleny jen v Xi 1-4 a kombinovane
|
---|
454 | x_Fi(1, :).*x_Fi(2, :); ...
|
---|
455 | x_Fi(1, :).*x_Fi(3, :); ...
|
---|
456 | x_Fi(1, :).*x_Fi(4, :); ...
|
---|
457 | x_Fi(1, :).*log(x_Fi(5, :)); ...
|
---|
458 | x_Fi(1, :).*log(x_Fi(6, :)); ...
|
---|
459 | x_Fi(1, :).*log(x_Fi(7, :)); ...
|
---|
460 | x_Fi(1, :).*log(x_Fi(8, :)); ...
|
---|
461 | x_Fi(2, :).^2; ...
|
---|
462 | x_Fi(2, :).*x_Fi(3, :); ...
|
---|
463 | x_Fi(2, :).*x_Fi(4, :); ...
|
---|
464 | x_Fi(2, :).*log(x_Fi(5, :)); ...
|
---|
465 | x_Fi(2, :).*log(x_Fi(6, :)); ...
|
---|
466 | x_Fi(2, :).*log(x_Fi(7, :)); ...
|
---|
467 | x_Fi(2, :).*log(x_Fi(8, :)); ...
|
---|
468 | x_Fi(3, :).^2; ...
|
---|
469 | x_Fi(3, :).*x_Fi(4, :); ...
|
---|
470 | x_Fi(3, :).*log(x_Fi(5, :)); ...
|
---|
471 | x_Fi(3, :).*log(x_Fi(6, :)); ...
|
---|
472 | x_Fi(3, :).*log(x_Fi(7, :)); ...
|
---|
473 | x_Fi(3, :).*log(x_Fi(8, :)); ...
|
---|
474 | x_Fi(4, :).^2; ...
|
---|
475 | x_Fi(4, :).*log(x_Fi(5, :)); ...
|
---|
476 | x_Fi(4, :).*log(x_Fi(6, :)); ...
|
---|
477 | x_Fi(4, :).*log(x_Fi(7, :)); ...
|
---|
478 | x_Fi(4, :).*log(x_Fi(8, :)); ...
|
---|
479 | ];
|
---|
480 |
|
---|
481 | end
|
---|
482 |
|
---|
483 | function [val_Fi] = difFi(x_Fi)
|
---|
484 | val_Fi = [ ...
|
---|
485 | 0 0 0 0 0 0 0 0; ...
|
---|
486 | 1 0 0 0 0 0 0 0; ...
|
---|
487 | 0 1 0 0 0 0 0 0; ...
|
---|
488 | 0 0 1 0 0 0 0 0; ...
|
---|
489 | 0 0 0 1 0 0 0 0; ...
|
---|
490 | 0 0 0 0 1/x_Fi(5) 0 0 0; ...
|
---|
491 | 0 0 0 0 0 1/x_Fi(6) 0 0; ...
|
---|
492 | 0 0 0 0 0 0 1/x_Fi(7) 0; ...
|
---|
493 | 0 0 0 0 0 0 0 1/x_Fi(8); ...
|
---|
494 | 2*x_Fi(1) 0 0 0 0 0 0 0; ...
|
---|
495 | x_Fi(2) x_Fi(1) 0 0 0 0 0 0; ...
|
---|
496 | x_Fi(3) 0 x_Fi(1) 0 0 0 0 0; ...
|
---|
497 | x_Fi(4) 0 0 x_Fi(1) 0 0 0 0; ...
|
---|
498 | log(x_Fi(5)) 0 0 0 x_Fi(1)/x_Fi(5) 0 0 0; ...
|
---|
499 | log(x_Fi(6)) 0 0 0 0 x_Fi(1)/x_Fi(6) 0 0; ...
|
---|
500 | log(x_Fi(7)) 0 0 0 0 0 x_Fi(1)/x_Fi(7) 0; ...
|
---|
501 | log(x_Fi(8)) 0 0 0 0 0 0 x_Fi(1)/x_Fi(8); ...
|
---|
502 | 0 2*x_Fi(2) 0 0 0 0 0 0; ...
|
---|
503 | 0 x_Fi(3) x_Fi(2) 0 0 0 0 0; ...
|
---|
504 | 0 x_Fi(4) 0 x_Fi(2) 0 0 0 0; ...
|
---|
505 | 0 log(x_Fi(5)) 0 0 x_Fi(2)/x_Fi(5) 0 0 0; ...
|
---|
506 | 0 log(x_Fi(6)) 0 0 0 x_Fi(2)/x_Fi(6) 0 0; ...
|
---|
507 | 0 log(x_Fi(7)) 0 0 0 0 x_Fi(2)/x_Fi(7) 0; ...
|
---|
508 | 0 log(x_Fi(8)) 0 0 0 0 0 x_Fi(2)/x_Fi(8); ...
|
---|
509 | 0 0 2*x_Fi(3) 0 0 0 0 0; ...
|
---|
510 | 0 0 x_Fi(4) x_Fi(3) 0 0 0 0; ...
|
---|
511 | 0 0 log(x_Fi(5)) 0 x_Fi(3)/x_Fi(5) 0 0 0; ...
|
---|
512 | 0 0 log(x_Fi(6)) 0 0 x_Fi(3)/x_Fi(6) 0 0; ...
|
---|
513 | 0 0 log(x_Fi(7)) 0 0 0 x_Fi(3)/x_Fi(7) 0; ...
|
---|
514 | 0 0 log(x_Fi(8)) 0 0 0 0 x_Fi(3)/x_Fi(8); ...
|
---|
515 | 0 0 0 2*x_Fi(4) 0 0 0 0; ...
|
---|
516 | 0 0 0 log(x_Fi(5)) x_Fi(4)/x_Fi(5) 0 0 0; ...
|
---|
517 | 0 0 0 log(x_Fi(6)) 0 x_Fi(4)/x_Fi(6) 0 0; ...
|
---|
518 | 0 0 0 log(x_Fi(7)) 0 0 x_Fi(4)/x_Fi(7) 0; ...
|
---|
519 | 0 0 0 log(x_Fi(8)) 0 0 0 x_Fi(4)/x_Fi(8); ...
|
---|
520 | ];
|
---|
521 | end
|
---|
522 |
|
---|
523 | function [c, ceq, GC, GCeq] = Cond2(x)
|
---|
524 | c = x(1)*x(1) + x(2)*x(2) - cC1;
|
---|
525 | ceq = [];
|
---|
526 | GC = [2*x(1); 2*x(2)];
|
---|
527 | GCeq = [];
|
---|
528 | end
|
---|
529 |
|
---|
530 | function [x_ret] = fceG(x_in, u_in)
|
---|
531 | x_ret = zeros(4, 1);
|
---|
532 | x_ret(1) = Ca * x_in(1) + Cb * x_in(3) * sin(x_in(4)) + Cc * u_in(1);
|
---|
533 | x_ret(2) = Ca * x_in(2) - Cb * x_in(3) * cos(x_in(4)) + Cc * u_in(2);
|
---|
534 | x_ret(3) = Cd * x_in(3) + Ce * (x_in(2) * cos(x_in(4)) - x_in(1) * sin(x_in(4)));
|
---|
535 | x_ret(4) = x_in(4) + x_in(3) * DELTAt;
|
---|
536 | end
|
---|
537 |
|
---|
538 | function [x_ret] = fceG_du(x_in, u_in)
|
---|
539 | x_ret = zeros(4, 2);
|
---|
540 | x_ret(1, 1) = Cc;
|
---|
541 | x_ret(2, 2) = Cc;
|
---|
542 | end
|
---|
543 |
|
---|
544 | function [y_ret] = fceH(x_in)
|
---|
545 | y_ret = zeros(2, 1);
|
---|
546 | y_ret(1) = x_in(1);
|
---|
547 | y_ret(2) = x_in(2);
|
---|
548 | end
|
---|
549 |
|
---|
550 | end
|
---|