Advanced Octave A49 — Multivariate dynamical systems

by Giux GX-TXT, octave-en, scripts-en 2 min read

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*A
  • dB/dt = k1*A - k2*B
  • dC/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

  1. Why is the sum of the three fractions constant in the model?
  2. What is the maximum of B?
  3. Does a correct numerical balance guarantee the physical validity of the model?

Worked solution

  1. The terms of transformation are erased by adding the three derivatives.
  2. The point where, in the model, training and consumption of B are instantly balanced.
  3. No: it retains a property of selected equations, but parameters and assumptions require comparison with the real system.

Download the Module 09 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *