resid.m 3.15 KB
Newer Older
1
2
3
4
function z = resid(junk)
% function z = resid(junk)
%
% Computes static residuals associated with the guess values.
assia's avatar
assia committed
5
6
% 
% INPUTS
7
%    junk:   dummy value for backward compatibility
assia's avatar
assia committed
8
9
%    
% OUTPUTS
10
%    z:      residuals
assia's avatar
assia committed
11
12
13
14
%        
% SPECIAL REQUIREMENTS
%    none

Sébastien Villemot's avatar
Sébastien Villemot committed
15
% Copyright (C) 2001-2012 Dynare Team
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
%
% 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 <http://www.gnu.org/licenses/>.
assia's avatar
assia committed
31

32
global M_ options_ oo_
michel's avatar
michel committed
33

34
35
36
37
38
39
40
41
42
43
44
tagname = 'name';
if nargin && ischar(junk)
    tagname = junk;
end

tags  = M_.equations_tags;
istag = 0;
if length(tags)
    istag = 1;
end

45
steady_state_old = oo_.steady_state;
46

47
48
49
50
51
52
% Keep of a copy of M_.Sigma_e
Sigma_e = M_.Sigma_e;

% Set M_.Sigma_e=0 (we evaluate the *deterministic* static model)
M_.Sigma_e = zeros(size(Sigma_e));

53
54
55
56
57
info = 0;
if options_.steadystate_flag
    [oo_.steady_state,M.params,info] = ...
        evaluate_steady_state(oo_.steady_state,M_,options_,oo_,0);
end
58

59
60
% Compute the residuals
if options_.block && ~options_.bytecode
61
    z = zeros(M_.endo_nbr,1);
62
    for i = 1:length(M_.block_structure_stat.block)
63
64
65
66
67
        [r, g, yy, var_indx] = feval([M_.fname '_static'],...
                                     i,...
                                     oo_.steady_state,...
                                     [oo_.exo_steady_state; ...
                            oo_.exo_det_steady_state], M_.params);
68
        idx = M_.block_structure_stat.block(i).equation;
69
        z(idx) = r;
70
    end
71
elseif options_.bytecode
72
73
    [check, z] = bytecode('evaluate','static');
    mexErrCheck('bytecode', check);
74
75
76
77
78
79
80
else
    z = feval([M_.fname '_static'],...
              oo_.steady_state,...
              [oo_.exo_steady_state; ...
               oo_.exo_det_steady_state], M_.params);
end

81
82
M_.Sigma_e = Sigma_e;

83

84
85
86
87
88
% Display the non-zero residuals if no return value
if nargout == 0
    for i = 1:4
        disp(' ')
    end
89
    ind = [];
90
91
    disp('Residuals of the static equations:')
    disp(' ')
92
    for i=1:M_.orig_endo_nbr
93
        if abs(z(i)) < options_.dynatol.f/100
94
95
96
97
            tmp = 0;
        else
            tmp = z(i);
        end
98
99
100
101
        if istag
            tg = tags(cell2mat(tags(:,1)) == i,2:3); % all tags for equation i
            ind = strmatch( tagname, cellstr( tg(:,1) ) );
        end
102
        if ~istag || length(ind) == 0
103
104
105
106
107
108
            disp(['Equation number ' int2str(i) ' : ' num2str(tmp)])
        else
            t1 = tg( ind , 2 );
            s = cell2mat(t1);
            disp( ['Equation number ', int2str(i) ,' : ', num2str(tmp) ,' : ' s])
        end
109
110
111
112
113
114
    end
    for i = 1:2
        disp(' ')
    end
end

115
116
117
118
119
if info(1)
    print_info(info,options_.noprint)
end


120
oo_.steady_state = steady_state_old;