1function [dr,info]=AIM_first_order_solver(jacobia,M,dr,qz_criterium)
2
3%@info:
4%! @deftypefn {Function File} {[@var{dr},@var{info}] =} AIM_first_order_solver (@var{jacobia},@var{M},@var{dr},@var{qz_criterium})
5%! @anchor{AIM_first_order_solver}
6%! @sp 1
7%! Computes the first order reduced form of the DSGE model using AIM.
8%! @sp 2
9%! @strong{Inputs}
10%! @sp 1
11%! @table @ @var
12%! @item jacobia
13%! Matrix containing the Jacobian of the model
14%! @item M
15%! Matlab's structure describing the model (initialized by @code{dynare}).
16%! @item dr
17%! Matlab's structure describing the reduced form solution of the model.
18%! @item qz_criterium
19%! Double containing the criterium to separate explosive from stable eigenvalues
20%! @end table
21%! @sp 2
22%! @strong{Outputs}
23%! @sp 1
24%! @table @ @var
25%! @item dr
26%! Matlab's structure describing the reduced form solution of the model.
27%! @item info
28%! Integer scalar, error code.
29%! @sp 1
30%! @table @ @code
31%! @item info==0
32%! No error.
33%! @item info==102
34%! roots not correctly computed by real_schur
35%! @item info==103
36%! Blanchard & Kahn conditions are not satisfied: no stable equilibrium.
37%! @item info==104
38%! Blanchard & Kahn conditions are not satisfied: indeterminacy.
39%! @item info==135
40%! too many explosive roots and q(:,right) is singular
41%! @item info==145
42%! too few big roots, and q(:,right) is singular
43%! @item info==105
44%! q(:,right) is singular
45%! @item info==161
46%! too many exact siftrights
47%! @item info==162
48%! too many numeric shiftrights
49%! @end table
50%! @end table
51%! @end deftypefn
52%@eod:
53
54% Copyright (C) 2001-2017 Dynare Team
55%
56% This file is part of Dynare.
57%
58% Dynare is free software: you can redistribute it and/or modify
59% it under the terms of the GNU General Public License as published by
60% the Free Software Foundation, either version 3 of the License, or
61% (at your option) any later version.
62%
63% Dynare is distributed in the hope that it will be useful,
64% but WITHOUT ANY WARRANTY; without even the implied warranty of
65% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
66% GNU General Public License for more details.
67%
68% You should have received a copy of the GNU General Public License
69% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
70
71info = 0;
72
73[dr,aimcode]=dynAIMsolver1(jacobia,M,dr);
74
75if aimcode ~=1
76    info(1) = convertAimCodeToInfo(aimCode); %convert to be in the 100 range
77    info(2) = 1.0e+8;
78    return
79end
80A = kalman_transition_matrix(dr,M.nstatic+(1:M.nspred), 1:M.nspred,...
81                             M.exo_nbr);
82dr.eigval = eig(A);
83disp(dr.eigval)
84nd = size(dr.kstate,1);
85nba = nd-sum( abs(dr.eigval) < qz_criterium );
86
87nsfwrd = M.nsfwrd;
88
89if nba ~= nsfwrd
90    temp = sort(abs(dr.eigval));
91    if nba > nsfwrd
92        temp = temp(nd-nba+1:nd-nsfwrd)-1-qz_criterium;
93        info(1) = 3;
94    elseif nba < nsfwrd
95        temp = temp(nd-nsfwrd+1:nd-nba)-1-qz_criterium;
96        info(1) = 4;
97    end
98    info(2) = temp'*temp;
99    return
100end
101