{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#Chapter 1: Preliminaries"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 1.1, Rounding off Numbers, Page no. 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "81.9773 becomes 81.98\n",
      "\n",
      "\n",
      "48.365 becomes 48.37\n",
      "\n",
      "\n",
      "21.385 becomes 21.39\n",
      "\n",
      "\n",
      "12.865 becomes 12.87\n",
      "\n",
      "\n",
      "27.553 becomes 27.55\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#variable declaration\n",
    "a=[81.9773,48.365,21.385,12.865,27.553]\n",
    "\n",
    "#calculation  and    result\n",
    "for i in xrange (0,5):\n",
    "    print '\\n%s becomes %.2f\\n' %(a[i],a[i])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 1.2, Relative Maximum Error, Page no. 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Maximum Error = 0.030\n",
      "\n",
      "Relative maximum error = 0.006\n"
     ]
    }
   ],
   "source": [
    "\n",
    " \n",
    "#variable declaration\n",
    "h=0.001;\n",
    "x=1;y=1;z=1;dx=0.001;dy=0.001;dz=0.001;\n",
    "def f(x,y,z):\n",
    "    return (5*x*y**2)/z**3\n",
    "\n",
    "#calculation\n",
    "du=abs(f(x+h,y,z)-f(x,y,z))*dx+abs(f(x,y+h,z)-f(x,y,z))*dy+abs(f(x,y,z+h)-f(x,y,z))*dz;\n",
    "du=du/h;\n",
    "Er=du/f(x,y,z)\n",
    "\n",
    "#result\n",
    "print '\\nMaximum Error = %.3f\\n\\nRelative maximum error = %.3f' %(du,Er)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 1.3, Absolute Error, Page no. 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Maximum Absolute Error of a+b+c+d = 600.050200\n",
      "\n",
      "\n",
      "Maximum Absolute Error of c^3 = -172.000000\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "#Variable declaration\n",
    "a=10;b=0.0356;c=15300;d=62000;\n",
    "ea=0.05;eb=0.0002;ec=100;ed=500;\n",
    "\n",
    "#Calculation\n",
    "e=ea+eb+ec+ed;\n",
    "E=(c+2*ec)^3-(c+ec)^3\n",
    "\n",
    "#result\n",
    "print '\\nMaximum Absolute Error of a+b+c+d = %f\\n' %e\n",
    "print '\\nMaximum Absolute Error of c^3 = %f' %E\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}