{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Checking H&H Section 4.4.2 -- functional approach" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Section 4.2.2 in Hughes & Hase is a worked example of the determination of pressure and its uncertainty using the van der Waals equation of state and the functional approach for determining uncertainties. Repeat these calculations for yourself, determining $P(\\bar{V}_{\\rm in},\\bar{T})$, $\\alpha_P^T$, $\\alpha_P^V$, and $\\alpha_P$. Identify the (slight) numerical errors made in the text." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def P(Vm,T):\n", " '''Returns pressure a function of measured volume and temperature'''\n", " return R*T/(Vm - b) - a/Vm**2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "R = 8.3145\n", "Tbest = 298.0\n", "alpha_T = 0.2\n", "Vmbest = 2.000e-4\n", "alpha_V = 0.003e-4\n", "a = 1.408e-1\n", "b = 3.913e-5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Calulate pressure" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1.188201e+07'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Pbest = P(Vmbest,Tbest)\n", "format(Pbest,'e')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or 11.882 MPa. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Uncertainties\n", "\n", "In this solution, I create a `numpy` array (`u`) containing the uncertainties. (This is, perhaps,\n", "overkill with only two measured quantities with uncertainties, \n", "but this procedure can simplify calculations in more complicated\n", "problems.)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "uncertainties in P due to uncertainties in V and T: [-18132.83430204 10336.91800833] \n", "\n", "fractional uncertainties in P due to uncertainties in V and T: [-0.00152607 0.00086996] \n", "\n", "total uncertainty (in MPa): 0.020872267575327286\n" ] } ], "source": [ "u = np.zeros(2)\n", "u[0] = P(Vmbest + alpha_V, Tbest)\n", "u[1] = P(Vmbest, Tbest + alpha_T)\n", "u = u - Pbest\n", "\n", "print('uncertainties in P due to uncertainties in V and T:',u,'\\n')\n", "print('fractional uncertainties in P due to uncertainties in V and T:',u/Pbest,'\\n')\n", "unc = np.sqrt(np.sum(u**2))\n", "print('total uncertainty (in MPa):', unc/1.e6)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So, the error in the pressure is \n", "\n", "$$ \n", "\\alpha_P = 0.02\\, \\mbox{MPa}.\n", "$$\n", "\n", "(This is a little different from what is given in early printings of the text -- the cause appears to be in the calculation of the uncertainty in $P$ due to the volume.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Version information\n", "`version_information` is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.\n", "\n", "`version_information` is installed on the linux network at Bucknell" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "%load_ext version_information" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.7 64bit [GCC 7.3.0]" }, { "module": "IPython", "version": "7.16.1" }, { "module": "OS", "version": "Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core" }, { "module": "numpy", "version": "1.18.5" } ] }, "text/html": [ "
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core
numpy1.18.5
Fri Aug 07 10:13:45 2020 EDT
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.7.7 64bit [GCC 7.3.0] \\\\ \\hline\n", "IPython & 7.16.1 \\\\ \\hline\n", "OS & Linux 3.10.0 1062.9.1.el7.x86\\_64 x86\\_64 with centos 7.7.1908 Core \\\\ \\hline\n", "numpy & 1.18.5 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Fri Aug 07 10:13:45 2020 EDT} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.7.7 64bit [GCC 7.3.0]\n", "IPython 7.16.1\n", "OS Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core\n", "numpy 1.18.5\n", "Fri Aug 07 10:13:45 2020 EDT" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%version_information numpy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "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.7.7" } }, "nbformat": 4, "nbformat_minor": 1 }