简体   繁体   English

连续求解微分方程

[英]Solving a differential equation continuously

For the context, I'm trying to model and simulate a spatiotemporal neural network in Matlab. 对于上下文,我正在尝试在Matlab中建模和模拟时空神经网络。 I've determined a differential equation that will represent the dynamics of my neurons. 我确定了一个微分方程,它将代表我神经元的动力学。

Now, I want this differential equation to be solved "continuously", meaning that my simulation should be running, doing some stuff, and in the meantime my neurons should update according to the differential equation. 现在,我希望该“微分方程”能够“连续地”求解,这意味着我的仿真应该正在运行,做了一些工作,与此同时,我的神经元也应该根据微分方程进行更新。

For the moment, I have two approaches: 目前,我有两种方法:

Firstly, I could do something like this: 首先,我可以做这样的事情:

ode45(@diffEquation, [0, inf], nn.U); % where nn.U is the initial (usually randomized) neuron state

function dUdt = diffEquation(t,U)
   nn.U = U;
   dUdt = % the equation
end

So the idea is to start a parallel task in the background that will run ode45 infinitely and directly update my neuron state nn.U . 因此,想法是在后台启动一个并行任务,该任务将无限次运行ode45并直接更新我的神经元状态nn.U However, as I know ode45 usually stores a "history" of values for each t and returns those values when the calculation is done (eg t is at TFINAL ). 但是,据我所知,ode45通常为每个t存储值的“历史记录”,并在完成计算后返回这些值(例如tTFINAL )。 I'm not interested in those values and I expect that by running ode45 this way, I will run out of memory soon. 我对这些值不感兴趣,我希望通过以这种方式运行ode45,我很快就会用完内存。

The other idea is to just call ode45 over and over, infinitely (also in an async background task): 另一个想法是无限地反复调用ode45(同样在异步后台任务中):

while 1 % i.e. simulation not over yet
    [~,y] = ode45(@diffEquation, [0, 0.001], nn.U);
    nn.U = y(end,:); 
end

This, like the first approach, seems extremely clumsy and awkward for me. 就像第一种方法一样,这对我来说似乎非常笨拙和尴尬。 I've got the feeling that there must be a more elegant solution to my problem. 我感到必须为我的问题提供一个更优雅的解决方案。

Maybe ode45 is not the right choice here? 也许ode45在这里不是正确的选择?

EDIT: Just to clarify, the diff. 编辑:只是为了澄清,差异。 equation is an ordinary equation over time, nothing fancy and solvable by ode45 (ie dUdt = -U + some-stuff * networkoutput ) 方程是一个随时间变化的普通方程,没有任何花哨的内容,可以通过ode45解决(即dUdt = -U + some-stuff * networkoutput

If your ode is simple enough. 如果您的颂歌足够简单。 you could provide and analytical solution and dispense with odesolve. 您可以提供分析解决方案并省去odesolve。 In any case. 任何状况之下。 you want to run a simulation, solving the ode in virtual time. 您想运行仿真,在虚拟时间内求解ode。 Simulink might be a better choice for this. Simulink可能是一个更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM