{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Examples 1 -- Unit Conversion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "m_per_in = 0.0254       # converts inches to meters (exact)\n",
    "m_per_ft = m_per_in*12  # converts ft to meters (exact)\n",
    "km_per_mi = 1.609       # converts miles to kilometers\n",
    "N_per_lb = 4.448        # converts pounds to Newtons\n",
    "kN_per_kip = 4.448      # converts kips to kiloNewtons\n",
    "kg_per_slug = 14.59     # converts slugs to kg\n",
    "s_per_hr = 3600.        # converts hours to seconds\n",
    "dtr = pi/180.           # converts degrees to radians"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A. perform unit conversions\n",
    "\n",
    "<img src=\"images/P1-03.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.056388"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l = 2.22  # in\n",
    "l * m_per_in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.05602"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = 0.278  # slug\n",
    "m * kg_per_slug"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "533.76"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "F = 120  # lb\n",
    "F * N_per_lb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "41.485962240000006"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M = 30.6  # ft.lb\n",
    "M * N_per_lb * m_per_ft"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## B. more unit conversions\n",
    "\n",
    "<img src=\"images/P1-11.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.763779527559056e-06"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l = 121e-9 # m\n",
    "l / m_per_in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "m = 1.970e-02 lb s^2/in\n"
     ]
    }
   ],
   "source": [
    "m = 3.45  # kg = N s^2 / m\n",
    "m2 = m / N_per_lb * m_per_in\n",
    "print ('m = {:.3e} lb s^2/in'.format(m2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2967.625899280575"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "F = 13.2e3   # N\n",
    "F / N_per_lb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I = 9.997e+03 slug in^2\n"
     ]
    }
   ],
   "source": [
    "I = 94.1  # kg m^2\n",
    "I2 = I / kg_per_slug / m_per_in**2\n",
    "print ('I = {:.3e} slug in^2'.format(I2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## C. density calculations with unit conversion\n",
    "\n",
    "<img src=\"images/P1-25.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14.294282052781353\n",
      "459.9619092226359\n"
     ]
    }
   ],
   "source": [
    "g = 9.81       # N/kg\n",
    "rho = 7.365e3  # kg / m^3\n",
    "print (rho / kg_per_slug * m_per_ft**3)\n",
    "print (rho*g / N_per_lb  * m_per_ft**3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.569273592104178\n",
      "243.56435111585603\n"
     ]
    }
   ],
   "source": [
    "rho = 3.90e3    # kg / m^3\n",
    "print (rho / kg_per_slug * m_per_ft**3)\n",
    "print (rho*g / N_per_lb  * m_per_ft**3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.8632058072871824\n",
      "59.954301813133796\n"
     ]
    }
   ],
   "source": [
    "rho = 960.    # kg / m^3\n",
    "print (rho / kg_per_slug * m_per_ft**3)\n",
    "print (rho*g / N_per_lb  * m_per_ft**3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.552671506072652\n",
      "49.961918177611494\n"
     ]
    }
   ],
   "source": [
    "rho = 0.8e3    # kg / m^3\n",
    "print (rho / kg_per_slug * m_per_ft**3)\n",
    "print (rho*g / N_per_lb  * m_per_ft**3)"
   ]
  },
  {
   "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.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
