[問題] else if 輸出值為0的問題
大家好
我是寫Fortran的新手
因為老師要叫我寫一個矩陣
之後要做對角化
但是有些項總是為0
例如HO(1,2,4)有輸出值1
但是HO(1,4,2)卻是0
想問各位前輩
我的問題錯在哪裡??
謝謝
以下是簡化的程式碼
program 111
parameter (na=100)
common /matrix_1/ H(na,na),
@ HO(na,na,na)
call matrix__
write(6,*)HO(1,2,4)
write(6,*)HO(1,4,2)
write(6,*)HO(2,4,2)
write(6,*)HO(3,4,2)
write(6,*)HO(4,4,2)
stop
end
subroutine matrix__
parameter (na=100)
common /matrix_1/ H(na,na),
@ HO(na,na,na)
do i=1,4
do j=i,4
ix=3*(i-1)+1
iy=3*(i-1)+2
iz=3*(i-1)+3
jx=3*(j-1)+1
jy=3*(j-1)+2
jz=3*(j-1)+3
do k=1,4
if(k.eq.i .and. k.eq.j) then
HO(k,ix,ix)=1
HO(k,iy,iy)=1
HO(k,iz,iz)=1
HO(k,ix,iy)=1
HO(k,ix,iz)=1
HO(k,iy,iz)=1
else if(k.ne.j .and. k.eq.i) then
HO(k,ix,jx)=1
HO(k,iy,jy)=1
HO(k,iz,jz)=1
HO(k,ix,jy)=1
HO(k,ix,jz)=1
HO(k,iy,jz)=1
HO(k,iy,jx)=1
else if(k.ne.i .and. k.eq.j) then
HO(k,ix,jx)=1
HO(k,iy,jy)=1
HO(k,iz,jz)=1
HO(k,ix,jy)=1
HO(k,ix,jz)=1
HO(k,iy,jz)=1
else if(k.ne.i .and. k.ne.j) then
HO(k,ix,jx)=1
HO(k,iy,jy)=1
HO(k,iz,jz)=1
HO(k,ix,jy)=1
HO(k,ix,jz)=1
HO(k,iy,jz)=1
endif
HO(k,jx,ix)=HO(k,ix,jx)
HO(k,jy,iy)=HO(k,iy,jy)
HO(k,jz,iz)=HO(k,iz,jz)
HO(k,jy,ix)=HO(k,ix,jy)
HO(k,jz,ix)=HO(k,ix,jz)
HO(k,jz,iy)=HO(k,iy,jz)
enddo
enddo
enddo
return
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.9.63
→
11/22 00:49, , 1F
11/22 00:49, 1F
→
11/22 00:57, , 2F
11/22 00:57, 2F
→
11/22 00:58, , 3F
11/22 00:58, 3F
→
11/22 09:20, , 4F
11/22 09:20, 4F
→
11/22 10:24, , 5F
11/22 10:24, 5F
推
12/15 23:48, , 6F
12/15 23:48, 6F
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章