通过读取外部强制来解决ODE系统 [英] solve system of ODEs with read in external forcing

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

问题描述

在Julia中,我想用外部强制g1(t), g2(t)来解决ODE系统

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天全站免登陆