Applying a Common for() Statement to Multiple Formulas
Another useful application of the for() definition is using one loop to compute multiple formulas. The two examples below are functionally identical.
Ex1.
"for(t in 2..time)" : {
"coordX[t]" : {dimensions: ['time'], formula: "coordX[t-1] + Vx[t]" }
}
"for(t in 2..time)" : {
"coordY[t]": {dimensions: ['time'], formula: "coordY[t-1} + Vy[t]" }
}
Ex2.
"for(t in 2..time)" : {
"coordX[t]": {dimensions: ['time'], formula: "coordX[t-1] + Vx[t]" }
"coordY[t]": {dimensions: ['time'], formula: "coordY[t-1} + Vy[t]" }
}
Note: It is also possible to bind data to external sources using indexed array formulas. See the earlier topic, Using the Binding Property under Defining Your Optimization Model, for more information.
To open the full example, click RASON Examples -- Example Models using Arrays Loops and Tables -- Using a For statement with recursive formulas. .
|