-1
我有以下子程序:FORTRAN90比較實值
SUBROUTINE matprod(nkval, matrix, tkval, field)
implicit none
integer, allocatable, intent(in) :: matrix(:,:,:)
real, allocatable, intent(inout) :: tkval(:,:,:)
real, allocatable, intent(in) :: nkval(:,:)
integer, intent(in) ::field
integer :: temp, i, j
allocate(tkval(field,size(matrix,dim=1),3))
temp=size(matrix,dim=1)
do i=1,field
do j=1,temp
tkval(i,j,:)=matmul(matrix(j,:,:),nkval(:,i))
if (tkval(i,j,1).eq.-0.5) then
tkval(i,j,1)=0.5
endif
if (tkval(i,j,2).eq.-0.5) then
tkval(i,j,2)=0.5
endif
if (tkval(i,j,3).eq.-0.5) then
tkval(i,j,3)=0.5
endif
enddo
enddo
END SUBROUTINE matprod
凡AFER矩陣乘法我有一組三維點,這是我知道的一個事實包含「-0.5」和我想抓住那些和把它們變成正值0.5。出於某種原因,我的if語句沒有看到這些。爲什麼?
這裏是「tkval」與J計數器的輸出樣本顯示:
1
0.2500000 0.7499999 0.7499999
2
0.2500000 0.7499999 0.7499999
3
0.7499999 0.2500000 0.7499999
4
0.7499999 0.7499999 0.2500000
5
0.7499999 0.2500000 0.7499999
6
0.7499999 0.7499999 0.2500000
7
-0.5000000 0.0000000 -0.7499999
8
-0.5000000 -0.7499999 0.0000000
9
0.0000000 -0.5000000 -0.7499999
10
0.0000000 -0.7499999 -0.5000000
11
-0.5000000 0.0000000 -0.7499999
12
-0.5000000 -0.7499999 0.0000000
13
0.5000000 0.5000000 -0.2500000
14
0.5000000 -0.2500000 0.5000000
15
0.0000000 -0.5000000 -0.7499999
16
0.0000000 -0.7499999 -0.5000000
17
0.5000000 0.5000000 -0.2500000
18
0.5000000 -0.2500000 0.5000000