Home > matlab > homotopic_steps.m

homotopic_steps

PURPOSE ^

Copyright (C) 2010 Dynare Team

SYNOPSIS ^

function [info,number_of_calls] = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step,init,number_of_calls)

DESCRIPTION ^

 Copyright (C) 2010 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/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [info,number_of_calls] = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step,init,number_of_calls)
0002 
0003 % Copyright (C) 2010 Dynare Team
0004 %
0005 % This file is part of Dynare.
0006 %
0007 % Dynare is free software: you can redistribute it and/or modify
0008 % it under the terms of the GNU General Public License as published by
0009 % the Free Software Foundation, either version 3 of the License, or
0010 % (at your option) any later version.
0011 %
0012 % Dynare is distributed in the hope that it will be useful,
0013 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 % GNU General Public License for more details.
0016 %
0017 % You should have received a copy of the GNU General Public License
0018 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0019 
0020 global oo_
0021 number_of_calls = number_of_calls + 1;
0022 max_number_of_calls = 50;
0023 if number_of_calls>max_number_of_calls
0024     info = NaN;
0025     return
0026 end
0027 max_iter = 100;
0028 weight   = init_weight;
0029 verbose  = 0;
0030 iter     = 0;
0031 time     = 0;
0032 reduce_step = 0;
0033 while iter<=max_iter &&  weight<=1
0034     iter = iter+1;
0035     old_weight = weight;
0036     weight = weight+step;
0037     oo_.exo_simul(tdx,positive_var_indx) = weight*shocks+(1-weight);
0038     if init
0039         info = perfect_foresight_simulation(oo_.dr,oo_.steady_state);
0040     else
0041         info = perfect_foresight_simulation;
0042     end
0043     time = time+info.time;
0044     if verbose
0045         [iter,step]
0046         [info.iterations.time,info.iterations.error]
0047     end
0048     if ~info.convergence
0049         if verbose
0050             disp('Reduce step size!')
0051         end
0052         reduce_step = 1;
0053         break
0054     else
0055         if length(info.iterations.error)<5
0056             if verbose
0057                 disp('Increase step size!')
0058             end
0059             step = step*1.5;
0060         end
0061     end
0062 end
0063 if reduce_step
0064     step=step/1.5;
0065     [info,number_of_calls] = homotopic_steps(tdx,positive_var_indx,shocks,old_weight,step,init,number_of_calls);
0066     if isstruct(info) && ~isnan(info.error)
0067         time = time+info.time;
0068         return
0069     else
0070         return
0071     end
0072 end
0073 if weight<1 && iter<max_iter
0074     oo_.exo_simul(tdx,positive_var_indx) = shocks;
0075     if init
0076         info = perfect_foresight_simulation(oo_.dr,oo_.steady_state);
0077     else
0078         info = perfect_foresight_simulation;
0079     end
0080     info.time = info.time+time;
0081 else
0082     info.time = time;
0083 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005