{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 7 : Transformations of Stress and Strain"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.01, Page number 446"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Principal planes = 26.550000 degree\n",
      "Case(a) Principal planes = 116.550000 degree\n",
      "Case(b) Maximum principal stress = 70.000000 MPa\n",
      "Case(b) Minimum principal stress = -30.000000 MPa\n",
      "Case(c) Maximum shearing stress = 50.000000 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,cos,sin\n",
    "\n",
    "#Variable declaration\n",
    "Sx=50                                                                               # Stress in x(MPa)\n",
    "n=-1\n",
    "Sy=n*10                                                                             # Stress in y(MPa)\n",
    "txy=40                                                                              # Shearing stress(MPa)  \n",
    "\n",
    "\n",
    "#Calculation         \n",
    "# Case(a) Principal axes\n",
    "phy1=(53.1)/2.0                                                                       # Angle(degree) \n",
    "phy2=(233.1)/2.0                                                                      # Angle(degree)\n",
    "\n",
    "# Case(b) Principal stresses\n",
    "Smax=20+math.sqrt(30**2+40**2)                                                           # Maximum principal stress(MPa)\n",
    "Smin=20-math.sqrt(30**2+40**2)                                                           # Maximum principal stress(MPa)\n",
    "Sxl=(50-10)/(2.0) + ((50+10)/(2.0))*cos(53.1*((math.pi)*2)/(360.0)) +40*sin(53.1*((math.pi)*2)/(360.0))  \n",
    "\n",
    "# Case(c) Maximum shearing stress\n",
    "tmax=math.sqrt(30**2+40**2)                                                              # Maximum shearing stress(MPa)\n",
    "Sl=(50-10)/2.0                                                                        # Normal stress on each of four walls(MPa)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Principal planes = %lf degree' %phy1)\n",
    "print ('Case(a) Principal planes = %lf degree' %phy2)\n",
    "print ('Case(b) Maximum principal stress = %lf MPa' %Smax)\n",
    "print ('Case(b) Minimum principal stress = %lf MPa' %Smin)\n",
    "print ('Case(c) Maximum shearing stress = %lf MPa' %tmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.1, Page number 447"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Normal stress = 8.840000 ksi\n",
      "Case(a) Shearing stress = 7.960000 ksi\n",
      "Case(b) Principal plane angle = -30.500000 degree\n",
      "Case(b) Principal plane angle = 119.000000 degree\n",
      "Case(c) Maximum stress at point H = 13.524834 ksi\n",
      "Case(c) Minimum stress at point H = -4.684834 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "P=150                                                                                # Horizontal force(lb)\n",
    "T=(150*18)/(1000.0)                                                                    # Force couple system(kip.in)\n",
    "Mx=(150*10)/(1000.0)                                                                   # Force couple system(kip.in)\n",
    "sx=0                                                                                 # Stress at x\n",
    "M=1.5                                                                                # Torque(kip.in)\n",
    "c=0.6                                                                                # Radius(in)\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Stresses S x , S y , T xy at Point H\n",
    "sy=round(((M)*(c))/((1/4.0)*(math.pi)*(pow(0.6,4))),2)                                 # Stress(ksi)\n",
    "txy=round(((T)*(c))/((1/2.0)*(math.pi)*(pow(0.6,4))),2)                                # Shearing stress(ksi)\n",
    "\n",
    "#Case(b) Principal Planes and Principal Stresses\n",
    "phyp1=(n*61)/2.0                                                                       # Angle(degree)\n",
    "phyp2=180-61                                                                         # Angle(degree)\n",
    "\n",
    "Smax=8.84/2.0 + math.sqrt(4.42**2 + 7.96**2)                                                # Maximum stress(ksi)  \n",
    "Smin=8.84/2.0 - math.sqrt(4.42**2 + 7.96**2)                                                # Minimum stress(ksi)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Normal stress = %lf ksi' %sy)\n",
    "print ('Case(a) Shearing stress = %lf ksi' %txy)\n",
    "print ('Case(b) Principal plane angle = %lf degree' %phyp1)\n",
    "print ('Case(b) Principal plane angle = %lf degree' %phyp2)\n",
    "print ('Case(c) Maximum stress at point H = %lf ksi' %Smax)\n",
    "print ('Case(c) Minimum stress at point H = %lf ksi' %Smin)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.02, Page number 454"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) radius of circle = 50.000000 MPa\n",
      "Case(b) Maximum principal stress = 70.000000 MPa\n",
      "Case(b) Minimum principal stress = -30.000000 MPa\n",
      "Case(c) Maximum shearing stress = 50.000000 MPa\n",
      "Case(c) Minimum shearing stress = 20.000000 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "#Variable declaration\n",
    "n=-1\n",
    "Sx=50                                                               # Force at x(MPa)\n",
    "Sy=n*10                                                             # Force at y(MPa)\n",
    "OC=20                                                               # Force(MPa)  \n",
    "CA=50                                                               # Force(MPa)\n",
    "BC=50                                                               # Force(MPa)\n",
    "\n",
    "#Calculation         \n",
    "# Case(a) Construction of Mohr’s Circle\n",
    "Save=(Sx+Sy)/2.0                                                      # Average stress(MPa)\n",
    "CF=50-20                                                            # Force(MPa)  \n",
    "FX=40                                                               # Force(MPa) \n",
    "R=math.sqrt(30**2 + 40**2)                                               # Radius of circle(MPa)\n",
    "# case(b) Principal Planes and Principal Stresses\n",
    "Smax=OC+CA                                                          # Maximum stress(MPa) \n",
    "Smin=OC-BC                                                          # Minimum stress(MPa)\n",
    "phyp=(53.1)/2.0                                                       # Angle(degree)\n",
    "# case(c) Maximum Shearing Stress\n",
    "tmax=50                                                             # Maximum shearing stress(MPa) \n",
    "Save=20                                                             # Maximum normal stress(MPa) \n",
    "\n",
    "# Result\n",
    "print ('Case(a) radius of circle = %lf MPa' %R)\n",
    "print ('Case(b) Maximum principal stress = %lf MPa' %Smax)\n",
    "print ('Case(b) Minimum principal stress = %lf MPa' %Smin)\n",
    "print ('Case(c) Maximum shearing stress = %lf MPa' %tmax)\n",
    "print ('Case(c) Minimum shearing stress = %lf MPa' %Save)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.2, Page number 457"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Principal planes angle = 33.700000 MPa\n",
      "Case(b) Maximum principal stress = 132.000000 MPa\n",
      "Case(b) Minimum principal stress = 28.000000 MPa\n",
      "Case(c) Stress in x direction = 48.416456 MPa\n",
      "Case(c) Stress in y direction = 111.583544 MPa\n",
      "Case(c) Stress in x and y direction = 41.309560 MPa\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,cos,sin\n",
    "\n",
    "#Variable declaration\n",
    "sx=100                                                                  # Force(MPa)\n",
    "sy=60                                                                   # Force(MPa)\n",
    "CF=20                                                                   # Force(MPa)\n",
    "FX=48                                                                   # Force(MPa) \n",
    "OC=80                                                                   # Force(MPa)\n",
    "CA=52                                                                   # Force(MPa)\n",
    "BC=52                                                                   # Force(MPa)  \n",
    "\n",
    "# Calculation\n",
    "#Construction of Mohr’s Circle\n",
    "R=math.sqrt(20**2+48**2)                                                     # Radius of circle(MPa)\n",
    "\n",
    "        \n",
    "#Case(a) Principal Planes and Principal Stresses\n",
    "phyp=(67.4)/2.0                                                           # Angle(degree)\n",
    "Smax=OC+CA                                                              # Maximum stress(MPa)\n",
    "Smin=OC-BC                                                              # Min stress(MPa)\n",
    "\n",
    "#Case(b) Stress Components on Element Rotated 30\n",
    "phy=180-60                                                              # Angle(degree)\n",
    "Sxl=80-(52*(cos(52.6*(math.pi*2)/(360.0))))\n",
    "Syl=80+(52*(cos(52.6*(math.pi*2)/(360.0))))\n",
    "txlyl=52*(sin(52.6*(math.pi*2)/(360.0)))\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Principal planes angle = %lf MPa' %phyp)\n",
    "print ('Case(b) Maximum principal stress = %lf MPa' %Smax)\n",
    "print ('Case(b) Minimum principal stress = %lf MPa' %Smin)\n",
    "print ('Case(c) Stress in x direction = %lf MPa' %Sxl)\n",
    "print ('Case(c) Stress in y direction = %lf MPa' %Syl)\n",
    "print ('Case(c) Stress in x and y direction = %lf MPa' %txlyl)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.3, Page number 458"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Shearing stress t0 for which the largest normal stress is 10 ksi = 4.472856 ksi\n",
      "Case(b) Maximum shearing stress = 6.000000 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,sin\n",
    "\n",
    "#Variable declaration\n",
    "S0=8                                                                         # Stress(ksi)\n",
    "Sx=8                                                                         # Stress in x direction(ksi)\n",
    "Sy=0                                                                         # Stress in y direction(ksi)   \n",
    "Smax=10                                                                      # Maximum stress(ksi)\n",
    "\n",
    "# Calculation\n",
    "#Construction of Mohr’s Circle\n",
    "Save=(1/2.0)*(Sx+Sy)                                                           # Average stress(ksi)  \n",
    "R=10-4                                                                       # Radius of mohr's circle(ksi) \n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Shearing Stress t0\n",
    "phyp=(48.2)/2.0                                                                # Angle(degree)               \n",
    "t0=R*sin(48.2*((math.pi)*2)/(360.0))                                           # Shearing stress(ksi)\n",
    "\n",
    "#Case(b) Maximum Shearing Stress\n",
    "tmax=R                                                                       # Maximum shearing stress(ksi)\n",
    "phyx=(90-48.2)/(2.0)                                                           \n",
    "\n",
    "#Result\n",
    "print ('Case(a) Shearing stress t0 for which the largest normal stress is 10 ksi = %lf ksi' %t0)\n",
    "print ('Case(b) Maximum shearing stress = %lf ksi' %tmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.03, Page number 466"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Principal stress at A = 8.000000 ksi\n",
      "Case(a) Principal stress at B = 1.500000 ksi\n",
      "Case(b) Principal plane = 33.700000 ksi\n",
      "Case(c) Maximum shearing stress = 4.000000 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "n=-1\n",
    "Sx=6\n",
    "Sy=3.5\n",
    "OC=4.75\n",
    "CA=3.25\n",
    "BC=3.25\n",
    "\n",
    "#Calculation         \n",
    "# Case(a) Principal Planes and Principal Stresses\n",
    "Save=(Sx+Sy)/2.0                                                                    # Average stress(ksi)\n",
    "R=math.sqrt(1.25**2 + 3**2)                                                            # Radius of circle(ksi)\n",
    "Sa=OC+CA                                                                          # Principal stress(ksi)\n",
    "Sb=OC-BC                                                                          # Principal stress(ksi) \n",
    "phyp=(67.4)/2.0\n",
    "\n",
    "# Case(b) Maximum shearing stress\n",
    "tmax=(1/2.0)*(Sa)                                                                   # Maximum torque(ksi)\n",
    " \n",
    "#Result\n",
    "print ('Case(a) Principal stress at A = %lf ksi' %Sa)\n",
    "print ('Case(a) Principal stress at B = %lf ksi' %Sb)\n",
    "print ('Case(b) Principal plane = %lf ksi' %phyp)\n",
    "print ('Case(c) Maximum shearing stress = %lf ksi' %tmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.4, Page number 472"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Factor of safety with respect to maximum shearing stress criteria = 1.923077 \n",
      "Case(b) Factor of safety with respect to maximum-distortion-energy criterion = 2.190000 \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "#Mohr’s Circle\n",
    "Sx=80                                                                                 # Stress at x(MPa)\n",
    "sy=-40                                                                                # Stress at y(MPa) \n",
    "CF=60                                                                                 # Stress(MPa) \n",
    "FX=25                                                                                 # Stress(MPa)\n",
    "OC=20                                                                                 # Stress(MPa)\n",
    "CA=65                                                                                 # Stress(MPa)\n",
    "BC=65                                                                                 # Stress(MPa)\n",
    "Save=(1/2.0)*(sx+sy)                                                                    # Stress average(MPa)                                                                \n",
    "R=math.sqrt(60**2+25**2)                                                                   # radius of mohr's circle(MPa)  \n",
    "Sy=250                                                                                # Tensile strength(MPa)   \n",
    "tm=65                                                                                 # Stress(MPa) \n",
    "\n",
    "#Principal Stresses\n",
    "sa=OC+CA                                                                              # Stress at A(MPa)\n",
    "sb=OC-BC                                                                              # Stress at B(MPa)\n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Maximum-Shearing-Stress Criterion                                                                                # \n",
    "ty=(1/2.0)*(Sy)                                                                         # Shearing stress at yield(MPa)\n",
    "FS1=(ty/tm)                                                                           # Factor of safety\n",
    "\n",
    "#Case(b) Maximum-Distortion-Energy Criterion\n",
    "FS2=round(math.sqrt((250**2)/(85.0**2+45.0**2+85.0*45)),2)                                       # Factor of safety  \n",
    "\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Factor of safety with respect to maximum shearing stress criteria = %lf ' %FS1)\n",
    "print ('Case(b) Factor of safety with respect to maximum-distortion-energy criterion = %lf ' %FS2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.5, Page number 481"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Normal stress  = 4230.000000 \n",
      "Case(a) Maximum shearing stress = 4230.000000 \n",
      "Case(b) Stress in direction perpendicular to helical weld = 4140.000000 \n",
      "Case(b) Stress in direction parallel to helical weld = 1344.000000 \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,cos,sin\n",
    "\n",
    "#Variable declaration\n",
    "p=180                                                                          # Internal gage pressure(psi)\n",
    "t=(5/16.0)                                                                       # Length(in)\n",
    "r=(15-t)                                                                       # Distance(in)\n",
    "\n",
    "\n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Spherical Cap\n",
    "s=((p)*(r))/(2.0*t)                                                          # Stress(psi)\n",
    "tmax=(1/2.0)*((p*r)/(t))                                                                  # Maximum shearing stress(psi)  \n",
    "\n",
    "#Case(b) Cylindrical Body of the Tank\n",
    "t=3/8.0                                                                          # Distance(in) \n",
    "r=15-t                                                                         # Distance(in)  \n",
    "s1=(p*r)/(t)                                                                   # Stress(psi)\n",
    "s2=(1/2.0)*s1                                                                    # Stress(psi)\n",
    "Save=(1/2.0)*(s1+s2)                                                             # Stress average(psi)                                \n",
    "R=(1/2.0)*(s1-s2)                                                                # Stress(psi) \n",
    "\n",
    "#Stresses at the Weld\n",
    "Sw=round(Save-(R*cos(50*(((math.pi)*2)/360.0))),-1)                              # Stress at the weld(psi)\n",
    "tw=round(R*sin(50*(((math.pi)*2)/360.0)),0)                                      # Shearing stress at the weld(psi)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Normal stress  = %lf ' %s)\n",
    "print ('Case(a) Maximum shearing stress = %lf ' %tmax)\n",
    "print ('Case(b) Stress in direction perpendicular to helical weld = %lf ' %Sw)\n",
    "print ('Case(b) Stress in direction parallel to helical weld = %lf ' %tw)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.04, Page number 490"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Principal strain = 483.000000 u\n",
      "Case(a) Principal strain = -83.000000 u\n",
      "Case(b) Maximum shearing strain = 566.000000 u \n",
      "Case(b) Normal strain = 200.000000 u\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "n=-1\n",
    "Sx=6                                                                        # Stress in x direction()\n",
    "Sy=3.5                                                                      # Stress in y direction()\n",
    "BC=3.25                                                                       \n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Principal Axes and Principal Strains\n",
    "Ex=4*(pow(10,-6))                                                           # Distance(u) \n",
    "Ey=0                                                                        # Distance(u)\n",
    "OC=(Ex+Ey)/(2.0)                                                              # Radius(u) \n",
    "OY=200                                                                      # Radius(u)\n",
    "\n",
    "R=math.sqrt(200**2 + 200**2)                                                     # Radius(u)\n",
    "\n",
    "Ea=200 + 283                                                                # Strain at point A(u)\n",
    "Eb=200 - 283                                                                # Strain at point A(u)\n",
    "\n",
    "#Case(b) Maximum shearing strain\n",
    "ymax=283*2                                                                  # Maximum shearing strain(u)\n",
    "El=200                                                                      # Normal strain(u)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Principal strain = %lf u' %Ea)\n",
    "print ('Case(a) Principal strain = %lf u' %Eb)\n",
    "print ('Case(b) Maximum shearing strain = %lf u ' %ymax)\n",
    "print ('Case(b) Normal strain = %lf u' %El)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.05, Page number 494"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Maximum in plane shearing strain = 0.000450 rad\n",
      "Case(b) Maximum shearing strain = -0.000150 u\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "#Variable declaration\n",
    "Ea=400*(pow(10,-6))                                                       # Principal strain(in./in)\n",
    "Eb=-50*(pow(10,-6))                                                       # Principal strain(in./in)\n",
    "v=0.30                                                                    # Poisson's ratio\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "#Case(a) Maximum In-Plane Shearing Strain\n",
    "Ymaxinplane=Ea-Eb                                                         # Maximum in-plane shearing strain(rad)\n",
    "#Case(b) Maximum Shearing Strain\n",
    "Ec=n*(v/(1.0-v))*(Ea+Eb)                                                    # Strain(in./in)                                                               # Maximum shearing strain(rad)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Maximum in plane shearing strain = %lf rad' %Ymaxinplane)\n",
    "print ('Case(b) Maximum shearing strain = %lf u' %Ec)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.6, Page number 496"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Gage pressure inside the tank = 546.000000 psi\n",
      "Case(b) Principal stress = 4.370000 ksi\n",
      "Case(b) Principal stress = 8.740000 ksi\n",
      "Case(b) Maximum shearing stress = 4.370000 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols\n",
    "\n",
    "#Variable declaration\n",
    "s1=symbols('s1')                                                          # Variable declaration\n",
    "s2=symbols('s2')                                                          # Variable declaration\n",
    "E1=255*(pow(10,-6))                                                       # Strain(in./in)   \n",
    "E2=60*(pow(10,-6))                                                        # Strain(in./in)\n",
    "G=11.2*(pow(10,6))                                                        # Modulus of rigidity(psi)\n",
    "\n",
    "#Calculation         \n",
    "#Gage Pressure Inside Tank\n",
    "ymax=E1-E2                                                                # Maximum in plane shearing strain(rad)\n",
    "tmax=(round(G*ymax,0))/(pow(10,3))                                        # Shearing stress(ksi) \n",
    "p=(2184*4*0.75)/12.0                                                        # Gage pressure(psi)\n",
    "\n",
    "#Principal Stresses and Maximum Shearing Stress\n",
    "s2=round(2*tmax,2)                                                        # Principal Stress(ksi)\n",
    "s1=round(2*s2,2)                                                          # Principal Stress(ksi)\n",
    "tmax=(1/2.0)*(s1)                                                           # Shearing stress(ksi) \n",
    "\n",
    "# Result\n",
    "print ('Case(a) Gage pressure inside the tank = %lf psi' %p)\n",
    "print ('Case(b) Principal stress = %lf ksi' %s2)\n",
    "print ('Case(b) Principal stress = %lf ksi' %s1)\n",
    "print ('Case(b) Maximum shearing stress = %lf ksi' %tmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SAMPLE PROBLEM 7.7, Page number 497"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case(a) Strain component are :-\n",
      "{ey: 860.050456293436, ex: 40.0000000000000, yxy: 750.577367205543}\n",
      "Case(b) Principal strains = -106.000000 ksi\n",
      "Case(b) Principal strains = 1006.000000 ksi\n",
      "Case(b) Principal strains = -367.605634 ksi\n",
      "Case(c) Maximum shearing strain = 1374.000000 ksi\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "from sympy import symbols,solve\n",
    "\n",
    "#Variable declaration\n",
    "E1=40                                                                              # Strain(u) \n",
    "E2=980                                                                             # Strain(u) \n",
    "E3=330                                                                             # Strain(u)\n",
    "exp1=symbols('exp1')                                                               # Variable declaration\n",
    "exp2=symbols('exp2')                                                               # Variable declaration\n",
    "exp3=symbols('exp3')                                                               # Variable declaration\n",
    "ex=symbols('ex')                                                                   # Variable declaration\n",
    "ey=symbols('ey')                                                                   # Variable declaration\n",
    "yxy=symbols('yxy')                                                                 # Variable declaration\n",
    "v=0.29\n",
    "n=-1\n",
    "\n",
    "#Calculation         \n",
    "#Strain Components ex, ey, yxy\n",
    "exp1=ex*1 + ey*0 + yxy*0*1-40                                                      # Strain equations\n",
    "exp2=ex*(pow(0.5,2)) + ey*(pow(0.866,2)) + yxy*(0.866*0.5)-980                     # Strain equations\n",
    "exp3=ex*(pow(-0.5,2)) + ey*(pow(0.866,2)) + yxy*(0.866*-0.5)-330                   # Strain equations\n",
    "Sol=solve((exp1,exp2,exp3),ex,ey,yxy)                                                  #  \n",
    "\n",
    "\n",
    "#Principal Strains\n",
    "Eave=(1/2.0)*(860+40)                                                                # Strain(u)\n",
    "R=math.sqrt(375**2+410**2)                                                              # Radius(u)\n",
    "phyp=(42.4)/2.0                                                                      # Angle(degree)\n",
    "Ea=-106                                                                            # Strain(u)\n",
    "Eb=1006                                                                            # Strain(u)\n",
    "Ec=n*(v/(1-v))*(Ea+Eb)                                                             # Strain(u)\n",
    "\n",
    "#Maximum Shearing Strain\n",
    "Ymax=(1006+368)\n",
    "\n",
    "# Result\n",
    "print ('Case(a) Strain component are :-')\n",
    "print(Sol)\n",
    "print ('Case(b) Principal strains = %lf ksi' %Ea)\n",
    "print ('Case(b) Principal strains = %lf ksi' %Eb)\n",
    "print ('Case(b) Principal strains = %lf ksi' %Ec)\n",
    "print ('Case(c) Maximum shearing strain = %lf ksi' %Ymax)\n"
   ]
  }
 ],
 "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
}
