import math
## initialization of variables
import numpy
E=2.*10**6. ## kg/cm^2
G=8.*10**5. ## kg/cm^2
ep=numpy.matrix([[0.001, 0, -0.002],
[0 ,-0.003, 0.0005],
[-0.002, 0.0005, 0]])
## calculations
nu=E/(2.*G)-1.
D=E*nu/((1.+nu)*(1.-2.*nu))
mu=G
sigma=2.*mu*ep[0,0]+D*(ep[0,0]+ep[1,1]+ep[2,2])
sigma=2.*mu*ep[1,1]+D*(ep[0,0]+ep[1,1]+ep[2,2])
sigma=2.*mu*ep[2,2]+D*(ep[0,0]+ep[1,1]+ep[2,2])
tau=2.*mu*ep[0,1]
tau=2.*mu*ep[0,2]
tau=2.*mu*ep[1,2]
tau=numpy.matrix([[sigma, tau, tau],
[tau, sigma, tau],
[tau, tau, sigma]])
## results
print'%s %.2f %s %.2f %s'%('The lames constants are ',D,' and ',mu,'kg/cm^2')
print('\n The stres tensor is')
print(tau)
print('in text book calculations are done wrong')
import math
## initialization of variables
#find the magnitude and direction of all the principal strains
sigma_x=1000. ##kg/cm^2
sigma_y=-500. ##kg/cm^2
sigma_z=0. ##kg/cm^2
tau_xy=500. ##kg/cm^2
E=2.*10**6 ## kg/cm^2
nu=0.25
##calculations
ep_x=1./E*(sigma_x-nu*(sigma_y+sigma_z))
ep_y=1./E*(sigma_y-nu*(sigma_x+sigma_z))
ep_z=1./E*(sigma_z-nu*(sigma_y+sigma_x))
J1=ep_x+ep_y+ep_z
sigma_1=(sigma_x+sigma_y)/2.+math.sqrt((1/2.*(sigma_x-sigma_y))**2+tau_xy**2)
sigma_2=(sigma_x+sigma_y)/2.-math.sqrt((1/2.*(sigma_x-sigma_y))**2+tau_xy**2)
th=1/2.*math.atan(2.*tau_xy/(sigma_x-sigma_y))
th=th*180/math.pi
ep_1=1./E*(sigma_1-nu*sigma_2)
ep_2=1./E*(sigma_2-nu*sigma_1)
ep_3=-1./E*nu*(sigma_1+sigma_2)
##results
print'%s %.5f %s'%('The magnitude of principal strain are ',abs(ep_1),'')
print'%s %.5f %s'%('The magnitude of principal strain are ',abs(ep_2),'')
print'%s %.5f %s'%('The magnitude of principal strain are ',abs(ep_3),'')
print'%s %.2f %s'%('\n and the diection is given by theta=',th,' degrees')
print'%s %.8f %s'%('\n J1 is ',J1,'')
import math
#findd the value of sigma y and principal stress
# initialization of variables
sigma_x=1400. ##kg/cm^2
tau_xy=400.## kg/cm^2
ep_z=-3.6*10**-6
nu=1/4.
E=2*10**8 ##kg/cm^2
## calculations
sigma_y=(-ep_z*E/nu)-sigma_x
sigma_1=(sigma_x+sigma_y)/2.+math.sqrt((1/2.*(sigma_x-sigma_y))**2+tau_xy**2)
sigma_2=(sigma_x+sigma_y)/2-math.sqrt((1/2.*(sigma_x-sigma_y))**2+tau_xy**2)
th=0.5*math.atan(2*tau_xy/(sigma_x-sigma_y))
th=th*180/math.pi
print'%s %.2f %s'%('sigma_y is ',sigma_y,' kg/cm^2')
print'%s %.2f %s %.2f %s '%('\n The principal stresses are',sigma_1,'kg/cm^2 'and '',sigma_2,'kg/cm^2')
print'%s %.2f %s'%('\n The direction is given by theta = ',-th,' degrees')
## angle was given wrong in the text
import math
##initialization of variables
#detemine wheather there is yielding according to tresca and von moises conditions or not
C=1000./3. ##kg/cm^2
sigma_x=2.*C
sigma_y=4.*C
tau_xy=4.*C
sigma_0=4.*C
sigma_1=3.+C*math.sqrt(2.)
sigma_2=3.-C*math.sqrt(2.)
sigma_3=0.
tau_oct=1/3.*math.sqrt((sigma_1-sigma_2)**2+(sigma_2-sigma_3)**2+(sigma_3-sigma_1)**2)
tau_max=sigma_1/2.
taU=1.885*C
tau_y=2.*C
print'%s %.2f %s'%('Actual tau is ',taU,'')
print'%s %.2f %s'%('\n tau_max at yield is ',tau_y,'')
print('\n Hence yielding doesn not occur according to Von-Miles condition \n but it occurs due to Tresca condition')
print('\n In text book C is not multiplied' )