In [2]:

```
import math
#initialisation
d = 1.5 # diameter of bar in inch
L = 54.0 # Length of bar in inch
G = 11.5e06 # modulus of elasticity in psi
#calculation
# Part (a)
T = 250.0 # torque
t_max = (16*T*12)/(math.pi*(d**3)) # maximum shear stress in bar
Ip = (math.pi*(d**4))/32 # polar miment of inertia
f = (T*12*L)/(G*Ip) # twist in radian
f_ = (f*180)/math.pi # twist in degree
print "Maximum shear stress in the bar is ", round(t_max), " psi"
print "Angle of twist is", round(f_,2), " degree"
#Part (b)
t_allow = 6000 # allowable shear stress
T1 = (math.pi*(d**3)*t_allow)/16 #allowable permissible torque in lb-in
T1_ = T1*0.0831658 #allowable permissible torque in lb-ft
f_allow = (2.5*math.pi)/180 # allowable twist in radian
T2 = (G*Ip*f_allow)/L # allowable stress via a another method
T2_ = T2*0.0831658 #allowable permissible torque in lb-ft
T_max = min(T1_,T2_) # minimum of the two
print "Maximum permissible torque in the bar is", round(T_max), " lb-ft"
```

In [5]:

```
import math
#initialisation
T = 1200.0 # allowable torque in N-m
t = 40e06 # allowable shear stress in Pa
f = (0.75*math.pi)/180.0 # allowable rate of twist in rad/meter
G = 78e09 # modulus of elasticity
#calculation
# Part (a) : Solid shaft
d0 = ((16.0*T)/(math.pi*t))**(1.0/3.0)
Ip = T/(G*f) # polar moment of inertia
d01 = ((32.0*Ip)/(math.pi))**(1.0/4.0) # from rate of twist definition
print "The required diameter of the solid shaft is ", round(d0,5), "m"
# Part (b) : hollow shaft
d2 = (T/(0.1159*t))**(1.0/3.0) # Diamater of hollow shaft in meter
d2_ = (T/(0.05796*G*f))**(1.0/4.0) # Another value of d2 by definition of theta(allow), f = T/(G*Ip)
d1 = 0.8*d2_ # because rate of twist governs the design
print "The required diameter of the hollow shaft is ", round(d2,5), "m"
# Part (c) : Ratio of diameter and weight
r1 = d2_/d01 # diameter ratio
r2 = ((d2_**2.0)-(d1**2.0))/(d01**2.0) # Weight Ratio
print "Ratio of the diameter of the hollow and solid shaft is", round(r1,2)
print "Ratio of the weight of the hollow and solid shaft is", round(r2,2)
```

In [11]:

```
import math
#Variable declaration
R1 = 0.6*1 #assumption for simplicity in calculations(for fig. a)
R2 = 1 #assumption for simplicity in calculations(for fig. b)
#Calculations
Ip1 = (math.pi/2)*(1-(R1**4))
Ip2 = (math.pi*R2**4)/2
B1 = Ip2/Ip1
B2 = Ip2/Ip1
Wh = (math.pi*R2**2)*(1-R1**2)
Ws = math.pi*R2**2
B3 = Wh/Ws
print "Maximum shear stress in the hollow shaft to that in the solid shaft is",round(B1,2)
print "The ratio of the angles of twists is",round(B2,2)
print "The ratio of the weight of the hollow shaft to the weight of the solid shaft is",B3
```

In [6]:

```
import math
#initialisation
d = 0.03 # diameter of the shaft in meter
T2 = 450.0 # Torque in N-m
T1 = 275.0
T3 = 175.0
Lbc = 0.5 # Length of shaft in meter
Lcd = 0.4 # Length of shaft in meter
G = 80e09 # Modulus of elasticity
#calculation
Tcd = T2-T1 # torque in segment CD
Tbc = -T1 # torque in segment BC
tcd = (16.0*Tcd)/(math.pi*(d**3)) # shear stress in cd segment
print "Shear stress in segment cd is", round(tcd/1000000,1), " MPa"
tbc = (16.0*Tbc)/(math.pi*(d**3)) # shear stress in bc segment
#answer given in the textbook for tbc is wrong
print "Shear stress in segment bc is", round(tbc/1000000,1), " MPa"
Ip = (math.pi/32)*(d**4) # Polar monent of inertia
fbc = (Tbc*Lbc)/(G*Ip) # angle of twist in radian
fcd = (Tcd*Lcd)/(G*Ip) # angle of twist in radian
fbd = fbc + fcd # angle of twist in radian
print "Angles of twist in section BD", round(fbd,3), " radian"
```

In [7]:

