odeint的非线性ODE解决方案

问题描述 投票:1回答:1

我必须解决以下微分方程:

enter image description here

enter image description here

没有F_1术语,代码很简单。但是我无法用包含的F_1项来解决它,尽管我知道该解决方案应该看起来像阻尼谐波振荡。

from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt

def harmonic_motion(X,t,k,m,tau):
    x,v=X
    F=-(k/m)*x


    F_1=tau/v*(np.gradient(x,t)**2) # This line doesn't work. 

    dx_dt=v
    dv_dt=F-F_1
    dX_dt=[dx_dt,dv_dt]
    return dX_dt


m=1
k=1
tau=0.1
X0=-3
V0=0

t = np.linspace(0, 15, 250)
sol = odeint(harmonic_motion, [X0,V0], t,args=(k,m,tau))
x=sol[:,0]
v=sol[:,1]

plt.plot(t,x,label='x')
plt.plot(t,v,label='v')
plt.legend()
plt.xlabel('t (s)')
plt.ylabel('x,v (m,m/s)')
plt.show()
python scipy differential-equations
1个回答
0
投票

具有空气摩擦力的弹簧的正确版本是>

m*x'' + tau*abs(x')*x' + k*x = 0

为此的一阶系统是

def harmonic_motion(X,t,k,m,tau):
    x,v = X
    return  v, -(tau*abs(v)*v + k*x)/m

现在,它的相图应该给原点一个很好的螺旋。

© www.soinside.com 2019 - 2024. All rights reserved.