TriDiag
Create a tridiagonal matrix.
Interface
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE FUNCTION Tridiag(d, da, db, diagNo) RESULT(Ans)
INTEGER(INT8| Int16 | Int32 | Int64 | Real32 | Real64), INTENT(IN) :: d(:)
!! main diagonal
INTEGER(INT8| Int16 | Int32 | Int64 | Real32 | Real64), INTENT(IN) :: da(:)
!! super diagonal
INTEGER(INT8| Int16 | Int32 | Int64 | Real32 | Real64) :: db(:)
!! subdiagonal
INTEGER(I4B), OPTIONAL, INTENT(IN) :: diagNo
!! sub and super diagonal number, default is 1
!! diagNo should be positive
REAL(DFP) :: ans(SIZE(d), SIZE(d))
END FUNCTION Tridiag
This example shows the use of TriDiag method.
program main
use easifemBase
implicit none
real(dfp), allocatable :: amat(:, :), d(:), da(:), db(:)
d = ones(5, 1.0_DFP)
da = 2.0*ones(4, 1.0_DFP) !! Above diagonal
db = -2.0*ones(4, 1.0_DFP) !! Below diagonal
amat = TriDiag(d=d, da=da, db=db, diagNo=1_I4B)
call Display(MdEncode(amat), "amat = ")
end program main
Results
amat =
1 | 2 | 0 | 0 | 0 |
-2 | 1 | 2 | 0 | 0 |
0 | -2 | 1 | 2 | 0 |
0 | 0 | -2 | 1 | 2 |
0 | 0 | 0 | -2 | 1 |