2. Example: Comparison

Here we compare the outcome of the PTRANS-I and PTRANS-II algorithm for a random input.

Out:

rel. diff X1 X2:  5.27456543735397e-15
max X1:  8146405710639.143
max X2:  8146405710639.057
max |M*X1 - V|:  4.2506144382059574e-08
max |M*X2 - V|:  1.2479722499847412e-07

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)))

Total running time of the script: ( 0 minutes 0.006 seconds)

Gallery generated by Sphinx-Gallery