## Considering initial conditions/values in temporal constraints

Problems with modeling
power_user
User Posts: 1
Joined: 5 months ago

### Considering initial conditions/values in temporal constraints

I have a problem where a variable (i.e. temperature) at one time-interval (t) is dependent on the value in the previous interval (t-1). This relationship has been modeled as the constraint given below:

dtemp(t) .. temp(t)=e=({temp(t-1)-A(t)}*exp{-delt*invTau(t)})+A(t) ;

Initial temperature value (i.e. at t=0) is known, but I don't know how to incorporate that into the given constraint. GAMS is considering the first equation as :

temp("1") =e= (0 - A("1"))*other terms.

I want the 0 in the above equation to be replaced with the initial known temperature value. How can I do that?
Thanks.

Fred
Posts: 174
Joined: 3 years ago

### Re: Considering initial conditions/values in temporal constraints

Hi,

There are many ways to accomplish what you want to do. I'll give you two brief examples, assuming that you have initial temperature value at t=0 stored in a scalar temp_t0.

Code: Select all

``````dtemp(t) .. temp(t)=e=({temp_t0\$(sameas(t,'1')+temp(t-1)-A(t)}*exp{-delt*invTau(t)})+A(t) ;
``````
2. let t run from 0 to ... (i used 100) but define the equation for t>=1 and fix temp value for t=0:

Code: Select all

``````set t  / 0*100 / ;
temp('0').fx = temp_t0;
dtemp(t)\$(ord(t)>=2).. temp(t)=e=({temp(t-1)-A(t)}*exp{-delt*invTau(t)})+A(t) ;
``````
I hope this helps!

Fred

dirkse
Moderator Posts: 91
Joined: 3 years ago
Location: Fairfax, VA

### Re: Considering initial conditions/values in temporal constraints

You can also use the technique used in the ramsey model in the model library. The link is below. This model is quite small and illustrates how to use subsets tfirst and tlast to handle the boundary times. It uses a lead to avoid an equation for tfirst:

Code: Select all

``kk(t+1)..       k(t+1) =e=  k(t) + i(t);``
https://www.gams.com/latest/gamslib_ml/ ... amsey.html