|
<< Click to Display Table of Contents >> VAL |
![]() ![]()
|
A Gekko value looks like for instance %v = 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 %x = %y/(1+%z);, where %x, %y and %z are values, but you may also combine timeseries and values, for instance x = 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 %v = 5;. An integer value may be used as a stand in for an annual or undated date.
%v = expression;
val ?; //print val scalars
Here, the value %v1 is used to adjust %v2 and x:
%v1 = 1.50; |
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 |
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; |
To convert dates or strings into values, you may use the val() function. For instance:
%s = '123.45'; |
You may compose the value names if you need to, using {}-curlies:
for val %i = 1 to 3; |
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.
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 = "";
DATE, FOR, LIST, MATRIX, MEM, SERIES, STRING