{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Chapter 2 : Stress and Strain—Axial Loading"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.01, Page number 69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deformation of the steel rod = 0.000000 in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "E=29*(pow(10,6))                                                   # Modulus of elasticity(psi)                        \n",
    "L1=12                                                              # Length(in) \n",
    "L2=12                                                              # Length(in)\n",
    "L3=16                                                              # Length(in)\n",
    "A1=0.9                                                             # Area(in**2) \n",
    "A2=0.9                                                             # Area(in**2)\n",
    "A3=0.3                                                             # Area(in**2) \n",
    "P1=60*(pow(10,3))                                                  # Internal force(lb)\n",
    "P2=15*(pow(10,3))                                                  # Internal force(lb)\n",
    "P3=30*(pow(10,3))                                                  # Internal force(lb)\n",
    "\n",
    "#Calculation         \n",
    "Delta=round((1/E)*(((P1*L1)/A1)+(-(P2*L2)/A2)+((P3*L3)/A3)),4)     # deformation of the steel rod(in)\n",
    "\n",
    "#Result\n",
    "print ('Deformation of the steel rod = %lf in' %Delta)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 2.1, Page number 70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Deflection of B = -0.514286 psi\n",
      "Case(b): Deflection of D = 0.300000 psi\n",
      "Case(c): Deflection of E = 1.928223 psi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Eab=70*(pow(10,9))                                                 # Modulus of elasticity of AB(GPa)  \n",
    "Aab=500*(pow(10,-6))                                               # Cross sectional area of AB(mm**2) \n",
    "Ecd=200*(pow(10,9))                                                # Modulus of elasticity of CD(GPa)\n",
    "Acd=600*(pow(10,-6))                                               # Cross sectional area of CD(mm**2) \n",
    "Fe=30                                                              # Force(kN) \n",
    "Pb=-60*(pow(10,3))                                                 # Internal force in link AB(kN)\n",
    "n=-1\n",
    "Pd=90*(pow(10,3))                                                  # Internal force in link CD(kN)\n",
    "Lab=0.3                                                            # Length of AB(m)\n",
    "Lcd=0.4                                                            # Length of CD(m)\n",
    "x=symbols('x')                                                     # Variable declaration \n",
    "Se=symbols('Se')                                                   # Variable declaration\n",
    "\n",
    "#Calculation         \n",
    "#Free Body: Bar BDE\n",
    "Fcd=(30*0.6)/(0.2)                                                 # Force of tension(kN)\n",
    "Fab=n*(30*0.4)/(0.2)                                               # Force of compression(kN)\n",
    "\n",
    "#Case(a)\n",
    "#Deflection of B.\n",
    "Sb=((Pb*Lab)/(Aab*Eab))*(1000)                                              # Deflection of B(mm)\n",
    "\n",
    "#Case(b)\n",
    "#Deflection of D.\n",
    "Sd=((Pd*Lcd)/(Acd*Ecd))*(1000)                                              # Deflection of D(mm)\n",
    "\n",
    "#Case(c)\n",
    "#Deflection of E.\n",
    "x=solve(((200-x)/x)-((0.514)/(0.300)),x)                           # Distance HD(mm)\n",
    "Se=solve(((400+73.7)/73.7)-(Se/0.300),Se)                          # Deflection of E(mm)\n",
    "\n",
    "#Result\n",
    "print('Case(a): Deflection of B = %1f psi' %Sb)\n",
    "print('Case(b): Deflection of D = %lf psi' %Sd)\n",
    "print('Case(c): Deflection of E = %lf psi' %Se[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## SAMPLE PROBLEM 2.2, Page number 71"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stress in rod = 10.533169 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Lb=18                                                        # Length of Bolt CD(in)\n",
    "Pb=symbols('Pb')                                             # Force(kips)\n",
    "Ab=((1/4.0)*(math.pi)*pow(0.75,2))                             # Area of cross section of CD and GH(in**2)                                                \n",
    "Eb=(29*(pow(10,6)))                                          # Modulus of elasticity of steel(psi)\n",
    "Lr=12                                                        # Length of Bolt EF(in)\n",
    "Pr=symbols('Pr')                                             # Force(kips)\n",
    "Ar=((1/4.0)*(math.pi)*pow(1.5,2))                              # Area of cross section of EF(in**2)                             \n",
    "Er=((10.6)*(pow(10,6)))                                      # Modulus of elasticity of aluminium(psi)\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "# Bolts CD and GH\n",
    "Sb=((Pb*Lb)/(Ab*Eb))                                         # Deformation        \n",
    "\n",
    "# Rod EF\n",
    "Sr=n*((Pr*Lr)/(Ar*Er))                                       # Deformation\n",
    "\n",
    "# Displacement of D Relative to B\n",
    "Eq=(1/4.0)*(0.1)-Sb+Sr                                         # Because displacements are equal to the deformations of the bolts and of the rod\n",
    "\n",
    "# Free Body: Casting B\n",
    "#Pr-2*Pb=0                                                   # Submission of forces is zero\n",
    "\n",
    "# Forces in Bolts and Rod\n",
    "Pb=(solve((Eq).subs(Pr,(2*Pb)))[0])/(1000.0)                   # Force in the bolt(kips)                                     \n",
    "Pr=2*Pb                                                      # Force in th rod(kips) \n",
    "\n",
    "# Stress in Rod\n",
    "er=Pr/Ar                                                     # Stress in rod(ksi)\n",
    "\n",
    "\n",
    "#Result\n",
    "print('Stress in rod = %1f ksi' %er)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.02, Page number 78"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deformation in the rod :-\n",
      "L*P/(A1*E1 + A2*E2)\n",
      "Deformation in the tube :-\n",
      "L*P/(A1*E1 + A2*E2)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "P1=symbols('P1')                                            # Axial force \n",
    "L=symbols('L')                                              # Length of rod\n",
    "A1=symbols('A1')                                            # Cross section of rod\n",
    "E1=symbols('E1')                                            # Modulus of elasticity\n",
    "P2=symbols('P2')                                            # Axial force\n",
    "A2=symbols('A2')                                            # Cross section of rod\n",
    "E2=symbols('E2')                                            # Modulus of elasticity     \n",
    "P=symbols('P')                                              # Total axial force \n",
    "\n",
    "\n",
    "#Calculation         \n",
    "S1=(P1*L)/(A1*E1)                                           # Deforamation in rod \n",
    "S2=(P2*L)/(A2*E2)                                           # Deformation in rod\n",
    "\n",
    "P1=((P2)/(A2*E2))*(A1*E1)                                   # Equating deformations S1 and S2 \n",
    "\n",
    "P2=solve(P1-P+P2,P2)                                        # Solving the above equation for P2\n",
    "P1=((P2[0]/(A2*E2))*(A1*E1))                                # Solving for P1  \n",
    "S1=(P1*L)/(A1*E1)\n",
    "S2=(P2[0]*L)/(A2*E2)\n",
    "\n",
    "#Result\n",
    "print(\"Deformation in the rod :-\")\n",
    "print(S1)\n",
    "print(\"Deformation in the tube :-\")\n",
    "print(S2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.03, Page number 79"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stress in AC :-\n",
      "L1*P1/(A*E)\n",
      "Stress in BC :-\n",
      "L2*P2/(A*E)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "Ra=symbols('Ra')                                                # Reaction at A\n",
    "Rb=symbols('Rb')                                                # Reaction at B\n",
    "P=symbols('P')                                                  # Net reaction \n",
    "S=symbols('S')                                                  # Total elongation\n",
    "S1=symbols('S1')                                                # Elongation of AC\n",
    "S2=symbols('S2')                                                # Elongation of BC\n",
    "L1=symbols('L1')                                                # Length of AC\n",
    "L2=symbols('L2')                                                # Length of BC\n",
    "P1=symbols('P1')                                                # Internal force   \n",
    "P2=symbols('P2')                                                # Internal force\n",
    "A=symbols('A')                                                  # Area of cross section\n",
    "E=symbols('E')                                                  # Modulus of elasticity \n",
    "\n",
    "\n",
    "#Calculation         \n",
    "S1=(P1*L1)/(A*E)                                                # Elongation of AC                                               \n",
    "S2=(P2*L2)/(A*E)                                                # Elongation of BC\n",
    "S=S1+S2                                                         # Total elongation of the bar \n",
    "S=0                                                             # Total elongation of the bar is zero  \n",
    "\n",
    "x=solve((Ra*L1-Rb*L2, Ra+Rb-P), Ra, Rb)                         # Solving the equations to find reactions at A and B. \n",
    "\n",
    "e1=(x[Ra])/A                                                    # Stress in AC\n",
    "e2=(x[Rb])/A                                                    # Stress in BC\n",
    "\n",
    "#Result\n",
    "print(\"Stress in AC :-\")\n",
    "print(S1)\n",
    "print(\"Stress in BC :-\")\n",
    "print(S2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.04, Page number 80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reaction at A = 577823.076923\n",
      "Reaction at B = 576923.076923\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "P1=0                                                                # Force in the first portion(N)       \n",
    "P2=600*(pow(10,3))                                                  # Force in the second portion(N)\n",
    "P3=600*(pow(10,3))                                                  # Force in the third portion(N)\n",
    "P4=900*(pow(10,3))                                                  # Force in the forth portion(N)   \n",
    "E=symbols('E')                                                      # Modulus of elasticity\n",
    "Rb=symbols('Rb')                                                    # Reaction at B(N) \n",
    "n=-1\n",
    "\n",
    "A1=400*(pow(10,-6))                                                 # Area of cross section of first portion(m**2)\n",
    "A2=400*(pow(10,-6))                                                 # Area of cross section of second portion(m**2)   \n",
    "A3=250*(pow(10,-6))                                                 # Area of cross section of third portion(m**2)\n",
    "A4=250*(pow(10,-6))                                                 # Area of cross section of forth portion(m**2)\n",
    "\n",
    "L1=0.150                                                            # Length of first portion(m) \n",
    "L2=0.150                                                            # Length of second portion(m)\n",
    "L3=0.150                                                            # Length of third portion(m)\n",
    "L4=0.150                                                            # Length of forth portion(m)\n",
    "\n",
    "#Calculation         \n",
    "Sl=((600*(pow(10,3)))/(400*(pow(10,-6))) + (600*(pow(10,3)))/(250*(pow(10,-6))) + (900*(pow(10,3)))/(250*(pow(10,-6))))*(0.150/E)        # Deformation(m)   \n",
    "P1=n*Rb                                                             # Force on first portion(N)  \n",
    "P2=n*Rb                                                             # Force on second portion(N) \n",
    "A1=400*(pow(10,-6))                                                 # Area of cross section of first portion(m**2)\n",
    "A2=250*(pow(10,-6))                                                 # Area of cross section of second portion(m**2)\n",
    "L1=0.300                                                            # Length of first portion(m) \n",
    "L2=0.300                                                            # Length of second portion(m)\n",
    "\n",
    "Sr=(P1*L1)/(A1*E) + (P2*L2)/(A2*E)                                  # Deformation(m)\n",
    "\n",
    "Rb=solve(Sl+Sr,Rb)                                                  # Reaction at B(N)\n",
    "\n",
    "Ra=900+(Rb[0])                                                      # Reaction at A(N)    \n",
    "\n",
    "#Result\n",
    "print('Reaction at A = %lf' %Ra)\n",
    "print('Reaction at B = %lf' %Rb[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.05, Page number 81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reaction at A = 784.615385\n",
      "Reaction at B = 115.384615\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "E=200*(pow(10,9))                                                   # Modulus of elasticity(GPa)\n",
    "Rb=symbols('Rb')                                                    # Reaction at B(N) \n",
    "Ra=symbols('Ra')                                                    # Reaction at A(N)\n",
    "#Calculation         \n",
    "Rb=(solve(((1.125*(pow(10,9)))/(200*(pow(10,9))))-(((1.95*(pow(10,3)))*Rb)/(200*(pow(10,9))))-(4.5*(pow(10,-3))),Rb))[0]/(10**3) # Solving for Rb(N)\n",
    "Ra=solve(Ra-900+Rb,Ra)                                              # Solving for Ra(N)   \n",
    "\n",
    "#Result\n",
    "print('Reaction at A = %lf' %Ra[0])\n",
    "print('Reaction at B = %lf' %Rb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.06, Page number 84"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stress in portion AC = 31.416667\n",
      "Stress in portion CB = 15.708333\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "E=29*(pow(10,6))*(1.0)                                                           # Modulus of elasticity(psi)\n",
    "Alpha=6.5*(pow(10,-6))                                                     # Constant(/F)\n",
    "n=-1\n",
    "L1=12                                                                      # Length of AC(m)\n",
    "L2=12                                                                      # Length of CB(m)\n",
    "A1=0.6                                                                     # Area of cross section of AC(m**2)\n",
    "A2=1.2                                                                     # Area of cross section of BC(m**2) \n",
    "Rb=symbols('Rb')                                                           # Reaction at B(N)\n",
    "P1=Rb                                                                      # Internal force(N)\n",
    "P2=Rb                                                                      # Internal force(N)\n",
    "DELTAt=n*(50+75)                                                           # Diff in temperature(F)\n",
    "AC=12                                                                      # Length of AC(m)\n",
    "CB=12                                                                      # Length of CB(m)\n",
    "\n",
    "#Calculation\n",
    "St=Alpha*DELTAt*24                                                         # Deformation(in)\n",
    "Sr=((P1*L1)/(A1*E)) +  ((P2*L2)/(A2*E))                                    # Deformation(in)\n",
    "\n",
    "Rb=(solve(St+Sr,Rb))[0]/(1000.0)                                             # Reaction at B(kips) \n",
    "S1=(Rb)/A1                                                                 # Stress in portion AC(ksi)\n",
    "S2=(Rb)/A2                                                                 # Stress in portion CB(ksi)\n",
    "\n",
    "Et=Alpha*DELTAt                                                            # Thermal strain(in./in.) \n",
    "Ratio=S1/E                                                                 # Other component of eAC(in./in.)\n",
    "Eac=Et + S1/E                                                              # Component of strain in AC(in)\n",
    "Ecb=Et + S2/E                                                              # Component of strain in CB(in) \n",
    "\n",
    "Sac=Eac*(AC)                                                               # Deformation of rod AC(in)\n",
    "Scb=Ecb*(CB)                                                               # Deformation of rod CB(in)\n",
    "\n",
    "#Result\n",
    "print('Stress in portion AC = %lf' %S1)\n",
    "print('Stress in portion CB = %lf' %S2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 2.3, Page number 86"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a): Force in rod DF = 7.5 psi\n",
      "Case(a): Force in rod CE = 2.497916 psi\n",
      "Case(b): Deflection of point A = 0.043249 psi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "Ldf=30                                                                 # Length of DF(in)\n",
    "Adf=(1/4.0)*(math.pi)*(3/4.0)*(3/4.0)                                        # Cross sectional area of DF(in**2) \n",
    "Lce=24                                                                 # Length of CE(in)\n",
    "Ace=(1/4.0)*(math.pi)*(1/2.0)*(1/2.0)                                        # Cross sectional area of DF(in**2) \n",
    "E=(10.6*pow(10,6))                                                     # Molulus of elasticity(psi)\n",
    "Fce=symbols('Fce')                                                     # Force on CE(N)  \n",
    "Fdf=symbols('Fdf')                                                     # Force on DF(N)\n",
    "Sd=symbols('Sd')                                                       # Force on CE(N)  \n",
    "\n",
    "\n",
    "#Calculation         \n",
    "# Case(a)\n",
    "# Statics\n",
    "Eq=Fce*12 +  Fdf*20  - 180                                             # Because submission of Mb is 0   \n",
    "\n",
    "# Geometry\n",
    "Sc=0.6*Sd                                                              # By using similar triangles\n",
    "Sa=0.9*Sd                                                              # By using similar triangles\n",
    "\n",
    "# Deformations\n",
    "Sc=(Fce*Lce)/(Ace*E)                                                   # Deformation at C(in) \n",
    "Sd=(Fdf*Ldf)/(Adf*E)                                                   # Deformation at D(in)  \n",
    "Fce=0.333*Fdf                                                          # By solving Sc= 0.6*Sd we get this result\n",
    "\n",
    "# Force in Each Rod\n",
    "Fdf=(180/(((12)*(0.333))+20))                                          # By using Eq and the value of Fce   \n",
    "Fce=0.333*Fdf                                                          # Force in CE(N)\n",
    "\n",
    "# Case(b)\n",
    "# Deflections\n",
    "Sd=(Fdf*(pow(10,3))*Ldf)/(Adf*E)                                       # Deflection of point D(in)\n",
    "Sa=0.9*Sd                                                              # Deflection of point A(in) \n",
    "\n",
    "\n",
    "#Result\n",
    "print('Case(a): Force in rod DF = %.1f psi' %Fdf)\n",
    "print('Case(a): Force in rod CE = %lf psi' %Fce)\n",
    "print('Case(b): Deflection of point A = %lf psi' %Sa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 2.4, Page number 87"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stress in cylinder = 44.8 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "Ldf=30                                                                 # Length of DF(in)\n",
    "Adf=(1/4.0)*(math.pi)*(3/4.0)*(3/4.0)                                        # Cross sectional area of DF(in**2) \n",
    "Lce=24                                                                 # Length of CE(in)\n",
    "Ace=(1/4.0)*(math.pi)*(1/2.0)*(1/2.0)                                        # Cross sectional area of DF(in**2) \n",
    "E=(10.6*pow(10,6))                                                     # Molulus of elasticity(psi)\n",
    "Fce=symbols('Fce')                                                     # Force on CE(N)  \n",
    "Fdf=symbols('Fdf')                                                     # Force on DF(N)\n",
    "Sd=symbols('Sd')                                                       # Force on CE(N)  \n",
    "Rb=symbols('Rb')                                                       # Reaction at B(m)   \n",
    "\n",
    "\n",
    "#Calculation  \n",
    "Ra=0.4*Rb                                                              # By considering the free body motion\n",
    "L=0.3                                                                  # Length of rod DE(m) \n",
    "DeltaT=30                                                              # Change in temperature(C)  \n",
    "Alpha=(20.9*pow(10,-6))                                                # Constant(/C)\n",
    "A=(1/4)*(math.pi)*(pow(0.22,2))                                        # Area of cross-section of rod AC(m**2)\n",
    "E=200                                                                  # Molulus of elasticity(psi)\n",
    "\n",
    "St=L*(DeltaT)*Alpha                                                    # Deflection(m)\n",
    "\n",
    "temp=(L/(A*E))                    \n",
    "Sc=str(temp)+'*Ra'                                                     # Deflection(m)  \n",
    "\n",
    "Sd=str(0.4)+'*Sc'                                                      # Deflection(m)\n",
    "Sd=4.74*pow(10,-9)                                                     # After computing the above equation\n",
    "\n",
    "Sbd=str(4.04*pow(10,-9))+'*Ra'                                         # Deflection(m)\n",
    "\n",
    "S1=str(5.94*pow(10,-9))+'*Rb'                                          # Deflection(m)\n",
    "\n",
    "Rb=((188.1*pow(10,-6))/(5.94*pow(10,-9)))/(pow(10,3))                  # Reaction at B(m) \n",
    "\n",
    "db=((round(Rb,1))/((1/4.0)*(math.pi)*(pow(0.03,2))))/(pow(10,3))         # Stress in cylinder(MPa)\n",
    "\n",
    "#Result\n",
    "print('Stress in cylinder = %.1f MPa' %db)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.07, Page number 94"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Modulus of elasticity = 99471839.4 GPa\n",
      "Poissons ratio = 0.2 \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "P=12*(pow(10,3))                                                                  # Axial load(kN)\n",
    "r=8*(pow(10,-3))                                                                  # Radius of the rod(m)\n",
    "n=-1\n",
    "\n",
    "#Calculation\n",
    "A=(math.pi)*(r**2)                                                                # Cross sectional area of rod(m**2)\n",
    "Sx=(P/A)                                                                          # Stress in cylinder(MPa) \n",
    "Ex=(300/500.0)                                                                      # Strain()\n",
    "Ey=(n*(2.4))/16.0                                                                   # Strain()\n",
    "\n",
    "E=Sx/Ex                                                                           # Modulus of elasticity(GPa)\n",
    "v=n*(Ey/Ex)                                                                       # Poissons ratio()  \n",
    "\n",
    "#Result\n",
    "print('Modulus of elasticity = %.1f GPa' %E)\n",
    "print('Poissons ratio = %.1f ' %v)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.08, Page number 96"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in length in y direction = -0.000600 in\n",
      "Change in length in z direction = -0.000900 in\n",
      "Pressure = 20.7 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "E=29*(pow(10,6))                                                     # Modulus of elasticity(GPa)\n",
    "v=0.29                                                               # Poissons ratio()\n",
    "Sx=symbols('Sx')                                                     # Strain variable \n",
    "Sy=symbols('Sy')                                                     # Strain variable\n",
    "Sz=symbols('Sz')                                                     # Strain variable\n",
    "Ex=symbols('Ex')                                                     # Stress variable\n",
    "Ey=symbols('Ey')                                                     # Stress variable\n",
    "Ez=symbols('Ez')                                                     # Stress variable\n",
    "p=symbols('p')                                                       # pressure\n",
    "n=-1\n",
    "Sx=n*p                                                               # Strain at x\n",
    "Sy=n*p                                                               # Strain at y\n",
    "Sz=n*p                                                               # Strain at z \n",
    "Ey=Ez=Ex                                                             # Equating all the stresses\n",
    "\n",
    "#Calculation\n",
    "# Case(a)\n",
    "Ex=((n*p)*(1-(2*v)))/E                                               # Stress                                             \n",
    "Ex=(n*1.2*(pow(10,3)))/4                                             # Stress(in./in)\n",
    "DELTAy=n*(300*(pow(10,-6)))*(2)                                       # Change in length(in)\n",
    "DELTAz=n*(300*(pow(10,-6)))*(3)                                       # Change in length(in)  \n",
    "# Case(b)\n",
    "p=(solve(p+((29*(pow(10,6)))*(n*300*(pow(10,-6))))/(1-0.58),p)[0])/(pow(10,3))          # pressure(ksi)\n",
    "\n",
    "#Result\n",
    "print('Change in length in y direction = %1f in' %DELTAy)\n",
    "print('Change in length in z direction = %1f in' %DELTAz)\n",
    "print('Pressure = %.1f ksi' %p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.09, Page number 98"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in volume = -217.728000 mm**3\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "p=180                                                               # Hydrostatic pressure(MPa)\n",
    "E=200                                                               # Modulus of elasticity(GPa)\n",
    "v=0.29                                                              # Poissons ratio() \n",
    "\n",
    "#Calculation\n",
    "k=E/(3*(1-(2*v)))                                                   # Bulk modulus of steel(GPa)\n",
    "e=-p/k                                                              # Dialation \n",
    "V=80*40*60                                                          # Volume of block in unstressed state(mm**3)\n",
    "DELTAv=(e*V)/(pow(10,3))                                            # change in volume per unit volume\n",
    "\n",
    "# Results\n",
    "print('Change in volume = %1f mm**3' %DELTAv)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.10, Page number 101"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shearing strain in rod=0.020000 rad\n",
      "Force exerted on the upper plate=36.000000 kips\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "G=90                                                                      # Modulus of rigidity(ksi)\n",
    "disp=0.04                                                                 # Displacement of upper rod(in)\n",
    "Lda=2                                                                     # Height of bar(in)\n",
    "A=8*2.5                                                                   # Area of cross section(in**2)\n",
    "\n",
    "#Calculation\n",
    "Yxy=(disp/Lda)                                                            # Shearing strain(rad)\n",
    "Txy=(90*(pow(10,3)))*(0.020)                                              # Shearing stress(psi) \n",
    "P=(Txy*A)/(pow(10,3))                                                     # Force exerted on the upper plate(kips) \n",
    "\n",
    "# Results\n",
    "print('Shearing strain in rod=%1f rad' %Yxy)\n",
    "print('Force exerted on the upper plate=%1f kips' %P)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.11, Page number 105"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in cube dimension in x direction=-14.981914 um\n",
      "Change in cube dimension in y direction=0.000000 um\n",
      "Change in cube dimension in z direction=5.443356 um\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "Ex=155.0                                                                      # Modulus of elasticity in x direction(GPa)\n",
    "Ey=12.10                                                                      # Modulus of elasticity in y direction(GPa)\n",
    "Ez=12.10                                                                      # Modulus of elasticity in z direction(GPa)\n",
    "Vxy=0.248                                                                     # Poissons ratio in xy direction\n",
    "Vxz=0.248                                                                     # Poissons ratio in xz direction\n",
    "Vyz=0.458                                                                     # Poissons ratio in yz direction\n",
    "n=-1\n",
    "F=140*(pow(10,3))                                                             # Compressive load(kN)\n",
    "L=0.060                                                                       # Length of cube(m)\n",
    "\n",
    "#Calculation\n",
    "#(a) Free in y and z Directions\n",
    "Sx=(n*F)/(0.060*0.060)                                                        # Stress in x direction(MPa)\n",
    "Sy=0                                                                          # Stress in y direction(MPa) \n",
    "Sz=0                                                                          # Stress in z direction(MPa)  \n",
    "ex=Sx/Ex                                                                      # Lateral strains \n",
    "ey=n*((Vxy*Sx)/Ex)                                                            # Lateral strains \n",
    "ez=n*((Vxy*Sx)/Ex)                                                            # Lateral strains\n",
    "DELTAx=ex*L                                                                   # Change in cube dimension in x direction(um) \n",
    "DELTAy=ey*L                                                                   # Change in cube dimension in y direction(um)\n",
    "DELTAz=ez*L                                                                   # Change in cube dimension in z direction(um)\n",
    "#(b) Free in z Direction, Restrained in y Direction\n",
    "Sx=n*38.89                                                                    # Stress in x direction(MPa)\n",
    "Sy=(Ey/Ex)*(Vxy)*(Sx)                                                         # Stress in y direction(MPa) \n",
    "Vyx=(Ey/Ex)*(Vxy)                                                             # Poissons ratio\n",
    "ex=(Sx/Ex)-(((Vyx)*(Sy))/Ey)                                                  # Lateral strains in x direction\n",
    "ey=0                                                                          # Lateral strains in y direction\n",
    "ez=n*((Vxz*Sx)/Ex)-(((Vyz)*(Sy))/Ey)                                          # Lateral strains in z direction\n",
    "DELTAx=ex*L*1000                                                              # Change in cube dimension in x direction(um) \n",
    "DELTAy=ey*L                                                                   # Change in cube dimension in y direction(um)\n",
    "DELTAz=ez*L*1000                                                              # Change in cube dimension in z direction(um)\n",
    "\n",
    "# Results\n",
    "print('Change in cube dimension in x direction=%1f um' %DELTAx)\n",
    "print('Change in cube dimension in y direction=%1f um' %DELTAy)\n",
    "print('Change in cube dimension in z direction=%1f um' %DELTAz)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 2.5, Page number 107"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in diamter of rod AB =0.004800 in\n",
      "Change in diamter of rod CD =0.014400 in\n",
      "Change in thickness =-0.000800 in\n",
      "Volume of the plate =0.180000 in**3\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "d=9                                                                              # Diameter of the rod(in)\n",
    "t=3/4.0                                                                            # Thickness of the rod(in)\n",
    "ex=12                                                                            # Normal stresses(ksi) \n",
    "ez=20                                                                            # Normal stresses(ksi)\n",
    "E=(10*pow(10,6))                                                                 # Moduluus of elasticity(psi)\n",
    "v=(1/3)                                                                          # Poissons ratio\n",
    "V=15*15*(3/4.0)                                                                    # Volume(in**3)\n",
    "n=-1\n",
    "\n",
    "#Calculation\n",
    "STRAINx=(1/(pow(10,7)*(1.0)))*(12-(20/3.0))*(1000)                                         # Strain in x direction(in./in) \n",
    "STRAINy=n*(1/(pow(10,7)*1.0))*((12/3.0)+(20/3.0))*(1000)                                   # Strain in y direction(in./in)\n",
    "STRAINz=(1/(pow(10,7)*(1.0)))*(20-(12/3.0))*(1000)                                         # Strain in z direction(in./in)\n",
    "\n",
    "\n",
    "#Case(a) \n",
    "DELTAba=(STRAINx)*(d)                                                            # Change in diameter(in)\n",
    "#Case(b) \n",
    "DELTAcd=(STRAINz)*(d)                                                            # Change in diameter(in)\n",
    "#Case(c) \n",
    "DELTAt=(STRAINy)*(t)                                                             # Change in thickness(in)\n",
    "#Case(d)          \n",
    "e=(STRAINx+STRAINy+STRAINz)                                                      # Volume of the plate(in**3)\n",
    "DeltaV=(e*V)         \n",
    "\n",
    "# Results\n",
    "print('Change in diamter of rod AB =%1f in' %DELTAba)\n",
    "print('Change in diamter of rod CD =%1f in' %DELTAcd)\n",
    "print('Change in thickness =%1f in' %DELTAt)\n",
    "print('Volume of the plate =%1f in**3' %DeltaV)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.12, Page number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Largest Axial Load =36.300000 in\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "D=60                                                                       # Width(mm) \n",
    "d=40                                                                       # Width(mm)\n",
    "r=8                                                                        # Radius(mm)\n",
    "K=1.82                                                                     # Stress-concentration factor\n",
    "Smax=165                                                                   # Allowable normal stress(MPa)\n",
    "\n",
    "#Calculation\n",
    "eave=(165/1.82)                                                            # Average stress in the narrower portion(MPa) \n",
    "P=round((40*10*eave)/(1000),1)                                             # Largest Axial Load(kN)\n",
    "\n",
    "# Results\n",
    "print('Largest Axial Load =%1f in' %P)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.13, Page number 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Permanent set deformation =6.250000 mm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "L=500.0                                                                   # Length of rod(mm)\n",
    "A=60                                                                      # Cross Sectional area(mm**2)\n",
    "E=200                                                                     # Modulus of elasticity(GPa)\n",
    "ey=300                                                                    # Yield Point(MPa)                                                                \n",
    "DELTAc=7                                                                  # Stretch(mm)  \n",
    "\n",
    "#Calculation\n",
    "ec=DELTAc/L                                                               # Maximum strain permitted on point C\n",
    "ey=(ey*(pow(10,6)))/(E*(pow(10,9))*(1.0))                                       # Maximum strain permitted on point Y \n",
    "ed=ec-ey                                                                  # Strain after unloading\n",
    "DELTAd=ed*L                                                               # Deformation(mm)\n",
    "\n",
    "# Results\n",
    "print('Permanent set deformation =%1f mm' %DELTAd)                         "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 2.6, Page number 123"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Required maximum value of Q =240.0 mm\n",
      "The final position of the beam =11.000000 mm\n"
     ]
    }
   ],
   "source": [
    "from sympy import symbols, solve\n",
    "\n",
    "#Variable declaration\n",
    "Lad=2                                                          # Length of AD(m)\n",
    "Lce=5                                                          # Length of CE(m)  \n",
    "E=200.0                                                        # Modulus of elasticity(GPa)\n",
    "ey=300                                                         # Stress(MPa)\n",
    "Aad=400                                                        # Area of cross section of AD(mm**2)\n",
    "Ace=500.0                                                      # Area of cross section of CE(mm**2)\n",
    "STRAINad=ey/E                                                  # Stress(MPa)                                                         # \n",
    "\n",
    "#Calculation\n",
    "Pad=symbols('Pad')                                             # Variable declaration\n",
    "Pce=symbols('Pce')                                             # Variable declaration\n",
    "Pce=Pad\n",
    "Q=symbols('Q')                                                 # Variable declaration\n",
    "Q=2*Pad                                                        # Force(kN)    \n",
    "d=ey                                                           # Maximum elastic deflection of point A\n",
    "PadM=ey*Aad                                                    # Maximum force(kN)   \n",
    "Q=(2*PadM)/(1000.0)                                                        # Maximum force(kN)\n",
    "Sa1=STRAINad*Lad                                               # Maximum deflection of point A(mm)\n",
    "Pce=120                                                        # This implies Pad is also 120\n",
    "ece=Pce/Ace                                                    # Stress in rod CE(MPa)\n",
    "STRAINce=ece/E                                                 # Strain CE\n",
    "Sc1=STRAINce*Lce                                               # Deflection of point C(mm)\n",
    "Sb=(1/2)*(Sa1+Sc1)                                             # Deflection of point B(mm)\n",
    "\n",
    "# Since we must have Sb 10 mm, we conclude that plastic deformation will occur.\n",
    "\n",
    "# Plastic Deformation\n",
    "eAD=ey                              # Equating stresses\n",
    "Sc=6                                # Deflection in C(mm)\n",
    "Sa2=symbols('Sa2')                  # Variable declaration \n",
    "Sa2=solve(((1/2)*(Sa2+6)-10),Sa2)   # The deflection Sa for which Sb = 10\n",
    "\n",
    "# Unloading\n",
    "Sa3=14-3                            #Since the stress in rod CE remained within the elastic range, we note that the final deflection of point C is zero.\n",
    "\n",
    "print('Required maximum value of Q =%.1f mm' %Q)\n",
    "print('The final position of the beam =%1f mm' %Sa3)"
   ]
  }
 ],
 "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
}
