Triu
This function returns the upper triangle part of a matrix.
Interface 1
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE FUNCTION Triu(A, diagNo) RESULT(ans)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), INTENT(IN) :: A(:, :)
INTEGER(I4B), OPTIONAL, INTENT(IN) :: diagNo
!! diagonal number, default = 0
!! diagNo>0 means super diagonal
!! diagNo<0 means subdiagonal
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64) :: ans(SIZE(A, 1), SIZE(A, 2))
END FUNCTION Triu
program main
use easifemBase
implicit none
BLOCK
REAL( Real32 ) :: A( 4, 4 )
CALL RANDOM_NUMBER(A); A = A*10
CALl Display(MdEncode(A), "A = " // CHAR_LF // CHAR_LF)
CALL Display(MdEncode(Triu(A,diagNo=0)), "(3,3) diagNo=0, = " // CHAR_LF // CHAR_LF )
CALL Display(MdEncode(Triu(A,diagNo=1)), "(3,3) diagNo=1, = " // CHAR_LF // CHAR_LF)
CALL Display(MdEncode(Triu(A,diagNo=2)), "(3,3) diagNo=2, = " // CHAR_LF // CHAR_LF )
END BLOCK
See results
Let's get the upper triangular form above Subdiagonals.
BLOCK
REAL( Real32 ) :: A( 4, 4 )
CALL RANDOM_NUMBER(A); A = A*10
CALl Display(MdEncode(A), "A = " // CHAR_LF // CHAR_LF)
CALL Display(MdEncode(Triu(A,diagNo=-1)), "(3,3) diagNo=-1, = " // CHAR_LF // CHAR_LF)
CALL Display(MdEncode(Triu(A,diagNo=-2)), "(3,3) diagNo=-2, = " // CHAR_LF // CHAR_LF )
END BLOCK
See results
end program main
Interface 2
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE FUNCTION Triu_12(A, flate, diagNo) RESULT(ans)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), INTENT(IN) :: A(:, :)
LOGICAL(LGT), INTENT(IN) :: flate
!! This variable is only for creating unique interface
INTEGER(I4B), OPTIONAL, INTENT(IN) :: diagNo
!! diagonal number, default = 0
!! diagNo>0 means super diagonal
!! diagNo<0 means subdiagonal
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), ALLOCATABLE :: ans(:)
END FUNCTION Triu_12
In this case the upper triangular part is returned in flat form. That is, the first n
entries of ans
denotes the main diagonal. Then next n-1
entries denotes first super-diagonal, and so on.
program main
use easifemBase
implicit none
REAL( Real32 ) :: A( 4, 4 )
CALL RANDOM_NUMBER(A); A = A*10
CALl Display(MdEncode(A), "A = " // CHAR_LF // CHAR_LF)
CALL Display(MdEncode(Triu(A, flate=.TRUE., diagNo=0)), "diagNo=0, = " // CHAR_LF // CHAR_LF )
CALL Display(MdEncode(Triu(A, flate=.TRUE., diagNo=1)), "diagNo=1, = " // CHAR_LF // CHAR_LF)
CALL Display(MdEncode(Triu(A, flate=.TRUE., diagNo=2)), "diagNo=2, = " // CHAR_LF // CHAR_LF )
end program main