VAL

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

VAL

Previous pageReturn to chapter overviewNext page

A Gekko value looks like for instance %= 10.5;, note that value names always start with the symbol % (like the other scalars string and date). Normal mathematical expressions are allowed, for instance %= %y/(1+%z);, where %x, %y and %z are values, but you may also combine timeseries and values, for instance = y/(1+%z); where x and y are timeseries and %z is a value.

 

Gekko has no particular integer type: just use an integer value like %= 5;. An integer value may be used as a stand in for an annual or undated date.

 


 

Syntax

 

%v = expression;
val ?; //print val scalars

 

Note: You may use the non-mandatory val keyword to indicate value type (like val %x = %y + %z;).

 


 

Examples

 

Here, the value %v1 is used to adjust %v2 and x:

 

%v1 = 1.50;
%v2 = 1/(+ %v1);
tell '%v1={%v1}, %v2={%v2}';
prt %v1, %v2;
time 2021 2023;
= 100, 101, 102;
= %v1 * x;
+= (%v2, -%v2, 0.5*%v2); //must use parentheses when not simple numbers
prt x;

 

When printing values and series at the same time in a PRT statement, note that the values are held constant over any time period. You can pick out individual timeseries observations with [] and put these into a value:

 

//..continued
%v3 = x[2022];
prt %v3;

 

After this, the value %v3 stores the value of x in 2022.

 

The following uses af FOR loop to calculate the sum of intergers 1 to 100:

 

%sum = 0;
for val %= 1 to 100;
  %sum += %i; //or: %sum = %sum + %i
end;
prt %sum;
// 
// %sum
// 5050

 

To convert dates or strings into values, you may use the val() function. For instance:

 

%= '123.45';
prt val(%s)*10;
//
// val(%s)*10
// 1234.5

 

You may compose the value names if you need to, using {}-curlies:

 

for val %= 1 to 3;
  %v{%i} = 100 * %i;  //defines %v1 = 100, %v2 = 200, %v3 = 300
end;
for val %= 1 to 3;
  %= %v{%i};
  tell 'Index {%i} has value {%v}';
end;
//
// Index 1 has value 100
// Index 2 has value 200
// Index 3 has value 300

 

Here, the expression %v{%i} picks out the corresponding v-value. In general however, for such use column vectors (n x 1 matrices) or lists of values are recommended, cf. the identical example in the MATRIX section.

 


 

Note

 

See the page with syntax diagrams if the basics of names, expressions, etc. is confusing.

 

If you need to convert a date or string scalar to a avlue type, use the val() conversion function.

 

You may use m() to indicate a missing value.

 

See also the format() function and option string interpolate format val = ... ; regarding {...}-formatting of values inside strings.

 

Regarding variable types and the Gekko type system, see the VAR section. In this appendix, variable assignment rules, including variable types, is explained in more detail.

 


 

Related options

 

option string interpolate format val = "";

 

 


 

Related statements

 

DATE, FOR, LIST, MATRIX, MEM, SERIES, STRING