{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ideal Gas Law\n", "\n", "The following cells compute pressure using the ideal gas law.\n", "\n", "$$P = \\frac{n R T}{V}$$" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Comment\n", "\n", "V = 22.4\n", "T = 284.\n", "R = 8314.\n", "n = 2." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "P = n*R*T/V" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pressure = 210819.285714 pascals\n" ] } ], "source": [ "print \"Pressure = \", P, \"pascals\"" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied (use --upgrade to upgrade): pint in /Users/jeff/anaconda/lib/python2.7/site-packages\n", "\u001b[33mYou are using pip version 8.1.1, however version 8.1.2 is available.\n", "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n" ] } ], "source": [ "!pip install pint" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from pint import UnitRegistry\n", "ur = UnitRegistry()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "210819.285714 pascal\n" ] } ], "source": [ "V = 22.4 * ur.liter\n", "T = 284. * ur.kelvin\n", "n = 2.0 * ur.mol\n", "R = 8314.0 * ur.Pa * ur.liter/ur.kelvin/ur.mol\n", "\n", "P = n*R*T/V\n", "print P" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "30.5767522699 psi\n" ] } ], "source": [ "print P.to(ur.psi)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.08062458144 atmosphere\n" ] } ], "source": [ "print P.to(ur.atm)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }