Van der Waals.py

From Werner KRAUTH

Revision as of 05:49, 30 September 2019; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

This is the python2 program useful for the homework session of week 04 of my ICFP Lectures on statistical mechanics. You can run it directly, or else translate it into the computer language of your choice.


import pylab, numpy
for t in numpy.arange(0.3, 1.5, 0.1):
    vval = []
    pval = []
    for v in numpy.arange(0.34, 4.0, 0.001):
        p = 8.0 * t / 3.0 / (v - 0.333333) - 3.0 / v ** 2
        vval.append(v)
        pval.append(p)
    pylab.plot(vval, pval, label='$T=$'+ str(t))
pylab.title("van der Waals equation of state")
pylab.xlabel("reduced volume $v$")
pylab.ylabel("reduced pressure $p$")
pylab.xlim([0.0,3.5])
pylab.ylim([-2.0,4.0])
pylab.legend(loc='upper right')
pylab.savefig('Eq_state_vdw.png')
pylab.show()
Personal tools