Package lib :: Package linear_algebra :: Module matrix_exponential
[hide private]
[frames] | no frames]

Source Code for Module lib.linear_algebra.matrix_exponential

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2013-2014 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Module for the calculation of the matrix exponential.""" 
24   
25  # Python module imports. 
26  from numpy import array, diag, dot, exp 
27  from numpy.linalg import eig, inv 
28   
29  # relax module imports. 
30  from lib.check_types import is_complex 
31   
32   
33 -def matrix_exponential(A):
34 """Calculate the exact matrix exponential using the eigenvalue decomposition approach. 35 36 @param A: The square matrix to calculate the matrix exponential of. 37 @type A: numpy rank-2 array 38 @return: The matrix exponential. This will have the same dimensionality as the A matrix. 39 @rtype: numpy rank-2 array 40 """ 41 42 # Is the original matrix real? 43 complex_flag = is_complex(A[0, 0]) 44 45 # The eigenvalue decomposition. 46 W, V = eig(A) 47 48 # Calculate the exact exponential. 49 eA = dot(dot(V, diag(exp(W))), inv(V)) 50 51 # Return the complex matrix. 52 if complex_flag: 53 return array(eA) 54 55 # Return only the real part. 56 else: 57 return array(eA.real)
58