Raising matrix to power (EV 6)

For questions regarding programming in the EViews programming language.

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

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Raising matrix to power (EV 6)

Postby nadja123 » Sat May 08, 2010 5:27 am

Hi there,

a quick reply to this (stupid) question would be of a great help (deadline pressure etc):

How shall I raise matrix to power, I mean e.g. A^i, i=1 to 5, so that A^2 = A * A, etc? By mistake I thought, @epow() does this, but in fact that command raises each element to a power.

Many thanks!!!

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

Raising matrix to power (EV 6)

Postby EViews Gareth » Sat May 08, 2010 8:48 am

Don't think so

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Raising matrix to power (EV 6)

Postby nadja123 » Sat May 08, 2010 11:19 am

Hi Gareth,

thanks for reply, which I, however, do not understand at all. I just need to use in a code something like A^i, i=1 to 5, so that A^2 = A * A, etc... Please can my question be replied, in the event I did not write some mathematical nonsense? It is maybe a small thing, but it is urgent for me.

Thanks!!

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

Re: Raising matrix to power (EV 6)

Postby EViews Gareth » Sat May 08, 2010 12:54 pm

There is no function to raise a matrix to a power. Thus you'll have to write matrix A2 = A*A

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Raising matrix to power (EV 6)

Postby nadja123 » Sat May 08, 2010 1:10 pm

Gareth,

you are nice I mean but... I was not serious when I wrote i=1 to 5, that was just kinda give an example. I need to take it to 30 or so! I am writing a code for IRFs that use an externally estimated indentification (transformation matrix) and quite need to compute about 30 periods ahead :shock: :shock: :shock: :shock: :shock: :shock:

I think this topic belongs under tips and missing things in EV rather than under programming forum. I'm going to paste it there... :?

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

Re: Raising matrix to power (EV 6)

Postby EViews Gareth » Sat May 08, 2010 1:16 pm

Code: Select all

matrix a30 = a for !i=2 to 30 a30 = a30*a next

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Raising matrix to power (EV 6)

Postby nadja123 » Sat May 08, 2010 1:42 pm

Gareth,

I tried to run your small code. It worked as it was. Now I ma trying to get it to a loop:
for !j = 2 to 5
matrix a{!j} = a
a{!j} = a{!j} * a
next
I do not understand everything about it, but it seems to me that it is using some sort of memory. I mean, at debugging it continues instead of running from the beginning. If I clear the memory by closing the workfile and program, anyway it does strange things.

In particular, it does not take the matrix to 0 or 1. But these two cases I can easily sacrifice as they give an easily known result.

Then, anyway I am getting strange things as from 2 on. I am sorry, I am not any strong in programming and maths... May I just please ask for more helping...? Thanks!! I am lost in this.
Attachments
commandpower.prg
(81 Bytes) Downloaded 599 times
matrixpower.WF1
(8.13 KiB) Downloaded 492 times

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

Re: Raising matrix to power (EV 6)

Postby EViews Gareth » Sat May 08, 2010 1:58 pm

Can you describe what you're trying to do?

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Raising matrix to power (EV 6)

Postby nadja123 » Sat May 08, 2010 3:02 pm

Well, I just need to compute a set of impulse response coefficient matrices phi_{i}, using two known matrices A and B.
The formula is in the attached .pdf. Maybe I am stupid but I automatically supposed I could write a loop in Eviews using a command that would raise the A matrix to a power i going from 0 to an integer. I need to store the phi matrices to the workfile, extract coefficients from them into graphs... etc. I hope this attempt for explanation makes it more clear.... Thanks for helping, it is really important (urgent :| :| :| )

PS By the way, the whole stuff with writing own code for IRF started when I realized that one is not really permitted to use an externally estimated identification (transformation) matrix in EV 6 VAR model. It was my post under the programming forum, "Structural VAR (EV 6) by nadja123 on Wed Apr 28, 2010 2:57 pm"
Attachments
08052010.pdf
(15.84 KiB) Downloaded 664 times

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

Re: Raising matrix to power (EV 6)

Postby EViews Gareth » Sat May 08, 2010 3:19 pm

Code: Select all

for !i=1 to !n matrix a!i = a for !j=2 to !i a!i = a!i*a next next

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Raising matrix to power (EV 6)

Postby nadja123 » Sat May 08, 2010 3:25 pm

While you were writing the last post, I too wrote a few lines. I will have a look on your suggestion tomorrow (it is 0:22am for me), until then thanks. My apologies to Gareth and all forum users, my brain just stopped working when I was posting this whole question :oops: :oops: :oops:

Code: Select all

'starting with an existing matrix a matrix a1 = a for !j = 2 to 5 !i = !j - 1 matrix a{!j} = a{!i} * a next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests