我对编程非常陌生,对Sympy来说更是如此。我试图从网上找到的用于求解微分方程组的算法的语法中,我能掌握些什么。但是我通过运行以下代码得到错误:
from sympy import *
init_printing(use_unicode=True)
"""
Parameters
"""
g=9.81
r=1.6e-2
R=2.75e-2
a=0.01
h=0.1
beta=3.0*pi/4
theta_p=pi/6.0
k=2.35
L0=1.5e-2
m=1
accx = 0
accy = 0
demi = Rational(1,2)
"""
Resolution
"""
t=symbols('t')
a1,a2,gamma,OGy = symbols('a1 a2 gamma OGy',cls=Function,real=True)
L1,L2,OGx = symbols('L1 L2 OGx',cls=Function,real=True,positive=True)
sgam = (L1(t)*cos(a1(t))-L2(t)*cos(a2(t)))/(2*r) # Physically corresponding to sin(gamma) where gamma is fully defined with the other variables
cgam = (2*R-L1(t)*sin(a1(t))-L2(t)*sin(a2(t)))/(2*r) # cos(gamma)
OGx = -L2(t)*cos(a2(t))+a*sgam+h*(sgam*cos(beta)-sin(beta)*cgam) # Position of the center of mass on x
OGy = -R-L2(t)*sin(a2(t))-a*cgam+h*(cos(beta)*cgam+sin(beta)*sgam) # Position of the center of mass on y
Fr1 = k*(L1(t)-L0)
Fr2 = k*(L2(t)-L0)
e1 = Eq(m*(OGx.diff(t).diff(t)+accx),Fr1*cos(a1(t))+Fr2*cos(a2(t))-m*g*sin(theta_p)+Fpv)
e2 = Eq(m*(OGy.diff(t).diff(t)+accy),Fr1*sin(a1(t))+Fr2*sin(a2(t))-m*g*cos(theta_p))
e3 = Eq(Fr1*((2*r+a)*(cos(a1(t))*cgam-sin(a1(t))*sgam)-h*(sin(a1(t))*(cgam*cos(beta)-sgam*sin(beta))+(cgam*sin(beta)+sgam*cos(beta))*cos(a1(t))))+Fr2*(a*(cgam*cos(a2(t))+sgam*sin(a2(t)))-h*((cgam*cos(beta)+sgam*sin(beta))*cos(a2(t))+(sgam*cos(beta)-cgam*sin(beta))*sin(a2(t))))+Fpv*((r+a)*cgam-h*(cgam*cos(beta)+sgam*sin(beta))))
e4 = Eq(L2(t),demi*(2*L1(t)*(cos(a1(t))*cos(a2(t))-sin(a1(t))*sin(a2(t)))+4*R*sin(a2(t))-sqrt((2*L1(t)*(cos(a1(t))*cos(a2(t))-sin(a1(t))*sin(a2(t)))+4*R*sin(a2(t)))**2-4*(L1(t)**2+4*R**2-4*r**2-4*R*L1(t)*sin(a1(t))))))
dsolve([e1,e2,e3,e4],[L1(t),L2(t),a1(t),a2(t)])
Python返回以下错误:
runfile('C:/Users/joris/OneDrive/Documents/Prépa/PT/TIPE/Méthode 2.py', wdir='C:/Users/joris/OneDrive/Documents/Prépa/PT/TIPE')
Traceback (most recent call last):
File "<ipython-input-65-133ac906ac79>", line 1, in <module>
runfile('C:/Users/joris/OneDrive/Documents/Prépa/PT/TIPE/Méthode 2.py', wdir='C:/Users/joris/OneDrive/Documents/Prépa/PT/TIPE')
File "C:\Users\joris\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\joris\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/joris/OneDrive/Documents/Prépa/PT/TIPE/Méthode 2.py", line 76, in <module>
dsolve([e1,e2,e3,e4],[L1(t),L2(t),a1(t),a2(t)])
File "C:\Users\joris\Anaconda3\lib\site-packages\sympy\solvers\ode.py", line 585, in dsolve
match = classify_sysode(eq, func)
File "C:\Users\joris\Anaconda3\lib\site-packages\sympy\solvers\ode.py", line 1530, in classify_sysode
if len(func_elem.args) != 1:
AttributeError: 'list' object has no attribute 'args'
我想这是我的语法中的错误,但我不能指责...
编辑:如下所述,这可能是由于它不是ODE系统,因为其中两个等式没有任何导数。那我该怎么办?