## Calibration by linear interpolation

Problems with syntax of GAMS
Loreno
User
Posts: 5
Joined: 9 months ago

### Calibration by linear interpolation

Hello,

i have a functioning model with time steps of 5 years. i want to rewrite the code to timesteps of 1 year. for that i need to recalibrate certain values. first step to do so is to get yearly values for a variable, that has only values every 5 years. so the originial code works with a set "t":

set t Time periods (5 years per period) /1*10/ ;

my variable is depending on t:

Variable
E(t) Total CO2 emissions (GtCO2 per year)
;

after solving the model i want to work with the values, introduce a new set "year" and then find values for E on a yearly basis:

set year Years /1*50/;

PARAMETERS
Eyear(year) Linear intorpoled yearly Emissions
;
Loop (year, Eyear(year)=E(ceil(year/5))+((E(ceil(year/5)+1)-E(ceil(year/5)))/5)**(year-5*ceil(year/5)););

gams doesnt like, that i use "year" in a variable that is defined in "t", but by ceil(year/5) i shouldnt ask for a value that doesnt exist.

after solving a model, are the values for E(t) fixed and i can use it as a parameter or is an addition step needed?
how can i refere to E(t) using "year"? is it even possible to use "year" in a variable defined in "t"?

Manassaldi
User
Posts: 59
Joined: 1 year ago
Location: Rosario - Argentina

### Re: Calibration by linear interpolation

Hello, according to your example I think that the final periods correspond to 45 years. A zero-time value is required to complete the 50 years.
I can be wrong anyway
Bye!

This is an example:

set t /1*10/
set year Years /1*45/;
PARAMETERS
E(t)
/1 100
2 200
3 300
4 400
5 500
6 600
7 700
8 800
9 900
10 1000/
Eyear(year) Linear intorpoled yearly Emissions
;
Loop((year,t)\$(ord(t) eq ceil(ord(year)/5)),
if(ord(t) eq 1,
Eyear(year) = E(t) + ((E(t+1)-E(t))/4)*(ord(year) - 1);
else
Eyear(year) = E(t) + ((E(t+1)-E(t))/5)*(ord(year)- (ord(t)-1)*5);
););

Loreno
User
Posts: 5
Joined: 9 months ago

### Re: Calibration by linear interpolation

thank you, that helped already enormously. i want to use, what i learned here for another part of the calibration..

in order to calibrate some values from 5 year time steps to 1 year time steps, i want to minimize the difference between values where i used E(t) and where i used Eyear(year), but only where there is an actual value for t(every 5 years), so i tried this:

lsquaredeq\$ord(t) eq ceil(ord(year)/5).. lsquared =E= sum(t,year, ((MATy(year)-MAT.l(t))/MAT.l(t))**2+((MLy(year)-ML.l(t))/ML.l(t))**2+((MUy(year)-MU.l(t))/MU.l(t))**2+((TATMy(year)-TATM.l(t))/TATM.l(t))**2+((TOCEANy(year)-TOCEAN.l(t))/TOCEAN.l(t))**2);

i get those errors:
\$154\$36 \$409

can someone explain, what went wrong or suggest another way to do this? are more informations needed?

Manassaldi
User
Posts: 59
Joined: 1 year ago
Location: Rosario - Argentina

### Re: Calibration by linear interpolation

hi, try this:

lsquaredeq.. lsquared =E= sum((t,year)\$(ord(t) eq ceil(ord(year)/5)), power((MATy(year)-MAT.l(t))/MAT.l(t),2) + power((MLy(year)-ML.l(t))/ML.l(t),2) + power((MUy(year)-MU.l(t))/MU.l(t),2) + power((TATMy(year)-TATM.l(t))/TATM.l(t),2) + power((TOCEANy(year)-TOCEAN.l(t))/TOCEAN.l(t),2) );

Bye!