File: buildGmatrix.m

package info (click to toggle)
dynare 6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 67,632 kB
  • sloc: cpp: 79,090; ansic: 28,916; objc: 12,430; yacc: 4,528; pascal: 1,993; lex: 1,441; sh: 1,121; python: 634; makefile: 626; lisp: 163; xml: 18
file content (57 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download | duplicates (2)
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
function G = buildGmatrix(alpha, beta)
    
% Builds the G matrix needed for PAC.
%
% INPUTS 
% - alpha    [double]    m*1 vector of PAC parameters (lag polynomial parameters).
% - beta     [double]    scalar, discount factor.
%
% OUTPUTS 
% - G         [double]    (m+1)*(m+1) matrix.

% Copyright © 2018 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <https://www.gnu.org/licenses/>.

if nargin<2
    error('Two input arguments are required (vector of alpha parameters and beta discount parameter)!')
end

% Return an error if the first input is not a real vector.
if ~isnumeric(alpha) || ~isreal(alpha) || ~isvector(alpha)
    error('First input argument has to be a vector of doubles!')
end 

% Return an error if the second input argument is not a discount factor
if ~isnumeric(beta) || ~isreal(beta) || ~isscalar(beta) || beta<eps || beta>1-eps
    error('Second input argument has to be a discount factor!')
end 

% Get the number of parameters
m = length(alpha);

% Return an error if params is too small.
if m<1
    error('First input argument has to be a vector with at least one element.')
end

% Initialize the returned G matrix.
G = zeros(m);

% Fill the returned G matrix.
G(1:m-1,2:m) = eye(m-1);
G(m, :) = -flip(transpose(alpha));
G(m, :) = G(m, :).*flip(cumprod(beta*ones(1,m)));