Page 1 of 1

Summation over a Intervall

Posted: Tue Jul 09, 2019 4:33 pm
by MES
I want to do a summation over the intervall FE(i) to SE(i). My idea was to solve it like this (the whole code you can find at the end of the text):

TEST(i)=sum(t$(t ge FE(i) and t le SE(i)),1;

This returns errors. How can i code it whitout using card()? Since I want to make use of the value and not the postition of the set member.

Thank you in advance :)

-----------------------------------------------------------------------------------------------------------------------------------------------
set i /1*4/;
set t /1*100/;

parameter FE(i) /1 3
2 8
3 10
4 15/;

parameter SE(i) /1 5
2 11
3 14
4 20/;

parameter TEST(i);

TEST(i)=sum(t$(t ge FE(i) and t le SE(i)),1;

Re: Summation over a Intervall

Posted: Tue Jul 09, 2019 8:05 pm
by Renger
Hi

Use the ord operator (t is not an integer, but treated as a character/string):

Code: Select all

TEST(i)=sum(t$(ord(t) ge FE(i) and ord(t) le SE(i)),1);
Cheers
Renger

Re: Summation over a Intervall

Posted: Tue Jul 09, 2019 9:39 pm
by MES
Thank you for you reply. :)

But sorry I made a mistake. I meant how can I solve it whitout using ord() but wrote without using card().

Isn't it possible to treat t as a value?

Re: Summation over a Intervall

Posted: Wed Jul 10, 2019 7:12 am
by Renger
You can also use t.val if the set element is an integer.

Code: Select all

TEST(i)=sum(t$(t.val ge FE(i) and t.val le SE(i)),1);
Cheers
Renger

Re: Summation over a Intervall

Posted: Wed Jul 10, 2019 1:04 pm
by MES
Thank you very much!