Catalyst.jl: Algebraically relate two species

Using Catalyst.jl (DSL) to develop a model with pharmacology. The drug concentration is tracked in milligrams, but the pharmacology requires an algebraic transformation to ng/mL-unbound (multiplication by a few parameters). Is there a simple way to just relate two quantities algebraically within the DSL? It looks messy to call a function everywhere.

You can define an observable, or the easier thing to do is just use the observed indexing. sol[x^2 + y^2] just works on the solution, so you can do something like sol[p*x] to get the solution of p*x at all of the saveat points.

1 Like

@ChrisRackauckas’s suggestions are probably the best way to handle this, especially just making an observed equation, but another option if you are planning to convert to ODEs or nonlinear equations is to add an algebraic constraint equation (which structural_simplify in ModelingToolkit should essentially handle moving to be an observed equation for you after conversion). See Constraint Equations and Events · Catalyst.jl and note this requires Catalyst V13.