如何在 ODE 中插入列表: [英] How to insert list in a ODE:

查看:58
本文介绍了如何在 ODE 中插入列表:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试数值求解以下 ODE

I am trying to numerically solve the following ODE

有边界条件

y(x=0)=0;y(x=20)=1

其中 f(x) 是我已经通过数值求解的另一个 ODE 的解.我正在尝试使用 解决我的 ODEhttps://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.integrate.solve_bvp.html,但我遇到的问题是 f(x) 被写成列表

Where f(x) is the solution of another ODE that I already solved numerically. I am trying to solve my ODE with https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.integrate.solve_bvp.html, but the problem that I have is that f(x) is written as a list for

 coordinates x = np.arange(0,20.01,0.05)

而且我不知道如何在 scipy.integrate.solve_bvp 中插入列表以获得 ODE 的解.

and I do not know how to insert the list in scipy.integrate.solve_bvp to obtain the solution of ODE.

提前致谢

推荐答案

最好的办法是解决耦合系统,也就是将f的DE与当前DE同时集成.如果这是您之前在 math.SE 上的问题的变体,那么这种耦合方法是不可避免的.

The best way is to solve the coupled system, that is to integrate the DE for f at the same time as the current DE. If this is a variant of your previous problem on math.SE then this coupled approach is unavoidable.

至于字面解,使用插值

def f(x): return numpy.interp(x, x_samples, f_samples)

然后在ODE函数中调用这个函数

and then call this function in the ODE function

def y_ODE(x,y): return [y[1], -0.5*f(x)*y[1]]

这篇关于如何在 ODE 中插入列表:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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