Source code for naginterfaces.library.examples.lapacklin.dgesv_ex
#!/usr/bin/env python3
"``naginterface.library.lapacklin.dgesv`` Python Example."
# NAG Copyright 2017-2019.
# pylint: disable=invalid-name
import numpy as np
from naginterfaces.library import lapacklin
[docs]def main():
"""
Example for :func:`naginterfaces.library.lapacklin.dgesv`.
Compute the solution to a real system of linear equations, :math:`AX = B`.
>>> main()
naginterfaces.library.lapacklin.dgesv Python Example Results.
Solution of a square linear system with multiple right-hand sides.
Solution X:
[[ 1.]
[-1.]
[ 3.]
[-5.]]
Pivots:
[2 2 3 4]
"""
print('naginterfaces.library.lapacklin.dgesv Python Example Results.')
print('Solution of a square linear system with multiple right-hand sides.')
a = np.array(
[[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]],
)
b = np.array(
[[9.52], [24.35], [0.77], [-6.22]],
)
_, ipiv, x = lapacklin.dgesv(a, b)
print('Solution X:')
print(x)
print('Pivots:')
print(ipiv)
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.REPORT_NDIFF,
).failed
)