1 ## Copyright (C) 2010 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19 ## @deftypefn{Function File} {[@var{p}, @var{q}] =} covar (@var{sys}, @var{w})
20 ## Return the steady-state covariance.
27 ## Intensity of Gaussian white noise inputs which drive @var{sys}.
38 ## @seealso{lyap, dlyap}
41 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
42 ## Created: January 2010
45 function [p, q] = covar (sys, w)
51 if (! isa (sys, "lti"))
52 error ("covar: first argument must be an LTI model");
56 error ("covar: system must be stable");
59 [a, b, c, d] = ssdata (sys);
63 error ("covar: system is not strictly proper");
66 q = lyap (a, b*w*b.');
69 q = dlyap (a, b*w*b.');
70 p = c*q*c.' + d*w*d.';
76 %!shared p, q, p_exp, q_exp
77 %! sys = ss (-1, 1, 1, 0);
78 %! [p, q] = covar (sys, 5);
81 %!assert (p, p_exp, 1e-4);
82 %!assert (q, q_exp, 1e-4);
85 %!shared p, q, p_exp, q_exp
86 %! sys = ss ([-0.2, -0.5; 1, 0], [2; 0], [1, 0.5], [0], 0.1);
87 %! [p, q] = covar (sys, 5);
89 %! q_exp = [27.1493, -3.6199; -3.6199, 27.1493];
90 %!assert (p, p_exp, 1e-4);
91 %!assert (q, q_exp, 1e-4);