Simple "Sum" solution

Problems with modeling
Post Reply
pmgcs74@gmail.com
User
User
Posts: 18
Joined: 3 years ago

Simple "Sum" solution

Post by pmgcs74@gmail.com »

Hi,

I want to sum the last 4 hours of a data set and the only solution I encounter was:

eq33(i).. sum_last_4hours(i)=e=(discharge_total(i)+discharge_total(i-1)+discharge_total(i-2)+discharge_total(i-3));

It is important for me to have the sum of the last 4 hours (i) in order to (afterwards) constraint this value.

For sure there is a simple way to do it instead of repeating the i, i-1, i-2, ...

Furthermore I would like to put the 4 (hours) as a Scalar

Thanks
Regards
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Simple "Sum" solution

Post by abhosekar »

One way to do this is as follows. The code fragment is not tested so you may have to play around a bit.
You could do
alias(i, ii);
eq33(i).. sum_last_4hours(i)=e=sum(ii $((ord(ii) > ord(i) -4) and (ord(ii) < ord(i) + 1)), discharge_total(ii));

You can also make 4 a scalar and use it as a parameter in this equation.

Hope this helps.

- Atharv
pmgcs74@gmail.com
User
User
Posts: 18
Joined: 3 years ago

Re: Simple "Sum" solution

Post by pmgcs74@gmail.com »

Thanks

Worked perfectly
Post Reply