{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7: Vibrations-Fundamental Concepts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 1, Page number 271"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "force constant is 0.02 N/m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=-0.0176;       #acceleration(m/s**2)\n",
    "x=0.44;        #displacement(m)\n",
    "m=0.5;     #mass(kg)\n",
    "\n",
    "#Calculation\n",
    "omega0=math.sqrt(-a/x);       #frequency\n",
    "k=m*omega0**2;      #force constant(N/m)\n",
    "\n",
    "#Result\n",
    "print \"force constant is\",k,\"N/m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 2, Page number 271"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frequency of oscillation is 1.114 Hertz\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "g=9.8;       #acceleration(m/s**2)\n",
    "x=0.5;        #displacement(m)\n",
    "m1=5;     #mass(kg)\n",
    "m2=2;     #mass(kg)\n",
    "\n",
    "#Calculation\n",
    "k=m1*g/x;      #spring constant(N/m)\n",
    "omega=math.sqrt(k/m2)/(2*math.pi);       #frequency of oscillation(Hertz)\n",
    "\n",
    "#Result\n",
    "print \"frequency of oscillation is\",round(omega,3),\"Hertz\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 4, Page number 272"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "amplitude is 0.3 m\n",
      "frequency of oscillation is 1.0 /(2 math.pi) Hertz\n",
      "initial phase is -2 *math.pi/6 rad\n",
      "answer for initial phase given in the book is wrong\n",
      "displacement is 0.3 m\n",
      "velocity is -0.26 m/sec\n",
      "acceleration is 0.15 m/s**2\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "#given y=0.3sin(t+pi/6)\n",
    "A=0.3;     #value of amplitude by comparing with the given equation\n",
    "omega=1;     #angular freuency(rad/sec)\n",
    "theta=math.pi/6;     #angle(rad)\n",
    "t1=math.pi/3;        #time(sec)\n",
    "t2=2*math.pi/3;      #time(sec)\n",
    "t3=math.pi;          #time(sec)\n",
    "\n",
    "#Calculation\n",
    "new=omega/(2*math.pi);       #frequency of oscillation(Hertz)\n",
    "phi=theta-(math.pi/2);        #initial phase(rad)\n",
    "y=A*math.sin(theta+(math.pi/6));      #displacement(m)\n",
    "V=omega*A*math.cos((omega*t2)+theta);      #velocity(m/sec)\n",
    "a=-A*omega**2*math.sin((omega*t3)+theta);      #acceleration(m/s**2)\n",
    "\n",
    "#Result\n",
    "print \"amplitude is\",A,\"m\"\n",
    "print \"frequency of oscillation is\",new*2*math.pi,\"/(2 math.pi) Hertz\"\n",
    "print \"initial phase is\",int(phi*6/math.pi),\"*math.pi/6 rad\"\n",
    "print \"answer for initial phase given in the book is wrong\"\n",
    "print \"displacement is\",round(y,1),\"m\"\n",
    "print \"velocity is\",round(V,2),\"m/sec\"\n",
    "print \"acceleration is\",a,\"m/s**2\""
   ]
  }
 ],
 "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
}
