15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

48 CHAPTER 4. DISCRETE-TIME MODELS I: MODELING1.51.00.50.00.50 5 10 15 20 25 30Figure 4.2: Visual output <strong>of</strong> Code 4.11. This result is actually wrong.Code 4.13: oscillation-correct.pynextx = 0.5 * x + ynexty = -0.5 * x + yx, y = nextx, nextyHere we have two sets <strong>of</strong> state variables, x, y <strong>and</strong> nextx, nexty. We first calculate <strong>the</strong>next state values <strong>and</strong> s<strong>to</strong>re <strong>the</strong>m in nextx, nexty, <strong>and</strong> <strong>the</strong>n copy <strong>the</strong>m <strong>to</strong> x, y, which willbe used in <strong>the</strong> next iteration. In this way, we can avoid any interference between <strong>the</strong> statevariables during <strong>the</strong> updating process. If you apply this change <strong>to</strong> <strong>the</strong> code, you will get acorrect simulation result (Fig. 4.3).The issue <strong>of</strong> how <strong>to</strong> implement simultaneous updating <strong>of</strong> multiple variables is a commontechnical <strong>the</strong>me that appears in many complex systems simulation models, as wewill discuss more in later chapters. As seen in <strong>the</strong> example above, a simple solution is <strong>to</strong>prepare two separate sets <strong>of</strong> <strong>the</strong> state variables, one for now <strong>and</strong> <strong>the</strong> o<strong>the</strong>r for <strong>the</strong> immediatefuture, <strong>and</strong> calculate <strong>the</strong> updated values <strong>of</strong> state variables without directly modifying<strong>the</strong>m during <strong>the</strong> updating.In <strong>the</strong> visualizations above, we simply plotted <strong>the</strong> state variables over time, but <strong>the</strong>re is

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!