Documentation for module mathlib

Collection of simple mathematical functions and subroutines

source: mathlib.F
Loading...

Generic procedures:

det_3x3
invert_matrix
unit_matrix

public Subroutines/Functions:

FUNCTION
LOGICAL
abnormal_value (a)
determins if a value is not normal (e.g. for Inf and Nan) based on IO to work also under optimization.
FUNCTION
REAL(dp)
angle (a, b)
Calculation of the angle between the vectors a and b. The angle is returned in radians.
FUNCTION
REAL(dp)
binomial (n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
SUBROUTINE
build_rotmat (phi, a, rotmat)
The rotation matrix rotmat which rotates a vector about a rotation axis defined by the vector a is build up. The rotation angle is phi (radians).
SUBROUTINE
diag (n, a, d, v)
Diagonalize matrix a. The eigenvalues are returned in vector d and the eigenvectors are returned in matrix v.
SUBROUTINE
diamat_all (a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix a is used. Externals (LAPACK 3.0)
FUNCTION
REAL(dp)
dihedral_angle (ab, bc, cd)
Returns the dihedral angle, i.e. the angle between the planes defined by the vectors (-ab,bc) and (cd,-bc). The dihedral angle is returned in radians.
FUNCTION
REAL(dp)
dotprod_3d (vec1, vec2)
...
FUNCTION
REAL(dp)
expint (n, x)
computes the exponential integral En(x) = Int(exp(-x*t)/t^n,t=1..infinity) x>0, n=0,1,.. Note: Ei(-x) = -E1(x)
FUNCTION
INTEGER ELEMENTAL
gcd (a, b)
computes the greatest common divisor of two number
returns the pseudoinverse of a real, symmetric and positive definite matrix using diagonalization.
returns the pseudoinverse of a real, square matrix using singular value decomposition
SUBROUTINE
invmat (a, info)
returns inverse of matrix using the lapack routines DGETRF and DGETRI
returns inverse of real symmetric, positive definite matrix
FUNCTION
REAL(dp)
inv_3x3 (a)
Returns the inverse of the 3 x 3 matrix a.
SUBROUTINE
jacobi (a, d, v)
Jacobi matrix diagonalization. The eigenvalues are returned in vector d and the eigenvectors are returned in matrix v in ascending order.
FUNCTION
INTEGER ELEMENTAL
lcm (a, b)
computes the least common multiplier of two numbers
FUNCTION
REAL(dp)
matmul_3x3 (mat1, mat2)
...
SUBROUTINE
matvec_3x3 (res, mat, vec)
...
FUNCTION
REAL(dp)
multinomial (n, k)
Calculates the multinomial coefficients
FUNCTION
REAL(dp)
reflect_vector (a, b)
Reflection of the vector a through a mirror plane defined by the normal vector b. The reflected vector a is stored in a_mirror.
FUNCTION
REAL(dp)
rotate_vector (a, phi, b)
Rotation of the vector a about an rotation axis defined by the vector b. The rotation angle is phi (radians). The rotated vector a is stored in a_rot.
SUBROUTINE
symmetrize_matrix (a, option)
Symmetrize the matrix a.
FUNCTION
REAL(dp)
transpose_3d (mat)
...
FUNCTION
REAL(dp) PURE
vector_product (a, b)
Calculation of the vector product c = a x b.

Generic procedure det_3x3

...

REAL(dp),
INTENT(in)
:: a(3,3) ×
REAL(dp),
INTENT(in)
:: a1(3) ×
REAL(dp),
INTENT(in)
:: a2(3) ×
REAL(dp),
INTENT(in)
:: a3(3) ×

Generic procedure invert_matrix

...

REAL(dp),
INTENT(in)
:: a(:,:) ×
COMPLEX(dp),
INTENT(in)
:: a(:,:) ×
REAL(dp),
INTENT(out)
:: a_inverse(:,:) ×
COMPLEX(dp),
INTENT(out)
:: a_inverse(:,:) ×
REAL(dp),
INTENT(out)
:: eval_error × ×
CHARACTER(1),
INTENT(in),
OPTIONAL
:: option × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: improve ×

Generic procedure unit_matrix

Set the matrix a to be a unit matrix.

REAL(dp),
INTENT(inout)
:: a(:,:) ×
COMPLEX(dp),
INTENT(inout)
:: a(:,:) ×

FUNCTIONabnormal_value(a)

determins if a value is not normal (e.g. for Inf and Nan) based on IO to work also under optimization.

Return Value ::
LOGICAL
TRUE for NaN and Inf
Arguments:
REAL(dp)
:: a input value

FUNCTIONangle(a, b)

Calculation of the angle between the vectors a and b. The angle is returned in radians.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a(:) ...
REAL(dp),
INTENT(in)
:: b(:) ...

FUNCTIONbinomial(n, k)

The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.

Return Value ::
REAL(dp)
Arguments:
INTEGER,
INTENT(in)
:: n ...
INTEGER,
INTENT(in)
:: k ...

SUBROUTINEbuild_rotmat(phi, a, rotmat)

The rotation matrix rotmat which rotates a vector about a rotation axis defined by the vector a is build up. The rotation angle is phi (radians).

Arguments:
REAL(dp),
INTENT(in)
:: phi ...
REAL(dp),
INTENT(in)
:: a(3) ...
REAL(dp),
INTENT(out)
:: rotmat(3,3) ...

SUBROUTINEdiag(n, a, d, v)

Diagonalize matrix a. The eigenvalues are returned in vector d and the eigenvectors are returned in matrix v.

Arguments:
INTEGER,
INTENT(in)
:: n ...
REAL(dp),
INTENT(inout)
:: a(n,n) ...
REAL(dp),
INTENT(out)
:: d(n) ...
REAL(dp),
INTENT(out)
:: v(n,n) ...

SUBROUTINEdiamat_all(a, eigval, dac)

Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix a is used. Externals (LAPACK 3.0)

Arguments:
REAL(dp),
INTENT(inout)
:: a(:,:) ...
REAL(dp),
INTENT(out)
:: eigval(:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: dac ...

FUNCTIONdihedral_angle(ab, bc, cd)

Returns the dihedral angle, i.e. the angle between the planes defined by the vectors (-ab,bc) and (cd,-bc). The dihedral angle is returned in radians.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: ab(3) ...
REAL(dp),
INTENT(in)
:: bc(3) ...
REAL(dp),
INTENT(in)
:: cd(3) ...

FUNCTIONdotprod_3d(vec1, vec2)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: vec1(3) ...
REAL(dp),
INTENT(in)
:: vec2(3) ...

FUNCTIONexpint(n, x)

computes the exponential integral En(x) = Int(exp(-x*t)/t^n,t=1..infinity) x>0, n=0,1,.. Note: Ei(-x) = -E1(x)

Return Value ::
REAL(dp)
Arguments:
INTEGER
:: n ...
REAL(dp)
:: x ...

ELEMENTAL FUNCTIONgcd(a, b)

computes the greatest common divisor of two number

Return Value ::
INTEGER
Arguments:
INTEGER,
INTENT(in)
:: a ...
INTEGER,
INTENT(in)
:: b ...

SUBROUTINEget_pseudo_inverse_diag(a, a_pinverse, rskip)

returns the pseudoinverse of a real, symmetric and positive definite matrix using diagonalization.

Arguments:
REAL(dp)
:: a(:,:) matrix a
REAL(dp)
:: a_pinverse(:,:) pseudoinverse of matrix a
REAL(dp),
INTENT(in)
:: rskip parameter for setting small eigenvalues to zero

SUBROUTINEget_pseudo_inverse_svd(a, a_pinverse, rskip)

returns the pseudoinverse of a real, square matrix using singular value decomposition

Arguments:
REAL(dp)
:: a(:,:) matrix a
REAL(dp)
:: a_pinverse(:,:) pseudoinverse of matrix a
REAL(dp),
INTENT(in)
:: rskip parameter for setting small singular values to zero

SUBROUTINEinvmat(a, info)

returns inverse of matrix using the lapack routines DGETRF and DGETRI

Arguments:
REAL(dp),
INTENT(inout)
:: a(:,:) ...
INTEGER,
INTENT(out)
:: info ...

SUBROUTINEinvmat_symm(a, cholesky_triangle)

returns inverse of real symmetric, positive definite matrix

Arguments:
REAL(dp),
INTENT(inout)
:: a(:,:) matrix
CHARACTER(1),
INTENT(in),
OPTIONAL
:: cholesky_triangle if cholesky decomposition of a was already done using dpotrf, indicating if the upper or lower triangle of a is stored. If not given, cholesky decomposition of a will be done before inversion.

FUNCTIONinv_3x3(a)

Returns the inverse of the 3 x 3 matrix a.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a(3,3) ...

SUBROUTINEjacobi(a, d, v)

Jacobi matrix diagonalization. The eigenvalues are returned in vector d and the eigenvectors are returned in matrix v in ascending order.

Arguments:
REAL(dp),
INTENT(inout)
:: a(:,:) ...
REAL(dp),
INTENT(out)
:: d(:) ...
REAL(dp),
INTENT(out)
:: v(:,:) ...

ELEMENTAL FUNCTIONlcm(a, b)

computes the least common multiplier of two numbers

Return Value ::
INTEGER
Arguments:
INTEGER,
INTENT(in)
:: a ...
INTEGER,
INTENT(in)
:: b ...

FUNCTIONmatmul_3x3(mat1, mat2)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: mat1(3,3) ...
REAL(dp),
INTENT(in)
:: mat2(3,3) ...

SUBROUTINEmatvec_3x3(res, mat, vec)

...

Arguments:
REAL(dp),
INTENT(out)
:: res(3) ...
REAL(dp),
INTENT(in)
:: mat(3,3) ...
REAL(dp),
INTENT(in)
:: vec(3) ...

FUNCTIONmultinomial(n, k)

Calculates the multinomial coefficients

Return Value ::
REAL(dp)
Arguments:
INTEGER,
INTENT(in)
:: n ...
INTEGER,
INTENT(in)
:: k(:) ...

FUNCTIONreflect_vector(a, b)

Reflection of the vector a through a mirror plane defined by the normal vector b. The reflected vector a is stored in a_mirror.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a(3) ...
REAL(dp),
INTENT(in)
:: b(3) ...

FUNCTIONrotate_vector(a, phi, b)

Rotation of the vector a about an rotation axis defined by the vector b. The rotation angle is phi (radians). The rotated vector a is stored in a_rot.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a(3) ...
REAL(dp),
INTENT(in)
:: phi ...
REAL(dp),
INTENT(in)
:: b(3) ...

SUBROUTINEsymmetrize_matrix(a, option)

Symmetrize the matrix a.

Arguments:
REAL(dp),
INTENT(inout)
:: a(:,:) ...
CHARACTER(*),
INTENT(in)
:: option ...

FUNCTIONtranspose_3d(mat)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: mat(3,3) ...

PURE FUNCTIONvector_product(a, b)

Calculation of the vector product c = a x b.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a(3) ...
REAL(dp),
INTENT(in)
:: b(3) ...

FUNCTIONdet_3x3_1(a)

Returns the determinante of the 3x3 matrix a.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a(3,3) ...

FUNCTIONdet_3x3_2(a1, a2, a3)

Returns the determinante of the 3x3 matrix a given by its columns.

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: a1(3) ...
REAL(dp),
INTENT(in)
:: a2(3) ...
REAL(dp),
INTENT(in)
:: a3(3) ...

SUBROUTINEinvert_matrix_d(a, a_inverse, eval_error, option, improve)

Compute the inverse of the n by n real matrix a using the LAPACK library

Arguments:
REAL(dp),
INTENT(in)
:: a(:,:) ...
REAL(dp),
INTENT(out)
:: a_inverse(:,:) ...
REAL(dp),
INTENT(out)
:: eval_error ...
CHARACTER(1),
INTENT(in),
OPTIONAL
:: option ...
LOGICAL,
INTENT(in),
OPTIONAL
:: improve ...

SUBROUTINEinvert_matrix_z(a, a_inverse, eval_error, option)

Compute the inverse of the n by n complex matrix a using the LAPACK library

Arguments:
COMPLEX(dp),
INTENT(in)
:: a(:,:) ...
COMPLEX(dp),
INTENT(out)
:: a_inverse(:,:) ...
REAL(dp),
INTENT(out)
:: eval_error ...
CHARACTER(1),
INTENT(in),
OPTIONAL
:: option ...

SUBROUTINEunit_matrix_d(a)

Set the matrix a to be a unit matrix.

Arguments:
REAL(dp),
INTENT(inout)
:: a(:,:) ...

SUBROUTINEunit_matrix_z(a)

...

Arguments:
COMPLEX(dp),
INTENT(inout)
:: a(:,:) ...