Problems whit syms: Variable "iv" has been previously used as a function or command name
2 ビュー (過去 30 日間)
古いコメントを表示
Hi! While running this code
function [nfx,nfxp,nfy,nfyp] = rw
%This program computes a log-linear approximation to the function f for a small open economy without stationarity inducing features. The model is described in ``Closing Small Open Economy Models,'' by Stephanie Schmitt-Grohe and Martin Uribe. The function f defines the DSGE model (a p denotes next-period variables) :
% E_t f(yp,y,xp,x) =0.
%
%Inputs: none
%
%Output: Numerical first derivative of f
%
%Calls: anal_deriv.m num_eval.m rw_ss.m
%
%(c) Stephanie Schmitt-Grohe and Martin Uribe
%
%Date November 8, 2001
%Define parameters
approx = 1; %Order of approximation desired
syms GAMA DELTA ALFA RHO OMEGA PHI R DBAR
%Define variables
syms c cp k kp k1 k1p a ap h hp d dp yy yyp iv ivp tb tbp la lap tby tbyp cay cayp
%Give functional form for utility and production functions
u = ((c - h^OMEGA/OMEGA)^(1-GAMA)-1)/(1-GAMA);
up = ((cp - hp^OMEGA/OMEGA)^(1-GAMA)-1)/(1-GAMA);
output = a * k^ALFA * h^(1-ALFA);
outputp = ap * kp^ALFA * hp^(1-ALFA);
%Write equations (e1, e2,...en)
%Note: we take a linear, rather than log-linear, approximation with respect to tb, the trade balance)
e1 = (1+R) * d - log(tb) - dp;
e2 = -log(tb) + yy - c - iv - PHI/2 * (kp -k)^2;
e3 = -yy + a * k^ALFA * h^(1-ALFA);
e4 = -iv + kp - (1-DELTA) *k;
e5 = - la + lap;
e6 = - la + diff(u,'c');
e7 = -diff(u,'h') - la * diff(output,'h');
e8 = -la * (1+ PHI*(kp-k)) + 1 / (1+R) * lap* (diff(outputp,'kp') + 1 - DELTA + PHI * (k1p -k1));
e9 = -k1 + kp;
e10 = -log(ap) + RHO * log(a);
e11 = -log(tby) + log(tb) / yy;
e12 = -log(cay) - R*d / yy + log(tby);
%Create function f
f = [e1;e2;e3;e4;e5;e6;e7;e8;e9;e10;e11;e12];
% Define the vector of controls, y, and states, x
x = [k d a];
y = [yy c iv h tby cay tb la k1];
xp = [kp dp ap];
yp = [yyp cp ivp hp tbyp cayp tbp lap k1p];
%Make f a function of the logarithm of the state and control vector
f = subs(f, [x,y,xp,yp], exp([x,y,xp,yp]));
%Compute analytical derivatives of f
[fx,fxp,fy,fyp]=anal_deriv(f,x,y,xp,yp,approx);
%Numerical evaluation
%Assign values to parameters and steady-state variables
[GAMA,DELTA,ALFA,RHO,OMEGA,PHI,R,DBAR,c,cp,h,hp,k,kp,k1,k1p,d,dp,iv,ivp,tb,tbp,la,lap,yy,yyp,a,ap,tby,tbyp,cay,cayp]=rw_ss;
%Compute numerical derivatives of f
num_eval
Matlab give me this error message:
Error: File: rw_or.m Line: 81 Column: 66
Variable "iv" has been previously used as a function or command name
I also attached here the code of anal_deriv
function [fx,fxp,fy,fyp,fypyp,fypy,fypxp,fypx,fyyp,fyy,fyxp,fyx,fxpyp,fxpy,fxpxp,fxpx,fxyp,fxy,fxxp,fxx]=anal_deriv(f,x,y,xp,yp,approx);
%[fx,fxp,fy,fyp,fypyp,fypy,fypxp,fypx,fyyp,fyy,fyxp,fyx,fxpyp,fxpy,fxpxp,fxpx,fxyp,fxy,fxxp,fxx]=anal_deriv(f,x,y,xp,yp,approx);
% Computes analytical first and second (if approx=2) derivatives of the function f(yp,y,xp,x) with respect to x, y, xp, and yp. For documentation, see the paper ``Solving Dynamic General Equilibrium Models Using a Second-Order Approximation to the Policy Function,'' by Stephanie Schmitt-Grohe and Martin Uribe, 2001).
%
%Inputs: f, x, y, xp, yp, approx
%
%Output: Analytical first and second derivatives of f.
%
%If approx is set at a value different from 2, the program delivers the first derivatives of f and sets second derivatives at zero. If approx equals 2, the program returns first and second derivatives of f. The default value of approx is 2.
%Note: This program requires MATLAB's Symbolic Math Toolbox
%
%(c) Stephanie Schmitt-Grohe and Martin Uribe
%Date July 17, 2001
if nargin==5
approx=2;
end
nx = size(x,2);
ny = size(y,2);
nxp = size(xp,2);
nyp = size(yp,2);
n = size(f,1);
%Compute the first and second derivatives of f
fx = jacobian(f,x);
fxp = jacobian(f,xp);
fy = jacobian(f,y);
fyp = jacobian(f,yp);
if approx==2
fypyp = reshape(jacobian(fyp(:),yp),n,nyp,nyp);
fypy = reshape(jacobian(fyp(:),y),n,nyp,ny);
fypxp = reshape(jacobian(fyp(:),xp),n,nyp,nxp);
fypx = reshape(jacobian(fyp(:),x),n,nyp,nx);
fyyp = reshape(jacobian(fy(:),yp),n,ny,nyp);
fyy = reshape(jacobian(fy(:),y),n,ny,ny);
fyxp = reshape(jacobian(fy(:),xp),n,ny,nxp);
fyx = reshape(jacobian(fy(:),x),n,ny,nx);
fxpyp = reshape(jacobian(fxp(:),yp),n,nxp,nyp);
fxpy = reshape(jacobian(fxp(:),y),n,nxp,ny);
fxpxp = reshape(jacobian(fxp(:),xp),n,nxp,nxp);
fxpx = reshape(jacobian(fxp(:),x),n,nxp,nx);
fxyp = reshape(jacobian(fx(:),yp),n,nx,nyp);
fxy = reshape(jacobian(fx(:),y),n,nx,ny);
fxxp = reshape(jacobian(fx(:),xp),n,nx,nxp);
fxx = reshape(jacobian(fx(:),x),n,nx,nx);
else
fypyp=0; fypy=0; fypxp=0; fypx=0; fyyp=0; fyy=0; fyxp=0; fyx=0; fxpyp=0; fxpy=0; fxpxp=0; fxpx=0; fxyp=0; fxy=0; fxxp=0; fxx=0;
end
I'd appreciate some help! Thanks!
1 件のコメント
Walter Roberson
2016 年 8 月 23 日
Difficult to say without the complete source. The file name from the error message does not match any function you show here, and the line number matches a comment.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!