import math
# Variables
h_1 = 1;
k_1 = 1;
l_1 = 1;
#Miller indices of slip plane
h_2 = 1;
k_2 = -1;
l_2 = 1;
#Miller indices of stress plane
h_3 = 1;
k_3 = 1;
l_3 = 0;
# Calculation
#Miller indices of slip direction
A = (h_1*h_2+k_1*k_2+l_1*l_2)/(((h_1**2+k_1**2+l_1**2)**(1./2))*((h_2**2+k_2**2+l_2**2)**(1./2))); #Value of math.cos(x) where x = angle between slip plane and stress plane
B = (h_1*h_3+k_1*k_3+l_1*l_3)/(((h_1**2+k_1**2+l_1**2)**(1./2))*((h_3**2+k_3**2+l_3**2)**(1./2))); #Value of math.cos(y) where y = angle between slip direction and stress direction
C = (1-A**2)**(1./2); #Value of math.sin(x)
stress = 3.5; #Applied Stress in Mpa
T_cr = stress*A*B*C; #Critical resolved shear stress(in MPa)
# Results
print 'Critical resolved shear stress in = %.3f MPa'%T_cr
import math
# Variables
D = 0.022; #Grain diameter(in mm)
d = D*10**(-3); #Grain diameter(in m)
K = 0.63; #Constant(in MNm**(-3/2))
# Calculation
sigma_i = 80; #in MNm**-2
sigma_y = sigma_i+K*d**(-1./2); #Yield stress for a polycrystalline alloy
# Results
print 'Yield stress for a polycrystalline alloy in = %.2f MN/m**2'%sigma_y
import math
# Variables
sigma_y1 = 120; #primary yield strength of polycrystalline material(in MN*m**-2)
sigma_y2 = 220; #increased yield strength of polycrystalline material(in MN*m**-2)
d_1 = 0.04*10**(-3); #primary grain diameter(in meter)
d_2 = 0.01*10**(-3); #grain diameter after decreasing(in meter)
# Calculation
#sigma_y1 = sigma_i+K*(d_1)**(-1/2)
#sigma_y2 = sigma_i+K*(d_2)**(-1/2)
#putting the values and solving the equation
K = (220-120)/((d_2**(-1./2))-((d_1**(-1./2)))); #consmath.tant(in MN*m(-3/2))
sigma_i = sigma_y1-K*(d_1)**(-1./2); #in MN*m**-2
d = 1./((10**4)*(256./645))**(1./2); #grain diameter for grain size ASTM 9(in mm)
D = d*10**(-3); #grain diameter for grain size ASTM 9(in meter)
sigma_y = sigma_i+K*(D)**(-1./2); #Yield stress for a polycrystalline alloy for grain size ASTM 9(in MN*m**-2)
# Results
print 'Yield stress for a polycrystalline alloy for grain size ASTM 9 in = %.0f MN*m**-2'%round(sigma_y)