1 | function [ulq] = c2008lqcM(A, B, C, Xk, w, N, No, Nu, Qy, Qu, ukm1) |
---|
2 | |
---|
3 | % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
---|
4 | % funkce vrac��n� generovan�Q ��algoritmem. /* tvar m - file */ % |
---|
5 | % function [ulq] = c2004lqM(AD, BD, CD, Xk, w, N, No, Nu, Qy, Qu, ukm1); % |
---|
6 | % Out: ugpc ��(mx1). % |
---|
7 | % In: discr. matice: /AD(stav�n]), BD(vstup�m]), CD(v� [rxn])/, % |
---|
8 | % Xk - stav v k (nx1), w - �adan�� k+1:k+N-No (((N-No)*r)x1), % |
---|
9 | % horizont: N = nstep (1) /No - necitlivosti (1), Nu - ��1)/, % |
---|
10 | % penaliza� matice: Qy - v� (((N-No)*r)x((N-No)*r)) - (Qy !> 0) % |
---|
11 | % Qu - vstup�u*mxNu*m) % |
---|
12 | % ukm1 - predchozi hodnota ulq tj. ulq(k-1) % |
---|
13 | %=====================================================================================% |
---|
14 | % � Feb 2008, Jednoduch�Q ��a horizontu N = nstep % |
---|
15 | %=====================================================================================% |
---|
16 | % |
---|
17 | % [rr,ss,kon,clw,clu0,cld,s,ds,du]=lqex2(b,a,k,nstep,qur,d) |
---|
18 | % |
---|
19 | % LQ optimal controller with external disturbance |
---|
20 | % |
---|
21 | % b(z^-1)/(a(z^-1) system discrete transfer function |
---|
22 | % k/(a(z^-1) system offset |
---|
23 | % nstep number of iterations of the Riccati equation (horizon) |
---|
24 | % qur input penalization |
---|
25 | % d(z^-1)/(a(z^-1) disturbance discrete transfer function |
---|
26 | % |
---|
27 | % ss(z^-1)/rr(z^-1) controller feedback part transfer function |
---|
28 | % kon/rr(z^-1) offset term of the controller |
---|
29 | % clw/rr(z^-1) transfer function of the output reference filter |
---|
30 | % clu0/rr(z^-1)transfer function of the input refrence filter |
---|
31 | % cld(z^-1)/rr(z^-1)transfer function of the disturbance filter |
---|
32 | % s,ds Riccati matrix factors s'* ds * s |
---|
33 | % du weight of the control law |
---|
34 | % |
---|
35 | |
---|
36 | echo on |
---|
37 | |
---|
38 | n=size(A,1); m=size(B,2); r=size(C,1); |
---|
39 | |
---|
40 | qy=eye(r)*Qy(1); Qu=eye(m)*Qu(1); qx=C'*qy*C; % do�n�apln� matic penalizac� |
---|
41 | if 0, |
---|
42 | if ~isequal(size(qx),[n n]), error('bad dimension of state penalization'); end |
---|
43 | if ~isequal(size(qy),[r r]), error('bad dimension of output penalization'); end |
---|
44 | if ~isequal(size(qu),[m m]), error('bad dimension of input penalization'); end |
---|
45 | if No<0, error('bad initial insensitivity horizon'); end |
---|
46 | if Nu<0, error('bad control horizon'); end |
---|
47 | end |
---|
48 | |
---|
49 | qux=zeros(m,n+2*m+r); % qyx=zeros(r,n+m+r); % pomocn�enalizace % ??? qux=zeros(m,n+2*m+r); qyx=qux; |
---|
50 | qux(:,1:m)=eye(m); |
---|
51 | qux(:,n+m+r+1:end)=-eye(m); |
---|
52 | qux=qux*Qu(1); |
---|
53 | qyx=[C,-eye(r),zeros(r,m)]; |
---|
54 | |
---|
55 | %if size(s)~=size(eye(n+m+r)), s=s*eye(n+m+r); disp('1'), end |
---|
56 | s=1e-5*eye(n+m+r); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
57 | |
---|
58 | pr=[B,A, zeros(n, m+r); zeros(m+r,m+n), eye(m+r)]; % paramentry |
---|
59 | |
---|
60 | % size(pr), |
---|
61 | % size(qyx) |
---|
62 | %h=s*pr; |
---|
63 | %hqx=qx*pr; |
---|
64 | |
---|
65 | % hqy=qyx*pr |
---|
66 | hqy=qy*qyx*pr; |
---|
67 | % keyboard |
---|
68 | |
---|
69 | nstep=N; |
---|
70 | for i=1:nstep, |
---|
71 | h= s*pr; % s1=s; |
---|
72 | % diag(w((N-i)*r+1:(N-i)*r+r)) |
---|
73 | hqy(:,m+n+1:m+n+r)=-qy*diag(w((N-i)*r+1:(N-i)*r+r)); |
---|
74 | % hqy |
---|
75 | % keyboard |
---|
76 | hn=triu(qr([h;hqy;qux])); % QR rozklad bez uchov� ortogon��atice Q |
---|
77 | s=hn(m+1:2*m+n+r,m+1:2*m+n+r); |
---|
78 | end |
---|
79 | |
---|
80 | ws=hn(1:m,m+1:2*m+n+r); |
---|
81 | wsd=hn(1:m,1:m); |
---|
82 | |
---|
83 | |
---|
84 | % Lklq=-inv(wsd)*ws; % ���n z�an� synt� |
---|
85 | % ulq=Lklq*[Xk;eye(r,1);eye(m,1)]; % �� z LQ synt� |
---|
86 | |
---|
87 | |
---|
88 | %pom=ws*[Xk;ones(r,1);zeros(m,1)]; |
---|
89 | pom=ws*[Xk;ones(r,1);ukm1]; |
---|
90 | ulq=-inv(wsd)*pom; % �� na z�d�Q synt� |
---|
91 | %keyboard |
---|
92 | |
---|
93 | % % % uNu=zeros(Nu*m,1); % nezn� z maticov�ovnice R*uNu=c |
---|
94 | % % % uNu(Nu*m,1)=c(Nu*m,1)/(R(Nu*m,Nu*m)); |
---|
95 | % % % for i=(Nu*m-1):-1:1, |
---|
96 | % % % uNu(i,1)=(1/(R(i,i)))*(c(i,1)-R(i,i+1:Nu*m)*uNu(i+1:Nu*m,1)); |
---|
97 | % % % end |
---|
98 | % % % |
---|
99 | % % % % V�rvn� m ak�ch z�h�. pro � k*Ts, krok k; m - po� vstup�k�ch z�h�% % ugpc=uNu(1:m,1); |
---|
100 | % % % |
---|