{
 "metadata": {
  "name": "",
  "signature": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2, Damped harmonic oscillator"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, page 102"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from math import log\n",
      "# relaxation time ,damping force ,time and total distance\n",
      "v=10 #cm/s\n",
      "vo=100 #cm/s\n",
      "t=23 #sec\n",
      "x=-(log(v/vo))/t #\n",
      "t=(1/x)*1 #seconds\n",
      "print \"Relaxation time  = %0.f seconds \" %t\n",
      "m=40 #gm\n",
      "vx=50 #cm/sec\n",
      "fd=((-x*m*10**-3*vx*10**-2)) #newton\n",
      "print \"Damping force = %0.e N\" %fd\n",
      "tx=5*(log(10)) #\n",
      "print \"Time in which kinetic energy will reduce to 1/10th of its value = %0.1f seconds \" %tx\n",
      "xx=v*1 #\n",
      "print \"Distance travelled = %0.f m \" %xx"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Relaxation time  = 10 seconds \n",
        "Damping force = -2e-03 N\n",
        "Time in which kinetic energy will reduce to 1/10th of its value = 11.5 seconds \n",
        "Distance travelled = 10 m \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, page 104"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt, pi\n",
      "# period\n",
      "#given data :\n",
      "m=2 # in g\n",
      "k=30 # in dynes/cm\n",
      "b=5 # in dynes/cm-sec**-1\n",
      "r=b/(2*m) \n",
      "w0=sqrt(k/m) \n",
      "T=2*pi/sqrt(w0**2-r**2) \n",
      "print \"The time period, T = %0.2f s  \" %T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The time period, T = 1.71 s  \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5, page 105"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# time\n",
      "tr=50 #seconds\n",
      "r=(1/(2*tr)) #s**-1\n",
      "t=1/r #seconds\n",
      "print \"Time in which amplitude falls to 1/e times the initial value = %0.f seconds \" %t\n",
      "t2=tr #\n",
      "print \"Time in which system falls to 1/e times the initial value = %0.f seconds\" %t2\n",
      "t3=2*(1/r) #f \n",
      "print \"Time in which energy falls to 1/e^4 of the initial value = %0.f seconds \" %t3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time in which amplitude falls to 1/e times the initial value = 100 seconds \n",
        "Time in which system falls to 1/e times the initial value = 50 seconds\n",
        "Time in which energy falls to 1/e^4 of the initial value = 200 seconds \n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6, page 106"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt, pi\n",
      "import sympy\n",
      "# relaxation time ,frequency ,energy ,time ,rate and number of vibrations\n",
      "k=20 #N/m\n",
      "m=5#N-s/m\n",
      "wo=sqrt(k/m) #\n",
      "v1=2 #m/s\n",
      "to=m/v1 #seconds\n",
      "print \"(a) Relaxation time = %0.1f seconds \" %to\n",
      "w=wo*(1-(1/(2*wo*to))**2) #\n",
      "lf=w/(2*pi) #vibration/s\n",
      "print \"(b) Linear frequency = %0.3f vibration/s \" %lf\n",
      "a=1 #\n",
      "e=((1/2)*m*a**2*wo**2) #joule\n",
      "print \"(c) Energy = %0.f J \"%e\n",
      "tm=v1*to #seconds\n",
      "print \"(d) Time taken in fall of amlitude to 1/e value = %0.f seconds \" %tm\n",
      "print \"(e) Time taken in fall of velocity amplitude to 1/2 value = %0.f seconds \" %tm\n",
      "tr=to #\n",
      "print \"(f) Time taken in fall of energy to 1/e value = %0.2f seconds\" %tr\n",
      "eng=(1/2)*m*a*v1**2*(2/tm) #\n",
      "print \"(g) Rate of loss of energy at t=0 seconds is\",eng,\"J/s and at any time is\",eng,\"e^-2*t/\",tm,\"J/s\"\n",
      "rel=((eng*2*pi)/wo) #J/s\n",
      "print \"(h) Rate of loss of energy per cycle at t=0 seconds is\",rel,\"J/s and at any time is\",round(rel,2),\"e^-2*t/\",tm,\"J/s\"\n",
      "nv=tm/((2*sympy.pi)/wo) #\n",
      "print \"(i) Number of vibratios made are =\",nv"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) Relaxation time = 2.5 seconds \n",
        "(b) Linear frequency = 0.315 vibration/s \n",
        "(c) Energy = 10 J \n",
        "(d) Time taken in fall of amlitude to 1/e value = 5 seconds \n",
        "(e) Time taken in fall of velocity amplitude to 1/2 value = 5 seconds \n",
        "(f) Time taken in fall of energy to 1/e value = 2.50 seconds\n",
        "(g) Rate of loss of energy at t=0 seconds is 4.0 J/s and at any time is 4.0 e^-2*t/ 5.0 J/s\n",
        "(h) Rate of loss of energy per cycle at t=0 seconds is 12.5663706144 J/s and at any time is 12.57 e^-2*t/ 5.0 J/s\n",
        "(i) Number of vibratios made are = 5.0/pi\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7, page 109"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# time and distance\n",
      "b=5 #N-s/m\n",
      "v=10 #m/s\n",
      "to=b/v #second\n",
      "print \"(a) Time in which velocity falls to 1/e times the initial value = %0.2f second \" %to\n",
      "t2=b*to #\n",
      "print \"(b) Time in which velocity falls to half the initial value = %0.2f second \" %t2\n",
      "print \"(c) Distance traversed by the particle before the velocity falls to half the initial value is\",b,\"*(1-exp(log)\",(2*to)/to\n",
      "x=b #m\n",
      "print \"(d) Distance traversed by the particle it comes to rest = %0.2f m \" %x"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) Time in which velocity falls to 1/e times the initial value = 0.50 second \n",
        "(b) Time in which velocity falls to half the initial value = 2.50 second \n",
        "(c) Distance traversed by the particle before the velocity falls to half the initial value is 5 *(1-exp(log) 2.0\n",
        "(d) Distance traversed by the particle it comes to rest = 5.00 m \n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8, page 111"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log, pi\n",
      "# time interval\n",
      "q=5*10**4 #quality factor\n",
      "x=1/10 #\n",
      "fr=300 #second**-1\n",
      "to=q/(2*pi*fr) #second\n",
      "xm=((to*log(10))) #seconds\n",
      "print \"Time interval = %0.f seconds \" %xm"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time interval = 61 seconds \n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9, page 111"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Time\n",
      "#given data :\n",
      "n=240 # in sec**-1\n",
      "w=2*pi*n \n",
      "Q=2*10**3 \n",
      "tau=Q/w \n",
      "t=4*tau \n",
      "print \"Time, t = %0.1f s \" %t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time, t = 5.3 s \n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10, page 112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "# Logarithmic decrement\n",
      "#given data :\n",
      "a=100 \n",
      "l1=20 # in cm\n",
      "l2=2 # in cm\n",
      "l=l1/l2 \n",
      "lamda=(1/100)*log(l) \n",
      "print \" Logarithmic decrement = %0.3f \" %lamda"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Logarithmic decrement = 0.023 \n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12, page 116"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt, pi\n",
      "# Frequency\n",
      "#given data :\n",
      "C=10**-6 # in F\n",
      "L=0.2 # in H\n",
      "R=800 # in ohm\n",
      "Rm=2*sqrt(L/C) \n",
      "n=sqrt((1/(L*C))-(R**2/(4*L**2)))/(2*pi) \n",
      "print \"The frequency, n = %0.1f cycles/s \" %n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency, n = 159.2 cycles/s \n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13, page 116"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt\n",
      "# Resistance\n",
      "#given data :\n",
      "C=0.0012*10**-6 # in F\n",
      "L=0.2 # in H\n",
      "Rm=2*sqrt(L/C) \n",
      "print \"The maximum value of resistance, Rm = %0.2e ohms \" %Rm"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The maximum value of resistance, Rm = 2.58e+04 ohms \n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14, page 117"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt, pi\n",
      "# Q factor\n",
      "#given data :\n",
      "C=5*10**-6 # in F\n",
      "L=2*10**-3 # in H\n",
      "R=0.2 # in ohm\n",
      "w=round(sqrt((1/(L*C))-(R**2/(4*L**2)))) \n",
      "f=w/(2*pi) \n",
      "Q=w*L/R \n",
      "print \"Frequency = %0.2e Hz \" %f\n",
      "print \"Quality factor, Q = %0.f \" %Q"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency = 1.59e+03 Hz \n",
        "Quality factor, Q = 100 \n"
       ]
      }
     ],
     "prompt_number": 38
    }
   ],
   "metadata": {}
  }
 ]
}