```
import math
#initialisation
d1 = 0.06 # Inner diameter in meter
d2 = 0.08 # Outer diameter in meter
r = d2/2.0 # Outer radius
G = 27e09 # Modulus of elasticity
T = 4000.0 # Torque in N-m
#calculation
Ip = (math.pi/32)*((d2**4)-(d1**4)) # Polar moment of inertia
t_max = (T*r)/Ip # maximum shear stress
print "Maximum shear stress in tube is ", t_max, " Pa"
s_t = t_max # Maximum tensile stress
print "Maximum tensile stress in tube is ", s_t, " Pa"
s_c = -(t_max) # Maximum compressive stress
print "Maximum compressive stress in tube is ", s_c, " Pa"
g_max = t_max / G # Maximum shear strain in radian
print "Maximum shear strain in tube is ", round(g_max,4), " radian"
e_t = g_max/2.0 # Maximum tensile strain in radian
print "radian",e_t,"Maximum tensile strain in tube is ", round(e_t,4), " radian"
e_c = -g_max/2.0 # Maximum compressive strain in radian
print "Maximum compressive strain in tube is ", round(e_c,4), " radian"
```

In [8]:

```
import math
#initialisation
H = 40.0 # Power in hp
s = 6000.0 # allowable shear stress in steel in psi
#calculation
# Part (a)
n = 500.0 # rpm
T = ((33000.0*H)/(2*math.pi*n))*(5042.0/420.0) # Torque in lb-in
d = ((16.0*T)/(math.pi*s))**(1.0/3.0) # diameter in inch
print "Diameter of the shaft at 500 rpm", round(d,2), " inch"
# Part (b)
n1 = 3000.0 # rpm
T1 = ((33000.0*H)/(2*math.pi*n1))*(5042.0/420.0) # Torque in lb-in
d1 = ((16*T1)/(math.pi*s))**(1.0/3.0) # diameter in inch
print "Diameter of the shaft at 3000 rpm", round(d1,2), " inch"
```

In [9]:

```
import math
#initialisation
d = 0.05 # diameter of the shaft
Lab = 1.0 # Length of shaft ab in meter
Lbc = 1.2 # Length of shaft bc in meter
Pa = 50000.0 # Power in Watt at A
Pb = 35000.0 # Power in Watt at B
Ip = (math.pi/32)*(d**4) # Polar moment of inertia
Pc = 15000.0 # Power in Watt at C
G = 80e09 # Modulus of elasticity
f = 10.0 # frequency in Hz
#Calculations
Ta = Pa/(2*math.pi*f) # Torque in N-m at A
Tb = Pb/(2*math.pi*f) # Torque in N-m at B
Tc = Pc/(2*math.pi*f) # Torque in N-m at B
Tab = Ta # Torque in N-m in shaft ab
Tbc = Tc # Torque in N-m in shaft bc
tab = (16*Tab)/(math.pi*(d**3)) # shear stress in ab segment
fab = (Tab*Lab)/(G*Ip) # angle of twist in radian
tbc = (16*Tbc)/(math.pi*(d**3)) # shear stress in ab segment
fbc = (Tbc*Lbc)/(G*Ip) # angle of twist in radian
fac = (fab+fbc)*(180.0/math.pi) # angle of twist in degree in segment ac
tmax = Tab # Maximum shear stress
#Result
print "The maximum shear stress tmax in the shaft", round(tmax), " Nm"
print "Angle of twist in segment AC", round(fac,2), " degree"
```

In [7]:

```
import math
#initialisation
Ta = 100.0 # Torque in N-m at A
Tb = 150.0 # Torque in N-m at B
L = 1.6 # Length of shaft in meter
G = 80e09 # Modulus of elasticity
Ip = 79.52e-09 # polar moment of inertia in m4
#calculation
Ua = ((Ta**2)*L)/(2*G*Ip) # Strain energy at A
print "Torque acting at free end", round(Ua,2), " joule"
Ub = ((Tb**2)*L)/(4*G*Ip) # Strain energy at B
print "Torque acting at mid point", round(Ub,2), " joule"
a = (Ta*Tb*L)/(2*G*Ip) # dummy variabble
Uc = Ua+a+Ub # Strain energy at C
print "Total torque", round(Uc,2), "joule"
```

In [11]:

```
import math
t = 480.0 # Torque of consmath.tant intensity
L = 144.0 # Length of bar
G = 11.5e06 # Modulus of elasticity in Psi
Ip = 17.18 # Polar moment of inertia
#Calculation
U = ((t**2)*(L**3))/(G*Ip*6) # strain energy in in-lb
#Result
print "The strain energy for the hollow shaft is", round(U), "in-lb"
```

In [13]:

```
import math
#Variable declaration
r = 1 #assuming r = 1 for simplicity in calculations
#Calculations
Am2 = (math.pi*r)**2/4
Am1 = math.pi*r**2
T1_T2 = Am2/Am1
t = 1 #assuming t = 1 for simplicity in calculations
J2 = ((math.pi*r)**3*t)/8
J1 = 2*math.pi*r**3*t
phi1_phi2 = J2/J1
#Results
print "Ratio of shear stress is ", round(T1_T2,2)
print "Ratio of angle of twist is ", round(phi1_phi2, 2)
```