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
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.
Construct the Strang matrix of size n.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=ilp), | intent(in) | :: | n |
Dimension of the matrix. |
Strang matrix of size n.
Convert a matrix of type Strang to its dense representation as a
standard rank-2 array
B = dense(A)
A : Matrix of type Strang. It is an intent(in) argument.
B : Rank-2 array representation fo the matrix .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
Dense representation.
This interface overloads the det interface from stdlib_linalg
to compute the determinant where is of type
Strang.
d = det(A)
A : Matrix of type Strang. It is an intent(in) argument.
d : Determinant of the matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
Determinant of the matrix.
This interface overloads the eigh interface from stdlib_linalg
to compute the eigenvalues and eigenvectors of a Strang matrix.
call eigh(A, lambda, vectors)
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.
| Type | Intent | Optional | 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. |
This interface overloads the eigvalsh interface from stdlib_linalg
to compute the eigenvalues of a Strang matrix. Note that these
eigenvalues are known analytically.
lambda = eigvalsh(A)
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
Eigenvalues.
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.
y = matmul(A, x)
Driver for the matrix-vector product.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(in) | :: | x(:) |
Input vector. |
Output vector.
Driver for the matrix-matrix product.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(in) | :: | X(:,:) |
Input vector. |
Output vector.
Utility function returning the shape of a Strang matrix .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
Shape of the matrix.
Utility function returning the size of a Strang matrix
along a given dimension.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
||
| integer(kind=ilp), | intent(in) | :: | dim |
Queried dimension. |
Corresponding size.
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.
x = solve(A, b)
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.
| Type | Intent | Optional | 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. |
Solution vectors.
| Type | Intent | Optional | 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. |
Solution vector.
This interface overloads the trace interface from stdlib_linalg
to compute the trace of a matrix of type Strang.
tr = trace(A)
A : Matrix of Strang type. It is an intent(in) argument.
tr: Trace of the matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Strang), | intent(in) | :: | A |
Input matrix. |
Trace of the matrix.
Base type used to define the Strang matrix.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=ilp), | public | :: | n |
Dimension of the matrix. |
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
| private pure, module function initialize (n) | Construct the Strang matrix of size |