光束偏转图 [英] BeamDeflection Plot
问题描述
我的脚本没有显示情节时遇到了问题.该图必须将梁的偏转显示为整个梁的 x 坐标的函数.我不知道我是否可以做出以下陈述:x[i]>a[v]"如果没有给出 x...
I'm having trouble with my script not showing a plot. The plot must show the deflection of the beam as a function of the x-coordinate of the entire beam. I don't know if I can make the statements: "x[i]>a[v]" if x is not given...
import numpy as np #Imports NumPy
import matplotlib.pyplot as plt
def beamPlot(beamLength, loadPositions, loadForces, beamSupport):
l=beamLength #Scalar
a=loadPositions #Vector
W=loadForces #Vector
x=np.array(range(0,l))
E=200*10**9 #Constant [N/m^2]
I=0.001 #Constant [m^4]
#Makes an empty vector with the same size as x
y=np.empty_like(x)
for i in range(np.size(x)): #Continues as long as the vector x
for v in range(np.size(a)):
if a[v]==[ ] and W[v]==[ ]:
return np.zeros(np.size(x))
elif beamSupport=="both" and x[i]<a[v]:
y[i]=np.sum(((W[v]*(l-a[v])*x[i])/(6*E*I*l))*(l**2-x[i]**2-(l-a[v])**2))
elif beamSupport=="both" and x[i]>=a[v]:
y[i]=np.sum(W[v]*a[v]*(l-x[i])/(6*E*I*l)*(l**2-(l-x[i])**2-a[v]**2))
elif beamSupport=="cantilever" and x[i]<a[v]:
y[i]=np.sum((W[v]*x[i]**2)/(6*E*I)*(3*a[v]-x[i]))
elif beamSupport=="cantilever" and x[i]>=a[v]:
y[i]=np.sum((W[v]*a[v]**2)/(6*E*I)*(3*x[i]-a[v]))
deflection=y
plt.ylim([0,10000])
plt.xlim([0,l])
plt.title("Beam deflection")
plt.plot(x, deflection)
plt.show()
推荐答案
您的数组 x
是使用 range(0,l)
中的整数列表创建的,其中表示数组中的元素属于 int
类型.您可以使用 np.epty_like()
创建 y
数组,这意味着它还有 int
类型的元素.除非您对负载使用大值,否则您的计算创建的浮点值在转换为 int 时会四舍五入为 0
,因此该图是 y=0 处的一条平线.
Your array x
is created with a list of integers from range(0,l)
, which means that the elements in the array are of type int
. You create the y
array using np.epty_like()
which means that it also has elements of type int
. Unless you are using huge values for the loads, the float values created by your calculations get rounded to 0
when converted to int, so the plot is a flat line at y=0.
您可以通过在创建时指定 y
应包含浮点值来解决此问题,方法是将 dtype=float
添加到:
You can fix this by specifying that y
should contain float values when it is created by adding dtype=float
to:
y=np.empty_like(x, dtype=float)
您还应该删除 plt.ylim(0,10000)
并让 matplotlib 自动缩放您的 y 轴,因为对于任何合理的载荷值,位移可能不会这么大(考虑到你的僵硬)
You should also remove the plt.ylim(0,10000)
and instead let matplotlib autoscale your y-axis, since the displacements are probably not going to be this large for any reasonable values of loads (given your stiffness)
这篇关于光束偏转图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!