-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1.py
More file actions
70 lines (55 loc) · 2.04 KB
/
Copy pathex1.py
File metadata and controls
70 lines (55 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from matplotlib import pyplot
class Ex1:
def __init__(self):
self.message = "Exercice 1 initialized"
#exercise parameters
self.P = 400 #kN
self.q = 25 #N/m
self.M1 = -69.14 #Bending moment at each point [kNm]
self.M2 = -238.27
self.M3 = -218.52
self.M4 = 0
self.M1P = 0 #Abscisse of the M points are along the beam
self.M2P = 4
self.M3P = 10
self.M4P = 14
self.L = 14 #Length of the beam
self.numberOfPoints = 100 #number of points to calculate bending moment
print(self.message)
def run(self):
print("Running Exercice 1...")
x_values = [i * self.L / self.numberOfPoints for i in range(self.numberOfPoints + 1)]
y_values = [self.calculateBendingMomentAtAPoint(x) for x in x_values]
pyplot.plot(x_values, y_values)
pyplot.title('Bending Moment at each point')
pyplot.xlabel('Position along beam (m)')
pyplot.ylabel('Bending moment (kNm)')
pyplot.show()
def calculateBendingMomentAtAPoint(self, position):
#determine the value of µ
µ = 0
x = position
Mleft = 0
Mright = 0
if position < self.M1P or position > self.L: #verify if the position is valid
print("Error: position out of bounds")
return None
if position < self.M2P:
µ = (self.q * self.L * x) / 2 - (self.q * x**2) / 2
Mleft = self.M1P
Mright = self.M2P
elif position < self.L/2:
µ = (self.P * x) / 4
Mleft = self.M2P
Mright = self.M3P
elif position < self.M3P:
µ = (self.P * (self.L - x)) / 4
Mleft = self.M2P
Mright = self.M3P
elif position > self.M3P:
µ = (self.q * self.L * x) / 2 - (self.q * x**2) / 2
Mleft = self.M3P
Mright = self.M4P
#calculate bending moments
M = µ + Mleft * (self.L - x) / self.L + Mright * x / self.L
return M