Matrix sum loop

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

LuisReyes
Posts: 17
Joined: Wed Jan 09, 2013 5:23 am

Matrix sum loop

Postby LuisReyes » Wed Jan 09, 2013 5:29 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Matrix sum loop

Postby EViews Gareth » Wed Jan 09, 2013 8:45 am

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

LuisReyes
Posts: 17
Joined: Wed Jan 09, 2013 5:23 am

Re: Matrix sum loop

Postby LuisReyes » Wed Jan 09, 2013 9:40 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Matrix sum loop

Postby EViews Gareth » Wed Jan 09, 2013 9:44 am

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

LuisReyes
Posts: 17
Joined: Wed Jan 09, 2013 5:23 am

Re: Matrix sum loop

Postby LuisReyes » Wed Jan 09, 2013 9:56 am

This is it, thanks a lot !!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests