Advanced Octave A51 — Stiff systems and solver choices
Advanced GNU Octave with GX-TXT · Module 09
When a system contains phenomena with very different times, an explicit solutor may have to use very small steps even after the fast phenomenon has exhausted. We compare two methods with an exact solution available.
Objectives and prerequisites
Let’s repeat A49’s systems. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0. Import rigidita.m, register it and run it in the Runner.
The dimensional system is y1' = -1000*y1, y2' = -y2, with initial [1; 1] status and time in seconds. The exact solution is [exp(-1000*t), exp(-t)]: the two scales are 0.001 s and 1 s.
Two solutors, an independent control
The script uses ode45 and lsode set to the stiff mode, with relative tolerance 1e-6 and absolute 1e-9. Both return values for the same 101 times required between 0 and 1 s. The number of points required does not necessarily correspond to the number of internal steps and is not a measure of the cost of methods.
In the test ode45 produces at the final time approximately [8,47 × 10⁻¹¹, 0,36787944], while the lsode produces about [−3,43 × 10⁻¹³, 0,36787880] ; the exact solution is approximately [0, 0,36787944]. The final maximum errors are about 8.47 × 10⁻¹¹ and 6.39 × 10⁻⁷ respectively. The very small negative value of y1 with lsode is a numerical effect in this test, not a negative physical amount to be interpreted as an exact result.
In this build of Octave ode15s is present but not usable because the SUNDIALS support required is not available; therefore the example uses lsode in stiff mode, actually verified. The availability of the solutors depends on the installed build.
Choose and verify
Comparison with analytical solution is an independent control for this simple problem. In real problems it also compares tolerances, methods and physical properties: the success of the solutor does not guarantee a correct model. In order to assess efficiency, time and internal work must be measured in comparable conditions, without deducting them from the exit points alone.
Exercise
- What are the two time scales of the system?
- Are the 101 points required necessarily the internal steps of the solver?
- Why do we compare the numerical solution to the exact one?
Worked solution
- 0.001 s and 1 s.
- No: the solutor can use other internal steps.
- To evaluate directly the error on a problem in which the independent solution is known.
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