Vector and Matrix Multiplications

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Vector and Matrix Multiplications

Unread post by RK2509 »

Hi Tom,

I have a question regarding multiplication of a matrix and a vector.
So this is what I wrote:

declare RECT [SERIES[REAL]] Z(N,1)
do i=1,N
compute Z(i,1)=lambda(i,1)*IMPULSES(1,5)
end do i

My N is 72, lambda is a matrix and the impulses is a vector ( impulse of the first variable to a shock to the 5th variable)
I want to compute Z but I get the error
## SX22. Expected Type SERIES[REAL], Got MATRIX[REAL] Instead
>>>>i,1)*IMPULSES(1,5)<<<<

and also Subscripting Error.
Had Array Reference with (INTEGER). Needed (INTEGER)

I have tried putting matrix[real] and integer also, but it still gives me the same error.

Could you please tell me how should I correct it.

Thank you so much
Last edited by RK2509 on Wed Aug 26, 2015 1:36 pm, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Vector and Matrix Multiplications

Unread post by TomDoan »

Matrix multiplication doesn't have to be written out using loops. compute a=b*v multiplies matrix b by vector v and produces result a. So I'm very unclear about what you're trying to do. First of all, this is clearly wrong:

declare RECT [SERIES[REAL]] Z(i,1)

since I is the index on your upcoming loop, not the dimension (which appears like it should be N). However, you're saying that LAMBDA is a matrix and IMPULSES is a VECTOR, so why are you creating a RECT[SERIES]? If IMPULSES are a set of IRF's, then IMPULSES(1,5) would be a SERIES. Assuming that's correct, what are you trying to do with it?
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Vector and Matrix Multiplications

Unread post by RK2509 »

So yes, its Z(N,1)..thank you so much.

So the impulses(1,5) is the [series]. Is it possible to multiply each element of lambda (i,1) to the impulses(1,5).

Thank you so much
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Vector and Matrix Multiplications

Unread post by TomDoan »

LAMBDA is an N-vector? And for each element of LAMBDA you want a series of scaled impulse responses?
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Vector and Matrix Multiplications

Unread post by RK2509 »

Yes Lambda is a N vector and for each element of LAMBDA I want a series of impulse responses. That is why I was thinking how to multiply the elements of lambda with the impulse(1,5).

So I am not too sure if this is possible. I am new to RATS.
Many Thanks
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Vector and Matrix Multiplications

Unread post by RK2509 »

Hi Tom,

I just figured it out. I was making a conceptual error in theory.

Thank you so much anyways.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Vector and Matrix Multiplications

Unread post by TomDoan »

If I understand what you're asking, it's rather easy. First of all, if LAMBDA is a VECTOR, you just use LAMBDA(i), not LAMBDA(i,1). Then it's just

dec vect[series] z(N)
do i=1,N
set z(i) = lambda(i)*impulse(1,5)
end do i
RK2509
Posts: 30
Joined: Wed Apr 15, 2015 3:16 pm

Re: Vector and Matrix Multiplications

Unread post by RK2509 »

Hi Tom,

Thank you so much. Actually conceptually, I discovered in my code, my mistake, that my z is a rectangular series and my lambda is also a rectangular matrix. so I did, using what you wrote:

dec rect[series] z(N,1)
do i=1,N
set z(i,1) = lambda(i,1)*impulses(1,5)
end do i

It perfectly worked ...Thanks so much.
Best
Post Reply