Em 16 de abril de 2010 Allin <cottrell(a)wfu.edu> escreveu:

 On Fri, 16 Apr 2010, Henrique Andrade wrote:
>
> > I have a matrix "r" (attached in the Gretl session file)  and need to
> > calculate the following values:
> >
> > R6 = r[6,1] + r[5,2] + r[4,3] + r[3,4] + r[2,5] + r[1,6]
> > R7 = r[7,1] + r[6,2] + r[5,3] + r[4,4] + r[3,5] + r[2,6]
> > .
> > .
> > .
> > R12 = r[12,1] + r[11,2] + r[10,3] + r[9,4] + r[8,5] + r[7,6]
> >
> > After this I need to make a new matrix:
> >
> > [R6 R7 R8 ... R12]'
> >
> > I know how to do this "by hand", but I would like to perform this task
> using
> > a script. Would you help me?
>
> matrix R_6_12 = zeros(6,1)
>
> loop i=1..6
>  loop j=6..12
>    R_6_12[i] += r[j+1-i, i]
>  endloop
> endloop
>

Dear Allin, thanks a lot for the script, but unfortunately I think it
doesn't do what I need. My aim goal is to build a matrix with this elements:
R6_1, R6_2, R6_3, R6_4, R6_5, R6_6, ..., R6_12. I'm not interested in the
elements R6_1, ..., R6_5, so it can be set to 0 (or any other value). The
number 6 (in R6_x) indicates that we have six elements to sum.

To calculate these elements I'm using this:

R6_6 = r[6,1] + r[5,2] + r[4,3] + r[3,4] + r[2,5] + r[1,6]
R6_7 = r[7,1] + r[6,2] + r[5,3] + r[4,4] + r[3,5] + r[2,6]
R6_8 = r[8,1] + r[7,2] + r[6,3] + r[5,4] + r[4,5] + r[3,6]
R6_9 = r[9,1] + r[8,2] + r[7,3] + r[6,4] + r[5,5] + r[4,6]
R6_10 = r[10,1] + r[9,2] + r[8,3] + r[7,4] + r[6,5] + r[5,6]
R6_11 = r[11,1] + r[10,2] + r[9,3] + r[8,4] + r[7,5] + r[6,6]
R6_12 = r[12,1] + r[11,2] + r[10,3] + r[9,4] + r[8,5] + r[7,6]

Where r[i,j] represents the row "i" column "j" of the "r" matrix. I'm trying
to simplify these calculations using the following instructions (I'm just
starting to learn how to use loops in my scripts, therefore, I would like to
apologize in advance for the simplicity and the errors of my scripts).

<script>
matrix R = zeros(12,1)

loop i=6..12
    R_$i = r[$i,1] + r[$i-1,2]+ r[$i-2,3]+ r[$i-3,4]+ r[$i-4,5]+ r[$i-5,6]
    R[i] = R_$i
end loop
</script>

This script does partly what I want. I need to make it more general in order
to allow me to calculate these kind of expressions:

R12_6 = r[12,1] + r[11,2] + ... + r[2,11] + r[1,12]
R12_7 = r[13,1] + r[12,2] + ... + r[3,11] + r[2,12]

I'd attached a .pdf file into this e-mail to show you a little bit better
what exactly I need.


> BTW, I've fixed in CVS the crash that occurred when one opened
> your session file (containing an empty dataset).
>

Thanks for this fix!


Best regards,
Henrique
Em 16 de abril de 2010 Allin <cottr...@wfu.edu> escreveu:

On Fri, 16 Apr 2010, Henrique Andrade wrote:

> I have a matrix "r" (attached in the Gretl session file)  and need to
> calculate the following values:
>
> R6 = r[6,1] + r[5,2] + r[4,3] + r[3,4] + r[2,5] + r[1,6]
> R7 = r[7,1] + r[6,2] + r[5,3] + r[4,4] + r[3,5] + r[2,6]
> .
> .
> .
> R12 = r[12,1] + r[11,2] + r[10,3] + r[9,4] + r[8,5] + r[7,6]
>
> After this I need to make a new matrix:
>
> [R6 R7 R8 ... R12]'
>
> I know how to do this "by hand", but I would like to perform this task using
> a script. Would you help me?

matrix R_6_12 = zeros(6,1)

loop i=1..6
 loop j=6..12
   R_6_12[i] += r[j+1-i, i]
 endloop
endloop

Dear Allin, thanks a lot for the script, but unfortunately I think it doesn't do what I need. My aim goal is to build a matrix with this elements: R6_1, R6_2, R6_3, R6_4, R6_5, R6_6, ..., R6_12. I'm not interested in the elements R6_1, ..., R6_5, so it can be set to 0 (or any other value). The number 6 (in R6_x) indicates that we have six elements to sum.

To calculate these elements I'm using this:

R6_6 = r[6,1] + r[5,2] + r[4,3] + r[3,4] + r[2,5] + r[1,6]
R6_7 = r[7,1] + r[6,2] + r[5,3] + r[4,4] + r[3,5] + r[2,6]
R6_8 = r[8,1] + r[7,2] + r[6,3] + r[5,4] + r[4,5] + r[3,6]
R6_9 = r[9,1] + r[8,2] + r[7,3] + r[6,4] + r[5,5] + r[4,6]
R6_10 = r[10,1] + r[9,2] + r[8,3] + r[7,4] + r[6,5] + r[5,6]
R6_11 = r[11,1] + r[10,2] + r[9,3] + r[8,4] + r[7,5] + r[6,6]
R6_12 = r[12,1] + r[11,2] + r[10,3] + r[9,4] + r[8,5] + r[7,6]

Where r[i,j] represents the row "i" column "j" of the "r" matrix. I'm trying to simplify these calculations using the following instructions (I'm just starting to learn how to use loops in my scripts, therefore, I would like to apologize in advance for the simplicity and the errors of my scripts).

<script>
matrix R = zeros(12,1)

loop i=6..12
    R_$i = r[$i,1] + r[$i-1,2]+ r[$i-2,3]+ r[$i-3,4]+ r[$i-4,5]+ r[$i-5,6]
    R[i] = R_$i
end loop
</script>

This script does partly what I want. I need to make it more general in order to allow me to calculate these kind of expressions:

R12_6 = r[12,1] + r[11,2] + ... + r[2,11] + r[1,12]
R12_7 = r[13,1] + r[12,2] + ... + r[3,11] + r[2,12]

I'd attached a .pdf file into this e-mail to show you a little bit better what exactly I need.
 
BTW, I've fixed in CVS the crash that occurred when one opened
your session file (containing an empty dataset).

Thanks for this fix!


Best regards,
Henrique
 

Attachment: GretlScriptHelp.pdf
Description: Adobe PDF document

Reply via email to