Summation over a Intervall Topic is solved

Problems with modeling
Post Reply
MES
User
User
Posts: 14
Joined: 4 years ago

Summation over a Intervall

Post 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;
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Summation over a Intervall

Post 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
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
MES
User
User
Posts: 14
Joined: 4 years ago

Re: Summation over a Intervall

Post 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?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Summation over a Intervall

Post 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
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
MES
User
User
Posts: 14
Joined: 4 years ago

Re: Summation over a Intervall

Post by MES »

Thank you very much!
Post Reply