I have a system of differential equations solved as following:
## Lets solve the ODE first without using Kalman Filters
function theo_ode!(du,u,p,t)
du[1] = u[2]
du[2] = -0.01*u[2] - u[1] + sin(2*t)
end
u₀ = [0.1, 0.5] # initial state vector
tspan = (0.0,50.0) # time interval
prob = ODEProblem(theo_ode!,u₀,tspan)
sol = solve(prob)
At every time step t I would like to get the current solved value of u, update it (a slight pertubation), and then use it as initial conditions for the next time step.
Would I be able to do that directly in theo_ode function or do I need some sort of callback?
You’ll need to use a callback, otherwise it can’t account for rejections. Discrete callback where the condition is just true, and then you apply the affect.
But is there a way to pass in an outside value to the affect function? I tried replacing affect!(integrator) with affect!(integrator, value) but that defines a new method that is not used.
Is there an example of this? Here is my version of this, and just want to confirm this is the correct way to go:
function out_affect!(integrator, value)
integrator.u[1] += value
end
outsidevalue = 109
cb = DiscreteCallback(condition, int -> out_affect!(int, outsidevalue))