主题:有什么办法实现复数相乘?
最近几天 调程序,发现一个严重错误,两个复数相乘直接用*啦。这是实数相乘的符号啊,怎么能用到复数相乘上呢。
[em1][em1][em1][em1][em1][em1][em3][em3][em3][em3][em6][em6][em6][em6][em6][em6]
看徐士良算法了,倒是给出一个解复数乘法的程序,但是那个要知道实部和虚部是什么才行,我这个程序里不知道实部和虚部是多少,不知道有没有算法能解决啊?
DIMENSION AR(3,4),AI(3,4),BR(4,4),BI(4,4),CR(3,4),CI(3,4)
DOUBLE PRECISION AR,AI,BR,BI,CR,CI
DATA AR/1.0,1.0,0.0,2.0,5.0,4.0,3.0,1.0,2.0,-2.0,3.0,-1.0/
DATA AI/1.0,-1.0,-3.0,3*-1.0,3*2.0,1.0,0.0,2.0/
DATA BR/1.0,3.0,6.0,2.0,4.0,0.0,3.0,-3.0,
* 5.0,2.0,1.0,-2.0,-2.0,-1.0,2.0,1.0/
DATA BI/-1.0,2.0,-3.0,-1.0,-1.0,1.0,2.0,-2.0,
* 1.0,0.0,1.0,1.0,-1.0,5.0,-1.0,-2.0/
CALL BCdMUL(AR,AI,BR,BI,3,4,4,CR,CI)
WRITE(*,10) ((CR(I,J),J=1,4),I=1,3)
WRITE(*,20)
WRITE(*,10) ((CI(I,J),J=1,4),I=1,3)
10 FORMAT(1X,4D15.6)
20 FORMAT(1X,'---------------------------------------')
END
SUBROUTINE BCdMUL(AR,AI,BR,BI,M,N,K,CR,CI)
DIMENSION AR(M,N),AI(M,N),BR(N,K),BI(N,K)
DIMENSION CR(M,K),CI(M,K)
DOUBLE PRECISION AR,AI,BR,BI,CI,CR,P,Q,S
DO I=1,M
DO J=1,K
CR(I,J)=0.0
CI(I,J)=0.0
DO 50 L=1,N
P=AR(I,L)*BR(L,J)
Q=AI(I,L)*BI(L,J)
S=(AR(I,L)+AI(I,L))*(BR(L,J)+BI(L,J))
CR(I,J)=CR(I,J)+P-Q
CI(I,J)=CI(I,J)+S-P-Q
50 CONTINUE
100 CONTINUE
RETURN
END
这是徐士良的程序,大家看下吧。程序集里找到的。
下面是我的部分程序:
do temp=1,i
conduc(temp)=0.0
ea(temp,:)=traneigv(temp,:).x.hx
ec(temp,:)=traneigv(temp,:).x.hy
ee(:,temp)=eigenvector(:,temp)
do j=i+1,4*m*n
ahxb=0.0
bhya=0.0
ahyb=0.0
bhxa=0.0
eb(j,:)=traneigv(j,:).x.hx
ed(j,:)=traneigv(j,:).x.hy
eg(:,j)=eigenvector(:,j)
ahxb(temp,j)=ea(temp,:)*eg(:,j)
bhya(j,temp)=ed(j,:)*ee(:,temp)
ahyb(temp,j)=ec(temp,pp)*eg(pp,j)
bhxa(j,temp)=eb(j,pp)*ee(pp,temp)
conduc(temp)=conduc(temp)+(ahxb(temp,j).x.bhya(j,temp)-ahyb(temp,j).x.bhxa(j,temp))/(avereig(temp)-avereig(j))**2
end do
end do
ahxb(temp,j).x.bhya(j,temp),两个复数相乘,中间不能用.x.,用*也不行,否则会出错。
ahxb(temp,j) temp行j列的一个复数
bhya(j,temp)j行temp列的一个复数
大家看下有 没有什么好办法啊
[em1][em1][em1][em1][em1][em1][em3][em3][em3][em3][em6][em6][em6][em6][em6][em6]
看徐士良算法了,倒是给出一个解复数乘法的程序,但是那个要知道实部和虚部是什么才行,我这个程序里不知道实部和虚部是多少,不知道有没有算法能解决啊?
DIMENSION AR(3,4),AI(3,4),BR(4,4),BI(4,4),CR(3,4),CI(3,4)
DOUBLE PRECISION AR,AI,BR,BI,CR,CI
DATA AR/1.0,1.0,0.0,2.0,5.0,4.0,3.0,1.0,2.0,-2.0,3.0,-1.0/
DATA AI/1.0,-1.0,-3.0,3*-1.0,3*2.0,1.0,0.0,2.0/
DATA BR/1.0,3.0,6.0,2.0,4.0,0.0,3.0,-3.0,
* 5.0,2.0,1.0,-2.0,-2.0,-1.0,2.0,1.0/
DATA BI/-1.0,2.0,-3.0,-1.0,-1.0,1.0,2.0,-2.0,
* 1.0,0.0,1.0,1.0,-1.0,5.0,-1.0,-2.0/
CALL BCdMUL(AR,AI,BR,BI,3,4,4,CR,CI)
WRITE(*,10) ((CR(I,J),J=1,4),I=1,3)
WRITE(*,20)
WRITE(*,10) ((CI(I,J),J=1,4),I=1,3)
10 FORMAT(1X,4D15.6)
20 FORMAT(1X,'---------------------------------------')
END
SUBROUTINE BCdMUL(AR,AI,BR,BI,M,N,K,CR,CI)
DIMENSION AR(M,N),AI(M,N),BR(N,K),BI(N,K)
DIMENSION CR(M,K),CI(M,K)
DOUBLE PRECISION AR,AI,BR,BI,CI,CR,P,Q,S
DO I=1,M
DO J=1,K
CR(I,J)=0.0
CI(I,J)=0.0
DO 50 L=1,N
P=AR(I,L)*BR(L,J)
Q=AI(I,L)*BI(L,J)
S=(AR(I,L)+AI(I,L))*(BR(L,J)+BI(L,J))
CR(I,J)=CR(I,J)+P-Q
CI(I,J)=CI(I,J)+S-P-Q
50 CONTINUE
100 CONTINUE
RETURN
END
这是徐士良的程序,大家看下吧。程序集里找到的。
下面是我的部分程序:
do temp=1,i
conduc(temp)=0.0
ea(temp,:)=traneigv(temp,:).x.hx
ec(temp,:)=traneigv(temp,:).x.hy
ee(:,temp)=eigenvector(:,temp)
do j=i+1,4*m*n
ahxb=0.0
bhya=0.0
ahyb=0.0
bhxa=0.0
eb(j,:)=traneigv(j,:).x.hx
ed(j,:)=traneigv(j,:).x.hy
eg(:,j)=eigenvector(:,j)
ahxb(temp,j)=ea(temp,:)*eg(:,j)
bhya(j,temp)=ed(j,:)*ee(:,temp)
ahyb(temp,j)=ec(temp,pp)*eg(pp,j)
bhxa(j,temp)=eb(j,pp)*ee(pp,temp)
conduc(temp)=conduc(temp)+(ahxb(temp,j).x.bhya(j,temp)-ahyb(temp,j).x.bhxa(j,temp))/(avereig(temp)-avereig(j))**2
end do
end do
ahxb(temp,j).x.bhya(j,temp),两个复数相乘,中间不能用.x.,用*也不行,否则会出错。
ahxb(temp,j) temp行j列的一个复数
bhya(j,temp)j行temp列的一个复数
大家看下有 没有什么好办法啊