In [1]: import numpy as np
import matplotlib.pyplot as plt
print("Simply Supported Beam")
print("\nType 1 for point load, Type 2 for UDL")
Type = int(input("Load case = "))
L = float(input("\nLength of beam in meter = "))
if Type == 1:
P = float(input("\nLoad applied in kN = "))
a = float(input("Location of Load from left end of the beam in meter = "))
c = L - a
R1 = P * (L - a) / L
R2 = P * a / L
else:
W = float(input("\nUniformly distributed load in kN/m = "))
b = float(input("Length of UDL in meter = "))
cg = float(input("C.G of UDL from left end of the beam in meter = "))
a = cg - b / 2
c = L - a - b
R1 = W * b * (b + 2 * c) / (2 * L)
R2 = W * b * (b + 2 * a) / (2 * L)
# Discretization
n = 1000
delta_x = L / n
x = np.linspace(0, L, n + 1)
V = np.zeros_like(x)
M = np.zeros_like(x)
# Calculation
if Type == 1:
for i in range(n + 1):
if x[i] < a:
V[i] = R1
M[i] = R1 * x[i]
else:
V[i] = R1 - P
M[i] = R1 * x[i] - P * (x[i] - a)
x1 = a
Mmax = P * a * (L - a) / L
else:
for i in range(n + 1):
if x[i] < a:
V[i] = R1
M[i] = R1 * x[i]
elif a <= x[i] < a + b:
V[i] = R1 - W * (x[i] - a)
M[i] = R1 * x[i] - W * ((x[i] - a) ** 2) / 2
else:
V[i] = -R2
M[i] = R2 * (L - x[i])
x1 = a + b * (b + 2 * c) / (2 * L)
Mmax = W * b * (b + 2 * c) * (4 * a * L + 2 * b * c + b ** 2) / (8 * L ** 2)
,# Results
print(f"\nLeft support Reaction = {R1:.2f} kN")
print(f"Right support Reaction = {R2:.2f} kN")
print(f"Maximum bending moment = {Mmax:.2f} kNm")
# Plotting
plt.figure(figsize=(10, 8))
# SFD
plt.subplot(2, 1, 1)
plt.plot(x, V, 'r', linewidth=1.5)
plt.axhline(0, color='k')
plt.axvline(0, color='r', linewidth=1.5)
plt.axvline(L, color='r', linewidth=1.5)
plt.title('Shear Force Diagram', fontsize=16)
plt.text(a / 2, V[0], f'{V[0]:.2f}', ha='center', fontweight='bold', fontsize=12)
plt.text(L - c / 2, V[-1], f'{V[-1]:.2f}', ha='center', fontweight='bold', fontsize=12
plt.grid(True)
# BMD
plt.subplot(2, 1, 2)
plt.plot(x, M, 'r', linewidth=1.5)
plt.axhline(0, color='k')
plt.axvline(x1, linestyle='--', color='b')
plt.title('Bending Moment Diagram', fontsize=16)
plt.text(x1 + 1 / L, Mmax / 2, f'{round(Mmax, 2):.2f}', ha='center', fontweight='bold'
plt.text(x1, 0, f'{round(x1, 2)} m', ha='center', fontweight='bold', fontsize=12)
plt.grid(True)
plt.tight_layout()
plt.show()
Simply Supported Beam
Type 1 for point load, Type 2 for UDL
Load case = 2
Length of beam in meter = 10
Uniformly distributed load in kN/m = 3
Length of UDL in meter = 10
C.G of UDL from left end of the beam in meter = 5
Left support Reaction = 15.00 kN
Right support Reaction = 15.00 kN
Maximum bending moment = 37.50 kNm
, In [2]: import numpy as np
import matplotlib.pyplot as plt
def get_input():
print("Simply Supported Beam Analysis\n")
load_type = int(input("Enter 1 for Point Load or 2 for UDL: "))
length = float(input("Enter beam length (m): "))
if load_type == 1:
P = float(input("Enter Point Load (kN): "))
a = float(input("Enter location of load from left support (m): "))
return load_type, length, {'P': P, 'a': a}
else:
W = float(input("Enter Uniformly Distributed Load (kN/m): "))
b = float(input("Enter length of UDL (m): "))
cg = float(input("Enter C.G. of UDL from left support (m): "))
return load_type, length, {'W': W, 'b': b, 'cg': cg}
def calculate_reactions(load_type, L, data):
if load_type == 1:
a = data['a']
c = L - a
P = data['P']
R1 = P * (L - a) / L
R2 = P * a / L
return R1, R2, a, c
else:
import matplotlib.pyplot as plt
print("Simply Supported Beam")
print("\nType 1 for point load, Type 2 for UDL")
Type = int(input("Load case = "))
L = float(input("\nLength of beam in meter = "))
if Type == 1:
P = float(input("\nLoad applied in kN = "))
a = float(input("Location of Load from left end of the beam in meter = "))
c = L - a
R1 = P * (L - a) / L
R2 = P * a / L
else:
W = float(input("\nUniformly distributed load in kN/m = "))
b = float(input("Length of UDL in meter = "))
cg = float(input("C.G of UDL from left end of the beam in meter = "))
a = cg - b / 2
c = L - a - b
R1 = W * b * (b + 2 * c) / (2 * L)
R2 = W * b * (b + 2 * a) / (2 * L)
# Discretization
n = 1000
delta_x = L / n
x = np.linspace(0, L, n + 1)
V = np.zeros_like(x)
M = np.zeros_like(x)
# Calculation
if Type == 1:
for i in range(n + 1):
if x[i] < a:
V[i] = R1
M[i] = R1 * x[i]
else:
V[i] = R1 - P
M[i] = R1 * x[i] - P * (x[i] - a)
x1 = a
Mmax = P * a * (L - a) / L
else:
for i in range(n + 1):
if x[i] < a:
V[i] = R1
M[i] = R1 * x[i]
elif a <= x[i] < a + b:
V[i] = R1 - W * (x[i] - a)
M[i] = R1 * x[i] - W * ((x[i] - a) ** 2) / 2
else:
V[i] = -R2
M[i] = R2 * (L - x[i])
x1 = a + b * (b + 2 * c) / (2 * L)
Mmax = W * b * (b + 2 * c) * (4 * a * L + 2 * b * c + b ** 2) / (8 * L ** 2)
,# Results
print(f"\nLeft support Reaction = {R1:.2f} kN")
print(f"Right support Reaction = {R2:.2f} kN")
print(f"Maximum bending moment = {Mmax:.2f} kNm")
# Plotting
plt.figure(figsize=(10, 8))
# SFD
plt.subplot(2, 1, 1)
plt.plot(x, V, 'r', linewidth=1.5)
plt.axhline(0, color='k')
plt.axvline(0, color='r', linewidth=1.5)
plt.axvline(L, color='r', linewidth=1.5)
plt.title('Shear Force Diagram', fontsize=16)
plt.text(a / 2, V[0], f'{V[0]:.2f}', ha='center', fontweight='bold', fontsize=12)
plt.text(L - c / 2, V[-1], f'{V[-1]:.2f}', ha='center', fontweight='bold', fontsize=12
plt.grid(True)
# BMD
plt.subplot(2, 1, 2)
plt.plot(x, M, 'r', linewidth=1.5)
plt.axhline(0, color='k')
plt.axvline(x1, linestyle='--', color='b')
plt.title('Bending Moment Diagram', fontsize=16)
plt.text(x1 + 1 / L, Mmax / 2, f'{round(Mmax, 2):.2f}', ha='center', fontweight='bold'
plt.text(x1, 0, f'{round(x1, 2)} m', ha='center', fontweight='bold', fontsize=12)
plt.grid(True)
plt.tight_layout()
plt.show()
Simply Supported Beam
Type 1 for point load, Type 2 for UDL
Load case = 2
Length of beam in meter = 10
Uniformly distributed load in kN/m = 3
Length of UDL in meter = 10
C.G of UDL from left end of the beam in meter = 5
Left support Reaction = 15.00 kN
Right support Reaction = 15.00 kN
Maximum bending moment = 37.50 kNm
, In [2]: import numpy as np
import matplotlib.pyplot as plt
def get_input():
print("Simply Supported Beam Analysis\n")
load_type = int(input("Enter 1 for Point Load or 2 for UDL: "))
length = float(input("Enter beam length (m): "))
if load_type == 1:
P = float(input("Enter Point Load (kN): "))
a = float(input("Enter location of load from left support (m): "))
return load_type, length, {'P': P, 'a': a}
else:
W = float(input("Enter Uniformly Distributed Load (kN/m): "))
b = float(input("Enter length of UDL (m): "))
cg = float(input("Enter C.G. of UDL from left support (m): "))
return load_type, length, {'W': W, 'b': b, 'cg': cg}
def calculate_reactions(load_type, L, data):
if load_type == 1:
a = data['a']
c = L - a
P = data['P']
R1 = P * (L - a) / L
R2 = P * a / L
return R1, R2, a, c
else: