specialmatrices_strang Module


Uses

    • stdlib_linalg_constants

Interfaces

public interface Strang

Constructor for generating the Strang matrix of size n. The matrix corresponds to the standard 3-point finite-difference approximation of the 1D Laplace operator with unit grid-spacing () and homogeneous Dirichlet boundary conditions. It reads

Syntax

  • Construct a Strang matrix of size 100.
   integer, parameter :: n = 100
   type(Strang) :: S
   S = Strang(n)

Note

Only double precision is currently supported for this matrix type.

  • private pure module function initialize(n) result(A)

    Construct the Strang matrix of size n.

    Arguments

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

    Dimension of the matrix.

    Return Value type(Strang)

    Strang matrix of size n.

public interface dense

Convert a matrix of type Strang to its dense representation as a standard rank-2 array

Syntax

   B = dense(A)

Arguments

  • A : Matrix of type Strang. It is an intent(in) argument.

  • B : Rank-2 array representation fo the matrix .

  • private pure module function dense_rdp(A) result(B)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp), allocatable, (:,:)

    Dense representation.

public interface det

This interface overloads the det interface from stdlib_linalg to compute the determinant where is of type Strang.

Syntax

   d = det(A)

Arguments

  • A : Matrix of type Strang. It is an intent(in) argument.

  • d : Determinant of the matrix.

  • private pure module function det_rdp(A) result(d)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp)

    Determinant of the matrix.

public interface eigh

This interface overloads the eigh interface from stdlib_linalg to compute the eigenvalues and eigenvectors of a Strang matrix.

Syntax

   call eigh(A, lambda, vectors)

Arguments

  • A : Matrix of type Strang. It is an intent(in) argument.

  • lambda : Rank-1 real array returning the eigenvalues of A in increasing order. It is an intent(out) argument.

  • vectors: Rank-2 real array of size [n x n] returning the eigenvectors of A. It is an intent(out) argument.

Note

Eigenvalues and eigenvectors of the Strang matrix are known analytically and can thus be constructed very efficiently.

  • private pure module subroutine eigh_rdp(A, lambda, vectors)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(out), allocatable :: lambda(:)

    Eigenvalues.

    real(kind=dp), intent(out), allocatable :: vectors(:,:)

    Eigenvectors.

public interface eigvalsh

This interface overloads the eigvalsh interface from stdlib_linalg to compute the eigenvalues of a Strang matrix. Note that these eigenvalues are known analytically.

Syntax

   lambda = eigvalsh(A)

Arguments

  • A : Matrix of type Strang. It is an intent(in) argument.

  • lambda : Rank-1 real array returning the eigenvalues of A in increasing order. It is an intent(out) argument.

  • private pure module function eigvalsh_rdp(A) result(lambda)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp), allocatable, (:)

    Eigenvalues.

public interface matmul

This interface overloads the Fortran intrinsic matmul for the Strang matrix, both for matrix-vector and matrix-matrix products. For matrix-matrix product , only can be a Strang matrix. Both and are standard rank-2 arrays. All underlying functions are defined as pure.

Syntax

   y = matmul(A, x)
  • private pure module function spmv(A, x) result(y)

    Driver for the matrix-vector product.

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(in) :: x(:)

    Input vector.

    Return Value real(kind=dp), allocatable, (:)

    Output vector.

  • private pure module function spmvs(A, X) result(Y)

    Driver for the matrix-matrix product.

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(in) :: X(:,:)

    Input vector.

    Return Value real(kind=dp), allocatable, (:,:)

    Output vector.

public interface shape

Utility function returning the shape of a Strang matrix .

  • private pure module function shape_rdp(A) result(arr_shape)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    Return Value integer(kind=ilp), (2)

    Shape of the matrix.

public interface size

Utility function returning the size of a Strang matrix along a given dimension.

  • private pure module function size_rdp(A, dim) result(arr_size)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    integer(kind=ilp), intent(in) :: dim

    Queried dimension.

    Return Value integer(kind=ilp)

    Corresponding size.

public interface solve

This interface overloads the solve interface from stdlib_linalg for solving a system where is a Strang matrix. It also enables to solve a linear system with multiple right-hand sides.

Syntax

   x = solve(A, b)

Arguments

  • A : Matrix of Strang type. It is an intent(in) argument.

  • b : Rank-1 or rank-2 array defining the right-hand side(s). It is an intent(in) argument.

  • x : Solution of the linear system. It has the same type and shape as b.

  • private module function solve_multi_rhs(A, b, refine) result(x)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Coefficient matrix.

    real(kind=dp), intent(in) :: b(:,:)

    Right-hand side vectors.

    logical(kind=lk), intent(in), optional :: refine

    Whether iterative refinement is used or not.

    Return Value real(kind=dp), allocatable, (:,:)

    Solution vectors.

  • private module function solve_single_rhs(A, b, refine) result(x)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Coefficient matrix.

    real(kind=dp), intent(in), target :: b(:)

    Right-hand side vector.

    logical(kind=lk), intent(in), optional :: refine

    Whether iterative refinement is used or not.

    Return Value real(kind=dp), allocatable, target, (:)

    Solution vector.

public interface trace

This interface overloads the trace interface from stdlib_linalg to compute the trace of a matrix of type Strang.

Strang

   tr = trace(A)

Arguments

  • A : Matrix of Strang type. It is an intent(in) argument.

  • tr: Trace of the matrix.

  • private pure module function trace_rdp(A) result(tr)

    Arguments

    Type IntentOptional Attributes Name
    type(Strang), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp)

    Trace of the matrix.


Derived Types

type, public ::  Strang

Base type used to define the Strang matrix.

Constructor

Constructor for generating the Strang matrix of size n. The matrix corresponds to the standard 3-point finite-difference approximation of the 1D Laplace operator with unit grid-spacing () and homogeneous Dirichlet boundary conditions. It reads

Read more…
private pure, module function initialize (n)

Construct the Strang matrix of size n.