Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_simul.m

raw
1 function simul = fn_simul(G1, impact, nsim, shocks, x0);
2 % Inputs:
3 % G1: n-by-n;
4 % impact: n-by-r;
5 % nsim: length of time series for simulation.
6 % shocks: r-by-nsim, exogenous driving processes
7 % x0: n-by-1, initial values for the variables of interest
8 %---
9 % Outputs:
10 % simul: nsim-by-n.
11 %
12 %
13 % Copyright (C) 1997-2012 Tao Zha
14 %
15 % This free software: you can redistribute it and/or modify
16 % it under the terms of the GNU General Public License as published by
17 % the Free Software Foundation, either version 3 of the License, or
18 % (at your option) any later version.
19 %
20 % It is distributed in the hope that it will be useful,
21 % but WITHOUT ANY WARRANTY; without even the implied warranty of
22 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 % GNU General Public License for more details.
24 %
25 % If you did not received a copy of the GNU General Public License
26 % with this software, see <http://www.gnu.org/licenses/>.
27 %
28
29 [n,r] = size(impact);
30
31 [n1,n2] = size(G1);
32 if (n1 ~= n2) || (n1 ~= n)
33 error('fn_simul.m: make sure that (1) G1 is square and (2) size(G1,1) = size(impact,1)');
34 end
35
36 simul_tmp = zeros(n, nsim);
37
38 simul_tmp(:, 1) = x0;
39 for ti = 2:nsim;
40 simul_tmp(:, ti) = G1*simul_tmp(:, ti-1) + impact*shocks(:, ti);
41 end;
42 simul = simul_tmp';