diff --git a/matlab/block_bytecode_mfs_steadystate.m b/matlab/block_bytecode_mfs_steadystate.m index d06fb1b8b247a65411f2f9e8c04bc33f675557b2..e0a718db94c6d6c89b986e79e808c26a3e8ae86f 100644 --- a/matlab/block_bytecode_mfs_steadystate.m +++ b/matlab/block_bytecode_mfs_steadystate.m @@ -1,4 +1,4 @@ -function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all) +function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all, exo, params, M) % Wrapper around the *_static.m file, for use with dynare_solve, % when block_mfs option is given to steady. @@ -19,8 +19,6 @@ function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all) % 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_ -indx = M_.blocksMFS{b}; +indx = M.blocksMFS{b}; y_all(indx) = y; -x = [oo_.exo_steady_state; oo_.exo_det_steady_state]; -[chk, r, g1] = bytecode( y_all, x, M_.params, y_all, 1, y_all, 'evaluate', 'static', ['block = ' int2str(b) ]); +[chk, r, g1] = bytecode( y_all, exo, params, y_all, 1, y_all, 'evaluate', 'static', ['block = ' int2str(b) ]); diff --git a/matlab/block_mfs_steadystate.m b/matlab/block_mfs_steadystate.m index f4bf4224f1c63b83b781d90d38286fc54ebe0fb2..e027ecb4c26fe58885604ab66c209031f4cec590 100644 --- a/matlab/block_mfs_steadystate.m +++ b/matlab/block_mfs_steadystate.m @@ -1,4 +1,4 @@ -function [r, g1] = block_mfs_steadystate(y, b, y_all) +function [r, g1] = block_mfs_steadystate(y, b, y_all, exo, params, M) % Wrapper around the *_static.m file, for use with dynare_solve, % when block_mfs option is given to steady. @@ -19,10 +19,7 @@ function [r, g1] = block_mfs_steadystate(y, b, y_all) % 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_ +y_all(M.blocksMFS{b}) = y; -y_all(M_.blocksMFS{b}) = y; -x = [oo_.exo_steady_state; oo_.exo_det_steady_state]; - -eval(['[r,g1] = ' M_.fname '_static(b, y_all, x, M_.params);']); +eval(['[r,g1] = ' M.fname '_static(b, y_all, exo, params);']); g1 = full(g1); \ No newline at end of file diff --git a/matlab/bytecode_steadystate.m b/matlab/bytecode_steadystate.m index 2aa2715a31ba7d4714d872273f840d647cc3d71b..3544034969a326c41f5a4aef218fe5ec581fe00f 100644 --- a/matlab/bytecode_steadystate.m +++ b/matlab/bytecode_steadystate.m @@ -1,4 +1,4 @@ -function [r, g1] = bytecode_steadystate(y) +function [r, g1] = bytecode_steadystate(y, exo, params) % Wrapper around the *_static.m file, for use with dynare_solve, % when block_mfs option is given to steady. @@ -19,6 +19,4 @@ function [r, g1] = bytecode_steadystate(y) % 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_ -x = [oo_.exo_steady_state; oo_.exo_det_steady_state]; -eval('[chk, r, g1] = bytecode( y, x, M_.params, oo_.steady_state, 1, x, ''evaluate'', ''static'', ''block = 1'');'); \ No newline at end of file +eval('[chk, r, g1] = bytecode( y, exo, params, y, 1, exo, ''evaluate'', ''static'');'); diff --git a/matlab/dynare_solve_block_or_bytecode.m b/matlab/dynare_solve_block_or_bytecode.m index 949778b9105fde3b8a41c0b9b57695df0124c892..8acaa1c7117eafd3a598e0c0de5ee29cec07e9a1 100644 --- a/matlab/dynare_solve_block_or_bytecode.m +++ b/matlab/dynare_solve_block_or_bytecode.m @@ -1,4 +1,4 @@ -function [x,info] = dynare_solve_block_or_bytecode(y, exo, params) +function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M) % Copyright (C) 2010-2011 Dynare Team % % This file is part of Dynare. @@ -16,48 +16,47 @@ function [x,info] = dynare_solve_block_or_bytecode(y, exo, params) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -global options_ M_ info = 0; x = y; -if options_.block && ~options_.bytecode - for b = 1:size(M_.blocksMFS,1) - n = size(M_.blocksMFS{b}, 1); +if options.block && ~options.bytecode + for b = 1:size(M.blocksMFS,1) + n = size(M.blocksMFS{b}, 1); ss = x; if n ~= 0 - if options_.solve_algo <= 4 + if options.solve_algo <= 4 [y, check] = dynare_solve('block_mfs_steadystate', ... - ss(M_.blocksMFS{b}), ... - options_.jacobian_flag, b, ss); + ss(M.blocksMFS{b}), ... + options.jacobian_flag, b, ss, exo, params, M); if check ~= 0 error(['STEADY: convergence problems in block ' int2str(b)]) end - ss(M_.blocksMFS{b}) = y; + ss(M.blocksMFS{b}) = y; else - [ss, check] = solve_one_boundary([M_.fname '_static_' int2str(b)], ss, exo, ... - params, [], M_.blocksMFS{b}, n, 1, 0, b, 0, options_.maxit_, ... - options_.solve_tolf, options_.slowc, 0, options_.solve_algo, 1, 0, 0); + [ss, check] = solve_one_boundary([M.fname '_static_' int2str(b)], ss, exo, ... + params, [], M.blocksMFS{b}, n, 1, 0, b, 0, options.maxit_, ... + options.solve_tolf, options.slowc, 0, options.solve_algo, 1, 0, 0); end end - [r, g1, x] = feval([M_.fname '_static'], b, ss, ... + [r, g1, x] = feval([M.fname '_static'], b, ss, ... exo, params); end -elseif options_.bytecode - if options_.solve_algo > 4 +elseif options.bytecode + if options.solve_algo > 4 [check, x] = bytecode('static', x, exo, params); mexErrCheck('bytecode', check); info = check; - elseif options_.block - for b = 1:size(M_.blocksMFS,1) - n = size(M_.blocksMFS{b}, 1); + elseif options.block + for b = 1:size(M.blocksMFS,1) + n = size(M.blocksMFS{b}, 1); if n ~= 0 [y, check] = dynare_solve('block_bytecode_mfs_steadystate', ... - x(M_.blocksMFS{b}), ... - options_.jacobian_flag, b, x); + x(M.blocksMFS{b}), ... + options.jacobian_flag, b, x, exo, params, M); if check ~= 0 error(['STEADY: convergence problems in block ' int2str(b)]) end - x(M_.blocksMFS{b}) = y; + x(M.blocksMFS{b}) = y; else [chk, nulldev, nulldev1, x] = bytecode( x, exo, params, x, 1, x, 'evaluate', 'static', ['block = ' int2str(b)]); end; @@ -65,7 +64,7 @@ elseif options_.bytecode else [x, check] = dynare_solve('bytecode_steadystate', ... y, ... - options_.jacobian_flag); + options.jacobian_flag, exo, params); if check ~= 0 error('STEADY: convergence problems') end diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index 0c3962e7d6ca413c81444e3d021d32f171d382e5..0035f438dba087e2c460146bcca10aa3d4e562b6 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -112,7 +112,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta end else % block or bytecode - [ys,check] = dynare_solve_block_or_bytecode(ys_init,exo_ss, params); + [ys,check] = dynare_solve_block_or_bytecode(ys_init,exo_ss, params, options, M); end if check diff --git a/matlab/solve_one_boundary.m b/matlab/solve_one_boundary.m index 1b4c390f9158ff512d4c61dd94be3d85f7b7335e..7d8ab99577b4508af855b299b11601ed70b93cbf 100644 --- a/matlab/solve_one_boundary.m +++ b/matlab/solve_one_boundary.m @@ -1,5 +1,5 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ... - y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, forward_backward, is_dynamic, verbose) + y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, forward_backward, is_dynamic, verbose, M, options, oo) % Computes the deterministic simulation of a block of equation containing % lead or lag variables % @@ -73,7 +73,6 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ... % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -global oo_ M_ options_; Blck_size=size(y_index_eq,2); g2 = []; g3 = []; @@ -145,9 +144,9 @@ for it_=start:incr:finish if(verbose==1) disp(['iteration : ' int2str(iter+1) ' => ' num2str(max_res) ' time = ' int2str(it_)]); if(is_dynamic) - disp([M_.endo_names(y_index_eq,:) num2str([y(it_,y_index_eq)' r g1])]); + disp([M.endo_names(y_index_eq,:) num2str([y(it_,y_index_eq)' r g1])]); else - disp([M_.endo_names(y_index_eq,:) num2str([y(y_index_eq) r g1])]); + disp([M.endo_names(y_index_eq,:) num2str([y(y_index_eq) r g1])]); end; end; if(~isreal(max_res) || isnan(max_res)) @@ -221,7 +220,7 @@ for it_=start:incr:finish end; ya_save=ya; g1a=g1; - if(~is_dynamic && options_.solve_algo == 0) + if(~is_dynamic && options.solve_algo == 0) if (verbose == 1) disp('steady: fsolve'); end @@ -242,7 +241,7 @@ for it_=start:incr:finish func = @(z) local_fname(z, x, params, steady_state, y, y_index_eq, fname, 0); % The Octave version of fsolve does not converge when it starts from the solution fvec = feval(func,y(y_index_eq)); - if max(abs(fvec)) >= options_.solve_tolf + if max(abs(fvec)) >= options.solve_tolf [yn,fval,exitval,output] = fsolve(func,y(y_index_eq),options); else yn = y(y_index_eq); @@ -256,7 +255,7 @@ for it_=start:incr:finish else info = -Block_Num*10; end - elseif((~is_dynamic && options_.solve_algo==2) || (is_dynamic && stack_solve_algo==4)) + elseif((~is_dynamic && options.solve_algo==2) || (is_dynamic && stack_solve_algo==4)) if (verbose == 1 && ~is_dynamic) disp('steady: LU + lnsrch1'); end @@ -287,7 +286,7 @@ for it_=start:incr:finish else y = ya'; end; - elseif(~is_dynamic && options_.solve_algo==3) + elseif(~is_dynamic && options.solve_algo==3) if (verbose == 1) disp('steady: csolve'); end @@ -295,7 +294,7 @@ for it_=start:incr:finish local_fname,1e-6,500, x, params, steady_state, y, y_index_eq, fname, 1); dx = ya - yn; y(y_index_eq) = yn; - elseif((stack_solve_algo==1 && is_dynamic) || (stack_solve_algo==0 && is_dynamic) || (~is_dynamic && (options_.solve_algo==1 || options_.solve_algo==6))), + elseif((stack_solve_algo==1 && is_dynamic) || (stack_solve_algo==0 && is_dynamic) || (~is_dynamic && (options.solve_algo==1 || options.solve_algo==6))), if (verbose == 1 && ~is_dynamic) disp('steady: Sparse LU '); end @@ -306,7 +305,7 @@ for it_=start:incr:finish else y(y_index_eq) = ya; end; - elseif((stack_solve_algo==2 && is_dynamic) || (options_.solve_algo==7 && ~is_dynamic)), + elseif((stack_solve_algo==2 && is_dynamic) || (options.solve_algo==7 && ~is_dynamic)), flag1=1; if exist('OCTAVE_VERSION') error('SOLVE_ONE_BOUNDARY: you can''t use solve_algo=7 since GMRES is not implemented in Octave') @@ -336,7 +335,7 @@ for it_=start:incr:finish end; end; end; - elseif((stack_solve_algo==3 && is_dynamic) || (options_.solve_algo==8 && ~is_dynamic)), + elseif((stack_solve_algo==3 && is_dynamic) || (options.solve_algo==8 && ~is_dynamic)), flag1=1; if (verbose == 1 && ~is_dynamic) disp('steady: BiCGStab'); @@ -355,7 +354,7 @@ for it_=start:incr:finish else [r, y, g1] = feval(fname, y, x, params); end; - if max(abs(r)) >= options_.solve_tolf + if max(abs(r)) >= options.solve_tolf [dx,flag1] = bicgstab(g1,-r,1e-7,Blck_size,L1,U1); else flag1 = 0; @@ -385,7 +384,7 @@ for it_=start:incr:finish if(is_dynamic) disp(['options_.stack_solve_algo = ' num2str(stack_solve_algo) ' not implemented']); else - disp(['options_.solve_algo = ' num2str(options_.solve_algo) ' not implemented']); + disp(['options_.solve_algo = ' num2str(options.solve_algo) ' not implemented']); end; info = -Block_Num*10; return; diff --git a/matlab/solve_two_boundaries.m b/matlab/solve_two_boundaries.m index de9c78aba64e6b8a3c40ff2c01d32df8501db5e3..cde94b9dda7d3a12821514fd5204765432b6ca03 100644 --- a/matlab/solve_two_boundaries.m +++ b/matlab/solve_two_boundaries.m @@ -1,4 +1,4 @@ -function y = solve_two_boundaries(fname, y, x, params, steady_state, y_index, nze, periods, y_kmin_l, y_kmax_l, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo) +function y = solve_two_boundaries(fname, y, x, params, steady_state, y_index, nze, periods, y_kmin_l, y_kmax_l, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, M, oo) % Computes the deterministic simulation of a block of equation containing % both lead and lag variables using relaxation methods % @@ -60,7 +60,6 @@ function y = solve_two_boundaries(fname, y, x, params, steady_state, y_index, nz % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -global oo_ M_; cvg=0; iter=0; Per_u_=0; @@ -158,7 +157,7 @@ while ~(cvg==1 || iter>maxit_), if(iter>0) if(~isreal(max_res) || isnan(max_res) || (max_resa<max_res && iter>1)) if(~isreal(max_res)) - disp(['Variable ' M_.endo_names(max_indx,:) ' (' int2str(max_indx) ') returns an undefined value']); + disp(['Variable ' M.endo_names(max_indx,:) ' (' int2str(max_indx) ') returns an undefined value']); end; if(isnan(max_res)) detJ=det(g1aa); @@ -191,12 +190,12 @@ while ~(cvg==1 || iter>maxit_), else fprintf('Error in simul: Convergence not achieved in block %d, after %d iterations.\n Increase "options_.maxit_" or set "cutoff=0" in model options.\n',Block_Num, iter); end; - oo_.deterministic_simulation.status = 0; - oo_.deterministic_simulation.error = max_res; - oo_.deterministic_simulation.iterations = iter; - oo_.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed. - oo_.deterministic_simulation.block(Block_Num).error = max_res; - oo_.deterministic_simulation.block(Block_Num).iterations = iter; + oo.deterministic_simulation.status = 0; + oo.deterministic_simulation.error = max_res; + oo.deterministic_simulation.iterations = iter; + oo.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed. + oo.deterministic_simulation.block(Block_Num).error = max_res; + oo.deterministic_simulation.block(Block_Num).iterations = iter; return; end; else @@ -314,18 +313,18 @@ while ~(cvg==1 || iter>maxit_), end; if (iter>maxit_) disp(['No convergence after ' num2str(iter,'%4d') ' iterations in Block ' num2str(Block_Num,'%d')]); - oo_.deterministic_simulation.status = 0; - oo_.deterministic_simulation.error = max_res; - oo_.deterministic_simulation.iterations = iter; - oo_.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed. - oo_.deterministic_simulation.block(Block_Num).error = max_res; - oo_.deterministic_simulation.block(Block_Num).iterations = iter; + oo.deterministic_simulation.status = 0; + oo.deterministic_simulation.error = max_res; + oo.deterministic_simulation.iterations = iter; + oo.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed. + oo.deterministic_simulation.block(Block_Num).error = max_res; + oo.deterministic_simulation.block(Block_Num).iterations = iter; return; end -oo_.deterministic_simulation.status = 1; -oo_.deterministic_simulation.error = max_res; -oo_.deterministic_simulation.iterations = iter; -oo_.deterministic_simulation.block(Block_Num).status = 1;% Convergency obtained. -oo_.deterministic_simulation.block(Block_Num).error = max_res; -oo_.deterministic_simulation.block(Block_Num).iterations = iter; +oo.deterministic_simulation.status = 1; +oo.deterministic_simulation.error = max_res; +oo.deterministic_simulation.iterations = iter; +oo.deterministic_simulation.block(Block_Num).status = 1;% Convergency obtained. +oo.deterministic_simulation.block(Block_Num).error = max_res; +oo.deterministic_simulation.block(Block_Num).iterations = iter; return;