{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 3 : Torsion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.01, Page number 150"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Largest permissible torque that can be applied to the shaft = 4.084070 kN\n",
      "Minimum shearing stress that can be applied to the shaft = 80.000000 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "l=1.5                                                 # length of the cylindrical shaft\n",
    "Tmax=120                                              # Maximum allowable torque\n",
    "c1=0.02                                               # Inner radius \n",
    "c2=0.03                                               # Outer radius\n",
    "\n",
    "\n",
    "\n",
    "#Calculation         \n",
    "#Case(a)\n",
    "J=(1/2.0)*(math.pi)*(c2**4-c1**4)                       # Polar moment of inertia \n",
    "c=c2                                                  # Letting c equal to c2\n",
    "T=((J*Tmax*(pow(10,6)))/(c))/(1000.0)                   # Largest Permissible Torque\n",
    "#Case(b)\n",
    "Tmin=(c1/c2)*(Tmax)                                   # Minimum Shearing Stress\n",
    "\n",
    "#Result\n",
    "print ('Largest permissible torque that can be applied to the shaft = %lf kN' %T)\n",
    "print ('Minimum shearing stress that can be applied to the shaft = %lf MPa' %Tmin)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.1, Page number 152"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum shearing stress in shaft BC = 86.229980 MPa\n",
      "Minimum shearing stress in shaft BC = 64.650000 MPa\n",
      "Required diamter of the shafts AB and CD = 78.353203 mm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "Din=90/(1000.0)                                                               # Inner diamter of shaft BC(m)                          \n",
    "Dout=120/(1000.0)                                                             # Outer diamter of shaft BC(m)\n",
    "Tab=symbols('Tab')\n",
    "Tbc=symbols('Tbc')\n",
    "\n",
    "#Calculation \n",
    "#Equations of statics\n",
    "Tab=solve(6-Tab,Tab)                                                        # Torque in the shaft AB(kN.m)\n",
    "Tbc=14+6                                                                    # Torque in the shaft BC(kN.m)\n",
    "\n",
    "#Case(a) Shaft BC\n",
    "J=((math.pi)/2.0)*((pow(Dout/2,4)-pow(Din/2,4)))                              # Polar moment of inertia(m**4)\n",
    "# Maximum Shearing Stress\n",
    "Tmax=((Tbc*(Dout/2))/(J))/(1000.0)                                            # Maximum shearing stress(MPa)\n",
    "#Minimum Shearing Stress\n",
    "Tmin=(45/60.0)*86.2                                                           # Minimum shearing stress(MPa) \n",
    "#Case(b) Shafts AB and CD\n",
    "c=((6*4)/(65*(math.pi)))**1/3                                               # Radius of the shafts(m)\n",
    "\n",
    "#Result\n",
    "print ('Maximum shearing stress in shaft BC = %lf MPa' %Tmax)  \n",
    "print ('Minimum shearing stress in shaft BC = %lf MPa' %Tmin)\n",
    "print ('Required diamter of the shafts AB and CD = %lf mm' %(c*2*1000))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.2, Page number 153"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a):Maximum torque that can be transmitted by the shaft as designed = 408.407045 kip.in\n",
      "Case(b):Maximum torque that can be transmitted by the shaft of equal weight = 210.744442 kip.in\n",
      "Case(c):Maximum torque that can be transmitted by the hollow shaft of equal weight and 8 in outer diameter = 636.000000 kip.in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "din=4                                                              # Inner diamter of shaft (in)\n",
    "dout=6                                                             # Outer diamter of shaft (in)\n",
    "STRESS=12                                                          # Shearing stress(ksi) \n",
    "\n",
    "#Calculation \n",
    "#Hollow Shaft as Designed.                                         \n",
    "J=((math.pi)/2.0)*(pow((dout/2),4)-pow((din/2),4))                   # Polar moment of inertia(in**4)\n",
    "Th=(J*STRESS)/3.0                                                     # Allowable shearing stress(kip.in)                            \n",
    "\n",
    "#Solid Shaft of Equal Weight\n",
    "rad=math.sqrt((dout/2)**2-(din/2)**2)                              # Radius of solid shaft of equal weight(in)\n",
    "Te=(12*(math.pi)*(pow(rad,3)))/2.0                                   # Maximum allowable torque(kip.in)\n",
    "\n",
    "#Hollow Shaft of 8-in. Diameter.\n",
    "c5=math.sqrt(4**2 + 2**2 -3**2)                                    # Inner radius of hallow shaft(in)\n",
    "J8=((math.pi)*(4**4-3.317**4))/2.0                                   # Polar moment of inertia(in**4) \n",
    "Tor=((212)*(12))/4.0  \n",
    "\n",
    "# Result\n",
    "print ('Case(a):Maximum torque that can be transmitted by the shaft as designed = %lf kip.in' %Th)  \n",
    "print ('Case(b):Maximum torque that can be transmitted by the shaft of equal weight = %lf kip.in' %Te)\n",
    "print ('Case(c):Maximum torque that can be transmitted by the hollow shaft of equal weight and 8 in outer diameter = %lf kip.in' %Tor)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.02, Page number 160"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum torque that can be transmitted by the shaft as designed = 1.829501 kN.m\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "G=77*(pow(10,9))                                      # Modulus of rigidity(GPa) \n",
    "L=1.5                                                 # length of the shaft(m)\n",
    "TWIST=2                                               # Allowable twist\n",
    "\n",
    "#Calculation         \n",
    "#Case(a)\n",
    "phy=(2)*((2*(math.pi))/(360))                         # Angle of twist(rad)\n",
    "#Case(b)\n",
    "J=1.021*(pow(10,-6))                                  # Polar moment of inertia(m**4)\n",
    "T=(((J*G)/(L))*(phy))/(1000)                          # Torque to be applied to the end of shaft(kN.m)\n",
    "\n",
    "# Result\n",
    "print ('Maximum torque that can be transmitted by the shaft as designed = %lf kN.m' %T)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.03, Page number 160"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum torque that can be transmitted by the shaft as designed = 3.906530 degree\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "tmin=70*(pow(10,6))                                   # Shearing stress(Pa) \n",
    "G=77*(pow(10,9))*(1.0)                                      # Modulus of rigidity(Pa)\n",
    "L=1500                                                # ength of arc AA'(mm)\n",
    "c1=20                                                 # inner radius(mm)\n",
    "\n",
    "#Calculation         \n",
    "#Case(a)\n",
    "Ymin=tmin/G                                           # shearing strain on the inner surface of the shaft\n",
    "#Case(b)\n",
    "phy=((L*Ymin)/(c1))*(360/(2*(math.pi)))               # Angle of twist(degrees)\n",
    "\n",
    "# Result\n",
    "print ('Maximum torque that can be transmitted by the shaft as designed = %lf degree' %phy)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.04, Page number 163"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Angle of rotation of end E\n",
      "5*L*T/(G*J)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "rA=symbols('rA')                                                        # Variable declaration                               \n",
    "rB=symbols('rB')                                                        # Variable declaration  \n",
    "Tad=symbols('Tad')                                                      # Variable declaration\n",
    "T=symbols('T')                                                          # Variable declaration\n",
    "L=symbols('L')                                                          # Variable declaration \n",
    "J=symbols('J')                                                          # Variable declaration\n",
    "G=symbols('G')                                                          # Variable declaration\n",
    "\n",
    "#Calculation         \n",
    "rA=2*rB                                                                 # Given relation \n",
    "Tad=2*T                                                                 # Given relation \n",
    "phya=(Tad*L)/(J*G)                                                      # Angle of rotation phyA of gear A\n",
    "phyb=(rA/rB)*(phya)                                                     # Angle of rotation phyB of gear B\n",
    "phyEB=(T*L)/(J*G)                                                       # Angle of rotation phyEB through which end E rotates with respect to end B\n",
    "phyE=phyb+phyEB                                                         # Angle of rotation of end E\n",
    "\n",
    "# Result\n",
    "print ('Angle of rotation of end E')  \n",
    "print (phyE)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.05, Page number 164"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Torque exerted on the shaft by support A. = 51.736527 lb.ft\n",
      "Torque exerted on the shaft by support B. = 38.285030 lb.ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "L=10                                                          # Outer Length(in)\n",
    "r=(7/16.0)                                                      # Outer radius(in)\n",
    "Li=5                                                          # Internal Length(in)\n",
    "ri=(5/16.0)                                                     # Inner radius(in)\n",
    "L1=5                                                          # Equivalent to internal length(in)\n",
    "L2=5                                                          # Equivalent to internal length(in)\n",
    "Ta=symbols('Ta')                                              # Torque at a\n",
    "Tb=symbols('Tb')                                              # Torque at b \n",
    "L1=symbols('L1')                                              # Length\n",
    "L2=symbols('L2')                                              # Length  \n",
    "J1=symbols('J1')                                              # polar moment of inertia\n",
    "J2=symbols('J2')                                              # polar moment of inertia\n",
    "G=symbols('G')                                                # modulus of rigidity of steel.\n",
    "\n",
    "#Calculation         \n",
    "Tb=solve(((Ta*L1)/(J1*G))-((Tb*L2)/(J2*G)),Tb)                # Internal torque\n",
    "Tb[0]=Tb[0].subs([ (J1, 57.6*(pow(10,-3))), (J2, 42.6*(pow(10,-3))),(L1, 5), (L2, 5)])  \n",
    "Ta=solve(90-Tb[0]-Ta,Ta)                                      # Internal torque(lb.ft)\n",
    "Tb=0.740*Ta[0]                                                # Internal torque(lb.ft) \n",
    "\n",
    "# Result\n",
    "print ('Torque exerted on the shaft by support A. = %lf lb.ft' %Ta[0])\n",
    "print ('Torque exerted on the shaft by support B. = %lf lb.ft' %Tb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.3, Page number 165"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Angle of twist at end A = 2.310432 degree\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "Tab=symbols('Tab')                                            # Torque on shaft AB\n",
    "Tbc=symbols('Tbc')                                            # Torque on shaft BC \n",
    "Tcd=symbols('Tcd')                                            # Torque on shaft CD \n",
    "\n",
    "#Calculation\n",
    "#Statics\n",
    "Tab=solve(250-Tab,Tab)                                        # Using the free body shown(N.m)\n",
    "Tbc=2000+250                                                  # Torque on BC(N.m)\n",
    "Tcd=Tbc                                                       # Torque on CD(N.m)\n",
    "\n",
    "#Polar Moments of Inertia\n",
    "Jab=((math.pi)*((0.015)**4))/2.0                                # Polar moment of inertia AB(m**4) \n",
    "Jbc=((math.pi)*((0.030)**4))/2.0                                # Polar moment of inertia BC(m**4)\n",
    "Jcd=((math.pi)*((0.030)**4-(0.022)**4))/2.0                     # Polar moment of inertia CD(m**4) \n",
    "\n",
    "#Angle of Twist\n",
    "AngleA=((1/77.0)*(((250*0.4)/(0.0795))+(((2250)*(0.2))/(1.272))+(((2250)*(0.6))/(0.904))))/((pow(10,-6))*(pow(10,9))*(1.0)) # Angle of twist(rad)\n",
    "AngleA=AngleA*(360/(2*math.pi))                  # convertiong radian into degree\n",
    "\n",
    "# Result\n",
    "print ('Angle of twist at end A = %lf degree' %AngleA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.4, Page number 166"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Maximum permissible torque = 561.0 lb.in\n",
      "Case(b): The corresponding angle through which end A of shaft AB rotates = 10.5 degrees\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols \n",
    "\n",
    "#Variable declaration\n",
    "T0=symbols('T0')                                          # Variable declaration\n",
    "Tab=symbols('Tab')                                        # Variable declaration  \n",
    "F=symbols('F')                                            # Force\n",
    "phyB=symbols('phyB')                                      # Variable declaration\n",
    "phyC=symbols('phyC')                                      # Variable declaration\n",
    "Smax=8000                                                 # Maximum permissible shearing stress(psi) \n",
    "cAB=0.375                                                 # Radius of shaft AB(in)\n",
    "cCD=0.5                                                   # Radius of shaft CD(in)\n",
    "rC=2.45                                                   # Radius at C(in)\n",
    "rB=0.875                                                  # Radius at B(in)  \n",
    "Tcd=symbols('Tcd')                                        # Variable declaration\n",
    "\n",
    "# Calculation\n",
    "# Statics\n",
    "T0=F *0.875                                               # Equation 1 by Submission of Mb\n",
    "Tcd=F*2.45                                                # Equation 2 by Submission of Mc\n",
    "phyB=phyC*(rC/rB)                                         # By noting that the peripheral motions of the gears are equal\n",
    "#Shaft AB\n",
    "Tab=T0                                                    # Variable declaration\n",
    "T0=round((8000)*(1/2.0)*(math.pi)*(0.375)**3)               # Largest torque that must be applied to end A of shaft AB(lb.in)               \n",
    "#Shaft CD\n",
    "T0=symbols('T0')                                          # Variable declaration\n",
    "Tcd=2.8*T0                                                # Equation \n",
    "T0=round((8000*(1/2.0)*(math.pi)*(0.5)**3)/2.8)             # Largest torque that must be applied to end C of shaft CD(lb.in)\n",
    "#Angle of Rotation at End A\n",
    "#Shaft AB\n",
    "phyAB=(((561)*(24))/((1/2.0)*(math.pi)*((0.375)**4)*(11.2*pow(10,6))))*(360/(2*math.pi)) \n",
    "#Shaft CD\n",
    "phyCD=(((561)*(36)*(2.8))/((1/2.0)*(math.pi)*((0.5)**4)*(11.2*pow(10,6))))*(360/(2*math.pi)) \n",
    "phyC=phyCD\n",
    "phyB=2.8*(phyC)\n",
    "phyA=phyB+phyAB\n",
    "\n",
    "#Result\n",
    "print('Case(a): Maximum permissible torque = %.1f lb.in' %T0)\n",
    "print('Case(b): The corresponding angle through which end A of shaft AB rotates = %.1f degrees' %phyA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.5, Page number 167"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Maximum permissible torque = 6.3 lb.in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols \n",
    "\n",
    "#Variable declaration\n",
    "T0=symbols('T0')                                                # Variable declaration\n",
    "T1=symbols('T1')                                                # Variable declaration \n",
    "T2=symbols('T2')                                                # Variable declaration \n",
    "phy1=symbols('phy1')                                            # Variable declaration\n",
    "phy2=symbols('phy2')                                            # Variable declaration\n",
    "Ts=120                                                          # Maximum allowable stress in stell(MPa)\n",
    "Ta=70                                                           # Maximum allowable stress in aluminum(MPa)\n",
    "Gs=77                                                           # Modulus of regidity for steel(GPa)        \n",
    "Ga=27                                                           # Modulus of regidity for aluminium(GPa)       \n",
    "T0=T1+T2                                                        # Equation \n",
    "phy1=phy2                                                       # Equation\n",
    "T2=T1*(77/27)*(0.614/2.003)                                     # Since both the tube and the shaft are connected to the rigid disk\n",
    "# Shearing Stresses\n",
    "T1=round(((70*pow(10,6))*(2.003*pow(10,-6)))/(0.038))           # Torque(N.m)\n",
    "T2=(0.874)*(3690)                                               # Torque(N.m)\n",
    "tsteel=((3225)*(0.025)*(pow(10,-6)))/(0.614*pow(10,-6))         # Maximum shearing stress in steel shaft(MPa) \n",
    "T2=round(((120)*pow(10,6)*(0.614*pow(10,-6)))/(0.025),-1)       # Reobtaining torque as our earlier assumption was wrong(N.m)\n",
    "T1=round(2950/0.874)                                            # Torque(N.m)   \n",
    "T0=(T1+T2)/(1000)                                               # maximum torque(N.m) \n",
    "\n",
    "#Result\n",
    "print('Case(a): Maximum permissible torque = %.1f lb.in' %T0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.06, Page number 178"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Size of shaft = 0.374342 lb.in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "P=5                                                           # Power(hp)\n",
    "f=3600                                                        # frequency(rpm) \n",
    "Tmax=8500                                                     # Maximum torque(psi)\n",
    "\n",
    "#Calculation         \n",
    "P=P*(6600)                                                    # Converting power into lb/s\n",
    "f=(3600)/(60.0)                                                 # Converting frequency into cycles per second\n",
    "T=(P)/(2*(math.pi)*f)                                         # Torque exerted on the shaft\n",
    "Ratio=T/Tmax                                                  # Here we are finding the value of J/c\n",
    "c=(((10.30)*(pow(10,-3))*(2))/(math.pi))**(1/3.0)\n",
    "d=2*c                                                         # Diameter of the shaft that should be used\n",
    "\n",
    "#Result\n",
    "print('Case(a): Size of shaft = %1f lb.in' %d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.07, Page number 178"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Tube thickness that should be used = 4.414195 lb.in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "P=100                                                         # Power(kW)\n",
    "f=20                                                          # frequency(Hz) \n",
    "c2=25                                                         # radius(mm)  \n",
    "Smax=60                                                       # Shearing stress maximum(MPa)\n",
    "c1=symbols('c1')\n",
    "\n",
    "#Calculation         \n",
    "T=P/(2*(math.pi)*f)                                           # torque exerted on the shaft\n",
    "Ratio=T/(Tmax*(pow(10,6)))                                    # Here we are finding the value of J/c2\n",
    "c1=solve((0.025)**4-(0.050/math.pi)*(13.26*(pow(10,-6)))-(c1)**4,c1) \n",
    "Thickness=c2-(c1[1]*1000)                                     # Thickness that should be used if the shearing stress is not to exceed\n",
    "\n",
    "#Result\n",
    "print('Case(a): Tube thickness that should be used = %1f lb.in' %Thickness)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.6, Page number 180"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Maximum power that can be transmitted = 890.000000 hp\n",
      "Case(b): Percentage in power = 11.000000 \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "D=7.5                                                               # Diameter of the bigger shaft(in)\n",
    "d=3.75                                                              # Diameter of the smaller shaft(in)\n",
    "r=0.5625                                                            # Inner radius(in)\n",
    "k=1.33                                                              # Stress concentration factor\n",
    "\n",
    "#Calculation \n",
    "temp1=(D/d)                                                          \n",
    "temp2=(r/d)\n",
    "T=round((1/2)*(math.pi)*((1.875)**3)*(8/1.33),1)                    # Maximum torque(ksi)   \n",
    "#Power\n",
    "f=(900/60)                                                          # Frequency(Hz)\n",
    "Pa=(2*(math.pi)*15*62.3*pow(10,3))                                  # Power(lb/s)\n",
    "Pa=round(Pa/6600)                                                   # Power(hp) \n",
    "#Final Design\n",
    "r=15/16                                                             # Radius(in) \n",
    "temp2=(0.9375/3.75)                                                 \n",
    "k=1.20                                                              # Stress concentration factor\n",
    "T=(10.35*(8/1.20))                                                  # Torque(kip.in)\n",
    "Pb=(2)*(math.pi)*(15)*(69)*(pow(10,3))                              # Power(lb/s) \n",
    "Pb=round(Pb/6600)                                                   # Power(hp)\n",
    "#Percent Change in Power\n",
    "PC=round(((Pb-Pa)/Pa)*100)\n",
    "\n",
    "#Result\n",
    "print('Case(a): Maximum power that can be transmitted = %1f hp' %Pa)\n",
    "print('Case(b): Percentage in power = %1f ' %PC)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.08, Page number 189"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Radius of elastic core = 15.749013 mm\n",
      "Case(b): Angle of twist = 8.494327 degree \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "l=1.2                                                         # length(m)\n",
    "d=50                                                          # diameter(mm) \n",
    "T=4.60                                                        # torque(kN)  \n",
    "G=77                                                          # modulus of rigidity(GPa)\n",
    "ty=150                                                        # torque(MPa)\n",
    "c=25                                                          # radius(mm)\n",
    "py=symbols('py')\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "J=(1/2)*(math.pi)*(25*(pow(10,-3)))**4                        # Polar moment of inertia(m**4) \n",
    "Ty=(J*ty*(pow(10,6)))/(c*(pow(10,-3)))                        # Torque(kN.m)\n",
    "py=solve((py/c)**3-4+((3*4.60)/(3.68)),py)                    # Radius of elastic core(mm)\n",
    "# Case(b)\n",
    "phyY=(Ty*l*(pow(10,3)))/(J*G*(pow(10,9)))                     # Angle of twist at the onset of yield(rad) \n",
    "phy=((93.4*(pow(10,-3)))/(0.630))*(360/(2*math.pi))           # Angle of twist(degree)\n",
    "\n",
    "# Result\n",
    "print('Case(a): Radius of elastic core = %1f mm' %py[0])\n",
    "print('Case(b): Angle of twist = %1f degree ' %phy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.09, Page number 190"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Permanent twist = 1.810362 degree\n",
      "Case(b): Residual stress = 187.296417 MPa \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "T=4.60*(10**3)                                                # Torque(N.m)\n",
    "L=1.2                                                         # length(m) \n",
    "G=77*(10**9)                                                  # modulus of rigidity(Pa)\n",
    "J=614*(10**-9)                                                # Polar moment of inertia(m**4)\n",
    "phy=8.50  \n",
    "c=25*(10**-3)                                                 # radius(m)\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "phyl=((T*L)/(J*G))*(360/(2*(math.pi)))                        # Lateral twist(degree)\n",
    "phyp=phy-phyl                                                 # Permanent twist(degree)\n",
    "# Case(b)\n",
    "Tlmax=((T*c)/(J))/(pow(10,6))                                 # Residual stresses(MPa) \n",
    "\n",
    "# Result\n",
    "print('Case(a): Permanent twist = %1f degree' %phyp)\n",
    "print('Case(b): Residual stress = %1f MPa ' %Tlmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## SAMPLE PROBLEM 3.7, Page number 192"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Magnitude of T when yield first occurs = 5.730000 degree\n",
      "Case(b): Angle of twist when the deformation has become fully plastic.= 8.590000 MPa \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import integrate, symbols\n",
    "\n",
    "#Variable declaration\n",
    "p=symbols('p')\n",
    "G=(11.2*pow(10,6))                                                       # Modulus of rigidity(GPa)\n",
    "ty=21                                                                    # Stress(ksi) \n",
    " \n",
    "#Calculation\n",
    "#Geometric properties\n",
    "c1=(1/2)*(1.5)                                                           # Radius(in)\n",
    "c2=(1/2)*(2.25)                                                          # Radius(in) \n",
    "J=round((1/2)*(math.pi)*(c2**4-c1**4),2)                                 # Polar moment of inertia(in**4)\n",
    "#Case(a) Onset of yield\n",
    "tmax=ty\n",
    "Ty=round(((21)*(2.02))/1.125,1)                                          # Torque at y(kip.in)\n",
    "phyY=((21*(10**3))*(60))/(1.125*11.2*pow(10,6))                          # Onset of yield(rad)\n",
    "phyY=round(phyY*(360/(2*math.pi)),2)\n",
    "#Case(b) Fully Plastic Deformation\n",
    "Tp=round(2*math.pi*21*integrate(p**2, (p, c1, c2)),1)                    # Torque(kip.in) \n",
    "phyF=round((21*pow(10,3)*60)/(0.75*11.2*pow(10,6)),4)                    # Fully plastic deformation(rad)  \n",
    "phyF=round(phyF*(360/(2*math.pi)),2)\n",
    "\n",
    "# Result\n",
    "print('Case(a): Magnitude of T when yield first occurs = %1f degree' %phyY)\n",
    "print('Case(b): Angle of twist when the deformation has become fully plastic.= %1f MPa ' %phyF)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.8, Page number 193"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Residual stress = 0.000000 kip.in\n",
      "Case(b): Permanent angle of twist= 1.890000 degree \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "Tp=44.1\n",
    "phyF=8.59\n",
    "\n",
    "# Calculation\n",
    "# Elastic Unloading\n",
    "Tmax=((44.1)*(1.125))/2.02\n",
    "Tmin=(Tmax)*(0.75/1.125)\n",
    "phyl=round(((44.1*pow(10,3)*60)*(360/(2*math.pi)))/((2.02)*(11.2*pow(10,6))),2)\n",
    "phy=phyF-phyl\n",
    "\n",
    "# Result\n",
    "print('Case(a): Residual stress = %1f kip.in' %(0))\n",
    "print('Case(b): Permanent angle of twist= %1f degree ' %(phy))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.10, Page number 202"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Shearing stress in each wall = 8.346688 ksi\n",
      "Case(b): Shearing stress in wall AB and AC= 11.128917 ksi \n",
      "Case(b): Shearing stress in wall BD and CD= 6.677350 ksi \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "t=0.160                                               # thickness(in)\n",
    "T=24                                                  # Torque(kip.in) \n",
    "\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "Area=3.84*2.34                                        # Area bounded by centre line(in**2) \n",
    "t=(T)/(2*t*Area)                                      # shearing stress in wall(ksi) \n",
    "# Case(b)\n",
    "tABAC=0.120\n",
    "tBDCD=0.200\n",
    "tAB=(T)/(2*tABAC*Area)                                # shearing stress in wall(ksi)\n",
    "tAC=tAB\n",
    "tBD=(T)/(2*tBDCD*Area)                                # shearing stress in wall(ksi)\n",
    "tCD=tBD\n",
    "\n",
    "# Result\n",
    "print('Case(a): Shearing stress in each wall = %1f ksi' %t)\n",
    "print('Case(b): Shearing stress in wall AB and AC= %1f ksi ' %tAB)\n",
    "print('Case(b): Shearing stress in wall BD and CD= %1f ksi ' %tCD)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 3.9, Page number 203"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Largest torque on bar with square cross section = 532.480000 N.m\n",
      "Largest torque on bar with rectangular cross section = 414.400000 N.m\n",
      "Largest torque on square tube = 555.000000 N.m\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Bar with Square Cross Section\n",
    "#Variable declaration\n",
    "tALL=40                                                                  # Stress(MPa)\n",
    "\n",
    "\n",
    "#Calculation\n",
    "# Bar with square cross section\n",
    "a=0.040                                                                  # Length(m) \n",
    "b=0.040                                                                  # Length(m)\n",
    "temp=(a/b)                                                                \n",
    "c1=0.208                                                                 # Coefficient\n",
    "tmax=tALL                                                                # Maximum stress(MPa)\n",
    "T1=(40)*(pow(10,6))*(0.208)*(pow(0.040,3))                                           # Torque(N.m)\n",
    "\n",
    "# Bar with Rectangular Cross Section.\n",
    "a=0.064                                                                  # Length(m)\n",
    "b=0.025                                                                  # Length(m)\n",
    "temp2=(a/b)\n",
    "T2=(40)*(pow(10,6))*(0.259)*(0.064)*(pow(0.025,2))                                   # Torque(N.m)\n",
    "\n",
    "#Square Tube\n",
    "A=(0.034)*(0.034)                                                        # Area bounded by the center line of the cross section(m**2)\n",
    "T3=round((40)*(pow(10,6))*(2)*(0.006)*(1.156)*(pow(10,-3)),0)            # Torque(N.m)\n",
    "\n",
    "# Result\n",
    "print('Largest torque on bar with square cross section = %1f N.m' %T1)\n",
    "print('Largest torque on bar with rectangular cross section = %1f N.m' %T2)\n",
    "print('Largest torque on square tube = %1f N.m' %T3)"
   ]
  }
 ],
 "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
}
