Implemented MATLAB part of the block_mfs option to steady.
(Still need to fix a bug) git-svn-id: https://www.dynare.org/svn/dynare/trunk@2829 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
a089e59f3c
commit
e8700bc046
|
@ -0,0 +1,30 @@
|
|||
function [r, g1] = block_mfs_steadystate(y, b)
|
||||
% Wrapper around the *_static.m file, for use with dynare_solve,
|
||||
% when block_mfs option is given to steady.
|
||||
|
||||
% Copyright (C) 2009 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ oo_
|
||||
|
||||
ss = oo_.steady_state;
|
||||
indx = M_.blocksMFS{b};
|
||||
|
||||
ss(indx) = y;
|
||||
x = [oo_.exo_steady_state; oo_.exo_det_steady_state];
|
||||
|
||||
eval(['[r,g1] = ' M_.fname '_static(b, ss, x, M_.params);']);
|
|
@ -220,4 +220,8 @@ function global_initialization()
|
|||
|
||||
% prior analysis
|
||||
options_.prior_mc = 20000;
|
||||
options_.prior_analysis_endo_var_list = [];
|
||||
options_.prior_analysis_endo_var_list = [];
|
||||
|
||||
% block decomposition + minimum feedback set for steady state computation
|
||||
options_.block_mfs = 0;
|
||||
|
|
@ -77,13 +77,9 @@ function homotopy1(values, step_nbr)
|
|||
oo_.exo_steady_state(values(ix,2)) = points(ix,i);
|
||||
oo_.exo_det_steady_state(values(ixd,2)) = points(ixd,i);
|
||||
|
||||
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
|
||||
oo_.steady_state,...
|
||||
options_.jacobian_flag, ...
|
||||
[oo_.exo_steady_state; ...
|
||||
oo_.exo_det_steady_state], M_.params);
|
||||
|
||||
if check
|
||||
try
|
||||
steady_;
|
||||
catch
|
||||
error('HOMOTOPY mode 1: failed')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -99,13 +99,10 @@ function homotopy2(values, step_nbr)
|
|||
end
|
||||
|
||||
disp([ 'HOMOTOPY mode 2: lauching solver with ' strtrim(varname) ' = ' num2str(v) ' ...'])
|
||||
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
|
||||
oo_.steady_state,...
|
||||
options_.jacobian_flag, ...
|
||||
[oo_.exo_steady_state; ...
|
||||
oo_.exo_det_steady_state], M_.params);
|
||||
|
||||
if check
|
||||
try
|
||||
steady_;
|
||||
catch
|
||||
error('HOMOTOPY mode 2: failed')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,17 +89,10 @@ function homotopy3(values, step_nbr)
|
|||
oo_.exo_det_steady_state(values(ixd,2)) = curvalues(ixd);
|
||||
|
||||
old_ss = oo_.steady_state;
|
||||
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
|
||||
oo_.steady_state,...
|
||||
options_.jacobian_flag, ...
|
||||
[oo_.exo_steady_state; ...
|
||||
oo_.exo_det_steady_state], M_.params);
|
||||
|
||||
if check
|
||||
disp('HOMOTOPY mode 3: failed step, now dividing increment by 2...')
|
||||
inc = inc/2;
|
||||
oo_.steady_state = old_ss;
|
||||
else
|
||||
|
||||
try
|
||||
steady_;
|
||||
|
||||
if length([kplus; kminus]) == nv
|
||||
return
|
||||
end
|
||||
|
@ -110,7 +103,12 @@ function homotopy3(values, step_nbr)
|
|||
end
|
||||
oldvalues = curvalues;
|
||||
inc = 2*inc;
|
||||
end
|
||||
catch
|
||||
disp('HOMOTOPY mode 3: failed step, now dividing increment by 2...')
|
||||
inc = inc/2;
|
||||
oo_.steady_state = old_ss;
|
||||
end
|
||||
|
||||
curvalues = oldvalues + inc;
|
||||
kplus = find(curvalues(iplus) >= targetvalues(iplus));
|
||||
curvalues(iplus(kplus)) = targetvalues(iplus(kplus));
|
||||
|
|
|
@ -62,6 +62,20 @@ function steady_()
|
|||
options_.jacobian_flag, ...
|
||||
[oo_.exo_steady_state;oo_.exo_det_steady_state],indv);
|
||||
end
|
||||
elseif options_.block_mfs
|
||||
for b = 1:size(M_.blocksMFS,1)
|
||||
n = size(M_.blocksMFS{b}, 1);
|
||||
ss = oo_.steady_state;
|
||||
if n ~= 0
|
||||
[y, check] = dynare_solve('block_mfs_steadystate', ...
|
||||
ss(M_.blocksMFS{b}), ...
|
||||
options_.jacobian_flag, b);
|
||||
ss(M_.blocksMFS{b}) = y;
|
||||
end
|
||||
[r, g1, oo_.steady_state] = feval([M_.fname '_static'], b, ss, ...
|
||||
[oo_.exo_steady_state; ...
|
||||
oo_.exo_det_steady_state], M_.params);
|
||||
end
|
||||
else
|
||||
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
|
||||
oo_.steady_state,...
|
||||
|
|
|
@ -517,15 +517,11 @@ StaticModel::writeOutput(ostream &output) const
|
|||
if (!block_mfs)
|
||||
return;
|
||||
|
||||
output << "M_.blocks = cell(" << blocks.size() << ", 1);" << endl
|
||||
<< "M_.blocksMFS = cell(" << blocksMFS.size() << ", 1);" << endl;
|
||||
output << "M_.blocksMFS = cell(" << blocksMFS.size() << ", 1);" << endl;
|
||||
for(int b = 0; b < (int) blocks.size(); b++)
|
||||
{
|
||||
output << "M_.blocks{" << b+1 << "} = [ ";
|
||||
transform(blocks[b].begin(), blocks[b].end(), ostream_iterator<int>(output, " "), bind2nd(plus<int>(), 1));
|
||||
output << "];" << endl
|
||||
<< "M_.blocksMFS{" << b+1 << "} = [ ";
|
||||
transform(blocksMFS[b].begin(), blocksMFS[b].end(), ostream_iterator<int>(output, " "), bind2nd(plus<int>(), 1));
|
||||
output << "M_.blocksMFS{" << b+1 << "} = [ ";
|
||||
transform(blocksMFS[b].begin(), blocksMFS[b].end(), ostream_iterator<int>(output, "; "), bind2nd(plus<int>(), 1));
|
||||
output << "];" << endl;
|
||||
}
|
||||
}
|
||||
|
@ -533,7 +529,7 @@ StaticModel::writeOutput(ostream &output) const
|
|||
void
|
||||
StaticModel::writeStaticBlockMFSFile(ostream &output, const string &func_name) const
|
||||
{
|
||||
output << "function [y, residual, g1] = " << func_name << "(nblock, y, x, params)" << endl
|
||||
output << "function [residual, g1, y] = " << func_name << "(nblock, y, x, params)" << endl
|
||||
<< " switch nblock" << endl;
|
||||
|
||||
for(int b = 0; b < (int) blocks.size(); b++)
|
||||
|
@ -596,4 +592,7 @@ StaticModel::writeStaticBlockMFSFile(ostream &output, const string &func_name) c
|
|||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
output << " end" << endl
|
||||
<< "end" << endl;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue