{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 8: Damped and Forced Oscillations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 1, Page number 300"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "restoration energy is 125000 erg\n",
      "frequency is 5 /math.pi Hz\n",
      "time taken for reduction of amplitude is 3.22 sec\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "k=10**4;     #Force constant(dyne/cm)\n",
    "x=5;         #displacement(cm)\n",
    "m=100;       #mass(gm)\n",
    "R=100;       #resistance(dyne/cm)\n",
    "At=1;      #amplitude(cm)\n",
    "A0=5;      #amplitude(cm)\n",
    "\n",
    "#Calculation\n",
    "E=(1/2)*k*x**2;   #restoration energy(erg)\n",
    "v=1/(2*math.pi)*math.sqrt(k/m)  #frequency(Hz)\n",
    "b=R/(2*m);          \n",
    "t=math.log(A0/At)/b;      #time taken for reduction of amplitude(sec)\n",
    "\n",
    "#Result\n",
    "print \"restoration energy is\",int(E),\"erg\"\n",
    "print \"frequency is\",int(v*math.pi),\"/math.pi Hz\"\n",
    "print \"time taken for reduction of amplitude is\",round(t,2),\"sec\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 2, Page number 301"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time taken is 61.08 sec\n",
      "answer in the book varies due to rounding off errors\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "new=300;         #frequency(Hz)\n",
    "EbyE0=1/10;      #ratio of energy\n",
    "Q=5*10**4;       #Q factor\n",
    "\n",
    "#Calculation\n",
    "tbytow=math.log(1/EbyE0);\n",
    "tow=Q/(2*math.pi*new);   \n",
    "t=tbytow*tow;      #time taken(sec)\n",
    "\n",
    "#Result\n",
    "print \"time taken is\",round(t,2),\"sec\"\n",
    "print \"answer in the book varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 3, Page number 301"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time taken is 6 sec\n",
      "procedure followed in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "Q=2.2*10**3;       #Q value of sonometer wire\n",
    "new=210;           #frequency(Hz)\n",
    "\n",
    "#Calculation\n",
    "tow=Q/(2*math.pi*new);     #torque(Nm)\n",
    "t=4*tow;           #time taken(sec)\n",
    "\n",
    "#Result\n",
    "print \"time taken is\",int(t),\"sec\"\n",
    "print \"procedure followed in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 4, Page number 302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "damping factor is 0.0618 N/m\n",
      "Q-factor is 113.3\n",
      "answer given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "m=0.5;     #mass(kg)\n",
    "g=9.8;     #acceleration due to gravity(m/sec**2)\n",
    "x=0.05;    #displacement(m)\n",
    "\n",
    "#Calculation\n",
    "k=m*g/x;     \n",
    "omega0=math.sqrt(k/m);    #angular velocity\n",
    "T=50*2*math.pi/omega0;       #time taken for 50 oscillations(sec)\n",
    "b=math.log(4)/T;      #damping factor(N/m)\n",
    "R=2*b*m;     #resistance(ohm)\n",
    "Q=m*omega0/R;     #Q-factor\n",
    "\n",
    "#Result\n",
    "print \"damping factor is\",round(b,4),\"N/m\"\n",
    "print \"Q-factor is\",round(Q,1)\n",
    "print \"answer given in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 5, Page number 302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of oscillations is 27.73\n",
      "answer in the book varies due to rounding off errors\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "m=1;     #mass(gm)\n",
    "R=10;     #damping constant\n",
    "E=50;     #energy(J)\n",
    "E0=200;   #energy(J)\n",
    "new=200;    #frequency(Hz)\n",
    "\n",
    "#Calculation\n",
    "b=R/(2*m);\n",
    "t=math.log(E0/E)/(2*b);     #time taken(sec)\n",
    "n=new*t;          #number of oscillations\n",
    "\n",
    "#Result\n",
    "print \"number of oscillations is\",round(n,2)\n",
    "print \"answer in the book varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 6, Page number 303"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mechanical resistance is 0.0628 m/sec\n",
      "damping constant is 0.209\n",
      "spring constant 11.84 N/cm\n",
      "answer for spring constant given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "m=0.3;     #mass(kg)\n",
    "new=2;    #frequency(Hz)\n",
    "Q=60;     #Q-factor\n",
    "\n",
    "#Calculation\n",
    "omega=2*math.pi*new;   #angular velocity\n",
    "R=m*omega/Q;       #mechanical resistance(m/sec)\n",
    "b=R/m;       #damping constant\n",
    "k=4*(math.pi**2)*m;    #spring constant(N/cm)\n",
    "\n",
    "#Result\n",
    "print \"mechanical resistance is\",round(R,4),\"m/sec\"\n",
    "print \"damping constant is\",round(b,3)\n",
    "print \"spring constant\",round(k,2),\"N/cm\"\n",
    "print \"answer for spring constant given in the book is wrong\""
   ]
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
