.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02_compare.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_examples_02_compare.py: 2. Example: Comparison ---------------------- Here we compare the outcome of the PTRANS-I and PTRANS-II algorithm for a random input. .. GENERATED FROM PYTHON SOURCE LINES 8-30 .. rst-class:: sphx-glr-script-out .. code-block:: none rel. diff X1 X2: 5.766672433029218e-14 max X1: 354407160062376.9 max X2: 354407160062417.75 max |M*X1 - V|: 4.178291419520974e-07 max |M*X2 - V|: 3.284549165982753e-07 | .. code-block:: Python import numpy as np import pentapy as pp size = 1000 # create a flattened pentadiagonal matrix M_flat = (np.random.random((5, size)) - 0.5) * 1e-5 V = np.random.random(size) * 1e5 # compare the two solvers X1 = pp.solve(M_flat, V, is_flat=True, solver=1) X2 = pp.solve(M_flat, V, is_flat=True, solver=2) # calculate the error print("rel. diff X1 X2: ", np.max(np.abs(X1 - X2)) / np.max(np.abs(X1 + X2))) print("max X1: ", np.max(np.abs(X1))) print("max X2: ", np.max(np.abs(X2))) M = pp.create_full(M_flat, col_wise=False) # calculate the error print("max |M*X1 - V|: ", np.max(np.abs(np.dot(M, X1) - V))) print("max |M*X2 - V|: ", np.max(np.abs(np.dot(M, X2) - V))) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.002 seconds) .. _sphx_glr_download_examples_02_compare.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_compare.ipynb <02_compare.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_compare.py <02_compare.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_compare.zip <02_compare.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_