1 ## Copyright (C) 2009 Luca Favatella
2 ## Copyright (C) 2009, 2010, 2011 Lukas Reichlin
4 ## This file is part of LTI Syncope.
6 ## LTI Syncope is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
11 ## LTI Syncope is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} test ltimodels
21 ## @deftypefnx {Function File} ltimodels
22 ## @deftypefnx {Function File} ltimodels (@var{systype})
23 ## Test suite and help for LTI models.
26 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
27 ## Created: November 2009
30 function ltimodels (systype = "general")
36 ## TODO: write documentation
38 if (! ischar (systype))
39 error ("ltimodels: argument must be a string");
42 systype = lower (systype);
46 str = {"State Space (SS) Models"\
47 "-----------------------"\
51 str = {"Transfer Function (TF) Models"\
52 "-----------------------------"\
56 str = {"Linear Time Invariant (LTI) Models"\
57 "----------------------------------"\
69 ## ==============================================================================
71 ## ==============================================================================
76 %!assert (ltisys.ts, -2);
77 %!assert (isct (ltisys));
78 %!assert (isdt (ltisys));
82 %!assert (ltisys.ts, -2);
83 %!assert (isct (ltisys));
84 %!assert (isdt (ltisys));
87 %! ltisys = tf (1, [1 1]);
88 %!assert (ltisys.ts, 0);
89 %!assert (isct (ltisys));
90 %!assert (! isdt (ltisys));
94 %! ltisys = ss (-1, 1, 1, 0, ts);
95 %!assert (ltisys.ts, ts);
96 %!assert (! isct (ltisys));
97 %!assert (isdt (ltisys));
101 ## ==============================================================================
103 ## ==============================================================================
107 ## ==============================================================================
109 ## ==============================================================================
112 ## staircase (SLICOT AB01OD)
113 %!shared Ac, Bc, Ace, Bce
114 %! A = [ 17.0 24.0 1.0 8.0 15.0
115 %! 23.0 5.0 7.0 14.0 16.0
116 %! 4.0 6.0 13.0 20.0 22.0
117 %! 10.0 12.0 19.0 21.0 3.0
118 %! 11.0 18.0 25.0 2.0 9.0 ];
128 %! A = A.'; # There's a little mistake in the example
129 %! # program of routine AB01OD in SLICOT 5.0
131 %! [Ac, Bc, U, ncont] = slab01od (A, B, tol);
133 %! Ace = [ 12.8848 3.2345 11.8211 3.3758 -0.8982
134 %! 4.4741 -12.5544 5.3509 5.9403 1.4360
135 %! 14.4576 7.6855 23.1452 26.3872 -29.9557
136 %! 0.0000 1.4805 27.4668 22.6564 -0.0072
137 %! 0.0000 0.0000 -30.4822 0.6745 18.8680 ];
139 %! Bce = [ 31.1199 47.6865
145 %!assert (Ac, Ace, 1e-4);
146 %!assert (Bc, Bce, 1e-4);
149 ## controllability staircase form of descriptor state-space models (SLICOT TG01HD)
150 %!shared ac, ec, bc, cc, q, z, ncont, ac_e, ec_e, bc_e, cc_e, q_e, z_e, ncont_e
152 %! a = [ 2 0 2 0 -1 3 1
160 %! e = [ 0 0 1 0 0 0 0
176 %! c = [ 1 0 0 1 0 0 1
177 %! 0 -1 1 0 -1 1 0 ];
181 %! [ac, ec, bc, cc, q, z, ncont] = sltg01hd (a, e, b, c, tol);
185 %! ac_e = [ 0.0000 0.0000 0.0000 0.0000 -1.2627 0.4334 0.4666
186 %! 0.0000 2.0000 0.0000 -3.7417 -0.8520 0.2924 -0.4342
187 %! 0.0000 0.0000 1.7862 0.3780 -0.2651 -0.7723 0.0000
188 %! 0.0000 0.0000 0.0000 3.7417 0.8520 -0.2924 0.4342
189 %! 0.0000 0.0000 0.0000 0.0000 -1.5540 0.5334 0.5742
190 %! 0.0000 0.0000 0.0000 0.0000 -0.6533 0.2242 0.2414
191 %! 0.0000 0.0000 0.0000 0.0000 -0.5892 0.2022 0.2177 ];
193 %! ec_e = [ -1.8325 1.0000 2.3752 0.0000 -0.8214 0.2819 1.8016
194 %! 0.4887 0.0000 0.3770 -0.5345 0.1874 0.5461 0.0000
195 %! -0.1728 0.0000 -0.1333 -1.1339 0.1325 0.3861 0.0000
196 %! 0.0000 0.0000 0.0000 0.0000 0.8520 -0.2924 0.4342
197 %! 0.0000 0.0000 0.0000 0.0000 -1.0260 -0.1496 0.0000
198 %! 0.0000 0.0000 0.0000 0.0000 0.0000 1.1937 0.0000
199 %! 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 ];
201 %! bc_e = [ 1.0000 2.0000 3.0000
202 %! 2.0000 1.0000 0.0000
203 %! 0.0000 0.0000 0.0000
204 %! 0.0000 0.0000 0.0000
205 %! 0.0000 0.0000 0.0000
206 %! 0.0000 0.0000 0.0000
207 %! 0.0000 0.0000 0.0000 ];
209 %! cc_e = [ 0.0000 1.0000 0.0000 0.0000 -1.2627 0.4334 0.4666
210 %! 0.3665 0.0000 -0.9803 -1.6036 0.1874 0.5461 0.0000 ];
212 %! q_e = [ 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000
213 %! 0.0000 0.0000 0.7071 0.0000 0.2740 -0.6519 0.0000
214 %! 0.0000 0.0000 0.0000 0.0000 0.8304 0.3491 -0.4342
215 %! 0.0000 0.0000 0.0000 -1.0000 0.0000 0.0000 0.0000
216 %! 0.0000 0.0000 0.0000 0.0000 0.4003 0.1683 0.9008
217 %! 0.0000 0.0000 0.7071 0.0000 -0.2740 0.6519 0.0000
218 %! 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ];
220 %! z_e = [ 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000
221 %! -0.6108 0.0000 0.7917 0.0000 0.0000 0.0000 0.0000
222 %! 0.4887 0.0000 0.3770 -0.5345 0.1874 0.5461 0.0000
223 %! 0.0000 0.0000 0.0000 0.0000 -0.4107 0.1410 0.9008
224 %! 0.6108 0.0000 0.4713 0.2673 -0.1874 -0.5461 0.0000
225 %! -0.1222 0.0000 -0.0943 -0.8018 -0.1874 -0.5461 0.0000
226 %! 0.0000 0.0000 0.0000 0.0000 -0.8520 0.2924 -0.4342 ];
228 %!assert (ac, ac_e, 1e-4);
229 %!assert (ec, ec_e, 1e-4);
230 %!assert (bc, bc_e, 1e-4);
231 %!assert (cc, cc_e, 1e-4);
232 %!assert (q, q_e, 1e-4);
233 %!assert (z, z_e, 1e-4);
234 %!assert (ncont, ncont_e);
237 ## observability staircase form of descriptor state-space models (SLICOT TG01ID)
238 %!shared ao, eo, bo, co, q, z, nobsv, ao_e, eo_e, bo_e, co_e, q_e, z_e, nobsv_e
240 %! a = [ 2 0 0 0 0 0 0
248 %! e = [ 0 0 0 0 0 0 1
264 %! c = [ 2 0 0 0 0 0 1
270 %! [ao, eo, bo, co, q, z, nobsv] = sltg01id (a, e, b, c, tol);
274 %! ao_e = [ 0.2177 0.2414 0.5742 0.4342 0.0000 -0.4342 0.4666
275 %! 0.2022 0.2242 0.5334 -0.2924 -0.7723 0.2924 0.4334
276 %! -0.5892 -0.6533 -1.5540 0.8520 -0.2651 -0.8520 -1.2627
277 %! 0.0000 0.0000 0.0000 3.7417 0.3780 -3.7417 0.0000
278 %! 0.0000 0.0000 0.0000 0.0000 1.7862 0.0000 0.0000
279 %! 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 0.0000
280 %! 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ];
282 %! eo_e = [ 1.0000 0.0000 0.0000 0.4342 0.0000 0.0000 1.8016
283 %! 0.0000 1.1937 -0.1496 -0.2924 0.3861 0.5461 0.2819
284 %! 0.0000 0.0000 -1.0260 0.8520 0.1325 0.1874 -0.8214
285 %! 0.0000 0.0000 0.0000 0.0000 -1.1339 -0.5345 0.0000
286 %! 0.0000 0.0000 0.0000 0.0000 -0.1333 0.3770 2.3752
287 %! 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000
288 %! 0.0000 0.0000 0.0000 0.0000 -0.1728 0.4887 -1.8325 ];
290 %! bo_e = [ 0.4666 0.0000
298 %! co_e = [ 0.0000 0.0000 0.0000 0.0000 0.0000 2.0000 1.0000
299 %! 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 2.0000
300 %! 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 3.0000 ];
302 %! q_e = [ 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000
303 %! 0.0000 0.0000 0.0000 0.0000 0.7917 0.0000 -0.6108
304 %! 0.0000 0.5461 0.1874 -0.5345 0.3770 0.0000 0.4887
305 %! 0.9008 0.1410 -0.4107 0.0000 0.0000 0.0000 0.0000
306 %! 0.0000 -0.5461 -0.1874 0.2673 0.4713 0.0000 0.6108
307 %! 0.0000 -0.5461 -0.1874 -0.8018 -0.0943 0.0000 -0.1222
308 %! -0.4342 0.2924 -0.8520 0.0000 0.0000 0.0000 0.0000 ];
310 %! z_e = [ 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000
311 %! 0.0000 -0.6519 0.2740 0.0000 0.7071 0.0000 0.0000
312 %! -0.4342 0.3491 0.8304 0.0000 0.0000 0.0000 0.0000
313 %! 0.0000 0.0000 0.0000 -1.0000 0.0000 0.0000 0.0000
314 %! 0.9008 0.1683 0.4003 0.0000 0.0000 0.0000 0.0000
315 %! 0.0000 0.6519 -0.2740 0.0000 0.7071 0.0000 0.0000
316 %! 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 ];
318 %!assert (ao, ao_e, 1e-4);
319 %!assert (eo, eo_e, 1e-4);
320 %!assert (bo, bo_e, 1e-4);
321 %!assert (co, co_e, 1e-4);
322 %!assert (q, q_e, 1e-4);
323 %!assert (z, z_e, 1e-4);
324 %!assert (nobsv, nobsv_e);
327 ## ss2tf conversion by Slicot TB04BD
328 ## Test provided by Slicot
329 %!shared NUM, DEN, NUMe, DENe
330 %! A = [ -1.0 0.0 0.0
334 %! B = [ 0.0 1.0 -1.0
343 %! [NUM, DEN] = tfdata (ss (A, B, C, D));
345 %! NUMe = {[1, 5, 7], [1]; [1], [1, 5, 5]};
347 %! DENe = {[1, 5, 6], [1, 2]; [1, 5, 6], [1, 3, 2]};
349 %!assert (NUM, NUMe, 1e-4);
350 %!assert (DEN, DENe, 1e-4);
353 ## ss2tf conversion by Slicot TB04BD
355 %!shared NUM, DEN, NUMe, DENe
364 %! [NUM, DEN] = tfdata (ss (A, B, C, D));
370 %!assert (NUM, NUMe, 1e-4);
371 %!assert (DEN, DENe, 1e-4);
374 ## transfer function to state-space conversion
375 ## test from SLICOT TD04AD
379 %! DCOEFF = [ 1.0 6.0 11.0 6.0
380 %! 1.0 6.0 11.0 6.0 ];
382 %! UCOEFF = zeros (2, 2, 4);
384 %! u11 = [ 1.0 6.0 12.0 7.0 ];
385 %! u12 = [ 0.0 1.0 4.0 3.0 ];
386 %! u21 = [ 0.0 0.0 1.0 1.0 ];
387 %! u22 = [ 1.0 8.0 20.0 15.0 ];
389 %! UCOEFF(1,1,:) = u11;
390 %! UCOEFF(1,2,:) = u12;
391 %! UCOEFF(2,1,:) = u21;
392 %! UCOEFF(2,2,:) = u22;
394 %! [Ao, Bo, Co, Do] = sltd04ad (UCOEFF, DCOEFF, INDEX, 0);
396 %! Ae = [ 0.5000 -0.8028 0.9387
397 %! 4.4047 -2.3380 2.5076
398 %! -5.5541 1.6872 -4.1620 ];
400 %! Be = [ -0.2000 -1.2500
404 %! Ce = [ 0.0000 -0.8679 0.2119
405 %! 0.0000 0.0000 0.9002 ];
407 %! De = [ 1.0000 0.0000
410 %! Mo = [Ao, Bo; Co, Do];
411 %! Me = [Ae, Be; Ce, De];
413 %!assert (Mo, Me, 1e-4);