Page 1 of 1

Table as index

Posted: Tue Jan 09, 2018 8:45 pm
by kpetridis
Hello,

I have the following formulation:
CodeCogsEqn.gif
CodeCogsEqn.gif (779 Bytes) Viewed 3064 times
In the second summation, tj,i is a table containing for example the following values

(j=1,2, and i=1,2,3)

alias(i,k)

Table t(j,i)
1 2 3

1 1.000 3.000 2.000
2 1.000 1.000 1.000

I face the two following problems:

1. How to introduce a table and treat it as a set in the summation?
2. In the summation, for certain values, i index goes out of bounds.

More specifically I have the following:
CodeCogsEqn.gif
CodeCogsEqn.gif (779 Bytes) Viewed 3064 times
since the first elemnt of the table is t(j=1,i=1)=1.

Could you please help me?

Re: Table as index

Posted: Tue Jan 16, 2018 12:21 pm
by Renger
Hi

Is this you are looking for? I just assumed that the row index of the table starts with 1 instead of 0.

Code: Select all

set j /1,2/,
    i /1,2,3/;

alias(i,k,l);

table t(j,i)
       1        2        3
1   1.000    3.000    2.000
2   1.000    1.000    1.000
;

* Define a set that consists of all combinations of j and i
set tb(j,i) /#j.#i/;

display tb;

parameter w(i,k);

* Assign some numbers as they are not available in the quesion
w(i,k) = ord(i) + ord(k)
;

display w, t;

parameter wantedsum(j,i);

loop(tb(j,i),
        wantedsum(j,i) =  sum(l, sum(k$(ord(k) le t(j,i)), w(l,k)));
    );
display wantedsum;