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.

13.5. SIMULATION OF CONTINUOUS FIELD MODELS 257Below is a sample code for simulating this PDE model starting with an initial configurationwith two peaks, one for a <strong>and</strong> <strong>the</strong> o<strong>the</strong>r for b:Code 13.7: transport-ca-escaping.pyimport matplotlibmatplotlib.use(’TkAgg’)from pylab import *n = 100 # size <strong>of</strong> grid: n * nDh = 1. / n # spatial resolution, assuming space is [0,1] * [0,1]Dt = 0.01 # temporal resolutionmu_a = 0.001 # mobility <strong>of</strong> species amu_b = 0.001 # mobility <strong>of</strong> species bxvalues, yvalues = meshgrid(arange(0, 1, Dh), arange(0, 1, Dh))def initialize():global a, b, nexta, nextb# initial configurationa = exp(-((xvalues - 0.45)**2 + (yvalues - 0.45)**2) / (0.3**2))b = exp(-((xvalues - 0.55)**2 + (yvalues - 0.55)**2) / (0.1**2))nexta = zeros([n, n])nextb = zeros([n, n])def observe():global a, b, nexta, nextbsubplot(1, 2, 1)cla()imshow(a, vmin = 0, vmax = 1)title(’a’)subplot(1, 2, 2)cla()imshow(b, vmin = 0, vmax = 1)title(’b’)def update():

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

Saved successfully!

Ooh no, something went wrong!