Reply To: Gen~.chaos -> Codebox

Forums > Gen > Gen~.chaos -> Codebox
June 27, 2013 | 5:20 am

A couple of problems.
1. Inside the if(), the first line modifies the value of x, then the second line uses the value of x (which has been modified already). So x, y, z are not updated synchronously. To work around this, assign the expressions to new variables (e.g. x1, y1, z1) and then add more lines afterward to assign x, y, z = x1, y1, z1. This ensures the histories are updated after all new values have been computed.
2. The expressions need extra parentheses around them to make sure that the whole result is scaled by dt, instead of just the last term.
So this GenExpr works for me:

Param a(10);
Param b(28);
Param c(2.67);
Param dt(0.01);

History x(0.1);
History z(0.1);
History y(0.1);

out1 = x;
out2 = y;
out3 = z;

if (in1 != 0) {
x1 = x + dt * a * (y - x);
y1 = y + dt * ((x * (b - z)) - y);
z1 = z + dt * ((x * y) - (z * c));
x, y, z = x1, y1, z1;

Share this page