Extracting non-state variables from ode solver
⚓ Rust 📅 2026-01-26 👤 surdeus 👁️ 2New learner here. Thanks to help of several generous contributors I have a working “toy” of a two-pool compartmental mechanistic biological model, produced in Rust, using the “ode_solvers” crate. When I get this completed I will expand it to an actual 18-20 pool model.
My current problem is an inability to pull out the values of some non-state variables (results) at each iteration of the ode solver. I want to export these variable values to both a text file and to a simple onscreen graph. I can export and graph the State variable values, just not the non-state ones.
On “the bigger picture”, I might be able to attack this problem if I had a way to interrogate the the inner workings (options) of the ode_solver crate but I don’t yet know how to do that. Any advice on how to proceed in this area and learn myself most welcome!
Here is a sample of code from a working mwe, happy to supply the github repo address if anyone is interested.
//declare system function, used by the stepper above
struct TwoPool;
impl ode_solvers::System<f64, State> for TwoPool {
fn system(&self, time: Time, y: &State, dy: &mut State) {
/*calculate the concentration of metabolite in each pool at
each iteration*/
let con_a = y[0] / I[0];
let con_b = y[1] / I[1];
/*calculate fluxes corresponding to arrows on diagram, using a
HMM equation*/
let fab = C[0] / (1.0 + (C[3] / con_a));
let fba = C[1] / (1.0 + (C[4] / con_b));
let fbo = C[2] / (1.0 + (C[5] / con_b));
/* specify the differential equations for each of the state
variables*/
dy[0] = I[4] + fba - fab;
dy[1] = fab - fba - fbo;
// y[2] = con_a;
If I uncomment the last line and attempt to store the iterative values of “con_a” in the vector y (state variables) it blows up with a non-mutable vector error (not surprisingly!, my bad)
Main issue: Any suggestions on how to extract non-state variable values, eg. con_a and con_b and add them to my graph, which currently graphs the state variable values very nicely. Thx. J
1 post - 1 participant
🏷️ Rust_feed