{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 4 : Pure Bending"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.01, Page number 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bending moment = 30.000000 kip.in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "c=1.25                                                               # Radius(in)\n",
    "Sy=36                                                                # Stress(ksi)\n",
    "b=0.8                                                                # Breadth(in)\n",
    "h=2.5                                                                # Height(in)\n",
    "\n",
    "#Calculation         \n",
    "I=(1/12.0)*(b)*(h)**3                                                  # Centroidal moment of inertia(in**4)\n",
    "M=(I/c)*(Sy)                                                         # Bending moment(kip.in)\n",
    "\n",
    "# Result\n",
    "print ('Bending moment = %lf kip.in' %M)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.02, Page number 233"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum tensile stress = 193.397171 MPa\n",
      "Maximum compressive stress = -142.602829 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "r=12                                                                     # Radius(mm)\n",
    "p=2.5                                                                    # Mean radius(m)  \n",
    "E=70                                                                     # Modulus of rigidity(GPa)\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "Y=(4*r)/(3*(math.pi))                                                    # Ordinate(mm)\n",
    "c=r-Y                                                                    # Distance from the neutral axis to the point of crossection(mm) \n",
    "Em=(c*(10**-3))/p                                                        # Maximum absolute value of the strain\n",
    "Sm=((E*(pow(10,9)))*Em)/(pow(10,6)*(1.0))                                      # Maximum tensile stress(MPa)\n",
    "Scomp=(n)*(Y/c)*(Sm)                                                     # Maximum compressive stress(MPa) \n",
    "\n",
    "# Result\n",
    "print ('Maximum tensile stress = %lf MPa' %Sm)\n",
    "print ('Maximum compressive stress = %lf MPa' %Scomp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.1, Page number 235"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bending moment M for which factor of safety is 3 = 103.760000 kip.in\n",
      "Radius of curvature of tube = 110.400000 ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "sY=40                                                                   # Stress(ksi)\n",
    "sU=60                                                                   # Stress(ksi)\n",
    "E=(10.6)*(pow(10,6))                                                    # Modulus of rigidity(psi)\n",
    "FS=3                                                                    # Factor of safety\n",
    "\n",
    "#Calculation\n",
    "#Moment of Inertia\n",
    "E=(10.6)*(pow(10,6))                                                    # Modulus of rigidity(psi)\n",
    "I=round(((1/12.0)*3.25*pow(5,3))-((1/12)*(2.75)*pow(4.5,3)),2)            # Centroidal moment of inertia of a rectangle\n",
    "#Allowable Stress\n",
    "sALL=(sU/FS)                                                            # Allowable stress(ksi)\n",
    "#Case(a) Bending Moment\n",
    "c=(1/2.0)*(5)                                                             # Radius(in)\n",
    "M=((12.97)*(20))/2.5                                                    # Bending moment(kip.in)\n",
    "#Case(b) Radius of Curvature\n",
    "p=round((10.6*pow(10,6)*12.97)/(103.8*pow(10,3)),1)                     # Radius of curvature(in)\n",
    "p=round((p*0.08333),1)                                                  # Converting into feet(ft)  \n",
    "#Alternative Solution.\n",
    "Em=(sALL/(E*(pow(10,-3))*(1.0)))                                              # Maximum strain(in./in)\n",
    "p=(c/Em)                                                                # Radius of curvature(in)\n",
    "p=round((p*0.08333),1)                                                  # Converting into feet(ft) \n",
    "\n",
    "# Result\n",
    "print ('Bending moment M for which factor of safety is 3 = %lf kip.in' %M)\n",
    "print ('Radius of curvature of tube = %lf ft' %p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.2, Page number 236"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum tensile stress = 76.036866 MPa\n",
      "Maximum compressive stress = -131.336406 MPa\n",
      "Radius of curvature = 47.740000 ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "n=-1\n",
    "\n",
    "#Calculation\n",
    "#Centroid\n",
    "sumA=3000                                                                       # Summing up the area(mm**2) \n",
    "M=3                                                                             # Couple(kN.m) \n",
    "cA=0.022                                                                        # Distance(m)                 \n",
    "Y=(114*pow(10,6))/(3000.0)                                                        # Distance(mm)\n",
    "#Centroidal Moment of Inertia\n",
    "Ix=((1/12.0)*(90)*(pow(20,3)) + (90*20*pow(12,2)) + ((1/12.0)*(30)*(pow(40,3))) + (30*40*pow(18,2)))/(pow(10,12)*(1.0)) # Centroidal moment of inertia(m**4)  \n",
    "#Case(a) Maximum Tensile Stress\n",
    "sA=((M*cA)/(Ix)*(1.0))/(1000.0)                                                          # Maximum tensile stress(MPa) \n",
    "#Maximum Compressive Stress\n",
    "sB=n*(3*0.038)/((868*pow(10,-9)*pow(10,3)))                                      # Maximum compressive stress(MPa) \n",
    "#Case(b) Radius of Curvature\n",
    "p=((165*868*(pow(10,-9)))/(3))*(pow(10,6))                                       # Radius of curvature(m)\n",
    "\n",
    "\n",
    "# Result\n",
    "print ('Maximum tensile stress = %lf MPa' %sA)\n",
    "print ('Maximum compressive stress = %lf MPa' %sB)\n",
    "print ('Radius of curvature = %lf ft' %p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.03, Page number 244"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum stress in brass portion = 11.851852 ksi\n",
      "Maximum stress in steel portion = 22.909630 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "Es=29*(pow(10,6))                                                          # Modulus of rigidity(psi)\n",
    "Eb=15*(pow(10,6))*(1.0)                                                          # Modulus of rigidity(psi) \n",
    "M=40                                                                       # Bending moment(kip.in)\n",
    "h=3                                                                        # Height(3)\n",
    "b=2.25                                                                     # Breadth(in) \n",
    "c=1.5                                                                      # Distance(in)\n",
    "\n",
    "#Calculation         \n",
    "n=Es/Eb                                                                    # Ratio\n",
    "W=0.75*n                                                                   # width(in)\n",
    "I=(1/12.0)*(b)*((h)**3)                                                      # Moment of inertia of the transformed section(in**4)\n",
    "Sm=(M*c)/(I)                                                               # Maximum stress in the transformed section(ksi)\n",
    "Sbrass=Sm                                                                  # Maximum stress in brass portion(ksi)\n",
    "Ssteel=1.933*(Sbrass)                                                      # Maximum stress in steel portion(ksi)\n",
    "\n",
    "# Result\n",
    "print ('Maximum stress in brass portion = %lf ksi' %Sbrass)\n",
    "print ('Maximum stress in steel portion = %lf ksi' %Ssteel)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.04, Page number 247"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Smallest allowable width of the groves = 10.400000 mm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "depth=10                                                                 # Depth(mm)\n",
    "width=60                                                                 # Width(mm)\n",
    "thickness=9                                                              # Thickness(mm)\n",
    "Smax=150                                                                 # Maximum stress(MPa) \n",
    "M=180                                                                    # Bending moment(N.m) \n",
    "\n",
    "#Calculation         \n",
    "d=width-(2*depth)                                                        # Distance(mm) \n",
    "c=(1/2.0)*d                                                                # Distance(mm) \n",
    "b=9                                                                      # Distance(mm)\n",
    "I=(1/12.0)*(b*(pow(10,-3)))*((d*(pow(10,3)))**3)                           # Moment of inertia of the critical cross section(m**4)\n",
    "Ratio=((M)*(c)*(pow(10,3)))/(I)                                          # Stress(MPa)\n",
    "k=150/75.0                                                                 # Factor \n",
    "Ratio2=width/(d*1.0)                                                           # Ratio\n",
    "r=0.13*40                                                                # Radius(mm)\n",
    "wid=2*r                                                                  # Width(mm)\n",
    "\n",
    "# Result\n",
    "print ('Smallest allowable width of the groves = %lf mm' %wid)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.3, Page number 248"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum stress in the wood = 4.570000 MPa\n",
      "Stress in steel = 43.800000 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "# Variable declaration\n",
    "Es=200                                                                    # Moduluss of rigidity(GPa)\n",
    "Ew=12.5                                                                   # Moduluss of rigidity(GPa) \n",
    "\n",
    "#Transformed Section.\n",
    "n=(Es/Ew)                                                                 # Ratio\n",
    "#Neutral Axis\n",
    "Y=round(((0.160)*(3.2*0.020))/(3.2*0.020+0.470*0.300),2)                  # Distance(m) \n",
    "#Centroidal Moment of Inertia\n",
    "I=round(((1/12)*0.470*(pow(0.3,3)))+(0.470*0.3*(pow(0.05,2)))+((1/12)*(3.2)*(pow(0.020,3)))+(3.2*0.020*(pow(0.160-0.050,2))),5) # Centroidal Moment of Inertia \n",
    "#Maximum Stress in Wood\n",
    "sW=((50*(pow(10,3)))*(0.200))/(2.19*pow(10,-3))                           # Maximum stress in wood(MPa)\n",
    "sW=round((sW/(pow(10,6))),2)                                              # Rounding\n",
    "#Stress in Steel\n",
    "sS=((16)*(50*(pow(10,3)))*(0.120))/(2.19*(pow(10,-3)))                    # Stress in steel(MPa) \n",
    "sS=round((sS/(pow(10,6))),1)                                              # Rounding\n",
    "\n",
    "# Result\n",
    "print ('Maximum stress in the wood = %lf MPa' %sW)\n",
    "print ('Stress in steel = %lf MPa' %sS)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.4, Page number 249"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum stress in concrete = 1.306000 MPa\n",
      "Stress in steel = 18.520000 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "# Variable declaration\n",
    "x=symbols('x')                                                            # Variable declartion                                                       \n",
    "d=(5/8.0)                                                                   # Diameter(in)\n",
    "Es=(29*(pow(10,6)))                                                       # Modulus of elasticity for concrete(psi)\n",
    "Ec=(3.6*(pow(10,6)))                                                      # Modulus of elasticity for stell(psi)\n",
    "\n",
    "# Calculation\n",
    "#Transformed Section\n",
    "As=round((2)*(math.pi)*(pow(d/2,2)),3)                                    # Cross sectional area(in**2)\n",
    "n=round(Es/Ec,2)                                                          # Ratio\n",
    "TA=round(n*As,2)                                                          # Transformed steel area(in**2)\n",
    "#Neutral Axis\n",
    "x=(solve((12*x)*(x/2.0)-(4.95)*(4-x)))\n",
    "#Moment of inertia\n",
    "I=(1/3.0)*(12)*((1.450)**3) + 4.95*(4-1.450)**2                              # Centroidal moment of inertia(in**4) \n",
    "#Maximum Stress in Concrete\n",
    "sC=round(((40)*(1.450))/(44.4),3)                                         # Maximum stress in concrete(ksi) \n",
    "#Stress in Steel\n",
    "sS=round(((8.06)*(40)*(2.55))/(44.4),2)                                   # Stress in steel(ksi)\n",
    "\n",
    "# Result\n",
    "print ('Maximum stress in concrete = %lf MPa' %sC)\n",
    "print ('Stress in steel = %lf MPa' %sS)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.05, Page number 260"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thickness of elastic core = 80.000000 mm\n",
      "Radius of curvature = 33.333333 m\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve \n",
    "\n",
    "#Variable declaration\n",
    "M=36.8\n",
    "c=60*(pow(10,-3))                                                             # Half length of rod(mm)\n",
    "b=50*(pow(10,-3))                                                             # Breadth of rod(mm)\n",
    "Sy=240                                                                        # Stress(MPa) \n",
    "yY=symbols('yY')                                                              # Variable declaration\n",
    "E=200                                                                         # Modulus of elasticity(GPa)\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "Rt=(2/3.0)*(b)*(c)**2                                                           # Ratio(m**3)\n",
    "My=Rt*Sy                                                                      # Maximum elastic moment(kN.m) \n",
    "yY=solve(36.8-(3/2.0)*(28.8)*(1-((1/3.0)*(((yY)**2)/(60**2)))),yY)                # \n",
    "# Case(b)\n",
    "Ey=(Sy*(pow(10,6)))/(E*(pow(10,9)*(1.0)))\n",
    "p=(yY[0]*(pow(10,-3)))/(Ey)\n",
    "\n",
    "# Result\n",
    "print ('Thickness of elastic core = %lf mm' %(n*(2*yY[0])))\n",
    "print ('Radius of curvature = %lf m' %(n*p))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.06, Page number 262"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Residual stress = 306.666667 MPa\n",
      "Radius of curvature after unloading = 225 m\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "M=36.8                                                                           # Bending moment(kN)                              \n",
    "Sy=240                                                                           # Yield strength(MPa)\n",
    "yY=40                                                                            # Thickness of elastic core(mm) \n",
    "n=-1\n",
    "Sx=n*35.5*(pow(10,6))                                                            # Stress(Pa)    \n",
    "E=200*(pow(10,9))\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "Sml=((36.8)/(120*(pow(10,-6))))/(1000)                                           # Residual stress(MPa) \n",
    "# Case(b)\n",
    "Ex=Sx/E                                                                          # Residual strain \n",
    "p=(n*(40*(pow(10,-3))))/(Ex)                                                     # Radius of Curvature after Unloading(m)\n",
    "\n",
    "# Result\n",
    "print ('Residual stress = %lf MPa' %Sml)\n",
    "print ('Radius of curvature after unloading = %.lf m' %p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.5, Page number 263"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Bending moment = 9525.000000 kip.in\n",
      "Case(a) Radius of curvature = 4640 in\n",
      "Case(b) Bending moment = 10226.342000 kip.in\n",
      "Case(b) Radius of curvature = 338 ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "# variable declaration\n",
    "E=(29*pow(10,6))                                                               # Modulus of elastoplasticity(psi)\n",
    "sY=50                                                                          # Stress(ksi) \n",
    "\n",
    "# Calculation\n",
    "#Case(a) Onset Of Yield\n",
    "I=round((1/12.0)*(12)*(pow(16,3))-(1/12.0)*(12-0.75)*(pow(14,3)),0)                # Centroidal moment of inertia(in**4) \n",
    "#Bending Moment\n",
    "sMAX=sY                                                                        # Stress(ksi)\n",
    "c=8.0                                                                            # Distance(in)\n",
    "My=(sY*I)/c                                                                    # Bending moment(kip.in)\n",
    "#Radius of Curvature \n",
    "Ey=sY/(E*(1.0))                                                                        # Strain\n",
    "pY=(c/Ey)/(1000.0)                                                               # Radius of curvature(in)\n",
    "#Case(b) Flanges Fully Plastic\n",
    "R1=50*12*1                                                                     # Compressive forces on top(kips) \n",
    "R4=R1                                                                          # Compressive forces on top(kips) \n",
    "R2=round((1/2.0)*(50)*(7)*(0.75)+0.05,1)                                         # Compressive forces on top half(kips)\n",
    "R3=R2                                                                          # Compressive forces on top half(kips)\n",
    "#Bending Moment\n",
    "M=2*((R1*7.5)+(R2*4.67))                                                       # Bending moment(kip.in)\n",
    "#Radius of Curvature\n",
    "p=round(((7/0.001724)*0.0833),0)                                               # Radius of curvature(ft)        \n",
    "\n",
    "# Result\n",
    "print ('Case(a) Bending moment = %lf kip.in' %My)\n",
    "print ('Case(a) Radius of curvature = %.lf in' %pY)\n",
    "print ('Case(b) Bending moment = %lf kip.in' %M)\n",
    "print ('Case(b) Radius of curvature = %.lf ft' %p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.6, Page number 264"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Plastic moment = 44.160000 kN.m\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "\n",
    "# Variable declaration\n",
    "sY=240                                                                   # Yield strength(MPa)\n",
    "A1=(0.1*0.02)                                                            # Area of cross section(m**2)\n",
    "A2=(0.02*0.02)                                                           # Area of cross section(m**2)\n",
    "A3=(0.02*0.06)                                                           # Area of cross section(m**2)\n",
    "A4=(0.06*0.02)                                                           # Area of cross section(m**2)\n",
    "\n",
    "# Calculation\n",
    "#Neutral Axis\n",
    "A=(100)*(20) + (80)*(20) + (60)*(20)                                     # Total area(mm**2)\n",
    "y=(2400-((20)*(100)))/(20)                                               # Distance(mm)\n",
    "#Plastic Moment\n",
    "R1=(A1*sY*1000)                                                          # Resultant force(kN) \n",
    "R2=(A2*sY*1000)                                                          # Resultant force(kN)\n",
    "R3=(A3*sY*1000)                                                          # Resultant force(kN) \n",
    "R4=(A4*sY*1000)                                                          # Resultant force(kN) \n",
    "\n",
    "Mp=(0.030*R1) + (0.010*R2) + (0.030*R3) + (0.070*R4)                     # Plastic moment(kN.m)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Plastic moment = %lf kN.m' %Mp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.7, Page number 265"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Residual stress = 53.700787 ksi\n",
      "Case(a) Permanent radius of curvature = 5620.000000 ft\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "# Variable declaration\n",
    "y=7                                                                                  # Distance(in)\n",
    "s=-3.01                                                                              # Stress(ksi)\n",
    "\n",
    "# Calculation\n",
    "#Loading\n",
    "M=10230                                                                              # Couple of moment(kip.in)\n",
    "#Elastic Unloading\n",
    "sMl=((10230)*(8))/(1524.0)                                                             # Maximum stress(ksi)\n",
    "#Permanent Radius of Curvature\n",
    "p=round(((7)*(29*pow(10,6))*(pow(10,-3)))/(3.01),-2)                                 # Permanent radius of curvature(in)\n",
    "p=round((p*0.083333),-1)                                                             # Conversion(ft)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Residual stress = %lf ksi' %sMl)\n",
    "print ('Case(a) Permanent radius of curvature = %lf ft' %p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.8, Page number 273"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Largest allowable force = 76.972418 kN\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "# Variable declaration\n",
    "M=symbols('M')                                                                    # Variable declaration\n",
    "P=symbols('P')                                                                    # Variable declaration\n",
    "\n",
    "# Calculation\n",
    "#Properties of Cross Section.\n",
    "A=(3*pow(10,-3))                                                                  # Area of cross section(mm**2)\n",
    "Y=0.038                                                                           # Distance(m)\n",
    "I=868*(pow(10,-9))                                                                # Moment of inertia(m**4)\n",
    "d=(0.038-0.010)                                                                   # Distance(m) \n",
    "#Force and Couple at C\n",
    "M=0.028*P                                                                         # Equivalent force-couple system\n",
    "s0=(P*(round((1/(3*pow(10,-3))),0)))                                              # Stress compression\n",
    "s1=(P*round(((0.028)*(0.022))/(868*(pow(10,-9))),0))                              # Stress tension \n",
    "s2=(P*round(((0.028)*(0.038))/(868*pow(10,-9))))                                  # Stress compression\n",
    "#Superposition\n",
    "sA=-s0+s1                                                                         # Stress tension\n",
    "sB=-s0-s2                                                                         # Stress compression\n",
    "#Largest Allowable Force\n",
    "P1=(30/377.0)*(1000)                                                                # The magnitude of P for which the tensile stress at point A is equal to the allowable tensile stress of 30 MPa is found by writing\n",
    "P2=(120/1559.0)*(1000)                                                              # Determine the magnitude of P for which the stress at B is equal to the allowable compressive stress of 120 MPa.\n",
    "\n",
    "# Result\n",
    "print ('Largest allowable force = %lf kN' %P2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.09, Page number 285"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stress at A = -2.625000 MPa\n",
      "Stress at B = -1.375000 MPa\n",
      "Stress at C = 1.625000 MPa\n",
      "Stress at D = 0.375000 MPa\n",
      "Neutral axis BG = 36.666667 mm\n",
      "Neutral axis HA = 70.000000 mm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "F=4.80                                                    # Couple(lb)\n",
    "l=80                                                      # Length(mm)\n",
    "b=120                                                     # Breadth(mm)\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "Mx=(F)*(40)                                               # Stress in x(N.m)\n",
    "Mz=(F)*(60-35)                                            # Stress in z(N.m)\n",
    "A=(0.080)*(0.120)                                         # Area of cross section(m**2)\n",
    "Ix=(1/12.0)*(0.120)*(0.080**3)                              # Centroidal moment of inertia(m**4)\n",
    "Iz=(1/12.0)*(0.080)*(0.120**3)                              # Centroidal moment of inertia(m**4)\n",
    "S0=n*(P/A)                                                # Stress(MPa) \n",
    "S1=((192)*(40))/(5.12*(pow(10,-6)))                       # Stress in x(MPa)\n",
    "S2=((120)*(60))/(11.52*(pow(10,-6)))                      # Stress in y(MPa)\n",
    "Sa=-0.5-1.5-0.625                                         # Stress at A(MPa)\n",
    "Sb=-0.5-1.5+0.625                                         # Stress at B(MPa)\n",
    "Sc=-0.5+1.5+0.625                                         # Stress at C(MPa) \n",
    "Sd=-0.5+1.5-0.625                                         # Stress at D(MPa)\n",
    "\n",
    "\n",
    "# Case(b)\n",
    "BG=((1.375)/(1.625+1.375))*80                             # Distance(mm)\n",
    "HA=((2.625)/(2.625+0.375))*80                             # Distance(mm)\n",
    "\n",
    "# Result\n",
    "print ('Stress at A = %lf MPa' %Sa)\n",
    "print ('Stress at B = %lf MPa' %Sb)\n",
    "print ('Stress at C = %lf MPa' %Sc)\n",
    "print ('Stress at D = %lf MPa' %Sd)\n",
    "print ('Neutral axis BG = %lf mm' %BG)\n",
    "print ('Neutral axis HA = %lf mm' %HA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.9, Page number 287"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Largest permissible load = 14.251781 kips\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "# Variable declaration\n",
    "P=symbols('P')\n",
    "\n",
    "\n",
    "#Properties of Cross Section\n",
    "A=7.46                                                                  # Area of cross section(in**2)\n",
    "Sx=24.7                                                                 # Section moduli x(in**3)\n",
    "Sy=2.91                                                                 # Section moduli y(in**3) \n",
    "#Force and Couple at C\n",
    "Mx=4.75*P                                                               # Moment x()\n",
    "My=1.5*P                                                                # Moment y()\n",
    "#Normal Stresses\n",
    "s1=P*round((1/7.46),4)                                                  # Normal stresses \n",
    "s2=P*round((4.75/24.7),4)                                               # Normal stresses\n",
    "s3=P*round((1.5/2.91),4)                                                # Normal stresses\n",
    "#Superposition\n",
    "sA=-s1 + s2 +s3                                                         # Stress at A \n",
    "sB=-s1+s2-s3                                                            # Stress at B\n",
    "sD=-s1-s2+s3                                                            # Stress at D\n",
    "sE=-s1-s2-s3                                                            # Stress at E\n",
    "\n",
    "P=12/0.842                                                              # Maximum compressive stress(kips) \n",
    "\n",
    "# Result\n",
    "print ('Largest permissible load = %lf kips' %P)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.10, Page number 288"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stress at point A  = 13.866727 MPa\n",
      "The angle formed by the neutral axis and the horizontal is  = 41.400000 degree\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import sin,cos\n",
    "\n",
    "# Variable declaration  \n",
    "M0=1500                                                                 # Couple of magnitude(kN)\n",
    "yA=50                                                                   # Distance() \n",
    "zA=74\n",
    "Iy=(3.25*(pow(10,-6)))                                                  # Moment of inertia(m**4)\n",
    "Iz=(4.18*(pow(10,-6)))                                                  # Moment of inertia(m**4)\n",
    "Iyz=(2.87*(pow(10,-6)))                                                 # Moment of inertia(m**4)   \n",
    "\n",
    "# Calculation\n",
    "# Principal axes\n",
    "Theta=(80.8)/2.0                                                          # Angle \n",
    "R=math.sqrt(pow(0.465,2)+pow(2.87,2))                                        # Radius\n",
    "R=2.91*(pow(10,-6))                                                     # Converting to meter\n",
    "Iu=3.72-2.91                                                            # Moment of inertia(m**4)\n",
    "Iv=3.72+2.91                                                            # Moment of inertia(m**4) \n",
    "#Loading\n",
    "Mu=(M0*sin(40.4))                                                       # Applied couple(N.m)             \n",
    "Mv=(M0*cos(40.4))                                                       # Applied couple(N.m)\n",
    "#Case(a) Stress at A\n",
    "uA=50*cos(40.4*((2*math.pi)/360.0))+74*sin(40.4*((2*math.pi)/360.0))        # Perpendicular distances(mm)\n",
    "vA=-50*sin(40.4*((2*math.pi)/360.0))+74*cos(40.4*((2*math.pi)/360.0))       # Perpendicular distances(mm)\n",
    "sA=((972*0.0239)/(0.810*(pow(10,-6))) - ((1142)*(0.0860))/(6.63*pow(10,-6)))/(pow(10,6)) # Stress at A(MPa)\n",
    "#Case(b) Neutral Axis\n",
    "phy=81.8                                                                # Angle neutral axis with the v axis(degree) \n",
    "B=81.8-40.4                                                             # Angle neutral axis with the horizontal axis(degree)\n",
    "\n",
    "# Result\n",
    "print ('Stress at point A  = %lf MPa' %sA)\n",
    "print ('The angle formed by the neutral axis and the horizontal is  = %lf degree' %B)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.10, Page number 298"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The distance e between the centroid and the neutral axis of the cross section  = 0.031381 in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import integrate,symbols,log\n",
    "\n",
    "#Variable declaration\n",
    "r=6                                                    # mean radius(in)\n",
    "b=2.5                                                  # Breadth(in) \n",
    "h=1.5                                                  # Height(in)\n",
    "n=-1\n",
    "b=symbols('b')                                         # Variable declaration\n",
    "h=symbols('h')                                         # Variable declaration\n",
    "r=symbols('r')                                         # Variable declaration\n",
    "r1=symbols('r1')                                       # Variable declaration\n",
    "r2=symbols('r2')                                       # Variable declaration\n",
    "\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "A=b*h                                                  # Area\n",
    "R=A/(integrate((1/r), (r, r1, r2)))*(b)                # Radius\n",
    "r1=6-((1/2.0)*(1.5))                                     # Inner radius(in)\n",
    "r2=6+((1/2.0)*(1.5))                                     # Outer radius(in)\n",
    "# Case(b)\n",
    "R=(1.5)/(log(r2/r1))                                   # Distance(in)\n",
    "e=6-R                                                  # Distance between the centroid and the neutral axis \n",
    "\n",
    "# Result\n",
    "print ('The distance e between the centroid and the neutral axis of the cross section  = %lf in' %e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4.11, Page number 299"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum stress = 7.860974 ksi\n",
      "Minimum stress = -9.304620 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "M=8                                                                        # Bending moment(kip.in)\n",
    "A=(2.5)*(1.5)                                                              # Area(in**2)  \n",
    "R=5.969                                                                     \n",
    "e=0.0314                                                                   # Distance(in)\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "Smax=((8)*(6.75-5.969))/((3.75)*(0.0314)*(6.75))                           # Maximum stress(ksi)  \n",
    "Smin=((8)*(5.25-5.969))/((3.75)*(0.0314)*(5.25))                           # Minimum stress(ksi)\n",
    "\n",
    "# Result\n",
    "print ('Maximum stress = %lf ksi' %Smax)\n",
    "print ('Minimum stress = %lf ksi' %Smin)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 4.11, Page number 300"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Largest force that can applied to the component = 8.550000 kN\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import integrate,symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "P=symbols('P')                                                             # Variable declaration  \n",
    "s=symbols('s')                                                             # Variable declaration\n",
    "A=symbols('A')                                                             # Variable declaration\n",
    "M=symbols('M')                                                             # Variable declaration\n",
    "R=symbols('R')                                                             # Variable declaration \n",
    "e=symbols('e')                                                             # Variable declaration\n",
    "\n",
    "# Calculation\n",
    "#Centroid of the Cross Section\n",
    "r=(120*(pow(10,3)))/(2400.0)                                                 # Distance(m) \n",
    "#Force and Couple at D\n",
    "M=((50+60)/1000.0)*P                                                         # Moment\n",
    "#Superposition\n",
    "s=-(P/A) + (M*(r-R))/(A*e*r)                                               # Total stress\n",
    "#Radius of Neutral Surface\n",
    "r=symbols('r')                                                             # Variable declaration \n",
    "R=(2400)/((integrate((80/r), (r, 30, 50)))+(integrate((20/r), (r, 50, 90))))# Radius of neutral surface(m) \n",
    "#Allowable Load\n",
    "P=solve(-(P/(2.4*pow(10,-3))) + (0.110*P*(0.030-0.04561))/(2.4*(pow(10,-3))*(0.00439)*(0.030)) + (50*pow(10,6)),P) # Allowable load(kN)\n",
    "P=round((P[0]/1000.0),2)                                                     # Rounding off(kN) \n",
    "\n",
    "# Result\n",
    "print ('Largest force that can applied to the component = %lf kN' %P)                                 "
   ]
  }
 ],
 "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
}
