For the context, I’m trying to model and simulate a spatiotemporal neural network in 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. However, as I know ode45 usually stores a “history” of values for each tand returns those values when the calculation is done (eg t is at TFINAL). I’m not interested in those values and I expect that by running ode45 this way, I will run out of memory soon.
The other idea is to just call ode45 over and over, infinitely (also in an async background task):
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?
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)
If your ode is simple enough. you could provide and analytical solution and dispense with odesolve. In any case. you want to run a simulation, solving the ode in virtual time. Simulink might be a better choice for this.