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.

42 CHAPTER 4. DISCRETE-TIME MODELS I: MODELINGyour Python <strong>and</strong> make sure you don’t get any errors. If so, congratulations! You have justcompleted <strong>the</strong> first computer simulation <strong>of</strong> a dynamical system.Of course, this code doesn’t produce any output, so you can’t be sure if <strong>the</strong> simulationran correctly or not. An easy way <strong>to</strong> see <strong>the</strong> result is <strong>to</strong> add <strong>the</strong> following line <strong>to</strong> <strong>the</strong> end<strong>of</strong> <strong>the</strong> code:Code 4.5:print resultIf you run <strong>the</strong> code again, you will probably see something like this:Code 4.6:[1.0, 1.1, 1.2100000000000002, 1.3310000000000004, 1.4641000000000006,1.6105100000000008, 1.771561000000001, 1.9487171000000014,2.1435888100000016, 2.357947691000002, 2.5937424601000023,2.853116706110003, 3.1384283767210035, 3.4522712143931042,3.797498335832415, 4.177248169415656, 4.594972986357222,5.054470284992944, 5.559917313492239, 6.115909044841463,6.72749994932561, 7.400249944258172, 8.140274938683989,8.954302432552389, 9.849732675807628, 10.834705943388391,11.91817653772723, 13.109994191499954, 14.420993610649951,15.863092971714948, 17.449402268886445]We see that <strong>the</strong> value <strong>of</strong> x certainly grew. But just staring at those numbers won’t give usmuch information about how it grew. We should visualize <strong>the</strong>se numbers <strong>to</strong> observe <strong>the</strong>growth process in a more intuitive manner.To create a visual plot, we will need <strong>to</strong> use <strong>the</strong> matplotlib library 1 . Here we use itspylab environment included in matplotlib. Pylab provides a MATLAB-like working environmentby bundling matplotlib’s plotting functions <strong>to</strong>ge<strong>the</strong>r with a number <strong>of</strong> frequentlyused ma<strong>the</strong>matical/computational functions (e.g., trigonometric functions, r<strong>and</strong>om numbergenera<strong>to</strong>rs, etc.). To use pylab, you can add <strong>the</strong> following line <strong>to</strong> <strong>the</strong> beginning <strong>of</strong> yourcode 2 :1 It is already included in Anaconda <strong>and</strong> Enthought Canopy. If you are using a different distribution <strong>of</strong>Python, matplotlib is freely available from http://matplotlib.org/.2 Ano<strong>the</strong>r way <strong>to</strong> import pylab is <strong>to</strong> write “import pylab” instead, which is recommended by moreprogramming-savvy people. If you do this, however, pylab’s functions have <strong>to</strong> have <strong>the</strong> prefix pylab added<strong>to</strong> <strong>the</strong>m, such as pylab.plot(result). For simplicity, we use “from pylab import *” throughout this textbook.

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

Saved successfully!

Ooh no, something went wrong!