A simple 'loop()' without index sets and array assignment
[Example Model: Space1.json]
data: {
time: { value: 10 },
direction: { dimensions: ['time'], value: 1.570796327 }
},
variables: {
blast: { dimensions: ['time'], value: 20, lower: 0, upper: 30,
finalValue: [] },
change: { dimensions: ['time'], value: 5, lower: -6.28, upper: 6.28,
finalValue: [] }
},
formulas: {
"loop(t in 2..time)" : {
"direction[t]": { formula: "direction[t-1] + change[t]" },
"Vx[t]": { formula: "Vx[t-1] + COS(direction[t])*blast[t] +
x1grav[t-1] + x2grav[t-1]" },
...
}
}
In this example 'time' is the constant 10. We preliminarily define the formula assignments as arrays and initialize them with values. We cannot use the index ranges in 'loop()/for()' for dimensioning the result variables because the ranges determine the desired computation formulas only. For example, in this case there is no formula for t = 1, while direction[1] must exist in the model.
|