<< Click to Display Table of Contents >> VAL |
The VAL statement is used to assign a numeric value to a scalar variable of value type. Value names always start with the symbol %, like the other scalar types date and string. Using the VAL keyword is no longer mandatory in Gekko 3.0.
Note: the VAL type is sometimes called 'val' and sometimes 'value' in this documentation. These two are the exact same thing. Note however that you must use 'val' and not 'value' as type description in function and procedure definitions, and in for loops. Note also that Gekko has no integer type: just use a VAL type. |
Value scalars can be used in expressions, for instance in series or in PRT/MULPRT/PLOT/SHEET/CLIP statements. An integer value may be used as an annual or undated date.
%v = expression;
val %v = expression;
val ?; //print val scalars
It is no longer legal to use for instance val v = 1.23;, omitting the %.
You may use values as a container for fixed floating point numbers for use in your program.
%v1 = 1.10; |
When printing values and series at the same time in a PRT statement, note that these values are held constant over any time period.
You can pick out individual timeseries observations with [] and put these into a value:
%gdp2020 = gdp[2020]; |
After this, the value %gdp2020 stores the value of series gdp in 2020.
You may loop over value ranges, see FOR.
To convert dates or strings into values, you may use the val() function.
You may compose the value names if you need to, using {}-curlies:
for val %i = 1 to 3; |
The result:
Index 1 has value 100 |
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 or values are recommended, cf. the identical example in the MATRIX section.
The following creates values from a list:
reset; |
This creates value scalars %a, %b and %c, all with value 100.
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.
OPTION string interpolate format val = "";