-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunity_place.m
38 lines (38 loc) · 1.01 KB
/
unity_place.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
% place use Ackermann's formula unity rank method
% Author Jia Yansong
function K = unity_place(A, B, P)
[num_state, num_input] = size(B);
syms s;
q = create_q(num_input);
B = B*q;
W_c = [B A*B A^2*B A^3*B A^4*B A^5*B];
[row, col] = size(W_c);
r = min(row, col);
if rank(W_c) < r
error('it is uncontrollable!');
end
% select num_state independent vectors out of num_state*num_input
% vectors from the controllability matrix in the strict order form left
% to right:
C = W_c;
% inverse C:
C_inv = C^(-1);
co = 1;
for i = 1: num_state
co = co * (s - P(1,i));
end
co = expand(co);
coco = sym2poly(co);
phid = polyvalm(coco, A);
K = create_one(num_state)*C_inv*phid;
K = q*K;
end
function res = create_q(num_input)
res = zeros(num_input, 1);
res(num_input, 1) = 1;
res = [0.1;1];
end
function res = create_one(num_state)
res = zeros(1, num_state);
res(1, num_state) = 1;
end