1function z = resid(junk)
2% function z = resid(junk)
3%
4% Computes static residuals associated with the guess values.
5%
6% INPUTS
7%    junk:   dummy value for backward compatibility
8%
9% OUTPUTS
10%    z:      residuals
11%
12% SPECIAL REQUIREMENTS
13%    none
14
15% Copyright (C) 2001-2018 Dynare Team
16%
17% This file is part of Dynare.
18%
19% Dynare is free software: you can redistribute it and/or modify
20% it under the terms of the GNU General Public License as published by
21% the Free Software Foundation, either version 3 of the License, or
22% (at your option) any later version.
23%
24% Dynare is distributed in the hope that it will be useful,
25% but WITHOUT ANY WARRANTY; without even the implied warranty of
26% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27% GNU General Public License for more details.
28%
29% You should have received a copy of the GNU General Public License
30% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
31
32global M_ options_ oo_
33
34tagname = 'name';
35if nargin && ischar(junk)
36    tagname = junk;
37end
38
39tags  = M_.equations_tags;
40istag = 0;
41if length(tags)
42    istag = 1;
43end
44
45steady_state_old = oo_.steady_state;
46
47% Keep of a copy of M_.Sigma_e
48Sigma_e = M_.Sigma_e;
49
50% Set M_.Sigma_e=0 (we evaluate the *deterministic* static model)
51M_.Sigma_e = zeros(size(Sigma_e));
52
53info = 0;
54if any(imag(oo_.steady_state))
55    imagrow=find(imag(oo_.steady_state));
56    if ~isempty(imagrow)
57        fprintf('\nresid: The initial values for the steady state of the following variables are complex:\n');
58        for iter=1:length(imagrow)
59            fprintf('%s\n', M_.endo_names{imagrow(iter)});
60        end
61    end
62end
63
64if options_.steadystate_flag
65    [oo_.steady_state,M_.params,info] = ...
66        evaluate_steady_state(oo_.steady_state,M_,options_,oo_,0);
67end
68
69% Compute the residuals
70if options_.block && ~options_.bytecode
71    z = zeros(M_.endo_nbr,1);
72    for i = 1:length(M_.block_structure_stat.block)
73        [r, g, yy, var_indx] = feval([M_.fname '.static'],...
74                                     i,...
75                                     oo_.steady_state,...
76                                     [oo_.exo_steady_state; ...
77                            oo_.exo_det_steady_state], M_.params);
78        idx = M_.block_structure_stat.block(i).equation;
79        z(idx) = r;
80    end
81elseif options_.bytecode
82    [check, z] = bytecode('evaluate','static');
83    mexErrCheck('bytecode', check);
84else
85    z = feval([M_.fname '.static'],...
86              oo_.steady_state,...
87              [oo_.exo_steady_state; ...
88               oo_.exo_det_steady_state], M_.params);
89end
90
91M_.Sigma_e = Sigma_e;
92
93
94% Display the non-zero residuals if no return value
95if nargout == 0
96    skipline(4)
97    ind = [];
98    disp('Residuals of the static equations:')
99    skipline()
100    for i=1:M_.orig_endo_nbr
101        if abs(z(i)) < options_.solve_tolf/100
102            tmp = 0;
103        else
104            tmp = z(i);
105        end
106        if istag
107            tg = tags(cell2mat(tags(:,1)) == i,2:3); % all tags for equation i
108            ind = strmatch( tagname, cellstr( tg(:,1) ) );
109        end
110        if ~istag || length(ind) == 0
111            disp(['Equation number ' int2str(i) ' : ' num2str(tmp)])
112        else
113            t1 = tg( ind , 2 );
114            s = cell2mat(t1);
115            disp( ['Equation number ', int2str(i) ,' : ', num2str(tmp) ,' : ' s])
116        end
117    end
118    skipline(2)
119end
120
121oo_.steady_state = steady_state_old;
122