Advanced Octave A49 — Multivariate dynamical systems
Advanced GNU Octave with GX-TXT · Module 09
A dynamic model can describe quantities that are transformed into each other. We simulate a simple network A → B → C and check that the total is kept.
Objectives and prerequisites
Differential equations and basic course status vectors are useful. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0. Import reazioni.m, register it and run it in the Runner. The script creates three Datasets with ID octave_advanced_reaction_a, _b and _c : they are created-only, so to repeat, use a new Session or change all the corresponding IDs.
Model and solution
The dimensionless fractions A, B and C represent a preserved quantity that passes from one state to another, with unit ratios in the model. The equations are:
dA/dt = -k1*AdB/dt = k1*A - k2*BdC/dt = k2*B
With k1 = 0,5 s⁻¹, k2 = 0,2 s⁻¹ and initial [1; 0; 0], ode45 calculates the required solutions every 0.1 s up to 12 s. The anonymity function rhs returns the vector of derivatives; the tolerances set are relative 1e-8 and absolute 1e-10.
Summarizing the three equations you get total derived nothing: the model previews A+B+C = 1. The script controls the minimum fractions, the maximum deviation from the total and uses NUMERIC_API_v1 for the average of the total.
In the test the minimum is 0 and the maximum deviation of the total is about 3.55 × 10⁻¹⁵. At the final time the fractions are about A = 0.00248, B = 0.14707 and C = 0.85046. The control of the sum and the observed positivity are useful verifications of the result, but do not show that the model describes a real reaction.
Viewing states
The three series are published as separate Dataset by a batch publication and gathered in a PlotSpec. Open the variant in the Plots tab:
A decreases; B grows and then consumes; C increases. The fractions are dimensionless and the time is in seconds. In the model we hypothesize a closed system, constant coefficients and transformations of the first order: real applications may require other equations and experimental checks.
Exercise
- Why is the sum of the three fractions constant in the model?
- What is the maximum of B?
- Does a correct numerical balance guarantee the physical validity of the model?
Worked solution
- The terms of transformation are erased by adding the three derivatives.
- The point where, in the model, training and consumption of B are instantly balanced.
- No: it retains a property of selected equations, but parameters and assumptions require comparison with the real system.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A73 — Optimization landscapes and 3D trajectories