|
如果用数组片段的话,这个命题就更简单了。
[Fortran] 纯文本查看 复制代码 01 | Module KroneckerProduct_Mod |
03 | Integer , parameter , private :: DP = Selected_Real_Kind ( 9 ) |
06 | Subroutine KroneckerProduct ( A , B , H ) |
07 | Real ( Kind = DP ) , Intent ( IN ) :: A ( : , : ) , B ( : , : ) |
08 | Real ( Kind = DP ) , Intent ( OUT ) :: H ( : , : ) |
09 | Integer :: i , j , m , n , p , q |
10 | m = size ( A , dim = 1 ) |
11 | n = size ( A , dim = 2 ) |
12 | p = size ( B , dim = 1 ) |
13 | q = size ( B , dim = 2 ) |
16 | H ( p * ( i -1 ) +1 : p * i , q * ( j -1 ) +1 : q * j ) = B * A ( i , j ) |
19 | End Subroutine KroneckerProduct |
21 | End Module KroneckerProduct_Mod |
24 | use KroneckerProduct_Mod |
26 | Integer , parameter :: DP = Selected_Real_Kind ( 9 ) |
27 | Integer , parameter :: m = 2 , n = 3 , p = 4 , q = 5 , index 1 = m * p , index 2 = n * q |
28 | Real ( kind = 8 ) :: A ( m , n ) , B ( p , q ) , H ( index 1 , index 2 ) |
30 | A = reshape ( ( / 1 , 2 , 3 , 4 , 5 , 6 / ) , ( / 2 , 3 / ) ) |
31 | B = reshape ( ( / 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 / ) , ( / 4 , 5 / ) ) |
32 | call KroneckerProduct ( A , B , H ) |
34 | Write ( * , '(8(f5.1,1x))' ) H ( : , i ) |
36 | End Program www_fcode_cn |
|
|