看起来令人望而生畏,但请耐心等待,这并不像看起来那么困难。我在这里有一个关于光束偏转的代码。这只是一些数学和数字。只有最后一部分需要注意。“班级”任务(初学者)需要的指导
class beam(object):
"""This class is models the deflection of a simply supported beam under
multiple point loads, following Euler-Bernoulli theory and the principle of
superposition.
"""
def __init__(self, E, I, L):
"""The class costructor.
"""
self.E = 8.0E9 # Young's modulus of the beam in N/m^2
self.I = 1.333E-4 # Second moment of area of the beam in m^4
self.L = 5.0 # Length of the beam in m
self.Loads = [(0.0, 0.0)] # the list of loads applied to the beam
self.name = "beam"
def setLoads(self, Loads):
'''This function allows multiple point loads to be applied to the beam
using a list of tuples of the form (load, position)
'''
self.Loads = Loads
给出了“def __ init __”和“def setLoads”,所以上面不需要改变。我输入self.E,I和L的值,因为我认为我需要它们,但这些数字可以替换回它们以前的字母。
def beamDeflection(self, Load, x):
"""Just a simple calculation, really.
"""
E = 8.09 * (10 ** 9)
I = 1.333 * (10 ** -4)
L = 5
a = 2.5
b = a + (x - a)
(P1, a) = Load
if 0 <= x <= 2.5:
beamDeflection = ((P1*b*x)/(6*L*E*I))*((L**2)-(x**2)-(b**2))
else:
if 2.5 < x <= 5:
beamDeflection = ((P1*b)/(6*L*E*I))/(((L/b)*((x-a)**3)) -
(x**3) + (x*((L**2) -
(b**2))))
return beamDeflection
上述“beamDeflection”是简单的代码我输入了,仅仅使用一个已经被赋予了式计算在光束偏转。从本质上讲,如果一个重物放在横梁的左侧,它会计算出一个数字,而另一侧则相同。
def getTotalDeflection(self, x):
"""The function getTotalDeflection(self, x) should go through each load tuple in the
list.Loads and calculate the beam deflection at point x (Hint: the function you just
created could be handy here!). getTotalDeflection should return the total deflection at x,
which is the sum over each of the individual deflections.
"""
我的理解是,我需要一个“for”循环都要经过每个负载元组同时累及self.load。我不确定如何将这两件事结合在一起。如果有人能帮助我,我真的很感激。
为什么downvotes?这个问题对于新用户来说并不可怕。问题陈述非常明确,并且包含一些自己的解决方案。 +1 – timgeb