{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5 : Analysis and Design of Beams for Bending"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.1, Page number 322"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum normal stress in the beam = 60.000000 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "# Reactions\n",
    "Rb=40                                                                             # Reaction at B(kN)\n",
    "Rd=14                                                                             # Reaction at D(kN)\n",
    "\n",
    "# Calculations\n",
    "# Shear and Bending-Moment Diagrams\n",
    "V1=-20                                                                            # Force(kN) \n",
    "M1=0                                                                              # Moment(kN.m)\n",
    "V2=-20                                                                            # Force(kN) \n",
    "M2=-50                                                                            # Moment(kN.m) \n",
    "V3=26                                                                             # Force(kN) \n",
    "M3=-50                                                                            # Moment(kN.m)\n",
    "V4=26                                                                             # Force(kN)\n",
    "M4=28                                                                             # Moment(kN.m)\n",
    "V5=-14                                                                            # Force(kN)  \n",
    "M5=28                                                                             # Moment(kN.m)\n",
    "V6=-14                                                                            # Force(kN)\n",
    "M6=0                                                                              # Moment(kN.m)  \n",
    "# Maximum Normal Stress\n",
    "S=(1/6.0)*(0.080)*(pow(0.250,2))                                                    # Section modulus of the beam(m**3)\n",
    "Mb=(50*pow(10,3))                                                                 # Moment(N.m)\n",
    "sM=(Mb/S)/((pow(10,6)))                                                                         # Stress(Pa)\n",
    "\n",
    "# Result\n",
    "print ('Maximum normal stress in the beam = %lf MPa' %sM)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.2, Page number 323"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum normal stress to the left of point D = 16.000000 ksi\n",
      "Maximum normal stress to the right of point D = 14.095238 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "x=symbols('x')\n",
    "V=symbols('V')\n",
    "n=-1\n",
    "\n",
    "# Calculation\n",
    "#Equivalent Loading of Beam\n",
    "#Case(a) Shear and Bending-Moment Diagrams\n",
    "#From A to C\n",
    "V=n*(3*x)                                                                   # Force(kips) \n",
    "M=n*3*(1/2)*x*x                                                             # Moment(kip.ft)\n",
    "#From C to D\n",
    "V=-24                                                                       # Force(kips) \n",
    "M=96-(24*x)                                                                 # Moment(kip.ft)\n",
    "#From D to B\n",
    "V=-34                                                                       # Force(kips)  \n",
    "M=226-(34*x)                                                                # Moment(kip.ft)\n",
    "#Case(b) Maximum Normal Stress to the Left and Right of Point D\n",
    "#To the left of D\n",
    "S=126                                                                       # Volume(in**3)  \n",
    "M=2016                                                                      # Moment(kip.in)\n",
    "Sm=(M)/S                                                                    # Stress(ksi)\n",
    "#To the right of D\n",
    "M=1776                                                                      # Moment(kip.in)\n",
    "Sm2=(M/S)                                                                   # Stress(ksi)\n",
    "\n",
    "# Result\n",
    "print ('Maximum normal stress to the left of point D = %lf ksi' %Sm)\n",
    "print ('Maximum normal stress to the right of point D = %lf ksi' %Sm2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.03, Page number 331"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum value of the bending moment :-\n",
      "0.5*l*w*x - 0.5*w*x**2\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,integrate\n",
    "\n",
    "#Variable declaration\n",
    "Ra=symbols('Ra')                                                       # Variable declaration\n",
    "Rb=symbols('Rb')                                                       # Variable declaration\n",
    "w=symbols('w')                                                         # Variable declaration\n",
    "l=symbols('l')                                                         # Variable declaration\n",
    "x=symbols('x')                                                         # Variable declaration\n",
    "Ma=0                                                                   # Bending moment \n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "Ra=(1/2.0)*(w)*(l)                                                       # Reaction at A\n",
    "V=Ra+ n*integrate(w, (x, 0, x))                                        # Shear\n",
    "M=Ma + integrate(V, (x, 0, x))                                         # Bending moment\n",
    "\n",
    "# Result\n",
    "print ('Maximum value of the bending moment :-')\n",
    "print (M)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.3, Page number 333"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bending moment at A = 0.000000 kip.ft\n",
      "Bending moment at B = 108.000000 kip.ft\n",
      "Bending moment at C = 92.000000 kip.ft\n",
      "Bending moment at D = 76.000000 kip.ft\n",
      "Bending moment at E = 60.000000 kip.ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Mb=symbols('Mb')                                                       # Variable declaration\n",
    "Mc=symbols('Mc')                                                       # Variable declaration\n",
    "Md=symbols('Md')                                                       # Variable declaration\n",
    "Me=symbols('Me')                                                       # Variable declaration\n",
    "#Reactions\n",
    "D=((12)*(28) + (12)*(14) + (20)*(6))/24.0                                # Force(kips)\n",
    "Ay=20+12-26+12                                                         # Force(kips)\n",
    "Ax=0                                                                   # Force(kips)\n",
    "#Shear Diagram\n",
    "V=18-20                                                                # Force(kips)\n",
    "#Bending-Moment Diagram\n",
    "Ma=0                                                                   # Moment(kip.ft)\n",
    "Mb=solve(Mb-108,Mb)                                                    # Moment(kip.ft)\n",
    "Mc=solve(Mc-Mb[0]+16,Mc)                                               # Moment(kip.ft) \n",
    "Md=solve(Md-Mc[0]+16,Md)                                               # Moment(kip.ft)\n",
    "Me=solve(Me-Md[0]+16,Me)                                               # Moment(kip.ft)\n",
    "Vmax=18                                                                # Force(kips)\n",
    "Mmax=108                                                               # Moment(kip.ft)\n",
    "\n",
    "# Result\n",
    "print ('Bending moment at A = %lf kip.ft' %Ma)\n",
    "print ('Bending moment at B = %lf kip.ft' %Mb[0])\n",
    "print ('Bending moment at C = %lf kip.ft' %Mc[0])\n",
    "print ('Bending moment at D = %lf kip.ft' %Md[0])\n",
    "print ('Bending moment at E = %lf kip.ft' %Me[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.4, Page number 334"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Location of maximum normal stress = 4.000000 kip.ft\n",
      "Magnitude of maximum normal stress = 125.984252 kip.ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "x=symbols('x')                                                           # Variable declaration\n",
    "Ra=80                                                                    # Reaction at A(kN)\n",
    "Rc=40                                                                    # Reaction at C(kN)\n",
    "Va=80                                                                    # Force at A(kN)\n",
    "Ma=0                                                                     # Moment at A                                                                     \n",
    "S=1270\n",
    "\n",
    "#Calculation         \n",
    "#Case(a)\n",
    "Vb=-120+80                                                               # Force at B(kN)\n",
    "Vc=Vb                                                                    # Force at C(kN)   \n",
    "x=solve(0-80+(20*x),x)                                                   \n",
    "Md=Ma+160                                                                # Bending moment at point D(kN.m)\n",
    "Mb=Md-40                                                                 # Bending moment at point B(kN.m)  \n",
    "Mc=Mb-120                                                                # Bending moment at point C(kN.m)\n",
    "sm=((Md*pow(10,3))/(S*pow(10,-6)*pow(10,6)*(1.0)))                                       # Maximum normal stress(Pa)\n",
    "\n",
    "# Result\n",
    "print ('Location of maximum normal stress = %lf kip.ft' %x[0])\n",
    "print ('Magnitude of maximum normal stress = %lf kip.ft' %sm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.7, Page number 342"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum required depth of the beam = 14.546281 in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "x=symbols('x')                                                        # Variable declaration \n",
    "Ra=80                                                                 \n",
    "Rc=40                             \n",
    "sall=1.75                                                             # Allowable stress(ksi)\n",
    "\n",
    "#Calculation         \n",
    "#Reactions.\n",
    "B=((4.5*12)+(3.2*4))/8.0                                                # Reaction at B(kips)\n",
    "Ay=7.7-8.35                                                           # Reaction at A(kips)\n",
    "A=-Ay\n",
    "#Shear Diagram\n",
    "Va=Ay                                                                 # Force at A(kips) \n",
    "Vb=Va-((400*8)/1000.0)                                                  # Force at B(kips)   \n",
    "#Determination of |M| max\n",
    "Ma=Mc=0                                                               # Moment at C\n",
    "Mmax=18                                                               # Maximum moment(kip.ft)\n",
    "\n",
    "#Minimum Allowable Section Modulus\n",
    "Smin=((Mmax*12)/sall)                                                 # Minimum allowable section modulus(in**3)\n",
    "\n",
    "\n",
    "#Minimum Required Depth of Beam\n",
    "h=math.sqrt((123.43*6)/3.5)                                           # Minimum required depth of the beam\n",
    "\n",
    "# Result\n",
    "print ('Minimum required depth of the beam = %lf in' %h)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.8, Page number 343"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We select the lightest shape available, namely W360*32.9\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "x=symbols('x')                                                          # Variable declaration\n",
    "Ra=80                                                                   # Force on rod AC(lb)\n",
    "Rc=40                                                                   # Diameter at the upper junction of rod ABC(in)\n",
    "sall=160                                                                # Normal stress for the grade of steel(MPa) \n",
    "V=0\n",
    "\n",
    "#Calculation         \n",
    "#Reactions.\n",
    "D=((50*4)+(60*1.5))/5.0                                                   # Reaction(kN)\n",
    "Ay=60+50-58                                                             # Reaction(kN)  \n",
    "\n",
    "#Shear Diagram\n",
    "Va=Ay=52                                                                # Force at A(kN)\n",
    "Vb=52-60                                                                # Force at B(kN)\n",
    "x=(52/20.0)                                                               # Distance(m)\n",
    "\n",
    "#Determination of |M| max\n",
    "Mmax=Me=67.6                                                            # Maximum bending moment(kN.m)\n",
    "\n",
    "#Minimum Allowable Section Modulus\n",
    "Smin=(Mmax/sall)*(pow(10,-6))*(pow(10,9))                               # Minimum Allowable Section Modulus(mm**3) \n",
    "\n",
    "#Selection of Wide-Flange Shape\n",
    "#W410*38.8   629\n",
    "#W360*32.9   475\n",
    "#W310*38.7   547\n",
    "#W250*44.8   531\n",
    "#W200*46.1   451\n",
    "\n",
    "#Result\n",
    "print('We select the lightest shape available, namely W360*32.9')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 5.07, Page number 362"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The plate providing the most economical design is of triangular shape.\n",
      "Maximum depth h0  = 300.000000 in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,integrate\n",
    "\n",
    "#Variable declaration\n",
    "x=symbols('x')                                                            # Variable declaration\n",
    "w=symbols('w')                                                            # Variable declaration \n",
    "b=symbols('b')                                                            # Variable declaration\n",
    "Sall=symbols('Sall')                                                      # Variable declaration \n",
    "h=symbols('h')                                                            # Variable declaration\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "# Bending Moment\n",
    "Vx=n*integrate(w,x)                                                       # Force \n",
    "Mx=n*integrate(w*x,x)                                                     # Moment\n",
    "\n",
    "\n",
    "#Case(a) Shape Of Plate\n",
    "h=(n*(6*(Mx))/(b*(Sall)))**(1/2.0)                                             # Relation between h and x\n",
    "\n",
    "#Case(b) Shape Of Plate\n",
    "h0=(((3*135)/(0.040*1000.0*72.0))**(1/2.0))*(800)                               # Maximum depth h0(mm)\n",
    "\n",
    "#Result\n",
    "print('The plate providing the most economical design is of triangular shape.')\n",
    "print('Maximum depth h0  = %lf in' %h0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.11, Page number 363"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The required number of pair of planks = 3.000000\n",
      "Length of plank 1  = 130.500000 in\n",
      "Length of plank 2  = 111.300000 in\n",
      "Length of plank 3  = 83.800000 in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "#Variable declaration\n",
    "x=symbols('x')                                                      # Variable declaration\n",
    "M=symbols('M')                                                      # Variable declaration\n",
    "b=symbols('b')                                                      # Variable declaration \n",
    "h=symbols('h')                                                      # Variable declaration\n",
    "sall=symbols('sall')                                                # Variable declaration\n",
    "Mab=4.80*x                                                          # Moment AB(kip.in) \n",
    "Mbc=4.80*x-(4.80)*(x-48)                                            # Moment BC(kip.in)\n",
    "\n",
    "\n",
    "#Calculation         \n",
    "#Number of Pairs of Planks\n",
    "h=((6*M)/(b*sall))**(1/2.0)                                         # Eq 1\n",
    "h=((6*230.4)/(4*2.40))**(1/2.0)                                     # Height(in)\n",
    "No_Pl=3                                                             # Since the original beam has a depth of 4.50 in., the planks must provide an additional depth of 7.50 in. Recalling that each pair of planks is 2.50 in. thick\n",
    "\n",
    "#Length of Planks\n",
    "h=symbols('h')                                                      # Variable declaration\n",
    "x=(((4)*(2.40))/(6.0*4.80))*(h**2)                                    # from Eq 1\n",
    "x1=round(x.subs(h,4.50),2)                                          # Distance(in)\n",
    "x2=round(x.subs(h,7.00),2)                                          # Distance(in)\n",
    "x3=round(x.subs(h,9.50),2)                                          # Distance(in)\n",
    "l1=144-2*x1                                                         # Length(in)\n",
    "l2=round((144-2*x2),1)                                              # Length(in)\n",
    "l3=round((144-2*x3),1)                                              # Length(in)\n",
    "\n",
    "#Result\n",
    "print('The required number of pair of planks = %lf' %No_Pl)\n",
    "print('Length of plank 1  = %lf in' %l1)\n",
    "print('Length of plank 2  = %lf in' %l2)\n",
    "print('Length of plank 3  = %lf in' %l3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 5.12, Page number 364"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Length of plates = 3.530000 m\n",
      "Width of plates = 267.000000 mm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve,Function\n",
    "\n",
    "#Variable declaration\n",
    "#Bending Moment\n",
    "x=symbols('x')                                                  # Variable declaration \n",
    "M=symbols('M')                                                  # Variable declaration\n",
    "I=symbols('I')                                                  # Variable declaration\n",
    "Ip=Function('Ip')                                               # Variable declaration\n",
    "M=250*x                                                         # Bending moment   \n",
    "S=(3.49*pow(10,-3))                                             # Section modulus(m**3)\n",
    "sall=160*(pow(10,3))                                            # Stress all(kN/(m**2)) \n",
    "Ib=1190*(pow(10,6))                                             # the moment of inertia Ib of the two plates with respect to the neutral axis\n",
    "d=678                                                           # Depth(mm)\n",
    "t=16                                                            # Thickness(mm)\n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Required Length of Plates\n",
    "M=round(S*sall,1)                                               # Moment(kN.m)\n",
    "x=solve(M-250*x,x)                                              # Distance(m)\n",
    "x=round(x[0],3)                                                 # Rounding\n",
    "l=round(8-(2*x),2)                                              # Length of plates(m) \n",
    "\n",
    "\n",
    "#Case(b) Required Width of Plates\n",
    "M=250*4                                                         # Maximum bending moment(kN.m)\n",
    "Ip=(((1/6.0)*b*(t**3)) + 2*b*t*(((1/2.0)*d)+((1/2)*t))**2)*(pow(10,3))# Moment of inertia\n",
    "I=Ib+Ip                                                         # Moment of inertia of beam and plates \n",
    "c=(1/2.0)*d + t                                                   # Distance from neutral axis to surface(mm)\n",
    "I=round((M*c)/(sall),3)                                         # Moment of inertia(mm**4)\n",
    "I=I*(pow(10,9))                                                 # Conversion\n",
    "b=round((I-Ib)/(3.854*(pow(10,6))),0)                           # Distance(mm)\n",
    "\n",
    "#Result\n",
    "print('Length of plates = %lf m' %l)\n",
    "print('Width of plates = %lf mm' %b)"
   ]
  }
 ],
 "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
}
