1 ## Copyright (C) 2009 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{y}, @var{t}, @var{x}] =} initial (@var{sys}, @var{x0})
20 ## @deftypefnx{Function File} {[@var{y}, @var{t}, @var{x}] =} initial (@var{sys}, @var{x0}, @var{t})
21 ## @deftypefnx{Function File} {[@var{y}, @var{t}, @var{x}] =} initial (@var{sys}, @var{x0}, @var{tfinal})
22 ## @deftypefnx{Function File} {[@var{y}, @var{t}, @var{x}] =} initial (@var{sys}, @var{x0}, @var{tfinal}, @var{dt})
23 ## Initial condition response of state-space model.
24 ## If no output arguments are given, the response is printed on the screen.
31 ## Vector of initial conditions for each state.
33 ## Optional time vector. Should be evenly spaced. If not specified, it is calculated
34 ## by the poles of the system to reflect adequately the response transients.
36 ## Optional simulation horizon. If not specified, it is calculated by
37 ## the poles of the system to reflect adequately the response transients.
39 ## Optional sampling time. Be sure to choose it small enough to capture transient
40 ## phenomena. If not specified, it is calculated by the poles of the system.
46 ## Output response array. Has as many rows as time samples (length of t)
47 ## and as many columns as outputs.
51 ## State trajectories array. Has @code{length (t)} rows and as many columns as states.
58 ## Continuous Time: x = A x , y = C x , x(0) = x0
60 ## Discrete Time: x[k+1] = A x[k] , y[k] = C x[k] , x[0] = x0
64 ## @seealso{impulse, lsim, step}
67 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
68 ## Created: October 2009
71 function [y_r, t_r, x_r] = initial (sys, x0, tfinal = [], dt = [])
73 ## TODO: multiplot feature: initial (sys1, "b", sys2, "r", ..., x0, ...)
75 if (nargin < 2 || nargin > 4)
79 [y, t, x] = __time_response__ (sys, "initial", ! nargout, tfinal, dt, x0, inputname (1));
90 %!shared initial_c, initial_c_exp, initial_d, initial_d_exp
92 %! A = [ -2.8 2.0 -1.8
110 %! sysc = ss (A, B, C, D);
112 %! [yc, tc, xc] = initial (sysc, x_0, 0.2, 0.1);
113 %! initial_c = [yc, tc, xc];
115 %! sysd = c2d (sysc, 2);
117 %! [yd, td, xd] = initial (sysd, x_0, 4);
118 %! initial_d = [yd, td, xd];
120 %! ## expected values computed by the "dark side"
122 %! yc_exp = [ -1.0000 5.5000 5.6000
123 %! -0.9872 5.0898 5.7671
124 %! -0.9536 4.6931 5.7598 ];
130 %! xc_exp = [ 1.0000 2.0000 3.0000
131 %! 0.5937 1.6879 3.0929
132 %! 0.2390 1.5187 3.0988 ];
134 %! initial_c_exp = [yc_exp, tc_exp, xc_exp];
136 %! yd_exp = [ -1.0000 5.5000 5.6000
137 %! -0.6550 3.1673 4.2228
138 %! -0.5421 2.6186 3.4968 ];
144 %! xd_exp = [ 1.0000 2.0000 3.0000
145 %! -0.4247 1.5194 2.3249
146 %! -0.3538 1.2540 1.9250 ];
148 %! initial_d_exp = [yd_exp, td_exp, xd_exp];
150 %!assert (initial_c, initial_c_exp, 1e-4)
151 %!assert (initial_d, initial_d_exp, 1e-4)