代码展示:
import math
def f(x, a):
return a * math.cosh(x / a) - a
def f_prime(x, a):
return math.sinh(x / a)
def getWeight(x, a, delta):
left, weight = 0.0, 0.0
while left < x:
weight += (delta * math.sqrt(1.0 + (f_prime(left, a))**2))
left += delta
return weight
def getMoment(x, a, delta):
left, moment = 0.0, 0.0
while left < x:
moment += (delta * left * math.sqrt(1.0 + (f_prime(left, a))**2))
left += delta
return moment
def getGeometryCenter(x, a, delta):
return getMoment(x, a, delta) / getWeight(x, a, delta)
def getMechanicaCenter(x, a):
return x - f(x, a) / f_prime(x, a)
if __name__ == "__main__":
a = eval(input('请输入: a = ').strip())
x = eval(input('请输入: x = ').strip())
delta = eval(input('请输入: delta = ').strip())
x_center_mechanics = getMechanicaCenter(x, a)
print('由力矩间平衡计算得到的中心:',x_center_mechanics)
x_center_geometry = getGeometryCenter(x, a, delta)
print('由几何学分析得到的几何中心:', x_center_geometry)
运行结果: