ODEs with infinite initlal condition in python

只愿长相守 提交于 2019-12-03 09:08:40

This is far from being a full answer, but is posted here on the OP's request.

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)

would be rewitten as the system

z1' = z2
z2' = f(z1, t) - g z2 - k z1

and your boundary conditions are

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]])

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]

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])
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!