Sym
This function makes the symmetric matrix by using lower or part of the matrix.
note
Please use this function when the matrix is not too big, otherwise use GetSym.
- The following call will form symmetric matrix by using the upper triangle part of matrix
B
Sym from Upper part
A = Sym(mat=B, from="U")
- The following call will form symmetric matrix by using the lower triangle part of matrix
B
Sym from Lower part
A = Sym(mat=B, from="L")
Interface
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE FUNCTION Sym(mat, from) RESULT(ans)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), INTENT(IN) :: mat(:, :)
CHARACTER(1), INTENT(IN) :: from
!! from = "U", then upper triangular part must be provided
!! from = "L", then lower triangular part must be provided
INTEGER(INT8) :: ans(SIZE(mat, 1), SIZE(mat, 2))
END FUNCTION Sym
This example shows the usage of Sym method.
header
program main
use easifemBase
implicit none
For Real(DFP)
Sym from U
block
real(dfp), allocatable :: a(:,:), b(:, :)
call Reallocate(b, 5, 5)
call RANDOM_NUMBER(b)
b = b * 10.0
a = Sym(mat=b, from="U")
call Display( MdEncode(b), "b = " // CHAR_LF )
call Display( MdEncode(a), "a = Sym(b, 'U') = "// CHAR_LF )
end block
b =
9.1092 | 3.1157 | 2.4922 | 5.2597 | 5.7134 |
4.9975 | 7.2487 | 3.4857 | 2.0651 | 8.8911 |
6.248 | 6.3238 | 3.0667 | 2.7061 | 1.9605 |
3.5998 | 1.5125 | 8.7133 | 4.4033 | 4.1027 |
9.1797 | 0.34982 | 4.4058 | 5.9536 | 8.905 |
a = Sym(b, 'U') =
9.1092 | 3.1157 | 2.4922 | 5.2597 | 5.7134 |
3.1157 | 7.2487 | 3.4857 | 2.0651 | 8.8911 |
2.4922 | 3.4857 | 3.0667 | 2.7061 | 1.9605 |
5.2597 | 2.0651 | 2.7061 | 4.4033 | 4.1027 |
5.7134 | 8.8911 | 1.9605 | 4.1027 | 8.905 |
Sym from L
block
real(dfp), allocatable :: a(:,:), b(:, :)
call Reallocate(b, 5, 5)
call RANDOM_NUMBER(b)
b = b * 10.0
a = Sym(mat=b, from="L")
call Display( MdEncode(b), "b = " // CHAR_LF )
call Display( MdEncode(a), "a = Sym(b, 'L') = "// CHAR_LF )
end block
b =
5.0055 | 6.9798 | 4.7405 | 2.5558 | 9.0049 |
0.94932 | 4.4983 | 3.8745 | 4.7315 | 4.0114 |
1.8051 | 3.7857 | 6.4184 | 1.3453 | 0.66188 |
2.2517 | 5.5031 | 7.8064 | 0.72241 | 5.8013 |
6.5009 | 5.5032 | 0.86608 | 5.6514 | 8.6163 |
a = Sym(b, 'L') =
5.0055 | 0.94932 | 1.8051 | 2.2517 | 6.5009 |
0.94932 | 4.4983 | 3.7857 | 5.5031 | 5.5032 |
1.8051 | 3.7857 | 6.4184 | 7.8064 | 0.86608 |
2.2517 | 5.5031 | 7.8064 | 0.72241 | 5.6514 |
6.5009 | 5.5032 | 0.86608 | 5.6514 | 8.6163 |
cleanup
end program main