Created
February 8, 2024 19:37
-
-
Save joreilly86/e8e9971854d857ddf27f51a31c622abf to your computer and use it in GitHub Desktop.
Function for simply supported beam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot_beam_diagrams(length, w): | |
""" | |
Plot the shear force and bending moment diagrams for a simply supported beam. | |
Parameters: | |
- length: Length of the beam (m) | |
- w: Magnitude of the uniformly distributed load (kN/m) | |
""" | |
# Functions for shear force and bending moment | |
def shear_force(x): | |
return w * (length / 2 - x) # kN | |
def bending_moment(x): | |
return (w * x / 2) * (length - x) # kNm | |
# Maximum shear force and bending moment calculations | |
V_max = w * length / 2 | |
M_max = w * length ** 2 / 8 | |
print(f"Maximum Shear Force: {V_max} kN") | |
print(f"Maximum Bending Moment: {M_max} kNm") | |
# Generating points for plotting | |
x_values = np.linspace(0, length, 100) | |
sf_values = [shear_force(x) for x in x_values] | |
bm_values = [bending_moment(x) for x in x_values] | |
# Plotting Shear Force Diagram (SFD) and Bending Moment Diagram (BMD) | |
plt.figure(figsize=(12, 6)) | |
# Shear Force Diagram | |
plt.subplot(1, 2, 1) | |
plt.plot(x_values, sf_values, label='Shear Force (Vx)', lw=2, color='blue') | |
plt.fill_between(x_values, 0, sf_values, color='skyblue', alpha=0.5) | |
plt.axhline(0, color='black', lw=1) # Beam axis | |
plt.title('Shear Force Diagram (SFD)') | |
plt.xlabel('Position along the beam (m)') | |
plt.ylabel('Shear Force (kN)') | |
plt.grid(True) | |
plt.legend() | |
# Bending Moment Diagram | |
plt.subplot(1, 2, 2) | |
plt.plot(x_values, bm_values, color='red', label='Bending Moment (Mx)', lw=2) | |
plt.fill_between(x_values, 0, bm_values, color='salmon', alpha=0.5) | |
plt.axhline(0, color='black', lw=1) # Beam axis | |
plt.title('Bending Moment Diagram (BMD)') | |
plt.xlabel('Position along the beam (m)') | |
plt.ylabel('Bending Moment (kNm)') | |
plt.grid(True) | |
plt.legend() | |
plt.tight_layout() | |
plt.show() | |
# Example usage | |
plot_beam_diagrams(length=10, w=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment