import math
#calculate Normal stress intensity and Tangential stress intensity and Resultant stress intensity and angle
p_1 = 5.;##principal stress in tons/in^2
p_2 = 5./2.;##principal stress in tons/in^2
theta = 50*math.pi/180;##angle in degrees
p_n = p_1*math.cos(theta)**2+p_2*math.sin(theta)**2;##normal stress intensity
p_t = (p_1-p_2)*math.sin(theta)*math.cos(theta);##tangential stress intensity
p = math.sqrt((p_1*math.cos(theta))**2+(p_2*math.sin(theta))**2);##resultant intensity of stress
alpha = math.atan((p_2*math.sin(theta))/(p_1*math.cos(theta)));##in radians
alpha = alpha*180/math.pi;##in degrees
print'%s %.2f %s'%('Normal stress intensity p_n = ',p_n,' tons/in^2');
print'%s %.2f %s'%('h Tangential stress intensity p_t = ',p_t,' tons/in^2');
print'%s %.2f %s'%(' Resultant stress intensity p = ',p,'tons/in^2');
print'%s %.2f %s'%(' angle alpha p_n = ',alpha,' degrees');
##there is an error in the answer given in text book
import math
#calculate The inclination of principal planes to the axis of the bolt and p_2 and Maximum shear stress is p_max and stress which acting alone will produce the same maximum strain
d = 3./4. ;##inches
P = 2.;##tons
Q = 0.5;##tons
m = 4.;
A = 0.25*math.pi*d**2;##in^2
p = P/A ;##tons/in^2
q = Q/A;##tons/in^2
theta = 0.5*math.atan(2.*q/p);##radians
theta1 = theta*180/math.pi;##degrees
theta2 = theta1+90;##degrees
print'%s %.2f %s'%('The inclination of principal planes to the axis of the bolt will be',theta1,'degres')
print'%s %.2f %s'%('The inclination of principal planes to the axis of the bolt will be',180-theta2,'degrees')
print'%s %.2f %s'%('The inclination of maximum shear planes to the axis of the bolt will be',theta1+45,'degress')
print'%s %.2f %s'%('The inclination of principal planes to the axis of the bolt will be',180-theta2-45,'degrees')
p_1 = 0.5*p+math.sqrt(0.25*p**2+q**2);##tons/in^2
p_2 = 0.5*p-math.sqrt(0.25*p**2+q**2);##tons/in^2
p_max = 0.5*(p_1-p_2);##tons/in^2
p_s = p_1-(p_2/m);##tons/in^2
print'%s %.2f %s'%('The principal stresse are given by p_1 =',p_1,'tons/in^2.,tensile')
print'%s %.2f %s'%('p_2 =',p_2,'tons/in^2.,compressive')
print'%s %.2f %s'%('p_2 =',p_2,'tons/in^2 .,compressive');
print'%s %.2f %s'%('Maximum shear stress is p_max =',p_max,'tons/in^2');
print'%s %.2f %s'%('The stress which acting alone will produce the same maximum strain is given by,',p_s,'tons/in^2');
##there is an error in the answer given in text book
import math
#calculate The principal stresses and The maximum shear stress and the planes offering it being inclined and the normal stress intensity
q = 2.;##tons/in^2
p = 5.;##tons/in^2
p_dash = 2.;##tons/in^2
theta = 0.5*math.atan(2*q/(p-p_dash));##radians
theta1 = theta*180/math.pi;##degrees
theta2 = theta1+90;##degrees
p_1 = 0.5*(p+p_dash)+math.sqrt(q**2 + 0.25*(p-p_dash)**2);##tons/in^2
p_2 = 0.5*(p+p_dash)-math.sqrt(q**2 + 0.25*(p-p_dash)**2);##tons/in^2
q_max = 0.5*(p_1-p_2);##tons/in^2
print'%s %.2f %s'%('The principal stresses are p_1 =',p_1,'tons/in^2 .,tensile')
print'%s %.2f %s'%('The principal stresses arep_2 =',p_2,'tons/in^2., tensile');
print'%s %.1f %s'%('The maximum shear stress is',q_max,'tons/in^2.,')
print'%s %.2f %s'%('the planes offering it being inclined at',theta1+45,'degrees')
print'%s %.2f %s'%('the planes offering it being inclined at',theta2+45,'degrees')
print'%s %.2f %s'%('to the plane having the normal stress intensity of',p,'tons/in^2.')
##there is an error in the answer given in text book
import math
#calculate theta1 and theta2 and P_1 and P_2 and maximum shear intensity
p_res = 6.;##tons/in^2
p_dash = 4.;##tons/in^2
theta = 30.*math.pi/180.;##degrees
p_n = 4.;##tons/in^2
p = p_res*math.cos(theta);##tons/in^2
q = p_res*math.sin(theta);##tons/in^2
L = 2*q/(p-p_dash);
theta = 0.5*math.atan(2*q/(p-p_dash));
theta1 = theta*180/math.pi;##degrees
theta2 = theta1+90;##degrees
p_1 = 0.5*(p+p_dash)+math.sqrt(q**2 + 0.25*(p-p_dash)**2);##tons/in^2
p_2 = 0.5*(p+p_dash)-math.sqrt(q**2 + 0.25*(p-p_dash)**2);##tons/in^2
p_max = 0.5*(p_1-p_2);##tons/in^2
print'%s %.2f %s'%('Theta1 =',theta1,'degrees')
print'%s %.2f %s'%('Theta2 =',theta2,'degrees')
print'%s %.2f %s'%('p_1 =',p_1,'tons/in^2.,tensile')
print'%s %.2f %s'%('p_2 =',p_2,'tons/in^2.,tensile')
print'%s %.2f %s'%('The maximum shear intensity will be',p_max,'tons/in^2 across the planes of maximum shear.');
import math
#calculate tensiles and compressive
p_1 = 7.;##tons/in^2
p_2 = 4.;##tons/in^2
p_3 = 3.;##tons/in^2
m = 4.;
E = 13000.;##tons/in^2
e_1 = (p_1/E)+(p_2/(m*E))-(p_3/(m*E));
e_2 = (p_2/E)+(p_1/(m*E))+(p_3/(m*E));
e_3 = (p_3/E)-(p_1/(m*E))+(p_2/(m*E));
print'%s %.4f %s'%('e_1 =',e_1,'tensile')
print'%s %.4f %s'%('e_2 =',e_2,'compressive')
print'%s %.4f %s'%('e_3 =',e_3,'tensile')
import math
#calculate the contraction in the length
a = 2.;##inches
l = 6.;##inches
E = 13000.;##tons/In^2
m = 1./0.3;
P = 20.;##tons
p_1 = P/a**2;##tons/in^2
p_2 = p_1/(2.*(m-1));##tons/in^2
e_1 = (5.-0.6*p_2)/E;##tons/in^2
del_l = e_1*l;##inches
print'%s %.4f %s'%('The contraction in the length del_l =',del_l,'inches');