Page 1 of 1

Matrix sum loop

Posted: Wed Jan 09, 2013 5:29 am
by LuisReyes
Hi, I'm new in EViews and I have a (perhaps) dumb question concerning Matrices. What could be a short code to loop the summation of matrix A1 to An.
What I did (and I am aware it takes long) is to extract all the members of all the matrices and them make the sum and group them in a single matrix.
Does anyone know of a code to make that shorter?
Thanks in advance

Re: Matrix sum loop

Posted: Wed Jan 09, 2013 8:45 am
by EViews Gareth
The best way is probably just to do the sum yourself:

Code: Select all

!sum = 0 for !i=1 to !n !sum = !sum + mymatrix(1, !i) next

Re: Matrix sum loop

Posted: Wed Jan 09, 2013 9:40 am
by LuisReyes
Hi Gareth,

thank you for your quick response. It might be that I don't get your coding or I was not clear from the start.

I have a series of matrices ('mymatrix' in your code, I guess?) from A1, A2 all the way to An (that is, up to !n in your code). The question is then, which is the resulting matrix?

The problem, otherwise stated, is that I want to make a loop that creates a matrix called Asum which is equal to A1+A2+...+An, which exist already

Again, it might be that I don't know how to interpret your code

Thank you again in advance

Re: Matrix sum loop

Posted: Wed Jan 09, 2013 9:44 am
by EViews Gareth
Ah, I thought you wanted to sum the elements of a single matrix.

In that case, yeah, you'll just have to add the matrices to each other.

Code: Select all

matrix asum = a1 for !i=2 to !n asum = asum + a!i next

Re: Matrix sum loop

Posted: Wed Jan 09, 2013 9:56 am
by LuisReyes
This is it, thanks a lot !!