forked from ajt60gaibb/freeLYAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lyap.m
59 lines (44 loc) · 1.07 KB
/
test_lyap.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
58
59
function pass = test_lyap()
% Test LYAP against the built-in (i.e., Control Toolbox) implementation.
tol = 1e-10;
n = 3;
m = n+1;
currDir = cd;
lyapDir = fileparts(which('sylvslv'));
try
c = [0, 1, 0, 1];
err = zeros(2, 3);
for j = 1:2
rng(0)
A = rand(n) + c(j)*1i*rand(n);
Q = rand(n) + c(j)*1i*rand(n);
B = rand(m) + c(j)*1i*rand(m);
C = rand(n,m) + c(j)*1i*rand(n,m);
E = rand(n) + c(j)*1i*rand(n);
cd(lyapDir)
U = lyap(A, Q);
cd(currDir)
V = lyap(A, Q);
err(j,1) = norm(U - V, inf);
cd(lyapDir)
U = lyap(A, B, C);
cd(currDir)
V = lyap(A, B, C);
err(j,2) = norm(U - V, inf);
% Built-in LYAP is fussy in this mode:
Q = Q + Q';
E = real(E);
A = real(A);
Q = real(Q);
cd(lyapDir)
U = lyap(A, Q, [], E);
cd(currDir)
V = lyap(A, Q, [], E);
err(j,3) = norm(U - V, inf);
end
pass = err < tol;
catch ME
cd(currDir)
rethrow(ME);
end
end