求解具有读入外强迫的 ODE 系统 [英] solve system of ODEs with read in external forcing

查看:23
本文介绍了求解具有读入外强迫的 ODE 系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Julia 中,我想解决具有外部强迫的 ODE 系统 g1(t), g2(t)

In Julia, I want to solve a system of ODEs with external forcings g1(t), g2(t) like

dx1(t) / dt = f1(x1, t) + g1(t)
dx2(t) / dt = f2(x1, x2, t) + g2(t)

从文件中读取强制.

我正在使用这项研究来学习 Julia 和包微分方程,但我很难找到正确的方法.

I am using this study to learn Julia and the package DifferentialEquations, but I am having difficulties finding the correct approach.

我可以想象使用 callback 可以工作,但这似乎很麻烦.

I could imagine that using a callback could work, but that seems pretty cumbersome.

你知道如何实现这种外部强制吗?

Do you have an idea of how to implement such an external forcing?

推荐答案

您可以在集成函数内部使用函数.因此,您可以使用 Interpolations.jl 之类的方法从文件中的数据构建插值多项式,然后执行以下操作:

You can use functions inside of the integration function. So you can use something like Interpolations.jl to build an interpolating polynomial from the data in your file, and then do something like:

g1 = interpolate(data1, options...)
g2 = interpolate(data2, options...)
p = (g1,g2) # Localize these as parameters to the model

function f(du,u,p,t)
g1,g2 = p
  du[1] = ... + g1[t] # Interpolations.jl interpolates via []
  du[2] = ... + g2[t]
end
# Define u0 and tspan
ODEProblem(f,u0,tspan,p)

这篇关于求解具有读入外强迫的 ODE 系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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