Gen~.chaos -> Codebox

    Jun 27 2013 | 12:44 am
    Can someone explain to me why this isn't giving me a proper Lorenz Attractor? I'm trying to convert the code in gen~.chaos in the examples folder to a codebox, but I'm having issues with understanding how to code in the codebox.

    • Jun 27 2013 | 12:20 pm
      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; }
    • Jun 27 2013 | 3:05 pm
      Perfect, thanks! I had actually tried what you said in point 1, but I was still having tons of issues, it was the parenthesis that was throwing me off.
      Thanks for taking the time out to help.