.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_build/auto_examples/convergence/ExplicitRungeKutta_ivp.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__build_auto_examples_convergence_ExplicitRungeKutta_ivp.py: Convergence analysis of explicit Runge-Kutta methods for ODE IVP ================================================================ .. GENERATED FROM PYTHON SOURCE LINES 7-8 Evaluation of relative quadrature error with the following parameters: .. GENERATED FROM PYTHON SOURCE LINES 8-32 .. code-block:: Python eq_names = [ "y'' = -y" , "y'' = - exp(y)" , "y'' = xy" , "y' = Az; z' = By" , ] all_methods = { name : getattr(precomputed_tables,name) for name in dir(precomputed_tables) if isinstance(getattr(precomputed_tables,name),choreo.scipy_plus.ODE.ExplicitSymplecticRKTable) } method_order_hierarchy = {} for name, rk in all_methods.items(): order = rk.th_cvg_rate cur_same_order = method_order_hierarchy.get(order, {}) cur_same_order[name] = rk method_order_hierarchy[order] = cur_same_order sorted_method_order = sorted(method_order_hierarchy) .. GENERATED FROM PYTHON SOURCE LINES 107-108 The following plots give the measured relative error as a function of the number of quadrature subintervals .. GENERATED FROM PYTHON SOURCE LINES 108-113 .. code-block:: Python plt.show() .. image-sg:: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_001.png :alt: Relative error on integrand y'' = -y methods of order 1, Relative error on integrand y'' = - exp(y) methods of order 1, Relative error on integrand y'' = xy methods of order 1, Relative error on integrand y' = Az; z' = By methods of order 1, Relative error on integrand y'' = -y methods of order 2, Relative error on integrand y'' = - exp(y) methods of order 2, Relative error on integrand y'' = xy methods of order 2, Relative error on integrand y' = Az; z' = By methods of order 2, Relative error on integrand y'' = -y methods of order 3, Relative error on integrand y'' = - exp(y) methods of order 3, Relative error on integrand y'' = xy methods of order 3, Relative error on integrand y' = Az; z' = By methods of order 3, Relative error on integrand y'' = -y methods of order 4, Relative error on integrand y'' = - exp(y) methods of order 4, Relative error on integrand y'' = xy methods of order 4, Relative error on integrand y' = Az; z' = By methods of order 4, Relative error on integrand y'' = -y methods of order 5, Relative error on integrand y'' = - exp(y) methods of order 5, Relative error on integrand y'' = xy methods of order 5, Relative error on integrand y' = Az; z' = By methods of order 5, Relative error on integrand y'' = -y methods of order 6, Relative error on integrand y'' = - exp(y) methods of order 6, Relative error on integrand y'' = xy methods of order 6, Relative error on integrand y' = Az; z' = By methods of order 6, Relative error on integrand y'' = -y methods of order 8, Relative error on integrand y'' = - exp(y) methods of order 8, Relative error on integrand y'' = xy methods of order 8, Relative error on integrand y' = Az; z' = By methods of order 8, Relative error on integrand y'' = -y methods of order 10, Relative error on integrand y'' = - exp(y) methods of order 10, Relative error on integrand y'' = xy methods of order 10, Relative error on integrand y' = Az; z' = By methods of order 10 :srcset: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 160-162 The following plots give the measured convergence rate as a function of the number of quadrature subintervals. The dotted lines are theoretical convergence rates. .. GENERATED FROM PYTHON SOURCE LINES 162-166 .. code-block:: Python plt.show() .. image-sg:: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_002.png :alt: Approximate convergence rate on integrand y'' = -y methods of order 1, Approximate convergence rate on integrand y'' = - exp(y) methods of order 1, Approximate convergence rate on integrand y'' = xy methods of order 1, Approximate convergence rate on integrand y' = Az; z' = By methods of order 1, Approximate convergence rate on integrand y'' = -y methods of order 2, Approximate convergence rate on integrand y'' = - exp(y) methods of order 2, Approximate convergence rate on integrand y'' = xy methods of order 2, Approximate convergence rate on integrand y' = Az; z' = By methods of order 2, Approximate convergence rate on integrand y'' = -y methods of order 3, Approximate convergence rate on integrand y'' = - exp(y) methods of order 3, Approximate convergence rate on integrand y'' = xy methods of order 3, Approximate convergence rate on integrand y' = Az; z' = By methods of order 3, Approximate convergence rate on integrand y'' = -y methods of order 4, Approximate convergence rate on integrand y'' = - exp(y) methods of order 4, Approximate convergence rate on integrand y'' = xy methods of order 4, Approximate convergence rate on integrand y' = Az; z' = By methods of order 4, Approximate convergence rate on integrand y'' = -y methods of order 5, Approximate convergence rate on integrand y'' = - exp(y) methods of order 5, Approximate convergence rate on integrand y'' = xy methods of order 5, Approximate convergence rate on integrand y' = Az; z' = By methods of order 5, Approximate convergence rate on integrand y'' = -y methods of order 6, Approximate convergence rate on integrand y'' = - exp(y) methods of order 6, Approximate convergence rate on integrand y'' = xy methods of order 6, Approximate convergence rate on integrand y' = Az; z' = By methods of order 6, Approximate convergence rate on integrand y'' = -y methods of order 8, Approximate convergence rate on integrand y'' = - exp(y) methods of order 8, Approximate convergence rate on integrand y'' = xy methods of order 8, Approximate convergence rate on integrand y' = Az; z' = By methods of order 8, Approximate convergence rate on integrand y'' = -y methods of order 10, Approximate convergence rate on integrand y'' = - exp(y) methods of order 10, Approximate convergence rate on integrand y'' = xy methods of order 10, Approximate convergence rate on integrand y' = Az; z' = By methods of order 10 :srcset: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 227-233 We can see 3 distinct phases on these plots: * A first pre-convergence phase, where the convergence rate is growing towards its theoretical value. the end of the pre-convergence phase occurs for a number of sub-intervals roughtly independant of the convergence order of the quadrature method. * A steady convergence phase where the convergence remains close to the theoretical value * A final phase, where the relative error stagnates arround 1e-15. The value of the integral is computed with maximal accuracy given floating point precision. The approximation of the convergence rate is dominated by seemingly random floating point errors. .. GENERATED FROM PYTHON SOURCE LINES 235-236 Error as a function of running time .. GENERATED FROM PYTHON SOURCE LINES 236-240 .. code-block:: Python plt.show() .. image-sg:: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_003.png :alt: Relative error as a function of computational cost for equation y'' = -y methods of order 1, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 1, Relative error as a function of computational cost for equation y'' = xy methods of order 1, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 1, Relative error as a function of computational cost for equation y'' = -y methods of order 2, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 2, Relative error as a function of computational cost for equation y'' = xy methods of order 2, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 2, Relative error as a function of computational cost for equation y'' = -y methods of order 3, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 3, Relative error as a function of computational cost for equation y'' = xy methods of order 3, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 3, Relative error as a function of computational cost for equation y'' = -y methods of order 4, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 4, Relative error as a function of computational cost for equation y'' = xy methods of order 4, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 4, Relative error as a function of computational cost for equation y'' = -y methods of order 5, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 5, Relative error as a function of computational cost for equation y'' = xy methods of order 5, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 5, Relative error as a function of computational cost for equation y'' = -y methods of order 6, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 6, Relative error as a function of computational cost for equation y'' = xy methods of order 6, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 6, Relative error as a function of computational cost for equation y'' = -y methods of order 8, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 8, Relative error as a function of computational cost for equation y'' = xy methods of order 8, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 8, Relative error as a function of computational cost for equation y'' = -y methods of order 10, Relative error as a function of computational cost for equation y'' = - exp(y) methods of order 10, Relative error as a function of computational cost for equation y'' = xy methods of order 10, Relative error as a function of computational cost for equation y' = Az; z' = By methods of order 10 :srcset: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 300-301 Error as a function of running time for different orders .. GENERATED FROM PYTHON SOURCE LINES 301-306 .. code-block:: Python plt.show() .. image-sg:: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_004.png :alt: Relative error as a function of computational cost for equation y'' = -y, Relative error as a function of computational cost for equation y'' = - exp(y), Relative error as a function of computational cost for equation y'' = xy, Relative error as a function of computational cost for equation y' = Az; z' = By :srcset: /_build/auto_examples/convergence/images/sphx_glr_ExplicitRungeKutta_ivp_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 26.444 seconds) .. _sphx_glr_download__build_auto_examples_convergence_ExplicitRungeKutta_ivp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ExplicitRungeKutta_ivp.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ExplicitRungeKutta_ivp.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_