Apologies, I mixed up the plots. Yeah, it is strange that the “solution” looks like that.
It seems like the mechanism that turns u2 into an “observed” variable (because it’s not really a dynamic variable, it is not part of the variables of the ODE system in the end), doesn’t actually record the values, but assumes that the value is always the one at the final time ![]()
At least that would make sense if the observed variable is just equal to a parameter which is (?) assumed to be constant.
Here’s what I did to find out more about what’s going on, in case it helps you or someone else.
Details
The code was run with Julia 1.10.2 and
[961ee093] ModelingToolkit v9.5.0
[1dea7af3] OrdinaryDiffEq v6.74.0
[91a5bcdd] Plots v1.40.2
- check what are the actual variables and observed quantities of the system (the variable u2 is correctly identified as one that is not actually dynamic)
julia> unknowns(smp_sys)
1-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
u1(t)
julia> observed(smp_sys)
1-element Vector{Equation}:
u2(t) ~ q
- use Chtulhu to “descend” into the function call that extracts the solution (I find this very useful to quickly check which functions are called, especially when there is a lot of dispatch going on – since the types here have a lot of parameters, you might want to turn off the type information by pressing
twhile in the descend mode)
julia> using Cthulhu
julia> @descend sol[u2]
# lots of output here, press `t` to turn off all the type info and see the source code
# after a few more descends, we arrive at
function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic, sym)
...
elseif is_observed(A, sym)
return observed(A, sym).(A.u, (parameter_values(A),), A.t)
...
end
- the function above looks like a broadcastet call of whatever
observed(A, sym)returns over the values ofuand the times. The parameter values in(parameter_values(A),)are just the values at the end of the integration though
My best guess is that dynamically changing parameters should also be labelled as dynamic in some way. Otherwise, the values of the “observed” quantities is assumed to only depend on the values of the variables and the (constant) parameters.
Perhaps it is possible to use a time-dependent function instead of the parameter on the right-hand side of your ODE?