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