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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.3. SIMULATING DISCRETE-TIME MODELS WITH ONE VARIABLE 41Finally, we need <strong>to</strong> program <strong>the</strong> updating part. This is where <strong>the</strong> actual simulationoccurs. This can be implemented in ano<strong>the</strong>r function:Code 4.3:def update():global x, resultx = a * xNote that <strong>the</strong> last line directly overwrites <strong>the</strong> content <strong>of</strong> symbol x. There is no distinctionbetween x t−1 <strong>and</strong> x t , but this is okay, because <strong>the</strong> past values <strong>of</strong> x are s<strong>to</strong>red in <strong>the</strong> resultslist in <strong>the</strong> observe function.Now we have all <strong>the</strong> three crucial components implemented. We also need <strong>to</strong> addparameter settings <strong>to</strong> <strong>the</strong> beginning, <strong>and</strong> <strong>the</strong> iterative loop <strong>of</strong> updating at <strong>the</strong> end. Here,let’s let a = 1.1 so that <strong>the</strong> value <strong>of</strong> x increases by 10% in each time step. The completedsimulation code looks like this:Code 4.4:a = 1.1def initialize():global x, resultx = 1.result = [x]def observe():global x, resultresult.append(x)def update():global x, resultx = a * xinitialize()for t in xrange(30):update()observe()Here we simulate <strong>the</strong> behavior <strong>of</strong> <strong>the</strong> system for 30 time steps. Try running this code in

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

Saved successfully!

Ooh no, something went wrong!