20. Automatic step-size control#
Some ODEs have local features, which require locally small step sizes. For other regions on can use larger step sizes, and save computations. A simple adaptive algorithm is as follows.
To estimate the local error, we apply two different time stepping methods, and take the difference as error estimation. The error in one time-step should be about \(\tau \times \text{tol}\).
while t < Tend
y1 = y;
method1.doStep(tau, y1);
y2 = y;
method2.doStep(tau, y2);
double errest = norm(y2-y1);
if errest < tau*tol
t = t + tau;
y = y1; // accept step
tau = tau * 1.5; // increase step size
else
tau = tau * 0.5; // decrease step size
A better way to increase the time-step is
If Newton’s method did not converge, we also try with a smaller time-step:
try {
method1.doStep(tau,y1);
method2.doStep(tau,y2);
}
catch (std::exception & e) {. // Nowton did not converge
tau *= 0.5;
continue;
}
20.1. Examples#
20.1.1. Arenstorf-Orbit#
vgl. Aufgabe 4.4 aus Numerische Mathematik II, P. Deuflhard, F. Bornemann Die Differentialgleichungen der Bewegung eines Satelliten um das System Erde-Mond lautet in den Koordinaten \(x =(x_1,x_2)\) des mitrotierenden Schwerpunktsystems
mit den Abkürzungen
und den Daten
Dabei ist \(\mu\) das Verhältnis der Mondmasse zur Masse der Gesamtsystems. L”angeneinheit f”ur die euklidische Norm \(|x|\) ist die mittlere Entfernung Erde-Mond (ca. \(384000 \, km\)), Zeiteinheit ein Monat. Die Anfangswerte
sind so gewählt, dass sich der kleeblattförmige Arenstorf-Orbit ergibt. Die Periode dieses Orbits beträgt
Berechnen und plotten Sie die Bahnkurve \(x(t)\) (Empfehlung: RK4 Verfahren und automatische Schrittweitensteuerung). Es wird eine Genauigkeit von \(x(T)\) von 1 km gewünscht.
20.1.2. Chemical reaction equations:#
molecules of type A and type B react to form molecules of type C and type D.
The probability of the reaction is \(k c_A c_B\), where \(c_A, c_B, ...\) are concentrations of molecules. This leads to differential equations:
An interesting example is the Zhabotinski-Belousov-Reaction (the so called Oregonator) in simplified form is
The concentrations \((c_1, c_2, c_3, c_4, c_5)\) give the densities of (\(BrO_3\), \(Br\), \(HBrO_2\), \(HOBr\), \(H_2O\)), hydrogen is available as much as needed.
This results in the ODE system
With reaction constants
Initial conditions are
Solve the equation with automatic step-size control.