{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#21: Boats and Streams"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.1, Page number 21.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rate in still water is 5.0 km/h\n",
      "speed of current is 3.0 km/h\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "ds=8;     #speed downstream(km/h)\n",
    "us=2;     #speed upstream(km/h)\n",
    "\n",
    "#Calculation\n",
    "r=(ds+us)/2;     #rate in still water(km/h)\n",
    "s=(ds-us)/2;     #speed of current(km/h)\n",
    "\n",
    "#Result\n",
    "print \"rate in still water is\",r,\"km/h\"\n",
    "print  \"speed of current is\",s,\"km/h\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.2, Page number 21.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed of current is 1.0 km/h\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "ddn=30;     #distance downstream(km)\n",
    "dup=20;     #distance upstream(km)\n",
    "tdn=5;      #time downstream(hrs)\n",
    "tup=5;      #time upstream(hrs)\n",
    "\n",
    "#Calculation\n",
    "s=(1/2)*((ddn/tdn)-(dup/tup));      #speed of current(km/h)\n",
    "\n",
    "#Result\n",
    "print \"speed of current is\",s,\"km/h\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.3, Page number 21.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed in still water is 7.0 km/hr\n",
      "speed of current is 1.0 km/hr\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=2;    #distance(km)\n",
    "tdn=20;    #time downstream(min)\n",
    "tup=15;    #time upstream(min)\n",
    "\n",
    "#Calculation\n",
    "x=(d/2)*((1/tdn)+(1/tup));     #speed in still water(km/min)\n",
    "x=x*60;      #speed in still water(km/hr)\n",
    "y=(d/2)*(-(1/tdn)+(1/tup));     #speed of current(km/min)\n",
    "y=y*60;      #speed of current(km/hr)\n",
    "\n",
    "#Result\n",
    "print \"speed in still water is\",x,\"km/hr\"\n",
    "print \"speed of current is\",y,\"km/hr\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.4, Page number 21.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed of stream is 1.3 km/h\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r=4;       #rate in still water(km/hr)\n",
    "tdn=1;     #assume\n",
    "\n",
    "#Calculation\n",
    "tup=2*tdn;   \n",
    "d=(tdn+tup)/(tup-tdn);\n",
    "s=r/d;      #speed of stream(km/h)\n",
    "\n",
    "#Result\n",
    "print \"speed of stream is\",round(s,1),\"km/h\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.5, Page number 21.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "distance is 8.0 km\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "x=6;     #speed in still water(km/hr)\n",
    "y=2;     #speed of river(km/hr)\n",
    "t=3;     #time(hrs)\n",
    "\n",
    "#Calculation\n",
    "d=t*(x+y)/(1+y);     #distance(km)\n",
    "\n",
    "#Result\n",
    "print \"distance is\",d,\"km\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.6, Page number 21.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "distance in downstream is 7.0 km\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "x=15;     #speed in still water(km/hr)\n",
    "y=13;     #rate of current(km/hr)\n",
    "t=15/60;    #time(hrs)\n",
    "\n",
    "#Calculation\n",
    "d=(x+y)*t;    #distance in downstream(km) \n",
    "\n",
    "#Result\n",
    "print \"distance in downstream is\",d,\"km\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.7, Page number 21.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "average speed for total journey is 4.0 km/h\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "x=4.5;     #speed in still water(km/hr)\n",
    "y=1.5;     #rate of current(km/hr)\n",
    "\n",
    "#Calculation\n",
    "avgs=(x+y)*(x-y)/x;     #average speed for total journey(km/h)\n",
    "\n",
    "#Result\n",
    "print \"average speed for total journey is\",avgs,\"km/h\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.8, Page number 21.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed of rowing in still water is 22\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "T=55;       #time(min)\n",
    "c=60;      #conversion factor from min to h\n",
    "y=2;       #speed of stream(km/h)\n",
    "d=10;      #distance upstream(km)\n",
    "\n",
    "#Calculation\n",
    "a=T/5;    #coefficient of x**2\n",
    "b=-c*y**2;    #coefficient of x\n",
    "c=-a*y**2;     #constant\n",
    "x=(b**2)-(4*a*c);\n",
    "x1=-b+math.sqrt(x)/(2*a);\n",
    "x2=-b-math.sqrt(x)/(2*a);\n",
    "\n",
    "#Result\n",
    "print \"speed of rowing in still water is\",int(x2/10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 21.9, Page number 21.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "flow of river is 3.0 km/h\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "s=10;   #speed in still water(km/h)\n",
    "td=91;    #total distance(km)\n",
    "t=20;    #time(h)\n",
    "\n",
    "#Calculation\n",
    "d=t/s;    #distance(km)\n",
    "y2=(s**2)-td;     \n",
    "y=math.sqrt(y2);      #flow of river(km/h)\n",
    "\n",
    "#Result\n",
    "print \"flow of river is\",y,\"km/h\""
   ]
  }
 ],
 "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
}