import numpy as np import matplotlib.pyplot as plt # Function to analyze beams (simply supported and continuous) def analyze_beam(length, load, beam_type): if beam_type == "simply_supported": return analyze_simply_supported(length, load) elif beam_type == "continuous": return analyze_continuous(length, load) # Simply supported beam analysis def analyze_simply_supported(length, load): shear_force = load * length / 2 bending_moment = load * length**2 / 8 deflection = (5 * load * length**4) / (384 * 200000 * 100) return { "max_shear": shear_force, "max_bending_moment": bending_moment, "deflection": deflection } # Continuous beam analysis def analyze_continuous(length, load): shear_force = load * length / 3 bending_moment = load * length**2 / 12 deflection = (5 * load * length**4) / (384 * 200000 * 100) return { "max_shear": shear_force, "max_bending_moment": bending_moment, "deflection": deflection } # Function to plot the beam diagrams (SFD and BMD) def plot_beam_diagrams(beam_type, length, load): x = np.linspace(0, length, 100) shear = np.zeros_like(x) moment = np.zeros_like(x) if beam_type == "simply_supported": shear[:] = load / 2 moment[:] = (load * x * (length - x)) / (2 * length) elif beam_type == "continuous": shear[:] = load / 3 moment[:] = (load * x * (length - x)) / (3 * length) fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8)) ax1.plot(x, shear, label="Shear Force") ax1.set_title("Shear Force Diagram (SFD)") ax1.set_xlabel("Beam Length (ft)") ax1.set_ylabel("Shear Force (lb)") ax1.grid(True) ax2.plot(x, moment, label="Bending Moment", color="orange") ax2.set_title("Bending Moment Diagram (BMD)") ax2.set_xlabel("Beam Length (ft)") ax2.set_ylabel("Bending Moment (lb-ft)") ax2.grid(True) plt.tight_layout() plt.show()