Python中具有无限初始条件的ODE [英] ODEs with infinite initlal condition in python
问题描述
我有一个二阶微分方程,我想用python解决.问题在于,对于其中一个变量,我没有0
的初始条件,而只有无穷大的值.能否告诉我应该为scipy.integrate.odeint
提供哪些参数?能解决吗?
I have a second order differential equation that I want to solve it in python. The problem is that for one of the variables I don't have the initial condition in 0
but only the value at infinity. Can one tell me what parameters I should provide for scipy.integrate.odeint
? Can it be solved?
等式:
Theta需要在时间上找到.它的一阶导数在t=0
处等于零. Theta在t=0
处未知,但在足够大的时间变为零.所有其余的都是已知的.由于近似值I
可以设置为零,因此消除了二阶导数,这应该使问题更容易解决.
Theta needs to be found in terms of time. Its first derivative is equal to zero at t=0
. theta is not known at t=0
but it goes to zero at sufficiently large time. all the rest is known. As an approximate I
can be set to zero, thus removing the second order derivative which should make the problem easier.
推荐答案
这远不是一个完整的答案,而是应OP的要求张贴在这里.
This is far from being a full answer, but is posted here on the OP's request.
我在评论中描述的方法就是所谓的拍摄方法,它允许将边界值问题转换为初始值问题.为了方便起见,我将您的函数theta
重命名为y
.要用数字方式求解方程,您首先需要使用两个辅助函数z1 = y
和z2 = y'
将其转换为一阶系统,因此您的当前方程式
The method I described in the comment is what is known as a shooting method, that allows converting a boundary value problem into an initial value problem. For convenience, I am going to rename your function theta
as y
. To solve your equation numerically, you would first turn it into a first order system, using two auxiliary function, z1 = y
and z2 = y'
, and so your current equation
I y'' + g y' + k y = f(y, t)
将被系统迷惑
z1' = z2
z2' = f(z1, t) - g z2 - k z1
您的边界条件是
z1(inf) = 0
z2(0) = 0
因此,我们首先设置函数以计算新矢量函数的导数:
So first we set up the function to compute the derivative of your new vectorial function:
def deriv(z, t) :
return np.array([z[1],
f(z[0], t) - g * z[1] - k * z[0]])
如果我们有条件z1[0] = a
,我们可以在t = 0
和t = 1000
之间进行数值求解,并在最后一次获得y
的值,例如
If we had a condition z1[0] = a
we could solve this numerically between t = 0
and t = 1000
, and get the value of y
at the last time as something like
def y_at_inf(a) :
return scipy.integrate.odeint(deriv, np.array([a, 0]),
np.linspace(0, 1000, 10000))[0][-1, 0]
所以现在我们所需要知道的是a
的值使t = 1000
在我们穷人的无穷大t = 1000
处具有
So now all we need to know is what value of a
makes y = 0
at t = 1000
, our poor man's infinity, with
a = scipy.optimize.root(y_at_inf, [1])
这篇关于Python中具有无限初始条件的ODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!