You are on page 1of 5

import math

sigma_x = float(input("Stress in x dir = "))


sigma_y = float(input("Stress in y dir = "))
tau_xy = float(input("Shear stress = "))
theta = int(input("Plane angle = "))
print("Results:")
print(["theta","sigmaN","TAU","sigmaR"])
for theta in range(1,45):
sigma_n = ((sigma_x+sigma_y) + (sigma_x-
sigma_y)*(math.cos(math.radians(2*theta)))) / 2 + (tau_xy*
(math.sin(math.radians(2*theta))))
shear_stress = ((sigma_x-sigma_y)*(math.sin(math.radians(2*theta)))) / 2 - (tau_xy*
(math.cos(math.radians(2*theta))))
res_stress = math.sqrt((sigma_n ** 2) + (shear_stress ** 2))
sigma_1 = ((sigma_x + sigma_y) + math.sqrt((sigma_x - sigma_y) ** 2 + 4 * (tau_xy
** 2))) / 2
sigma_2 = ((sigma_x + sigma_y) - math.sqrt((sigma_x - sigma_y) ** 2 + 4 * (tau_xy
** 2))) / 2
if tau_xy==0:
tau_max=((sigma_x-sigma_y)/2)
print("Maximum Shear Stress = ", end =" ")
print (tau_max)
else:
tau_max=((sigma_1-sigma_2)/2)
print("Maximum Shear Stress = ", end =" ")
print (tau_max)
list=[theta,round(sigma_n,2),round(shear_stress,2),round(res_stress,2)]
print(list)
print("sigma1","sigma2","taumax")
print(sigma_1,sigma_2,tau_max)
#complete...........
print("Normal stress = ", end = " ")
print(sigma_n)
print("Shear Stress = ", end = " ")
print(shear_stress)
print("Resultant Stress = ", end = " ")
print(res_stress)
print("Major Principal Stress = ", end = " ")
print(sigma_1)
sigma_2 = ((sigma_x+sigma_y) - math.sqrt((sigma_x-sigma_y)**2 + 4*(tau_xy**2))) / 2
print("Minor Principal Stress = ", end = " ")
print(sigma_2)

import numpy as np
# create numpy 3d-array
rows_a = int(input("Enter the Number of rows for the first matrix: " ))
column_a = int(input("Enter the Number of Columns for the first matrix: "))
print("Enter the elements of First Matrix:")
matrix_a= [[int(input()) for i in range(column_a)] for i in range(rows_a)]
print("First Matrix is: ")
for n in matrix_a:
print(n)
# finding eigenvalues and eigenvectors
w,v2=np.linalg.eig(matrix_a)
# printing eigen values
print("Printing the Eigen values of the given square array:\n", w)
# printing eigen vectors
print("Printing Right eigen vectors of the given square array:\n", v2)

print("BENDING STRESSES IN BEAMS")


