{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 11: Energy Methods"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.01, Page number 699"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Strain energy :- \n",
      "0.5*L*P**2/(A*E)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "P=symbols('P')                                                               # Force                                                                   \n",
    "L=symbols('L')                                                               # Length\n",
    "A=symbols('A')                                                               # Area  \n",
    "E=symbols('E')                                                               # Modulus of elasticity  \n",
    "n=symbols('n')                                                               # Value\n",
    "\n",
    "#Calculation         \n",
    "Un=((P**2)*((1/2.0)*L))/(2*A*E) + ((P**2)*((1/2.0)*L))/(2*(n**2)*A*E)            # Strain energy\n",
    "U1=Un.subs(n,1)                                                              # Strain energy\n",
    "\n",
    "#Result\n",
    "print('Strain energy :- ')\n",
    "print(U1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.02, Page number 700"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Strain energy :-\n",
      "0.364*P**2*l/AE\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "Fbc=symbols('Fbc')                                                              # Force\n",
    "Fbd=symbols('Fbd')                                                              # Force\n",
    "BC=symbols('BC')                                                                # Length\n",
    "BD=symbols('BD')                                                                # Length \n",
    "AE=symbols('AE')                                                                # Length\n",
    "l=symbols('l')                                                                  # Length\n",
    "P=symbols('P')                                                                  # Force\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "U=((Fbc**2)*(BC))/(2*AE)  +  ((Fbd**2)*(BD))/(2*AE)                             # Strain energy\n",
    "SE=U.subs([(BC, (0.6*l)),(BD, (0.8*l)),(Fbc, (0.6*P)),(Fbd, (0.8*P))])          # Strain energy\n",
    "\n",
    "#Result\n",
    "print('Strain energy :-')\n",
    "print(SE)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.03, Page number 701"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Strain energy :- \n",
      "P**2*l**3/(6*E*I)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import integrate, symbols\n",
    "\n",
    "#Variable declaration\n",
    "P=symbols('P')                                                          # Force\n",
    "x=symbols('x')                                                          # Distance \n",
    "E=symbols('E')                                                          # Modulus of elasticity\n",
    "I=symbols('I')                                                          # Moment of inertia \n",
    "l=symbols('l')                                                          # Value                                                         \n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "U=integrate((((P**2)*(x**2))/(2*E*I)),(x,0,l))                            # Strain energy\n",
    "\n",
    "#Result\n",
    "print('Strain energy :- ')\n",
    "print(U)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.04, Page number 702"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Strain energy :- \n",
      "0.5*L*T**2/(G*j)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "T=symbols('T')                                                                     # Twisting couple\n",
    "L=symbols('L')                                                                     # Length\n",
    "G=symbols('G')                                                                     # Modulus of elasticity\n",
    "j=symbols('j')                                                                     # Polar moment of inertia\n",
    "n=symbols('n')                                                                     # Value \n",
    "\n",
    "#Calculation         \n",
    "Un=((T**2)*((1/2.0)*L))/(2*G*j) + ((T**2)*((1/2.0)*L))/(2*(n**4)*G*j)                  # Strain energy\n",
    "U1=Un.subs(n,1)                                                                       # Strain energy\n",
    "\n",
    "#Result\n",
    "print('Strain energy :- ')\n",
    "print(U1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 11.1, Page number 707"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Yield strength of steel :-\n",
      "36.2049720342386\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "E=29*(pow(10,6))                                                         # Elastic strain energy(psi)                           \n",
    "A=((math.pi)/4.0)*(pow(0.75,2))                                            # Area of cross section(in**2)\n",
    "L=60                                                                     # Length(in)\n",
    "Sy=symbols('Sy')                                                         # Stress\n",
    "\n",
    "#Calculation         \n",
    "#Factor Of Safety\n",
    "U=5*120                                                                  # Strain energy(in.lb)\n",
    "#Strain-Energy Density \n",
    "V=A*L                                                                    # Volume(in**3)\n",
    "u=(U/V)                                                                  # Strain energy density(in.lb/in**3)\n",
    "#Yield Strength\n",
    "Sy=solve(Sy**2/(2.0*29.0*pow(10.0,6))-22.6,Sy)                                    # Maximum stress(ksi)\n",
    "\n",
    "#Result\n",
    "print('Yield strength of steel :-')\n",
    "print(Sy[1]/1000) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 11.2, Page number 708"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Strain energy :-\n",
      "0.166666666666667*P**2*a**2*b**2*(a + b)/(E*I*L**2)\n",
      "Case(b): Evaluated Strain energy = 0.000025 psi \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import integrate,symbols\n",
    "\n",
    "#Variable declaration\n",
    "P=40                                                                         # Force(kips)\n",
    "L=12                                                                         # Length(ft)\n",
    "a=3                                                                          # Length(ft)\n",
    "b=9                                                                          # Length(ft)\n",
    "E=29*(pow(10,6))                                                             # Modulus of elasticity(psi)  \n",
    "P=symbols('P')                                                               # Force\n",
    "b=symbols('b')                                                               # Length  \n",
    "L=symbols('L')                                                               # Length\n",
    "P=symbols('P')                                                               # Force\n",
    "a=symbols('a')                                                               # Length \n",
    "x=symbols('x')                                                               # Length\n",
    "v=symbols('v')                                                               # Length\n",
    "E=symbols('E')                                                               # Modulus of elasticity\n",
    "I=symbols('I')                                                               # Moment of inertia\n",
    "\n",
    "#Calculation         \n",
    "#Bending Moment\n",
    "Ra=(P*b)/L                                                                   # Reaction\n",
    "Rb=(P*a)/L                                                                   # Reaction\n",
    "\n",
    "M1=((P*b)/L)*x                                                               # Bending moment\n",
    "M2=((P*a)/L)*v                                                               # Bending moment\n",
    "\n",
    "# Case(a) Bending Moment\n",
    "U=(1/(2.0*E*I))*(integrate(M1**2,(x,0,a))+integrate(M2**2,(v,0,b)))            # Total strain energy\n",
    "\n",
    "# Case(b) Evaluation of the Strain Energy\n",
    "P=40                                                                         # Central axial load(kips)\n",
    "a=36                                                                         # Length(in)\n",
    "L=144                                                                        # Length(in) \n",
    "b=108                                                                        # Length(in)\n",
    "I=248                                                                        # Moment of inertia(in**4)\n",
    "U=U.simplify()\n",
    "Usubs=(40*36*108)/(6.0*29*248*144*(pow(10,3)))                                 # Strain energy\n",
    "\n",
    "#Result\n",
    "print('Case(a): Strain energy :-')\n",
    "print(U)\n",
    "print('Case(b): Evaluated Strain energy = %lf psi '%Usubs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.06, Page number 717"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum value of stress in rod :-\n",
      "1.0*(Pm**2)**0.5/A\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "Pm=symbols('Pm')                                                                       # Force\n",
    "L=symbols('L')                                                                         # Length \n",
    "E=symbols('E')                                                                         # Modulus of elasticity\n",
    "A=symbols('A')                                                                         # Area\n",
    "m=symbols('m')                                                                         # Mass \n",
    "v0=symbols('v0')                                                                       # Velocity\n",
    "\n",
    "#Calculation         \n",
    "Um=(5*(Pm**2)*(L))/(16.0*A*E)                                                            # Strain energy\n",
    "Pm=((16/5.0)*((Um*A*E)/(L)))**(1/2.0)                                                      # Force\n",
    "Sm=Pm/A                                                                                # Stress \n",
    "\n",
    "#Result\n",
    "print('Maximum value of stress in rod :-')\n",
    "print(Sm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.07, Page number 717"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum stress in the beam :-\n",
      "L*c*(Pm**2)**0.5/I\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "Pm=symbols('Pm')                                                            # Force\n",
    "L=symbols('L')                                                              # Length\n",
    "E=symbols('E')                                                              # Modulus of elasticity\n",
    "I=symbols('I')                                                              # Moment of inertia  \n",
    "m=symbols('m')                                                              # Mass\n",
    "v0=symbols('v0')                                                            # Velocity\n",
    "Lc=symbols('Lc')                                                            # Length\n",
    "W=symbols('W')                                                              # Work \n",
    "h=symbols('h')                                                              # Height\n",
    "c=symbols('c')                                                              # Radius \n",
    "\n",
    "#Calculation         \n",
    "Um=((Pm**2)*(L**3))/(6.0*E*I)                                                 # Strain energy\n",
    "Pm=((6)*((Um*E*I)/(L**3)))**(1/2.0)                                           # Static force\n",
    "Sm=(Pm*L*c)/(I)                                                             # Maximum stress \n",
    "\n",
    "#Result\n",
    "print('Maximum stress in the beam :-')\n",
    "print(Sm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.08, Page number 721"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Equivalent static load :-\n",
      "48**0.5*(E*I*m*v0**2/L**3)**0.5\n",
      "Case(b): Maximum stress :-\n",
      "3**0.5*(E*c**2*m*v0**2/(I*L))**0.5\n",
      "Case(c): Maximum deflection :-\n",
      "48**0.5*L**3*(E*I*m*v0**2/L**3)**0.5/(48*E*I)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "Pm=symbols('Pm')                                                               # Force\n",
    "L=symbols('L')                                                                 # Length \n",
    "E=symbols('E')                                                                 # Modulus of elasticity\n",
    "I=symbols('I')                                                                 # Moment of inertia\n",
    "m=symbols('m')                                                                 # Mass\n",
    "v0=symbols('v0')                                                               # Velocity\n",
    "Lc=symbols('Lc')                                                               # Length                                                               \n",
    "h=symbols('h')                                                                 # Height\n",
    "c=symbols('c')                                                                 # Length\n",
    "xm=symbols('xm')                                                               # Distance\n",
    "\n",
    "#Calculation         \n",
    "Um=(1/2.0)*(m)*(v0**2)                                                           # Strain energy\n",
    "Um=(1/2.0)*(Pm)*(xm)                                                             # Expressing Um as the work of the equivalent horizontal static load\n",
    "xm=((Pm)*(L**3))/(48.0*E*I)                                                      # Deflection of c corresponding to static load Pm  \n",
    "Um=(((Pm**2)*(L**3))/(48.0*E*I))*(1/2.0)                                           # Substituting xm in strain energy\n",
    "Pm=((48.0*m*(v0**2)*(E)*I)/(L**3))**(1/2.0)                                        # Static load\n",
    "Sm=(Pm*Lc)/(4.0*I)                                                               # Maximum stress\n",
    "Sm=((3*m*(v0**2)*(E)*I)/(L*(I/c)**2))**(1/2.0)                                   # Maximum stress after sustituting for Pm\n",
    "xm=Pm*((L**3)/(48.0*E*I))                                                        # Maximum deflection\n",
    "\n",
    "#Result\n",
    "print('Case(a): Equivalent static load :-')\n",
    "print(Pm)\n",
    "print('Case(b): Maximum stress :-')\n",
    "print(Sm)\n",
    "print('Case(c): Maximum deflection :-')\n",
    "print(xm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.09, Page number 723"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Vertical deflection of B :-\n",
      "[0.728*L*P/(A*E)]\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Pm=symbols('Pm')                                                                      # Force\n",
    "L=symbols('L')                                                                        # Length \n",
    "E=symbols('E')                                                                        # Modulus of elasticity \n",
    "A=symbols('A')                                                                        # Area of crosssection\n",
    "m=symbols('m')                                                                        # Mass  \n",
    "v0=symbols('v0')                                                                      # Velocity \n",
    "P=symbols('P')                                                                        # Force\n",
    "yb=symbols('yb')                                                                      # Distance\n",
    "\n",
    "#Calculation         \n",
    "yb=solve(0.364*(((P**2.0)*L)/(A*E))-(1/2.0)*P*yb,yb)\n",
    "\n",
    "#Result\n",
    "print('Vertical deflection of B :-')\n",
    "print(yb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.10, Page number 723"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deflection of end A taking into account of normal stress only:-\n",
      "[0.333333333333333*L**3*P/(E*I)]\n",
      "Deflection of end A taking into account of both the normal and shearing stresses.:-\n",
      "[0.0333333333333333*L*P**2*(3.0*E*h**2 + 10.0*G*L**2)/(E*G*I)]\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Pm=symbols('Pm')                                                                      # Force  \n",
    "L=symbols('L')                                                                        # Length\n",
    "E=symbols('E')                                                                        # Modulus of elasticity\n",
    "I=symbols('I')                                                                        # Moment of inertia \n",
    "m=symbols('m')                                                                        # Mass\n",
    "P=symbols('P')                                                                        # Force\n",
    "yA=symbols('yA')                                                                      # Distance\n",
    "h=symbols('h')                                                                        # Height\n",
    "G=symbols('G')                                                                        # Modulus of elasticity \n",
    "\n",
    "#Calculation         \n",
    "yA1=solve((((P**2)*(L**3))/(6.0*E*I))-(1/2.0)*P*yA,yA)                                      # Deflection of end A  \n",
    "yA2=solve((((P**3)*(L**3))/(6.0*E*I))*(1+(3*E*(h**2))/(10.0*(G)*(L**2)))-(1/2.0)*(P)*(yA),yA) # Deflection of end A\n",
    "\n",
    "#Result\n",
    "print('Deflection of end A taking into account of normal stress only:-')\n",
    "print(yA1)\n",
    "print('Deflection of end A taking into account of both the normal and shearing stresses.:-')\n",
    "print(yA2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.11, Page number 724"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Angle of twist for entire shaft:-\n",
      "[0.53125*L*T/(G*J)]\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Pm=symbols('Pm')                                                                  # Force\n",
    "L=symbols('L')                                                                    # Length\n",
    "E=symbols('E')                                                                    # Modulus of elasticity\n",
    "I=symbols('I')                                                                    # Moment of inertia\n",
    "m=symbols('m')                                                                    # Mass\n",
    "P=symbols('P')                                                                    # Force\n",
    "yA=symbols('yA')                                                                  # Distance  \n",
    "h=symbols('h')                                                                    # Height\n",
    "G=symbols('G')                                                                    # Modulus of rigidity                                                   \n",
    "T=symbols('T')                                                                    # Torque\n",
    "J=symbols('J')                                                                    # Polar moment of inertia \n",
    "phyDB=symbols('phyDB')                                                            # Angle of twist\n",
    "\n",
    "#Calculation         \n",
    "phyDB=solve((17/32.0)*(T**2)*(L)*(1/(2.0*G*J))-(1/2.0)*(T)*(phyDB),phyDB)               # Angle of twist\n",
    "\n",
    "#Result\n",
    "print('Angle of twist for entire shaft:-')\n",
    "print(phyDB)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 11.3, Page number 725 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum deflection of point C:-\n",
      "10.2734993791682\n",
      "Maximum stress:-\n",
      "179.9296875\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "ym=symbols('ym')                                                         # Distance\n",
    "E=symbols('E')                                                           # Modulus of elasticity\n",
    "I=symbols('I')                                                           # Moment of inertia\n",
    "L=symbols('L')                                                           # Length\n",
    "W=symbols('W')                                                           # Weight  \n",
    "h=symbols('h')                                                           # Height\n",
    "\n",
    "#Calculation         \n",
    "#Principle of Work and Energy\n",
    "Pm=(48*E*I)/(L**3.0)                                                       # Force                                                      \n",
    "U2=(1/2.0)*Pm*ym                                                           # Strain energy\n",
    "Eq=U2-(W*(h+ym))                                                         # Equation\n",
    "\n",
    "#Case(a) Maximum Deflection of Point C\n",
    "E=73*(pow(10,9))                                                         # Modulus of elasticity(Pa) \n",
    "I=(1/12.0)*((0.04)**4)                                                     # Moment of inertia(m**4)  \n",
    "L=1                                                                      # Length(m)\n",
    "h=0.040                                                                  # Height(m)\n",
    "W=80*9.81                                                                # Force(N) \n",
    "ym=solve(373.8*(pow(10,3))*(ym**2)-(784.8)*ym-31.39,ym)                  # Distance(mm)\n",
    "\n",
    "\n",
    "#Case(b) Maximum Stress\n",
    "Pm=48*(15.573*(pow(10,3)))*(0.01027)                                     # Force(N)\n",
    "Sm=(((1/4.0)*(7677)*(0.020))/((1/12.0)*pow(0.040,4)))/(1000000.0)              # Stress(MPa)\n",
    "\n",
    "#Result\n",
    "print('Maximum deflection of point C:-')\n",
    "print(ym[1]*1000)\n",
    "print('Maximum stress:-')\n",
    "print(Sm)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
