Source code for naginterfaces.library.examples.matop.real_gen_matrix_fun_num_ex
#!/usr/bin/env python3
"``naginterfaces.library.matop.real_gen_matrix_fun_num`` Python Example."
# NAG Copyright 2017-2019.
# pylint: disable=invalid-name
import numpy as np
from naginterfaces.library import matop
[docs]def main():
"""
Example for :func:`naginterfaces.library.matop.real_gen_matrix_fun_num`.
Function of a real matrix.
>>> main()
naginterfaces.library.matop.real_gen_matrix_fun_num Python Example Results.
Function of a real matrix.
For A =
[[ 3. 0. 1. 2.]
[-1. 1. 3. 1.]
[ 0. 2. 2. 1.]
[ 2. 1. -1. 1.]]
cos(2A) =
[[-0.17036898 -1.15965573 -0.18778866 -0.73074175]
[-0.39503854 -0.44095146 0.76061992 0.06554174]
[-0.0949989 -0.07174814 0.06191979 -0.43512038]
[-0.10341444 0.64237026 -1.39636277 0.10421077]]
"""
print(
'naginterfaces.library.matop.real_gen_matrix_fun_num '
'Python Example Results.'
)
print('Function of a real matrix.')
# The input matrix:
a = np.array([
[3., 0., 1., 2.],
[-1., 1., 3., 1.],
[0., 2., 2., 1.],
[2., 1., -1., 1.],
])
print("For A =")
print(a)
print("cos(2A) =")
print(matop.real_gen_matrix_fun_num(a, lambda z: np.cos(2.*z)).a)
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.REPORT_NDIFF,
).failed
)