print("ENTER THE BEAM TYPE. THE CALCULATIONS ARE FOR SIMPLY SUPPORTED DETERMINATE
BEAMS ONLY")
l = float(input("Enter the length of the beam in meters : "))
z=int(input("Enter 1 for Simply supported beam with central point load and 2 for
simply supported beam with uniform UDL along its length "))
if z ==1:
W = float(input("Enter the magnitude of point load in N: "))
M = W*l/4
else:
w = float(input("Enter the magnitude of UDL in N/m :"))
M = w*l*l/8
print("Enter the cross section type")
t=int(input("Enter 1 for rectangular section and 2 for circular section : "))
if t == 1:
b=float(input("Enter the width of the section in mm :"))
d=float(input("Enter the depth of the section in mm: "))
Ir=(b*d*d*d)/12
yr=d/2
print("Moment of Inertia about netutral axis: ",Ir)
print("Distance of Outermost layer from Neutral axis :",yr)
sigma = M*yr/Ir
print("Bending Stresses in newton per meter square :",sigma*pow(10,9))
else:
dc=float(input("Enter the diameter in mm: "))
Ic=(3.14*(dc**4)/64)
yc=dc/2
print("Moment of Inertia about netutral axis: ",Ic)
print("Distance of Outermost layer from Neutral axis :",yc)
sigma = M*yc/Ic
print("Bending Stresses in newton per meter square :",sigma*pow(10,9))

# Program to calculate the Deflection of Beams of Standard Cases


l=int(input("Enter the length of the Beam in meters: "))
e=int(input("Enter the modulus of Elasticity in Newton per meter square: "))
print("Enter The choice for cross section ")
m=int(input("Enter 1 for Rectangular Cross section and 2 for circular cross
section: "))
if m==1:
b=int(input("Enter the width in mm: "))
de=int(input("Enter the depth in mm: "))
i= (b*de*de*de)/12
elif m==2:
d=int(input("Enter the diameter in mm: "))
i=(3.14*d*d*d*d)/64
print("Enter 1 for cantilever beam carrying point load at its end ")
print("Enter 2 for cantilever beam carrying uniformly distributed length over its
entire length ")
print("Enter 3 for simpy supported beam carrying point load at the middle ")
print("Enter 4 for simply supported beam carrying uniformly distributed load over
its entire length ")
a=int(input("Enter the choice for type of beam: "))
if a==1:
w=int(input("Enter load in Newton: "))
y=(w*l*l*l)/(3*e*i*pow(10,-12))
elif a==2:
w=int(input("Enter the load in Newton per meter: "))
y=-(w*l*l*l*l)/(8*e*i*pow(10,-12))
elif a==3:
w=int(input("Enter the load in Newton: "))
y=-(w*l*l*l)/(48*e*i*pow(10,-12))
elif a==4:
w=int(input("Enter the load in Newton per meter: "))
y=-(5*w*l*l*l*l)/(382*e*i*pow(10,-12))
print("The deflection in the beam is :",round(y,3)*pow(10,3),"mm")

l=float(input("Enter the length of the column in meters:"))


e=float(input("Enter modulus of elasticity in Newton per meter square:"))
cs=float(input("Enter the crushing stress in Newton per meter square:"))
a=float(input("Enter the value of Rankine constant:"))
print("Enter 1 for Rectangular cross section")
print("Enter 2 for circular cross section")
s=int(input("Enter choice for Cross section:"))
if s==1:
b=float(input("Enter the width in mm:"))
d=float(input("Enter the depth in mm:"))
I=(b*d*d*d)/12
A=b*d
c=I/A
K=pow(c,0.5)
elif s==2:
d=float(input("Enter the diamter in mm:"))
I=(3.14*d*d*d*d)/64
A= (3.14*d*d)/4
c=I/A
K=pow(c,0.5)

print("Enter 1 for both ends hinged column")


print("Enter 2 for one end fixed and other free")
print("Enter 3 for both ends fixed")
print("Enter 4 for one end fixed and other hinged")
z=int(input("Enter the choice for type of column:"))

if z==1:
le=l
Pcr=(3.14*3.14*e*I*pow(10,-12))/(le*le)
Pc= cs*A*pow(10,-6)
Pr=(cs*A*pow(10,-6))/(1+a*pow(le/K,2)*pow(10,6))
elif z==2:
le=2*l
Pcr=(3.14*e*I*pow(10,-12))/(le*le)
Pc=cs*A*pow(10,-6)
Pr=(cs*A*pow(10,-6))/(1+a*pow(le/K,2)*pow(10,6))
elif z==3:
le=l/2
Pcr=(3.14*e*I*pow(10,-12))/(le*le)
Pc=cs*A*pow(10,-6)
Pr=(cs*A*pow(10,-6))/(1+a*pow(le/K,2)*pow(10,6))
elif z==4:
le=l/1.414
Pcr=(3.14*e*I*pow(10,-12))/(le*le)
Pc=cs*A*pow(10,-6)
Pr=(cs*A*pow(10,-6))/(1+a*pow(le/K,2))

print("The value of Crippling Load in Newton is:",Pcr)


print("The value of Crushing load in Newton is:",Pc )
print("The value of Rankine Load in Newton is:",Pr )

print(" THIN CYLINDERS")


#Initilization of variables
pi = 3.14
#D=0.8 #m #Diameter of Shell
#L=3 #m #Length of shell
#t=0.01 #m #thickness of metal
#E=200*10**9 #Pa
#p=2.5*10**6 #Pa #Internal Pressure
#m=0.25 #Poisson's ratio
D = float(input("Enter the Diameter of the Shell in m : "))
L = float(input("Enter the length of the shell in m: "))
t = float(input("Enter the Thickness of the Shell in m: "))
E = float(input("Enter the value of Young's Modulas in N/m2 : "))
p = float(input("Enter the value of Internal Pressure of Fluid in the shell in N/m2
:"))
m = float(input("Enter the Value of Poisson's Ratio: "))
#Calculation
sigma_1=p*D*(2*t)**-1 #N/m**2 #Hoop stress
sigma_2=p*D*(4*t)**-1 #N/m**2 #Longitudinal stress
e_1=1*E**-1*(sigma_1-sigma_2*m) #Hoop strain
e_2=1*E**-1*(sigma_2-sigma_1*m) #Hoop strain
d=e_1*D*1000 #mm #Increase in Diameter
l=e_2*L*1000 #mm #Increase in Length
dell_v=2*e_1+e_2 #Volumetric strain
V=dell_v*pi*4**-1*D**2*L*10**9 #cm**3 #Increase in Volume
#Result
print("Change in Diameter is",round(d,3),"mm")
print("Change in Length is",round(l,3),"mm")
print("Change in Volume is",round(V,2),"mm**3")
rho = float(input("Enter the Longitudinal Joint Efficiency: "))
rho_e = float(input(" Enter the Circumferential Joint Efficiency: "))
D_1=sigma_1*2*t*rho*p**-1 #Diameter of boiler
D_2=sigma_2*4*t*rho_e*p**-1 #Diameter of boiler
#Max diameter of boiler is equal to minimum value of diameter
#Result
print("Maximum diameter of boiler is",round(D_2,2),"m")
k = float(input("Enter the magnitude of Bulk Modulas in N/m2 :"))
#Calculations
#Let X=dV_1*V_1**-1
X=p*(0.4-2*0.006)*(2*t*E)**-1*(5*2**-1-2*m) #Volumetric strain
dV_1 = round(X,5)*pi*4**-1*0.388**2*L #cm**3 #Increase in volume of cyclinder
V_1=pi*4**-1*0.388**2*L #VOlume
dV_2=p*k**-1*V_1 #Decrease in volume of oil due to increase in pressure
dV=(dV_1+dV_2) #Resultant additional space
#Result
print("additional quantity of oil to be pumped is",round(dV,2)," m3")

# Python program to find roots of quadratic equation


import math

# function for finding roots


def findRoots(a, b, c):

dis_form = b * b - 4 * a * c
sqrt_val = math.sqrt(abs(dis_form))

if dis_form > 0:
print(" real and different roots ")
print((-b + sqrt_val) / (2 * a))
print((-b - sqrt_val) / (2 * a))

elif dis_form == 0:
print(" real and same roots")
print(-b / (2 * a))

else:
print("Complex Roots")
print(- b / (2 * a), " + i", sqrt_val)
print(- b / (2 * a), " - i", sqrt_val)

a = int(input('Enter a:'))
b = int(input('Enter b:'))
c = int(input('Enter c:'))

# If a is 0, then incorrect equation


if a == 0:
print("Input correct quadratic equation")

else:
findRoots(a, b, c)

You might also like