我试图绘制四杆机构输出角度的角度与时间图(下图中的角度fi4
)。使用第23页https://scholar.cu.edu.eg/?q=anis/files/week04-mdp206-position_analysis-draft.pdf中的解计算该角度
我现在正试图绘制fi_4(t)
图,得到了一些奇怪的结果。该图将输入角度fi2
显示为蓝色,输出角度fi4
显示为红色。为什么fi2
会随着时间而波动?{
我是不是遗漏了什么
四连杆机构:
守则:
from __future__ import division
import math
import numpy as np
import matplotlib.pyplot as plt
# Input
#lengths of links (tube testing machine actual lengths)
a = 45.5 #mm
b = 250 #mm
c = 140 #mm
d = 244.244 #mm
# Solution for fi2 being a time function, f(time) = angle
f = 16.7/60 #/s
omega = 2 * np.pi * f #rad/s
t = np.linspace(0, 50, 100)
y = a * np.sin(omega * t)
x = a * np.cos(omega * t)
fi2 = np.arctan(y/x)
# Solution of the vector loop equation
#https://scholar.cu.edu.eg/?q=anis/files/week04-mdp206-position_analysis-draft.pdf
K1 = d/a
K2 = d/c
K3 = (a**2 - b**2 + c**2 + d**2)/(2*a*c)
A = np.cos(fi2) - K1 - K2*np.cos(fi2) + K3
B = -2*np.sin(fi2)
C = K1 - (K2+1)*np.cos(fi2) + K3
fi4_1 = 2*np.arctan((-B+np.sqrt(B**2 - 4*A*C))/(2*A))
fi4_2 = 2*np.arctan((-B-np.sqrt(B**2 - 4*A*C))/(2*A))
# Plot the fi2 time diagram and fi4 time diagram
plt.plot(t, np.degrees(fi2), color = 'blue')
plt.plot(t, np.degrees(fi4_2), color = 'red')
plt.show()
图表:
linespace(0, 50, 100)
太快了。将其替换为:其次,所有涉及裸} ,来确定正确的象限(与基于
np.arctan()
的计算都是不正确的。您应该使用^{y/x
的任何方法不同,x
和y
的各自符号丢失)。因此:在绘图上添加一些标签并显示
θ_4
的两种解决方案:通过这些MOD,我们可以:
顺便说一句,你想看到一个令人惊讶的懒惰的方式来解决这些问题吗?比您的代码效率要低得多,但在不尝试表达解决方案的封闭形式的情况下更容易派生(例如,对于其他结构):
应用程序:
根据机构的结构(例如5个连杆),您可能有两个以上的解决方案,当然还有更多的角度,因此您必须修改上述代码。但你明白了
请注意:
fsolve
迭代以找到合适的(足够接近的)解决方案,正如我所说的,它比封闭形式慢得多更新(一些澄清/解释):
函数
f
以两种不同的方式(通过R2-R3
和通过R1-R4
)计算点B
的位置,并返回差值(作为向量)。我们求差为零该函数接受两个参数:一个二维变量(
th34
,它是数组[th3, th4]
)和一个参数th2
;该参数在一次运行fsolve
期间为常量值
[0, -1.5]
和[0, 1.5]
是th34
(th3
和th4
)的初始化值(猜测)。我们调用fsolve
两次以得到两个可能的解决方案所有角度都参考你的图形。我使用
th
表示θ(θ,而不是φ),但我保留了原始的fi4_1
和fi4_2
进行比较模
2*pi
,th4_1
应等于fi4_1
等,由np.allclose
测试以说明数值舍入误差相关问题 更多 >
编程相关推荐