Skip to content
Snippets Groups Projects
Select Git revision
  • dbd9e36db9cc337721729a0c6dc95c978b7d327e
  • master default
  • nlf-fixes
  • newton-quadratic-equation-solver
  • nlf-fixes-r
  • nls-fixes
  • sep-fixes
  • sep
  • use-dprior
  • ep-sparse
  • rebase-1
  • parfor
  • reset-seed-in-unit-tests
  • remove-persistent-variables
  • nonlinear-filter-fixes
  • pac-mce-with-composite-target
  • 6.x
  • dprior
  • covariance-quadratic-approximation
  • benchmark-ec
  • kalman_mex
  • 5.5
  • 5.4
  • 5.3
  • 5.2
  • 5.1
  • 5.0
  • 5.0-rc1
  • 4.7-beta3
  • 4.7-beta2
  • 4.7-beta1
  • 4.6.4
  • 4.6.3
  • 4.6.2
  • 4.6.1
  • 4.6.0
  • 4.6.0-rc2
  • 4.6.0-rc1
  • 4.6-beta1
  • 4.5.7
  • 4.5.6
41 results

SPAmalg.m

Blame
  • Forked from Dynare / dynare
    Source project has a limited visibility.
    SPAmalg.m 3.53 KiB
    %  [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ...
    %                       SPAmalg(h,neq,nlag,nlead,condn,uprbnd)
    %
    %  Solve a linear perfect foresight model using the matlab eig
    %  function to find the invariant subspace associated with the big
    %  roots.  This procedure will fail if the companion matrix is
    %  defective and does not have a linearly independent set of
    %  eigenvectors associated with the big roots.
    % 
    %  Input arguments:
    % 
    %    h         Structural coefficient matrix (neq,neq*(nlag+1+nlead)).
    %    neq       Number of equations.
    %    nlag      Number of lags.
    %    nlead     Number of leads.
    %    condn     Zero tolerance used as a condition number test
    %              by numeric_shift and reduced_form.
    %    uprbnd    Inclusive upper bound for the modulus of roots
    %              allowed in the reduced form.
    % 
    %  Output arguments:
    % 
    %    b         Reduced form coefficient matrix (neq,neq*nlag).
    %    rts       Roots returned by eig.
    %    ia        Dimension of companion matrix (number of non-trivial
    %              elements in rts).
    %    nexact    Number of exact shiftrights.
    %    nnumeric  Number of numeric shiftrights.
    %    lgroots   Number of roots greater in modulus than uprbnd.
    %    aimcode     Return code: see function aimerr.
    
    % Original author: Gary Anderson
    % Original file downloaded from:
    % http://www.federalreserve.gov/Pubs/oss/oss4/code.html
    % Adapted for Dynare by Dynare Team, in order to deal
    % with infinite or nan values.
    %
    % This code is in the public domain and may be used freely.
    % However the authors would appreciate acknowledgement of the source by
    % citation of any of the following papers:
    %
    % Anderson, G. and Moore, G.
    % "A Linear Algebraic Procedure for Solving Linear Perfect Foresight
    % Models."
    % Economics Letters, 17, 1985.
    %
    % Anderson, G.
    % "Solving Linear Rational Expectations Models: A Horse Race"
    % Computational Economics, 2008, vol. 31, issue 2, pages 95-113
    %
    % Anderson, G.
    % "A Reliable and Computationally Efficient Algorithm for Imposing the
    % Saddle Point Property in Dynamic Models"
    % Journal of Economic Dynamics and Control, Forthcoming
    
    function [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ...
                            SPAmalg(h,neq,nlag,nlead,condn,uprbnd)
    b=[];rts=[];ia=[];nexact=[];nnumeric=[];lgroots=[];aimcode=[];
    if(nlag<1 || nlead<1) 
        error('Aim_eig: model must have at least one lag and one lead');
    end
    % Initialization.
    nexact=0;nnumeric=0;lgroots=0;iq=0;aimcode=0;b=0;qrows=neq*nlead;qcols=neq*(nlag+nlead);
    bcols=neq*nlag;q=zeros(qrows,qcols);rts=zeros(qcols,1);
    [h,q,iq,nexact]=SPExact_shift(h,q,iq,qrows,qcols,neq);
    if (iq>qrows)
        aimcode = 61;
        return;
    end
    [h,q,iq,nnumeric]=SPNumeric_shift(h,q,iq,qrows,qcols,neq,condn);