在找到局部最大值之前,我可以与scipy的odeint集成吗? [英] Can I integrate with scipy's odeint until a local max is found?

查看:105
本文介绍了在找到局部最大值之前,我可以与scipy的odeint集成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里的第一个问题,所以请对我轻松一点.我想知道是否只有在找到指定变量的局部最大值之前,才可以集成ODE系统.这里有一些详细信息:

This is my first question on here, so please go easy on me. I'm wondering if there is a way to integrate an ODE system only until a local max of a specified variable is found. Here is some more detail:

让我们调用我们的ODE系统dX/dt = F(X) where X(t) = [x1(t), x2(t), ... , xn(t)].假设该系统的解在任何一个不稳定的固定点p处都吸引到一个稳定的极限环C.选择一些初始条件X0而不是p,而不是C.我们希望遵循解的轨迹来实现:

Let's call our ODE system dX/dt = F(X) where X(t) = [x1(t), x2(t), ... , xn(t)]. Assume the solution to this system is attracted to a stable limit cycle C everywhere but at one unstable fixed point p. Choose some initial conditions X0 not p, and not in C. We wish to follow the trajectory of the solution to:

dX/dt = F(X), X(0) = X0    (*)

直到x1(t)达到其第一个局部最大值.

just until x1(t) reaches its first local max.

进度: 使用scipy.integrate.odeint,我可以找到极限环C及其周期T的解,但是从任意点开始,我能够解决此问题的唯一方法是将(*)求解为'长时间"(可能是4 * T),并假设这是一个足够长的时间,请确定事实后的x1的第一个局部最大值.我的大型项目需要多次执行此操作,因此,我试图尽可能地减少计算时间.似乎必须要有一种更快的方法,而无需编写自己的ode求解器.

Progress: Using scipy.integrate.odeint I am able to find the solution of the limit cycle C and its period T, but starting at an arbitrary point the only way I've been able to solve this problem is by solving (*) for a 'long time' (maybe 4*T) and, assuming this is a long enough time, determine the first local max of x1 after the fact. My larger project requires this to be done many times, so I'm trying to reduce computation time wherever I can. It seems like there has to be a faster way to do this without writing my own ode solver.

是否有可能(而且很可能)使事情变得太复杂了?如果您想到了其他方法,我将不胜感激.

It's possible (and likely) that I'm making this too complicated? If you think of a different way to do this I would appreciate any suggestions.

推荐答案

我尚未对此进行测试,但是以下代码应该可以工作,或者至少可以提供帮助:

I haven't tested this but the following code should work or at least help:

from scipy.integrate import ode

y0, t0 = [1.0j, 2.0], 0

def f(t, y, arg1):
    return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]

r = ode(f).set_integrator('zvode', method='bdf')
r.set_initial_value(y0, t0).set_f_params(2.0)
t1 = 10
dt = 1

older = 0
previous = 0
current = 0
while r.successful() and not (older <  previous and prevous > current):
    older = previous
    previous = current
    current = r.integrate(r.t+dt)

print("Maximum occurs at {}".format(r.t - dt))

我还将进一步研究 python ode

甚至更好的方法是使用solout,该solout可以在

even better would be to use the solout which can be found here

这篇关于在找到局部最大值之前,我可以与scipy的odeint集成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