Python 使用ODEINT的二阶耦合ODE

Python 使用ODEINT的二阶耦合ODE,python,scipy,Python,Scipy,我不熟悉用python解决耦合ODE,我想知道我的方法是否正确,目前这段代码输出的图形与预期的输出完全不同。以下是我试图解决的方程: 这是我正在使用的代码(对于函数f_gr,f_sc_phi和f_gTheta,您可以输入任何常量值) 当我将时间从0.1更改为5时,我得到一个错误: ODEintWarning:此调用完成了过多的工作(可能是错误的Dfun类型)。以full_output=1运行以获取定量信息 如果我的方法完全不正确,有没有关于如何改进此代码的想法 Radial.py的代码 imp

我不熟悉用python解决耦合ODE,我想知道我的方法是否正确,目前这段代码输出的图形与预期的输出完全不同。以下是我试图解决的方程:

这是我正在使用的代码(对于函数
f_gr
f_sc_phi
f_gTheta
,您可以输入任何常量值)

当我将时间从0.1更改为5时,我得到一个错误:

ODEintWarning:此调用完成了过多的工作(可能是错误的Dfun类型)。以full_output=1运行以获取定量信息

如果我的方法完全不正确,有没有关于如何改进此代码的想法

Radial.py的代码

import numpy as np
from scipy.special import spherical_jn
from scipy.special import spherical_yn
import sympy as sp
import matplotlib.pyplot as plt
R_r = 5.6*10**(-5) 
l = 720
n_w = 1.326
#k = 524.5/R_r
X_r = 524.5



# R is constant r is changing  
def f_gr(theta,x):
    f = ((sp.sin(theta))**(2*l-2))*(1+(sp.cos(theta))**2)
    b = (spherical_jn(l,n_w*x)*spherical_jn(l,n_w*x,True))+(spherical_yn(l,n_w*x)*spherical_yn(l,n_w*x,True))
    c = (spherical_jn(l,n_w*X_r)*spherical_jn(l,n_w*X_r,True))+(spherical_yn(l,n_w*X_r)*spherical_yn(l,n_w*X_r,True))
    n = b/c
    f = f*n
    return f
散点Zimuthal.py的代码

from scipy.special import spherical_jn, spherical_yn
import numpy as np
import matplotlib.pyplot as plt

l = 720
n_w = 1.326
n_p = 1.572
X_r = 524.5
R_r = 5.6*10**(-5)
R_p = 7.5*10**(-7)
k = X_r/R_r


def f_sc_phi(theta,x):
    f = (2/3)*(n_w**2)*((X_r**3)/x)*((R_p**3)/(R_r**3))*(((n_p**2)-(n_w**2))/((n_p**2)+(2*(n_w**2))))
    g = np.sin(theta)**(2*l-3)
    numerator = (l*(1+np.sin(theta))- np.cos(2*theta))\
                *((spherical_jn(l,n_w*x)*spherical_jn(l,n_w*x))+(spherical_yn(l,n_w*x)*spherical_yn(l,n_w*x)))
    denominator = ((spherical_jn(l,n_w*X_r)*spherical_jn(l,n_w*X_r,True))\
                   +(spherical_yn(l,n_w*X_r)*spherical_yn(l,n_w*X_r,True)))
    m = numerator/denominator
    final = f*g*m
    return final
PolarComponent.py的名称和代码

import numpy as np
from scipy.special import spherical_yn, spherical_jn
import matplotlib.pyplot as plt

l = 720
n_w = 1.326
X_r = 524.5 #this value is implemented in the ode file

#define dimensionless polar component
#X_r is radius, x is variable 
def f_gTheta(theta,x):
    bessel1 = (spherical_jn(l,n_w*x)*spherical_jn(l,n_w*x)) + \
              (spherical_yn(l,n_w*x)*spherical_yn(l,n_w*x))
    bessel2 = ((spherical_yn(l,n_w*X_r)*spherical_yn(l,n_w*X_r,True)) + \
              (spherical_yn(l,n_w*X_r)*spherical_yn(l,n_w*X_r,True)))*n_w*x
    bessels = bessel1/bessel2
    rest = (np.sin(theta)**(2*l-3))*((l-1)*(1+(np.cos(theta)**2)) \
                                     -((np.sin(theta)**2)*np.cos(theta)))
    final = rest*bessels
    return final

这是一个我非常喜欢的模拟二阶常微分方程的例子。它有一个optamization扭曲,因为它拟合模型以匹配模拟。它有几个odeint和gekko的例子。

通过查看问题方程,您的y2方程可能有错误的解释。谢谢你,我修好了!但是这并没有修复我在时间超过0.1的时候遇到的错误。你知道是什么导致了这个错误吗?你能提供一些关于pc.f\gTheta(theta,524.1+rho)的数字吗(theta,524.1+rho)这样我就可以在我这边试试了?嗨,我已经添加了三个值的所有文件!谢谢!
import numpy as np
from scipy.special import spherical_yn, spherical_jn
import matplotlib.pyplot as plt

l = 720
n_w = 1.326
X_r = 524.5 #this value is implemented in the ode file

#define dimensionless polar component
#X_r is radius, x is variable 
def f_gTheta(theta,x):
    bessel1 = (spherical_jn(l,n_w*x)*spherical_jn(l,n_w*x)) + \
              (spherical_yn(l,n_w*x)*spherical_yn(l,n_w*x))
    bessel2 = ((spherical_yn(l,n_w*X_r)*spherical_yn(l,n_w*X_r,True)) + \
              (spherical_yn(l,n_w*X_r)*spherical_yn(l,n_w*X_r,True)))*n_w*x
    bessels = bessel1/bessel2
    rest = (np.sin(theta)**(2*l-3))*((l-1)*(1+(np.cos(theta)**2)) \
                                     -((np.sin(theta)**2)*np.cos(theta)))
    final = rest*bessels
    return final