{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f225380f",
   "metadata": {},
   "source": [
    "# SIS Problem 1.2 - volume of water and mercury - EMF solution\n",
    "\n",
    "This notebok plots data given in the table for SIS problem 1.2. The original data source is R. H. Perry and D. Green, eds., Chemical Engineers’ Handbook, 6th ed., McGraw-Hill, New York, 1984, pp. 3-75–3-77.\n",
    "\n",
    "Eric Furst  \n",
    "August 2023"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "795db611",
   "metadata": {},
   "source": [
    "\n",
    "## Experimental Data\n",
    "\n",
    "The table in the problem gives the volume in cm<sup>3</sup> of one gram of each fluid between 0 and 100 C.\n",
    "  \n",
    "\n",
    "|Temperature, C| Volume of 1g H<sub>2</sub>O | Volume 1g of Hg |\n",
    "|:----:|:----:|:----:|\n",
    "|0|1.001329|0.0735560|\n",
    "|1|1.0000733|0.0735694|\n",
    "|2|1.0000321|0.0735828|\n",
    "|3|1.0000078|0.0735961|\n",
    "|4|1.0000000|0.0736095|\n",
    "|5|1.0000081|0.0736228|\n",
    "|6|1.0000318|0.0736362|\n",
    "|7|1.0000704|0.0736496|\n",
    "|8|1.0001236|0.0736629|\n",
    "|9|1.0001909|0.0736763|\n",
    "|10|1.0002719|0.0736893|\n",
    "|20|1.0015678|0.0738233|\n",
    "|30|1.0043408|0.0739572|\n",
    "|40|1.0078108|0.0740910|\n",
    "|50|1.012074|0.0742250|\n",
    "|60|1.017046|0.0743592|\n",
    "|70|1.022694|0.0744936|\n",
    "|80|1.028987|0.0746282|\n",
    "|90|1.035904|0.0747631|\n",
    "|100|1.043427|0.0748981|\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8ba8e9f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9cacacf5",
   "metadata": {},
   "source": [
    "The first step is to create numpy arrays of the data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f3d2f917",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Data, T in C volume in cm^3\n",
    "\n",
    "T1 = np.arange(0,10,1)\n",
    "T2 = np.linspace(10,100,10)\n",
    "T = np.concatenate((T1,T2))\n",
    "\n",
    "Vh2o = np.array([1.0001329, 1.0000733, 1.0000321, 1.0000078, 1.0000000, \n",
    "                 1.0000081, 1.0000318, 1.0000704, 1.0001236, 1.0001909,\n",
    "                 1.0002719, 1.0015678, 1.0043408, 1.0078108, 1.012074,\n",
    "                 1.017046, 1.022694, 1.028987, 1.035904, 1.043427])\n",
    "\n",
    "Vhg = np.array([0.0735560, 0.0735694, 0.0735828, 0.0735961, 0.0736095,\n",
    "                0.0736228, 0.0736362, 0.0736496, 0.0736629, 0.0736763,\n",
    "                0.0736893, 0.0738233, 0.0739572, 0.0740910, 0.0742250,\n",
    "                0.0743592, 0.0744936, 0.0746282, 0.0747631, 0.0748981])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4133d8cd",
   "metadata": {},
   "source": [
    "Now we can plot the data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7579e5f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Volume of water and mercury with temperature')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 22332 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot the data\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(T, Vh2o, 'o')\n",
    "ax.plot(T, Vhg, 'o')\n",
    "plt.xlabel('T (C)')\n",
    "plt.ylabel('Volume (cm^3)')\n",
    "plt.title('Volume of water and mercury with temperature')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69e5cfeb",
   "metadata": {},
   "source": [
    "On a single plot, the specific volumes of water and mercury are too different from each another. Let's plot them separately."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "807e8ac4",
   "metadata": {},
   "source": [
    "## Plot 1: Water specifc volume with temperature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c24d3d45",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Volume of water with temperature')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 23000 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(T, Vh2o, 'o')\n",
    "plt.xlabel('T (C)')\n",
    "plt.ylabel('Volume (cm^3)')\n",
    "plt.title('Volume of water with temperature')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a48234c",
   "metadata": {},
   "source": [
    "## Plot  2: Mercury specific volume with temperature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a4577546",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Volume of mercury with temperature')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 29536 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(T, Vhg, 'o')\n",
    "plt.xlabel('T (C)')\n",
    "plt.ylabel('Volume (cm^3)')\n",
    "plt.title('Volume of mercury with temperature')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dda12290",
   "metadata": {},
   "source": [
    "### End of Notebook Example\n",
    "emf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6511caab",
   "metadata": {},
   "source": [
    "Still... I wonder what the ratio looks like? It's easy to plot in Jupyter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bcc4e041",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Ratio of water and mercury specific volumes')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 31044 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(T, Vh2o/Vhg, 'o')\n",
    "plt.xlabel('T (C)')\n",
    "plt.ylabel(\"V_{H_2O}/V_{Hg}\")\n",
    "plt.title('Ratio of water and mercury specific volumes')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
