{
 "metadata": {
  "name": "",
  "signature": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7, Superposition of harmonic waves : Interference, Beats, Stationary waves, Phase and group velocities  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1, page 272"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from numpy import sqrt\n",
      "#  ratio\n",
      "ri=9/16 #ratio of intensities\n",
      "ra=sqrt(ri) #ratio of amplitude\n",
      "a1=1 #assume\n",
      "a2=ra*a1 #\n",
      "rim=(a1+a2)**2/(a1-a2)**2 #\n",
      "print \"Ratio of maximum intensity and minimum intensity in fringe system is %d\"%rim,\":\",a1"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Ratio of maximum intensity and minimum intensity in fringe system is 49 : 1\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2, page 272"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import cos, pi\n",
      "#  intensity\n",
      "I=1 #assume\n",
      "a1=1*I #\n",
      "a2=4*I #\n",
      "ph1=0 #degree\n",
      "i1=(a1+a2)+a2*cos(ph1*pi/180) #\n",
      "print \"Intensity where phase difference is zero =\",i1,\"*I\"\n",
      "ph2=90 #degree\n",
      "i2=(a1+a2)+a2*cos(ph2*pi/180) #\n",
      "print \"Intensity where phase difference is pi/2 =\",i2,\"*I\"\n",
      "ph3=180 #degree\n",
      "i3=(a1+a2)+a2*cos(ph3*pi/180) #\n",
      "print \"Intensity where phase difference is pi is =\",i3,\"*I\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Intensity where phase difference is zero = 9.0 *I\n",
        "Intensity where phase difference is pi/2 = 5.0 *I\n",
        "Intensity where phase difference is pi is = 1.0 *I\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, page 273"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Wavelength and frequency\n",
      "#given data :\n",
      "d=30 # in cm\n",
      "lamda=2*d*10**-2 \n",
      "v=330 # in m/s\n",
      "print \"The wavelength = %0.2f m \" %lamda\n",
      "n=v/lamda \n",
      "print \"The frequency, n = %0.2f vibrations/s \" %n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The wavelength = 0.60 m \n",
        "The frequency, n = 550.00 vibrations/s \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, page 281"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  number of beats and time interval\n",
      "from fractions import Fraction\n",
      "n1=300 #Hz\n",
      "n2=303 #Hz\n",
      "bfs=n2-n1 #\n",
      "print \"Beat frequency = %0.2f per second \" %bfs\n",
      "ti=Fraction(1/bfs).limit_denominator(3) #second\n",
      "print \"Time interval =\",ti,\"second  \""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Beat frequency = 3.00 per second \n",
        "Time interval = 1/3 second  \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5, page 281"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "#given data :\n",
      "n1=256 # in Hz\n",
      "x=4 # in beats per sec\n",
      "n2a=n1+x \n",
      "n2b=n1-x \n",
      "print \"The frequency, n2a = %0.2f Hz \" %n2a\n",
      "print \"The frequency, n2b = %0.2f Hz  \"% n2b "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency, n2a = 260.00 Hz \n",
        "The frequency, n2b = 252.00 Hz  \n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6, page 282"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "#given data :\n",
      "nA=256 # in Hz\n",
      "x=5 # in beats per sec\n",
      "nB1=nA+x \n",
      "nB2=nA-x \n",
      "print \"The frequency, nB = %0.f Hz or %0.f Hz\" %(nB1, nB2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency, nB = 261 Hz or 251 Hz\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7, page 283"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "#given data :\n",
      "nB=512 # in Hz\n",
      "x=5 # in beats per sec\n",
      "nA1=nB+x \n",
      "nA2=nB-x \n",
      "print \"The frequency of A, nA = %0.f Hz or %0.f Hz\" %(nA1, nA2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency of A, nA = 517 Hz or 507 Hz\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8, page 283"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Velocity of sound\n",
      "#given data :\n",
      "lamda1=1 # in m\n",
      "lamda2=1.01 # in m\n",
      "a=10/3 # in beats/sec\n",
      "v=a/((lamda2-lamda1)/(lamda1*lamda2)) \n",
      "print \"The velocity of sound, v = %0.1f m/s \" %v"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The velocity of sound, v = 336.7 m/s \n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9, page 284"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "n=273 #\n",
      "b1=4 #beats per second\n",
      "b2=b1-1 #\n",
      "t1=15 #degree celsius\n",
      "t2=10 #degree celsius\n",
      "v1510=sqrt((n+t1)/(n+t2)) #\n",
      "n=((b2*v1510-b1)/(1-v1510)) #\n",
      "print \"Frequency = %0.2f Hz \" %n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency = 110.70 Hz \n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10, page 284"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "b1=10 #beats per second\n",
      "f1=300 #Hz\n",
      "b2=15 #beats per second\n",
      "f2=325 #Hz\n",
      "n1=f1-b1 #Hz\n",
      "n2=f1+b1 #Hz\n",
      "n3=f2-b2 #Hz\n",
      "n4=f2+b2 #Hz\n",
      "print \"Frequency = %0.2f Hz \" %n2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency = 310.00 Hz \n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11, page 285"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Velocity of sound\n",
      "#given data :\n",
      "lamda1=5 # in m\n",
      "lamda2=5.5 # in m\n",
      "a=6 # beats/sec\n",
      "v=a/((lamda2-lamda1)/(lamda1*lamda2)) \n",
      "print \"The velocity of sound, v = %0.2f m/s  \" %v"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The velocity of sound, v = 330.00 m/s  \n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12, page 285"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "b1=5 #beats per second\n",
      "fr=384 #Hz\n",
      "fo=fr-b1 #Hz\n",
      "print \"Frequency = %0.2f Hz  \" %fo"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency = 379.00 Hz  \n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13, page 285"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#  Frequency\n",
      "b1=4 #beats per second\n",
      "fr=256 #Hz\n",
      "fo1=fr+b1 #Hz\n",
      "fo2=fr-b1 #Hz\n",
      "print \"Frequency = %0.f Hz or %0.f Hz\" %(fo1,fo2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency = 260 Hz or 252 Hz\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 18, page 297"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Frequency,wavelength, velocity and amplitude\n",
      "#given data :\n",
      "a=6 # in cm\n",
      "lamda=10 # in cm\n",
      "T=1/10 # in sec\n",
      "print \"Wavelength of progressive wave = %0.2f cm \" %lamda\n",
      "n=1/T \n",
      "print \"Frequency of progressive wave, n = %0.2f per sec \" %n\n",
      "v=n*lamda \n",
      "print \"The velocity, v = %0.2f cm/s \" %v\n",
      "print \"The amplitude, a = %0.2f cm \" %a"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Wavelength of progressive wave = 10.00 cm \n",
        "Frequency of progressive wave, n = 10.00 per sec \n",
        "The velocity, v = 100.00 cm/s \n",
        "The amplitude, a = 6.00 cm \n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 24, page 309"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Velocity\n",
      "#given data :\n",
      "c=3*10**8 # in m/s\n",
      "lamda1=4000 # in Angustrom\n",
      "lamda2=5000 # in Aungustrom\n",
      "mu1=1.540 \n",
      "mu2=1.530 \n",
      "vg=c*((mu1*lamda1)-(mu2*lamda2))/(mu1*mu2*(lamda1-lamda2)) \n",
      "print \"The velocity, vg = %0.3e m/s \" %vg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The velocity, vg = 1.897e+08 m/s \n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 25, page 310"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Velocity\n",
      "#given data :\n",
      "v=1.8*10**8 # in m/s\n",
      "lamda=3.6*10**-7 # in m\n",
      "dv_dlamda=3.8*10**13 # in per sec\n",
      "vg=v-(lamda*dv_dlamda) \n",
      "print \"The group velocity, vg = %0.2e m/s \" %vg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The group velocity, vg = 1.66e+08 m/s \n"
       ]
      }
     ],
     "prompt_number": 29
    }
   ],
   "metadata": {}
  }
 ]
}