matrix_m Module

This module implements standard operations from linear algebra, including including matrix construction, inversion, commutation, and taking traces.


Uses


Functions

public pure function identity(n) result(R)

Constructs an n×n identity matrix.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n

Matrix dimension

Return Value real(kind=wp), dimension(n, n)

Identity matrix [n×n]

public pure function matrix_inverse_re(A) result(R)

Wrapper for matrix_inverse_cx that operates on real matrices.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:, :) :: A

Matrix A [n×n]

Return Value real(kind=wp), dimension(size(A, 1), size(A, 1))

Matrix R=A¯¹

public pure function matrix_inverse_cx(A) result(R)

Inverts a square matrix via Gauss-Jordan elimination with partial pivot (general) or a cofactoring algorithm (2x2 matrices). The implementation is based on Algorithm #2 in "Efficient matrix inversion via Gauss-Jordan elimination and its parallelization" by E.S. Quintana et al. (1998).

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:, :) :: A

Matrix A [n×n]

Return Value complex(kind=wp), dimension(size(A, 1), size(A, 1))

Matrix R=A¯¹

public pure function matrix_trace(A) result(r)

Calculates the trace of a general complex matrix.

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:, :) :: A

Matrix [n×m]

Return Value complex(kind=wp)

r = Tr(A)

public pure function commutator(A, B) result(R)

Calculates the commutator between two complex square matrices.

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:, :) :: A

Left matrix [n×n]

complex(kind=wp), intent(in), dimension(size(A, 1), size(A, 1)) :: B

Right matrix [n×n]

Return Value complex(kind=wp), dimension(size(A, 1), size(A, 1))

Commutator R = [A,B]

public pure function anticommutator(A, B) result(R)

Calculates the anticommutator between two complex square matrices.

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:, :) :: A

Left matrix [n×n]

complex(kind=wp), intent(in), dimension(size(A, 1), size(A, 1)) :: B

Right matrix [n×n]

Return Value complex(kind=wp), dimension(size(A, 1), size(A, 1))

Anticommutator R = {A,B}

public pure function vector_diag(A) result(r)

Extracts the diagonal of a general complex matrix.

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:, :) :: A

Matrix [n×m]

Return Value complex(kind=wp), dimension(min(size(A, 1), size(A, 2)))

r = Diag(A)

public pure function matrix_diag(A, B) result(R)

Constructs a block-diagonal matrix R from two general matrices A and B.

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:, :) :: A

Left matrix [n×m]

complex(kind=wp), intent(in), dimension(:, :) :: B

Right matrix [p×q]

Return Value complex(kind=wp), dimension(size(A, 1) + size(B, 1), size(A, 2) + size(B, 2))

R = Diag(A,B)