我正在尝试解决这个问题:
U 在哪里
here:
s=c*e(t)+e_dot(t)
and
e(t)=theta(t)-thetad(t)
and
e_dot(t)=theta_dot(t)-thetad_dot(t)
其中thetad(thetadesired)=sin(t)——即要跟踪的信号!
且 thetad_dot=cos(t),J=10,c=0.5,eta=0.5
我首先尝试使用 odeint - 它在 t=0.4 之后给出了错误,即 theta(上述微分方程的解)降至 0 并在此后保持不变。然而,当我尝试将 mxstep 增加到 5000000 时,我可以获得一些正确的图表,直到 t=4.3s。
我想得到一个纯正弦图。也就是说,我想要 theta(上述微分方程的解)来跟踪 thetad,即 sin(t)。但在 t=4.3 秒后就无法准确跟踪 thetad。此后,theta(上述微分方程的解)就会下降到 0 并保持不变。
这是我的代码-
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
c=0.5
eta=0.5
def f(Y,t):
x=Y[0]
y=Y[1]
e=x-np.sin(t)
de=y-np.cos(t)
s=c*e+de
return [y,-c*(de)-np.sin(t)-eta*np.sign(s)]
t=np.linspace(0,10,1000)
y0=[0.5,1.0]
sol=odeint(f,y0,t,mxstep=5000000)
#sol=odeint(f,y0,t)
print(sol)
angle=sol[:,0]
omega=sol[:,1]
error=angle-np.sin(t)
derror=omega-np.cos(t)
plt.subplot(4,2,1)
plt.plot(t,angle)
plt.plot(t,error,'r--')
plt.grid()
plt.subplot(4,2,2)
plt.plot(t,omega)
plt.plot(t,derror,'g--')
plt.grid()
plt.subplot(4,2,3)
plt.plot(angle,omega)
plt.grid()
plt.subplot(4,2,4)
plt.plot(error,derror,'b--')
plt.savefig('signum_graph.eps')
plt.show()