from sympy.mpmath import *
我正在构建一个梁模型,但我在最后一部分遇到了一些问题 - getSlope。否则,其余的应该没问题。
class beam(object):
"""Model of a beam.
"""
def __init__(self, E, I, L):
"""The class costructor.
"""
self.E = E # Young's modulus of the beam in N/m^2
self.I = I # Second moment of area of the beam in m^4
self.L = L # Length of the beam in m
self.Loads = [(0.0, 0.0)] # the list of loads applied to the 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 beamDeflection(self, Load, x):
"""A measure of how much the beam bends.
"""
a = 2.5
b = a + (x - a)
(P1, A) = Load
if 0 <= x <= a:
v = ((P1*b*x)/(6*self.L*self.E*self.I))*((self.L**2)-(x**2)-(b**2))
else:
if a < x <= 5:
v = ((P1*b)/(6*self.L*self.E*self.I)) * (((self.L/b)*((x-a)**3)) - (x**3) + (x*((self.L**2) - (b**2))))
return v
上面的函数'beamDeflection'是我做过的一些简单的硬编码,如果一个负载放在左侧,那么使用某个公式,如果负载在另一侧,那么另一个公式是用过的。
def getTotalDeflection(self, x):
"""A superposition of the deflection.
"""
return sum(self.beamDeflection(loadall, x) for loadall in self.Loads)
'getTotalDeflection' 计算在其上放置多个载荷时的总挠度。
def getSlope(self, x):
"""Differentiate 'v' then input a value for x to obtain a result.
"""
mp.dps = 15
mp.pretty = True
theta = sympy.diff(lambda x: self.beamDeflection(self.Loads, x), x)
return theta
b = beam(8.0E9, 1.333E-4, 5.0)
b.setLoads([(900, 3.1), (700, 3.8), (1000, 4.2)])
print b.getSlope(1.0)
对于这个函数,我应该区分“beamDeflection”或“v”,因为我定义它时它处于多个负载下,然后输入 x 的值以找到梯度/斜率。
我正在关注这个:“ http://docs.sympy.org/dev/modules/mpmath/calculus/differentiation.html ”来区分,但它需要第二个参数(看起来是一个整数)才能工作,所以我不认为这是区分它的正确方法。任何人都可以对此有所了解吗?