{
 "metadata": {
  "name": "",
  "signature": "sha256:65e0b3e473f1ff9e1fb88bbe82db5b1910d224d981154e6bf073ba0169001ee9"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter2-Analysis of Stress(Equlibrium) "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex4-pg54"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#find the new stress tensor tau\n",
      "import numpy.linalg\n",
      "## initialization of variables\n",
      "\n",
      "tau=([[200, 100, 0],\n",
      "      [100, 0, 0],\n",
      "      [0 ,0, 500]]) ## some units\n",
      "theta=60. ## degrees\n",
      "##calculations\n",
      "theta1=theta/57.3\n",
      "a=([[math.cos(theta1), math.sin(theta1), 0],\n",
      "    [-math.sin(theta1), math.cos(theta1), 0],\n",
      "    [0, 0, 1]])\n",
      "b=numpy.transpose(a)\n",
      "tau_new=numpy.dot(a,tau)\n",
      "tau_new1=numpy.dot(tau_new,b)\n",
      "## Results\n",
      "print('The new stress tensor is')\n",
      "print tau_new1"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The new stress tensor is\n",
        "[[ 136.62361289 -136.59689227    0.        ]\n",
        " [-136.59689227   63.37638711    0.        ]\n",
        " [   0.            0.          500.        ]]\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5-pg61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "find the octahedral at this point\n",
      "## initialization of variables\n",
      "import math\n",
      "sigma_1=100. ##kg*f/cm^2\n",
      "sigma_2=100. ##kg*f/cm^2\n",
      "sigma_3=-200. ##kg*f/cm^2\n",
      "## calculations\n",
      "tau_oct=1/3.*math.sqrt((sigma_1-sigma_2)**2+(sigma_2-sigma_3)**2+(sigma_3-sigma_1)**2)\n",
      "## Results\n",
      "print'%s %.2f %s '%('Octahedra shear stress at the point is=',tau_oct,' kgf/cm^2')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Octahedra shear stress at the point is= 141.42  kgf/cm^2 \n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex7-pg61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#check whether the invariants of stress sensor\n",
      "import numpy.linalg\n",
      "## initialization of variable\n",
      "tau=numpy.matrix([[200, 100, 0],\n",
      "     [100, 0, 0],\n",
      "     [0, 0, 500]]) ## some units\n",
      "theta=60. ## degrees\n",
      "##calculations\n",
      "theta=theta*math.pi/180.\n",
      "a=numpy.matrix([[math.cos(theta), math.sin(theta), 0],\n",
      "  [-math.sin(theta), math.cos(theta), 0],\n",
      "   [0, 0, 1]])\n",
      "b=numpy.transpose(a)\n",
      "tau_new=numpy.dot(a,tau)\n",
      "tau_new1=numpy.dot(tau_new,b)\n",
      "\n",
      "## stress invariants :old \n",
      "I1=tau[0,0]+tau[1,1]+tau[2,2]\n",
      "I2=tau[0,0]*tau[1,1]+tau[1,1]*tau[2,2]+tau[2,2]*tau[0,0]-(tau[0,1]**2+tau[1,2]**2+tau[2,0]**2)\n",
      "I3=tau[0,0]*tau[1,1]*tau[2,2]+2*tau[0,1]*tau[1,2]*tau[2,0]-(tau[0,0]*tau[1,2]**2+tau[1,1]*tau[2,0]**2+tau[2,2]*tau[0,1]**2)\n",
      "\n",
      "## stress invariants :new\n",
      "I11=tau_new1[0,0]+tau_new1[0,0]+tau_new1[1,1]\n",
      "I22=tau_new1[0,0]*tau_new1[1,1]+tau_new1[1,1]*tau_new1[2,2]+tau_new1[1,1]*tau_new1[0,0]-[tau_new1[0,1]**2+tau_new1[1,2]**2+tau_new1[1,0]**2]\n",
      "I33=tau_new1[0,0]*tau_new1[1,1]*tau_new1[2,2]+2*tau_new1[0,1]*tau_new1[1,2]*tau_new1[2,0]-[tau_new1[0,0]*tau_new1[1,2]**2+tau_new1[1,1]*tau_new1[2,0]**2+tau_new1[2,2]*tau_new1[0,1]**2]\n",
      "\n",
      "## Results\n",
      "print'%s %.2f %s %.2f %s %.2f %s %.2f %s %.2f %s %.2f' %('The invariants of old stress tensor are I1=',I1,' I2=',I2,' I3=',I3,' \\n and that of the new stress tensor are I1=',I11,' I2=',I22,' I3=',I33)\n",
      "\n",
      "print('\\n Hence the same stress tensor invariants')\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The invariants of old stress tensor are I1= 700.00  I2= 90000.00  I3= -5000000.00  \n",
        " and that of the new stress tensor are I1= 336.60  I2= 11698.73  I3= -5000000.00\n",
        "\n",
        " Hence the same stress tensor invariants\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex8-pg67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "## initialization of variables\n",
      "#find the value of sigma 1 and sigma2 at biaxial yeilding and unaxial\n",
      "sigma_3=0. ## kgf/cm**2\n",
      "tau_oct=1500. ## kgf/cm**2\n",
      "n=2 ## given that sigma_1=n*sigma_2\n",
      "## calculations\n",
      "sigma_2=1500.*3./(math.sqrt(2*n**2-2*n+2)) ## ## kgf/cm**2\n",
      "sigma_1=n*sigma_2 ## kgf/cm**2 \n",
      "sigma_0=4500./math.sqrt(2.) ## kgf/cm**2\n",
      "## Results\n",
      "print'%s %.2f %s %.2f %s %.2f %s  '%('The necessary stresses sigma_1, sigma_2 for biaxial yielding are \\n ',sigma_2,' kgf/cm^2' '',sigma_1,' kgf/cm^2' and 'for uniaxial yielding sigma_0 ',sigma_0,'kgf/cm^2.')\n",
      "                    \n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The necessary stresses sigma_1, sigma_2 for biaxial yielding are \n",
        "  1837.12  kgf/cm^2 3674.23 for uniaxial yielding sigma_0  3181.98 kgf/cm^2.  \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex9-pg68"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "##initialization of variables\n",
      "#find the magnitude and direction of principal stress for the a b c\n",
      "## part (a)\n",
      "tau_xx=300 ## kgf/cm**2\n",
      "tau_yy=0 ## kgf/cm**2\n",
      "tau_xy=600 ## kgf/cm**2\n",
      "##calculations\n",
      "sigma_1=(tau_xx+tau_yy)/2.+math.sqrt((1./2.*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "sigma_2=(tau_xx+tau_yy)/2-math.sqrt((1/2.*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "Beta=math.atan(2*tau_xy/(tau_xx-tau_yy))\n",
      "Beta=Beta*180/math.pi\n",
      "##Results\n",
      "print'%s %.2f%s %.2f %s %.2f %s'%('\\n Part (a) \\n The magnitude of principal stresses are',sigma_1,''and '',sigma_2,'kgf/cm^2' and' \\n the direction is given by 2*beta=',Beta,'')\n",
      "\n",
      "\n",
      "##part (b)\n",
      "tau_xx=1000 ## kgf/cm**2\n",
      "tau_yy=150 ## kgf/cm**2\n",
      "tau_xy=450 ## kgf/cm**2\n",
      "## calculations\n",
      "sigma_1=(tau_xx+tau_yy)/2+math.sqrt((1/2*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "sigma_2=(tau_xx+tau_yy)/2-math.sqrt((1/2*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "Beta=math.atan(2*tau_xy/(tau_xx-tau_yy))\n",
      "Beta1=Beta*180./math.pi\n",
      "## Results\n",
      "print'%s %.2f %s  %.2f %s %.2f %s '%('\\n Part (b) \\n The magnitude of principal stresses are',sigma_1,''and '',sigma_2,'kgf/cm^2' and' \\n the direction is given by 2*beta=',Beta1,'')\n",
      "\n",
      "## part (c)\n",
      "tau_xx=-850 ## kgf/cm**2\n",
      "tau_yy=350 ## kgf/cm**2\n",
      "tau_xy=700 ## kgf/cm**2\n",
      "## calculations\n",
      "sigma_1=(tau_xx+tau_yy)/2+math.sqrt((1/2*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "sigma_2=(tau_xx+tau_yy)/2-math.sqrt((1/2*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "Beta=math.atan(2*tau_xy/(tau_xx-tau_yy))\n",
      "Beta=Beta*57.3\n",
      "## Results\n",
      "print'%s %.2f %s %.2f %s %.2f %s '%('\\n Part (c) \\n The magnitude of principal stresses are',sigma_1,''and '',sigma_2,'kgf/cm^2' and' \\n the direction is given by 2*beta=',-Beta,'')\n",
      "                   \n",
      "\n",
      "## wrong answers were given in textbook for part (b)\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        " Part (a) \n",
        " The magnitude of principal stresses are 768.47 -468.47  \n",
        " the direction is given by 2*beta= 75.96 \n",
        "\n",
        " Part (b) \n",
        " The magnitude of principal stresses are 1025.00   125.00  \n",
        " the direction is given by 2*beta= 45.00  \n",
        "\n",
        " Part (c) \n",
        " The magnitude of principal stresses are 450.00  -950.00  \n",
        " the direction is given by 2*beta= 63.44  \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex10-pg70"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import  math\n",
      "# initialization of variables\n",
      "#find the intensity of diagonal tension\n",
      "tau_xx= -1 # kgf/cm^2\n",
      "tau_yy= 0 # kgf/cm^2\n",
      "tau_xy= 7 # kgf/cm^2\n",
      "# calculations \n",
      "sigma_1=(tau_xx+tau_yy)/2.+math.sqrt((1/2.*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "sigma_2=(tau_xx+tau_yy)/2.-math.sqrt((1/2.*(tau_xx-tau_yy))**2+tau_xy**2)\n",
      "x=sigma_1 # positive one is tension\n",
      "if(sigma_2>sigma_1):\n",
      "    x=sigma_2\n",
      "\n",
      "# Results\n",
      "print'%s %.2f %s'%('The diagonal tension is ',x,' kgf/cm^2')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The diagonal tension is  6.52  kgf/cm^2\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex11-pg70"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# initialization of variables\n",
      "#find the state of stress at the joint\n",
      "d=2 # m\n",
      "l=10 # m\n",
      "t=1 # cm\n",
      "p=15 # kgf/cm^2\n",
      "pitch= 2*math.pi #m\n",
      "##calculations\n",
      "w=2*math.pi*d/2. # m\n",
      "theta=math.atan(w/(2*math.pi))\n",
      "sigma_z=p*d*100./(4.*t)\n",
      "sigma_th=p*d*100./(2.*t)\n",
      "sigma_th_new=(sigma_th+sigma_z)/2.+(sigma_th-sigma_z)/2.*math.cos(2*theta)\n",
      "tau_thz=(sigma_z-sigma_th)*math.sin(2.*theta)/2\n",
      "# results\n",
      "print'%s %.2f %s %.2f %s '%('At the junction, the normal and shear stresses are',sigma_th_new,'' and '',-tau_thz,' kgf/cm^2 \\n respectively, and the rivets must be designed for this')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "At the junction, the normal and shear stresses are 1125.00  375.00  kgf/cm^2 \n",
        " respectively, and the rivets must be designed for this \n"
       ]
      }
     ],
     "prompt_number": 12
    }
   ],
   "metadata": {}
  }
 ]
}