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
Matrix sum loop
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Matrix sum loop
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
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
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
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.
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
This is it, thanks a lot !!
Who is online
Users browsing this forum: No registered users and 1 guest
