-
Notifications
You must be signed in to change notification settings - Fork 5
/
KDefine.m
57 lines (49 loc) · 1.21 KB
/
KDefine.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
function [pwasys, sysloop]=KDefine(pwasys, Gain)
% This function ensures the controller gains K and k are either set or
% zero with proper sizes!
% Copyright: Mohsen Zamani Fekri, Concordia University April 2011
%
%
A=pwasys.A;
a=pwasys.a;
B=pwasys.B;
n=size(pwasys.Abar{1,1},1)-1;
m=size(pwasys.Bbar{1,1},2);
NR=size(A,1);
if nargin==2
pwasys.Kbar=Gain;
end
if isfield(pwasys, 'Kbar')
for i=1:NR
pwasys.K{i}=pwasys.Kbar{i}(:, 1:end-1);
pwasys.k{i}=pwasys.Kbar{i}(:,end);
end
else
for i=1:NR
try % ensuring K is defined properly
if isempty(pwasys.K{i})
pwasys.K{i}=zeros(m,n);
end
catch
pwasys.K{i}=zeros(m,n);
end
%-------------------------------------
try % ensuring k is defined properly
if isempty(pwasys.k{i})
pwasys.k{i}=zeros(m,1);
end
catch
pwasys.k{i}=zeros(m,1);
end
pwasys.Kbar{i}=[pwasys.K{i} pwasys.k{i}];
end
end
Norm=0;
for i=1:NR
Norm=Norm+norm(pwasys.K{i})+norm(pwasys.k{i});
end
if Norm==0
sysloop='open';
else
sysloop='closed';
end