Note
Go to the end to download the full example code
2. Example: Comparison
Here we compare the outcome of the PTRANS-I and PTRANS-II algorithm for a random input.
rel. diff X1 X2: 8.70816612593307e-15
max X1: 8466819268689.504
max X2: 8466819268689.651
max |M*X1 - V|: 2.5858753360807896e-08
max |M*X2 - V|: 2.3494067136198282e-08
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.009 seconds)