Save additional quantities using DifferentialEquations.jl pkg

I guess we can also add observed quantities ourselves, without using modelingtoolkit?
I was looking for some documentation to do this, but i couldn’t find any.

If possible I would like to define a function like (x,p) → some quantity.
Which can be accessed via sol like in the docs now for the DAE and then use interpolation on x etc.

I found that the code that adds such equations for ODAEPoblem is this, but it is a bit over my head.

I noticed ODEFunction has an ‘observed’ field. But couldn’t get it to work.

It would be a slightly horrifying function to build by hand. It’s shown here though:

Hi all, not sure this is exactly related, but after googling for how to save non-state variable quantities in DifferentialEquations.jl, I ended up here and feel that my question corresponds to this thread.

I’m currently trying to do something resembling the following simplifying pseudocode:

using DifferentialEquations

param1 = 0.1
param2 = 0.11

function some_parameter_changing_func(param, time)
    modified_parameter = param + 0.001 * time
end

function f(du, u, p, t)
    param1, param2 = p
    du[1] =  modified_parameter(param1, time) * u[2] - 0.09 * u[1] 
    du[2] =  modified_parameter(param2, time) * u[1] - 0.1 * u[2]
    desired_export = (1 - modified_parameter(param1, time)) * u[2] + (1 - modified_parameter(param2, time)) * u[1]
end

and then extract a vector for the desired_export values over some tspan. Coming into the thread in media res, I got a little lost, so I was wondering what was the best means of going about that? I could compute the value after the solutions have been obtained from the sol object, of course, but the actual system I’m working with is more tedious and would make computing a desired_export vector based on sol.u and sol.t less convenient.

Thanks!

Just calculate it algebraically. It’s more efficient. See all.

Sorry, what is the all here referring to?

There’s this thread and a few others all about control variables, and I’m writing a new system in the new month that will improve it, so I’m not taking the time to write another version of an answer I intend to obsolete soon. But if you search control variables and DEDataArray stuff you’ll get how to do it with callbacks and all of that.

3 Likes

I had no idea they were called explicit algebraic variables! Always glad to benefit from your expertise, thanks again for your time.