Skip to content
Snippets Groups Projects
Select Git revision
  • d06d0f94b6decfa11cf80c86ffa7d43ad2292cf8
  • master default protected
  • 6.x protected
  • madysson
  • 5.x protected
  • asm
  • time-varying-information-set
  • 4.6 protected
  • dynare_minreal
  • dragonfly
  • various_fixes
  • 4.5 protected
  • clang+openmp
  • exo_steady_state
  • declare_vars_in_model_block
  • julia
  • error_msg_undeclared_model_vars
  • static_aux_vars
  • slice
  • aux_func
  • penalty
  • 6.4 protected
  • 6.3 protected
  • 6.2 protected
  • 6.1 protected
  • 6.0 protected
  • 6-beta2 protected
  • 6-beta1 protected
  • 5.5 protected
  • 5.4 protected
  • 5.3 protected
  • 5.2 protected
  • 5.1 protected
  • 5.0 protected
  • 5.0-rc1 protected
  • 4.7-beta3 protected
  • 4.7-beta2 protected
  • 4.7-beta1 protected
  • 4.6.4 protected
  • 4.6.3 protected
  • 4.6.2 protected
41 results

csolve.m

Blame
  • csolve.m 5.60 KiB
    function [x,rc] = csolve(FUN,x,gradfun,crit,itmax,varargin)
    %function [x,rc] = csolve(FUN,x,gradfun,crit,itmax,varargin)
    % FUN should be written so that any parametric arguments are packed in to xp,
    % and so that if presented with a matrix x, it produces a return value of
    % same dimension of x.  The number of rows in x and FUN(x) are always the
    % same.  The number of columns is the number of different input arguments
    % at which FUN is to be evaluated.
    %
    % gradfun:  string naming the function called to evaluate the gradient matrix.  If this
    %           is null (i.e. just "[]"), a numerical gradient is used instead.
    % crit:     if the sum of absolute values that FUN returns is less than this,
    %           the equation is solved.
    % itmax:    the solver stops when this number of iterations is reached, with rc=4
    % varargin: in this position the user can place any number of additional arguments, all
    %           of which are passed on to FUN and gradfun (when it is non-empty) as a list of 
    %           arguments following x.
    % rc:       0 means normal solution, 1 and 3 mean no solution despite extremely fine adjustments
    %           in step length (very likely a numerical problem, or a discontinuity). 4 means itmax
    %           termination.
    
    % Original file downloaded from:
    % http://sims.princeton.edu/yftp/optimize/mfiles/csolve.m
    
    % Copyright (C) 1993-2007 Christopher Sims
    % Copyright (C) 2007-2011 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/>.
    
    %---------- delta --------------------
    % differencing interval for numerical gradient
    delta = 1e-6;
    %-------------------------------------
    %------------ alpha ------------------
    % tolerance on rate of descent
    alpha=1e-3;
    %---------------------------------------
    %------------ verbose ----------------
    verbose=0;% if this is set to zero, all screen output is suppressed
              %-------------------------------------
              %------------ analyticg --------------
    analyticg=1-isempty(gradfun); %if the grad argument is [], numerical derivatives are used.
                                  %-------------------------------------
    nv=length(x);
    tvec=delta*eye(nv);
    done=0;
    if isempty(varargin)
        f0=feval(FUN,x);
    else
        f0=feval(FUN,x,varargin{:});
    end   
    af0=sum(abs(f0));
    af00=af0;
    itct=0;
    while ~done
        %   disp([af00-af0 crit*max(1,af0)])
        if itct>3 && af00-af0<crit*max(1,af0) && rem(itct,2)==1
            randomize=1;