Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中更改DE的顺序(scipy.integrate.odeint)_Python_Differential Equations - Fatal编程技术网

在python中更改DE的顺序(scipy.integrate.odeint)

在python中更改DE的顺序(scipy.integrate.odeint),python,differential-equations,Python,Differential Equations,我面临微分方程(python)的问题: 这是我的德: m*x“(t)+d*x'(t)+k*x(t)=y(t) 其中y(t)=y*sin(w*t) 数据: m=3 d=79 k=200000 w=152 Y=0.05 t=np.linspace(t_0,t_1, n) # not that important. 我必须使用scipy.integrate.odeint获得x(t)的numpy.array,我在将2的DE转换为1的DE时遇到了很大的问题 我要找的是scipy.integrate

我面临微分方程(python)的问题:

这是我的德:

m*x“(t)+d*x'(t)+k*x(t)=y(t)

其中
y(t)=y*sin(w*t)

数据:

m=3
d=79
k=200000
w=152 
Y=0.05
t=np.linspace(t_0,t_1, n) # not that important.  
我必须使用
scipy.integrate.odeint
获得
x(t)
numpy.array
,我在将2的DE转换为1的DE时遇到了很大的问题

我要找的是scipy.integrate.odeint中的func
根据我的方程,首先需要找到x(t)的np.数组,然后是x'(t)和x'(t)。

通常的步骤是设置
v=x'
,以便

x' = v
v' = ( y(t) - d*v - k*x) / m

结果


但我不是从中得到速度(x是运动,x'是速度,x''是加速度)吗?我需要得到x(t)-运动你需要解耦合系统,然后从数值积分的向量值结果中提取你的值。所以如果我插入u[:,0],我会得到x(t)?因为如果我这样做,答案是错误的(我的t=np.linspace(2.5,4.51900)的数据)这一行做什么:x,v=u
x,v=u
将列表/数组/向量
u
解压到其组件中。采样范围没有初始条件那么重要,您没有给出它们。
def derivs(u,t):
    x,v = u
    return [ v, ( y(t) - d*v - k*x) / m ]


def y(t): return Y*np.sin(w*t)

t_0, t_1, n = 0, 1, 501
t=np.linspace(t_0,t_1, n)

x0, v0 = 0.0, 0.0
u0 = [ x0, v0 ]

u = odeint(derivs, u0, t)

plt.subplot(2,1,1); plt.title("x(t)"); plt.plot(t, u[:,0])
plt.subplot(2,1,2); plt.title("x'(t)"); plt.plot(t, u[:,1])
plt.show()