{
 "metadata": {
  "name": "chapter19.ipynb"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 19: Relative Motion"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19.19-1,Page no:503"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Initilization of variables\n",
      "\n",
      "v_t=10 # m/s # velocity of the train\n",
      "v_s=5 # m/s # velocity of the stone\n",
      "\n",
      "# Calculations\n",
      "\n",
      "# Let v_r be the relative velocity, which is given as, (from triangle law)\n",
      "v_r=(v_t**2+v_s**2)**0.5 # m/s\n",
      "# The direction ofthe stone is,\n",
      "theta=arctan(v_s*v_t**-1)*(180/pi) # degree\n",
      "\n",
      "# Results\n",
      "\n",
      "print\"The velocity at which the stone appears to hit the person travelling in the train is \",round(v_r,1),\"m\"\n",
      "print\"The direction of the stone is \",round(theta,2),\"degree\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The velocity at which the stone appears to hit the person travelling in the train is  11.2 m\n",
        "The direction of the stone is  26.57 degree\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19.19-2,Page No:504"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Initilization of variables\n",
      "\n",
      "v_A=5 # m/s # speed of ship A\n",
      "v_B=2.5 # m/s # speed of ship B\n",
      "theta=135 # degree # angle between the two ships\n",
      "\n",
      "# Calculations\n",
      "\n",
      "# Here,\n",
      "OA=v_A # m/s\n",
      "OB=v_B # m/s\n",
      "\n",
      "# The magnitude of relative velocity is given by cosine law as,\n",
      "AB=((OA**2)+(OB**2)-(2*OA*OB*cos(theta*(pi/180))))**0.5 # m/s\n",
      "\n",
      "# where AB gives the relative velocity of ship B with respect to ship A\n",
      "# Applying sine law to find the direction, Let alpha be the direction of the reative velocity, then\n",
      "alpha=arcsin((OB*sin(theta*(pi/180)))/(AB))*(180/pi) # degree\n",
      "\n",
      "# Results\n",
      "\n",
      "print\"The magnitude of relative velocity of ship B with respect to ship A is \",round(AB,2),\"m/s\"\n",
      "print\"The direction of the relative velocity is \",round(alpha,2),\"degree\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The magnitude of relative velocity of ship B with respect to ship A is  6.99 m/s\n",
        "The direction of the relative velocity is  14.64 degree\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19.19-3,Page No:505"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import numpy as np\n",
      "# Initilization of variables\n",
      "\n",
      "v_c=20 # km/hr # speed at which the cyclist is riding to west\n",
      "theta_1=45 # degree # angle made by rain with the cyclist when he rides at 20 km/hr\n",
      "V_c=12 # km/hr # changed speed\n",
      "theta_2=30 # degree # changed angle when the cyclist rides at 12 km/hr\n",
      "\n",
      "# Calculations\n",
      "\n",
      "# Solving eq'ns 1 & 2 simultaneously to get the values of components(v_R_x & v_R_y) of absolute velocity v_R. We use matrix to solve eqn's 1 & 2.\n",
      "A=np.array([[1 ,1],[1, 0.577]])\n",
      "B=np.array([20,12])\n",
      "C=np.linalg.solve(A,B) # km/hr\n",
      "\n",
      "# The X component of relative velocity (v_R_x) is C(1)\n",
      "# The Y component of relative velocity (v_R_y) is C(2)\n",
      "\n",
      "# Calculations\n",
      "\n",
      "# Relative velocity (v_R) is given as,\n",
      "v_R=((C[0])**2+(C[1])**2)**0.5 # km/hr\n",
      "# And the direction of absolute velocity of rain is theta, is given as\n",
      "theta=arctan(C[1]/C[0])*(180/pi) # degree\n",
      "\n",
      "# Results \n",
      "\n",
      "print\"The magnitude of absolute velocity is \",round(v_R,2),\"km/hr\"\n",
      "print\"The direction of absolute velocity is \",round(theta,1),\"degree\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The magnitude of absolute velocity is  18.94 km/hr\n",
        "The direction of absolute velocity is  86.7 degree\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19.19-4,Page No:508"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Initiization of variables\n",
      "\n",
      "a=1 # m/s^2 # acceleration of car A\n",
      "u_B=36*1000*3600**-1 # m/s # velocity of car B\n",
      "u=0 # m/s # initial velocity of car A\n",
      "d=32.5 # m # position of car A from north of crossing\n",
      "t=5 # seconds\n",
      "\n",
      "# Calculations\n",
      "\n",
      "# CAR A: Absolute motion using eq'n v=u+at we have,\n",
      "v=u+(a*t) # m/s\n",
      "# Now distance travelled by car A after 5 seconds is given by, s_A=u*t+(1/2)*a*t^2\n",
      "s_A=(u*t)+((0.5)*a*t**2)\n",
      "# Now, let the position of car A after 5 seconds be y_A\n",
      "y_A=d-s_A # m # \n",
      "\n",
      "# CAR B:\n",
      "# let a_B be the acceleration of car B\n",
      "a_B=0 # m/s\n",
      "# Now position of car B is s_B\n",
      "s_B=(u_B*t)+((0.5)*a_B*t**2) # m\n",
      "x_B=s_B # m\n",
      "\n",
      "# Let the Relative position of car A with respect to car B be BA & its direction be theta, then from fig. 19.9(b)\n",
      "OA=y_A\n",
      "OB=x_B\n",
      "BA=(OA**2+OB**2)**0.5 # m\n",
      "theta=arctan(OA/OB)*(180/pi) # degree\n",
      "\n",
      "# Let the relative velocity of car A w.r.t. the car B be v_AB & the angle be phi. Then from fig 19.9(c). Consider small alphabets\n",
      "oa=v\n",
      "ob=u_B\n",
      "v_AB=(oa**2+ob**2)**0.5 # m/s\n",
      "phi=arctan(oa/ob)*(180/pi) # degree\n",
      "\n",
      "# Let the relative acceleration of car A w.r.t. car B be a_A/B.Then,\n",
      "a_AB=a-a_B # m/s^2\n",
      "\n",
      "# Results\n",
      "\n",
      "print\"The relative position of car A relative to car B is \",round(BA,1),\"m\"\n",
      "print\"The direction of car A w.r.t car B is \",round(theta,1),\"degree\"\n",
      "print\"The velocity of car A relative to car B is \",round(v_AB,1),\"m/s\"\n",
      "print\"The direction of car A w.r.t (for relative velocity)is \",round(phi,1),\"degree\"\n",
      "print\"The acceleration of car A relative to car B is \",round(a_AB,1),\"m/s^2\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The relative position of car A relative to car B is  53.9 m\n",
        "The direction of car A w.r.t car B is  21.8 degree\n",
        "The velocity of car A relative to car B is  11.2 m/s\n",
        "The direction of car A w.r.t (for relative velocity)is  26.6 degree\n",
        "The acceleration of car A relative to car B is  1.0 m/s^2\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}