HELP FOR A LOOP FOR-END: In an assignment A(:) = B, the number of elements in A and B must be the same.
1 回表示 (過去 30 日間)
古いコメントを表示
%reduced form 18 in BULLARD 2002
T=10;
sigma=0.157;
k=0.024;
beta=0.99;
po=0.35;
phipi=1.5;
phiz=0;
z=zeros(T,1)
pi=zeros(T,1)
y=[z pi] %vettore endogene
k=[1 2; 3 4] %non conosco gli elementi della matrice k, ma so che la sua dimensione, essendo uguale a quella di B (cioè n x n) è 2,2
rn=randn(T,1)
% k*rn %NON conformabili per il prodotto
intercept=ones(T,1)
z=[intercept,rn]; %vettore intercetta + slope, dimensione 10x2
csi=zeros(2,T); %vettore dei parametri da stimare tramite RLS
B2=[sigma 1-beta*phipi; k*sigma k+beta*(sigma+phiz)] %perchè non funziona quando il commando non è dato all'inizio?
B1=1/(sigma+phiz+k*phipi)
B=B1*B2
%Initial conditions
y(1,1)=2
y(1,2)=3
csi(1,1)=1
csi(2,1)=2
r=eye(2)
for t=2:T
y(t)=B*csi(1,t-1)+(B*csi(2,t-1)*po+k)*rn(t) %ALM, RHS è conformabile
csi(:,t)=csi(:,t-1)+t^(-1)*inv(rnew)*z(t-1)*(y(t)-csi(:,t-1)'*z(t-1))' %10.11, RHS è conformabile
rnew=r+t^(-1)*(z(t-1)*z(t-1)'-r); %10.12 size 2x2
r=rnew
end
Hi everyone,
I have a problem in my code. The error message shows up when I try to launch the loop: anyone can help me?
2 件のコメント
Geoff Hayes
2019 年 6 月 15 日
Federico - when I run your code, I observe the following error
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
for the line
B2=[sigma 1-beta*phipi; k*sigma k+beta*(sigma+phiz)]
This is because k is a 2x2 matrix. You may have intended something like
B2=[sigma 1-beta*phipi; k*sigma ; k+beta*(sigma+phiz)]
which will ensure that B2 is a 5x2 matrix. Unfortunately, the next line of code will throw an error too
Error using /
Matrix dimensions must agree.
I recommend that you use the debugger to step through the code and verify that each line of code is doing exactly what you intend.
回答 (1 件)
Geoff Hayes
2019 年 6 月 18 日
Federico - the line of code that generates the error is
y(t)=B*csi(1,t-1)+(B*csi(2,t-1)*po+k)*rn(t)
because you are trying to assign a 2x2 matrix (the right-hand side) to a 1x1 scalar (the left-hand side). What are you expecting y to be? A set of 2x2 matrices or are you hoping it to be a scalar? Your subsequent line of code seems to assume that y is a scalar where you refer to y(t). You may want to reconsider the above calculation.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!