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.

106 CHAPTER 6. CONTINUOUS-TIME MODELS I: MODELINGdef initialize():global x, result, t, timestepsx = 0.1result = [x]t = 0.timesteps = [t]def observe():global x, result, t, timestepsresult.append(x)timesteps.append(t)def update():global x, result, t, timestepsx = x + r * x * (1 - x / K) * Dtt = t + Dtinitialize()while t < 50.:update()observe()plot(timesteps, result)show()Note that <strong>the</strong>re really isn’t much difference between this <strong>and</strong> what we did previously. Thiscode will produce a nice, smooth curve as a result <strong>of</strong> <strong>the</strong> numerical integration, shown inFig. 6.1. If you choose even smaller values for ∆t, <strong>the</strong> curve will get closer <strong>to</strong> <strong>the</strong> truesolution <strong>of</strong> Eq. (6.27).Exercise 6.4 Vary ∆t <strong>to</strong> have larger values in <strong>the</strong> previous example <strong>and</strong> see how<strong>the</strong> simulation result is affected by such changes.As <strong>the</strong> exercise above illustrates, numerical integration <strong>of</strong> differential equations involvessome technical issues, such as <strong>the</strong> stability <strong>and</strong> convergence <strong>of</strong> solutions <strong>and</strong> <strong>the</strong>possibility <strong>of</strong> “artifacts” arising from discretization <strong>of</strong> time. You should always be attentive<strong>to</strong> <strong>the</strong>se issues <strong>and</strong> be careful when implementing simulation codes for continuous-time

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

Saved successfully!

Ooh no, something went wrong!