#!/usr/bin/python -Wall # ================================================================ # John Kerl # kerl at math dot arizona dot edu # 2008-05-12 # ================================================================ from __future__ import division # 1/2 = 0.5, not 0. import random from math import * import copy import sys import re # ---------------------------------------------------------------- def usage(): print >> sys.stderr, "Usage: %s [options]" % (sys.argv[0]) print >> sys.stderr, "Options:" print >> sys.stderr, " T=[number]" print >> sys.stderr, " nt=[number]" sys.exit(1) # ---------------------------------------------------------------- # Complex Brownian motion: c_t = a_t + i b_t. T = 5 nt = 10000 argc = len(sys.argv) for argi in range(1, argc): if re.match(r'^T=', sys.argv[argi]): T = float(sys.argv[argi][2:]) elif re.match(r'^nt=', sys.argv[argi]): nt = int (sys.argv[argi][3:]) else: usage() dt = T/nt t = 0.0 At = 0.0 Bt = 0.0 sqrtdt = sqrt(dt) while (t < T): print "%11.7f %11.7f %11.7f" % (t, At, Bt) dA = random.gauss(0, sqrtdt) dB = random.gauss(0, sqrtdt) At += dA Bt += dB t += dt