Source code for naginterfaces.library.examples.matop.real_gen_matrix_fun_usd_ex

#!/usr/bin/env python3
"``naginterfaces.library.matop.real_gen_matrix_fun_usd`` 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_usd`. Function of a real matrix. >>> main() naginterfaces.library.matop.real_gen_matrix_fun_usd Python Example Results. Function of a real matrix. For A = [[ 1. 0. -2. 1.] [-1. 2. 0. 1.] [ 2. 0. 1. 0.] [ 1. 0. -1. 2.]] exp(2A) = [[-12.18798617 0. -3.47466326 8.3696757 ] [-13.72738367 54.59815003 -23.98010407 82.85926011] [ -9.79002487 0. -25.4526743 26.52937627] [-18.15970057 0. -34.89905197 49.24044206]] """ print( 'naginterfaces.library.matop.real_gen_matrix_fun_usd ' 'Python Example Results.' ) print('Function of a real matrix.') # The input matrix: a = np.array([ [1., 0., -2., 1.], [-1., 2., 0., 1.], [2., 0., 1., 0.], [1., 0., -1., 2.], ]) print("For A =") print(a) print("exp(2A) =") print( matop.real_gen_matrix_fun_usd(a, lambda m, z: 2.**m*np.exp(2.*z)).a )
if __name__ == '__main__': import doctest import sys sys.exit( doctest.testmod( None, verbose=True, report=False, optionflags=doctest.REPORT_NDIFF, ).failed )