Matrix Module programmed by Son, Sang-Kil in Feb. 2004 for PHSX815 : Computational Physics
Ref) Press et al., "Numerical Recipes in Fortran 77" Press et al., "Numerical Recipes in Fortran 90"
Main data types - LU_matrix : LU-decomposed matrix - F LU_decompose(A(N,N)) : create LU matrix by LU-decomposition of A - F LU_solve(LU, b(N)) : solve a linear equation for b with LU - F LU_inverse(LU) : inverse matrix of LU - F LU_determinant(LU) : determinant of LU - F LU_lower(LU) : return L matrix of LU - F LU_upper(LU) : return U matrix of LU
Auxiliary functions and subroutines - SR print_matrix(A(N,N)) : print out a matrix - SR print_vector(x(N)) : print out a vector
Operators for efficient matrix multiplication with LAPACK, but better readibility. (It is assumed that the dimensionality fits.)
multiply two real square matrices or a square matrix times a vector AB= A .m. B or Av= A .m. v
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:,:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:) |
multiply two real square matrices, the second is transposed A(B*T)= A .mt. B
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:,:) |
multiply two real square matrices, the first is transposed (A*T)B= A .tm. B
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:,:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:) |
substract two real square matrices element wise A-B = A .sub. B This functionality is provided by f90. Element wise, arrays (of same dimensionality) can be added, substracted, multiplied and divided. sub_real_matrix_matrix is not a LAPACK feature. (Michael)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:,:) |
Data type: LU_matrix it contains the dimension of the matrix, N and LU-decomposed matrix, LU(N,N) also, permutation(N) and the sign for determinant, d
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | n | ||||
real(kind=long), | public, | dimension(:, :), pointer | :: | lu | |||
integer, | public, | dimension(:), pointer | :: | permutation | |||
integer, | public | :: | d |
Carry out LU-decomposition for A and put the decomposed matrix into M implementation of Crout's method with partial pivoting.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in), | dimension(:, :) | :: | a |
n*N matrix |
Solve a linear equation for b with LU-decomposed matrix M Return the solution for b as a new vector x b : row vector, not column vector, that is, just 1D array of n
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lu_matrix), | intent(in) | :: | m | |||
real(kind=long), | intent(in), | dimension(:) | :: | b |
Return the inverse matrix of LU-decomposed matrix M using F solve(M, b)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lu_matrix), | intent(in) | :: | m |
returns the determinant value of LU-decomposed matrix M
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(lu_matrix), | intent(in) | :: | m |
returns the determinant of square matrix A slightly redundant to LU_determiant but allows also to return zero as a determinant
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) |
returns the trace of matrix A
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) |
computes the trace of the matrix A * B first dimension of A has to match second dimension of B second dimension of A has to match first dimension of B
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) | |||
real(kind=long), | intent(in) | :: | b(:,:) |
Print arbitrary N*M matrix
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in), | dimension(:, :) | :: | a |
solves AxB=D for D
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=long), | intent(in) | :: | a(:,:) |
matrix A of shape NxN |
||
real(kind=long), | intent(in) | :: | b(:) |
vector B of len N |
||
real(kind=long), | intent(out) | :: | d(size(b,1)) |
result vector of len N |
||
integer, | intent(out) | :: | ierr |
output status -1 is solution could not be found (A is singular) |
||
logical, | intent(in), | optional | :: | yes_verbose |
print message if A is singular |