Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Lecture notes

Programming in Civil engineering

Rating
-
Sold
-
Pages
16
Uploaded on
20-07-2025
Written in
2024/2025

By reading and practice these documents you will get very interested information

Institution
Module

Content preview

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:

Written for

Module

Document information

Uploaded on
July 20, 2025
Number of pages
16
Written in
2024/2025
Type
Lecture notes
Professor(s)
Sir ali
Contains
All classes

Subjects

£6.61
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
adilrazaq14

Get to know the seller

Seller avatar
adilrazaq14 Punjab college
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions