Asked by Uccio
on 15 Jun 2019

%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?

Answer by Geoff Hayes
on 18 Jun 2019

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.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Geoff Hayes (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/467237-help-for-a-loop-for-end-in-an-assignment-a-b-the-number-of-elements-in-a-and-b-must-be-the-s#comment_715024

## Uccio (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/467237-help-for-a-loop-for-end-in-an-assignment-a-b-the-number-of-elements-in-a-and-b-must-be-the-s#comment_715025

Sign in to comment.