Attachment ‘g-hint.py’

Download

from scipy import exp, infty
from scipy.integrate import quad
from scipy.special import gamma
from scipy.optimize import brentq

# GHG, 05-27-2013:
#
# This file is very incomplete.  It shows some code snippets which can be
# helpful in dealing with the BEC problem.
# 
# Assuming that you have scipy installed, running this file as
#          python g-hint.py
# at the command line should give you results that look like the following.
#
# Evaluating:  g (z=1, m=1.5) = 2.61237534869
# Evaluating:  g (z=0.9, m=1.5) = 1.61443852857
# Evaluating:  g (z=0., m=1.5) = 0.0
# Evaluating:  fugacity (3, N = 1000) = 0.296001870486
# Evaluating:  fugacity (1. / g(z=1), N = 1000) = 0.991688094173
# Evaluating:  fugacity (1. / g(z=1), N = 1e5) = 0.999619385047

def fugacity (nl3inv, N = 1.e5):
	assert N >= 100
	assert nl3inv >= 0
	gs_val = 1 / (1 + 1. / N)
	if nl3inv == 0:
		return gs_val
	# The tolerance (xtol) for brent might need tweaking if high precision is
	# required.
	return brentq (lambda x, nl3inv = nl3inv, N = N:
			1. - g (x, m = 1.5) * nl3inv - x / N / (1. - x),
			0, gs_val)

# This function calculates the g_m function, as required for the analysis
# of the Bose gas problem.

def g (z, m = 1.5):
	if z == 0:
		return 0.0
	# The tolerance (epsabs, epsrel) for quad might need tweaking when high
	# precision is required.
	return quad (lambda x, z = z, m = m: x ** (m - 1.) / (exp (x) / z - 1.)
			/ gamma (m), 0,  infty) [0]

if __name__ == '__main__':
	def eval_it (s):
		print 'Evaluating: ', s,
		try:
			ans = eval (s)
			print '=', ans
		except:
			print
			print '=' * 80
			print '** Oops ... an exception occured! ... reporting.'
			print '=' * 80
			import traceback
			traceback.print_exc ()
			print '=' * 80
	for s in ['g (z=1, m=1.5)',
			'g (z=0.9, m=1.5)',
			'g (z=0., m=1.5)',
			'fugacity (3, N = 1000)',
			'fugacity (1. / g(z=1), N = 1000)',
			'fugacity (1. / g(z=1), N = 1e5)']:
		eval_it (s)

Attached Files

  • <<la(1995-1999.SM.pdf)>> (9:43AM, Jun 08, 2013, 3236.1 KB) [get | view]
  • <<la(1995-2012.SM.pdf)>> (9:34AM, Jun 08, 2013, 9569.7 KB) [get | view]
  • <<la(2000-2004.SM.pdf)>> (9:44AM, Jun 08, 2013, 3525.4 KB) [get | view]
  • <<la(2005-2009.SM.pdf)>> (9:54AM, Jun 08, 2013, 2051.2 KB) [get | view]
  • <<la(2010-2012.SM.pdf)>> (9:54AM, Jun 08, 2013, 755.7 KB) [get | view]
  • <<la(H01-Thermo.pdf)>> (8:40AM, Apr 06, 2013, 247.7 KB) [get | view]
  • <<la(H02-Probability.pdf)>> (9:04AM, Apr 18, 2013, 237.5 KB) [get | view]
  • <<la(H03-Ensembles-Semi-Classical.pdf)>> (10:34PM, Jun 06, 2013, 206.2 KB) [get | view]
  • <<la(H04-Quantum-SM.pdf)>> (8:27PM, May 19, 2013, 226.1 KB) [get | view]
  • <<la(H05-Phase-Transition.pdf)>> (9:20PM, May 27, 2013, 303.3 KB) [get | view]
  • <<la(MC.py)>> (9:53PM, May 27, 2013, 11.8 KB) [get | view]
  • <<la(g-hint.py)>> (9:52PM, May 27, 2013, 1.9 KB) [get | view]
To refer to attachments on a page, use the local macros, lia or la.
  • For instance, <<lia(cool_fig.png,scale=0.3)>> or <<la(cool_paper.pdf,Here is a cool paper!))>> will do, assuming that these files do exist.
In these local macros, you should not include attachment: as part of the attachment name.
  • Alternatively, you can use the longer standard syntax, [[attachment:filename]], as shown above in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
Like to rename an existing attachment file? Use the move link above.

You are not allowed to attach a file to this page.