主题:关于复数矩阵
第一次编矩阵里有复数的程序!够烦人啊!
思路:在外部定义一系列变量,t,w,f,pi为实型,fi为复型;矩阵h0为复型,要求它的特征值,h0由内部子程序调用得到,它又由几个小矩阵:c,a,b组合得到。首先将h0定义为全0矩阵,然后再对它内部片段矩阵赋值,c,a,b按照一定顺序排列在h0里面,得到h0的值后将其传回主程序求特征值。大家能否帮忙看下,不知道h0定义为复型好不好啊
program main
use IMSL
implicit none
real,parameter::pi=3.1415927
complex,parameter::fi=(0.0,1.0)
complex q
real t,f,w
complex, allocatable::h0(:,:)
real, allocatable:: eigenvalue(:) !特征值的矩阵
integer :: i,n
read*,n
allocate(h0(4*n,4*n))
allocate(eigenvalue(n))
w=0.0
t=1.0
f=0.25
call hmatr(h0,n)
eigenvalue=eig(h0)
do i=1,4*n
write(*,"('eigenvalue=',f10.7)")eigenvalue(i)
! write(*,"('eigenvector=['3(f5.2'')']')")eigenvector(:,i)
end do
stop
contains
subroutine hmatr(h0,n)
integer n,i,j,n0
complex h0
complex,dimension(:,:)::c(4,4),a(4,4),b(4,4)
h0=0.0
a=reshape((/0.0,0.0,0.0,t,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0/),(/4,4/))
b=transpose(a)
do n0=1,2*n-1,2
c=((/w,t*cmplx(exp(-fi*(-pi+2*pi/3*f*(1.5*n0+1/4)))),0,0,t*exp(fi*(-pi+2*pi/3*f*(1.5*n0+1/4))),w,t,0,0,t,w,t*exp(fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),0,0,t*exp(-fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),w/),(/4,4/))
j=2*n0-1
do j=1,4*n-3,4
h0(j:j+3,j:j+3)=c
if(j==1) then
h0(j:j+3,j+4:j+7)=b;
h0(j:j+3,4*n-3:4*n)=a;
else if(j>=5.and.j<4*n-3) then
h0(j:j+3,j+4:j+7)=b;
h0(j:j+3,j-4:j-1)=a;
else
h0(4*n-3:4*n,1:4)=b;
h0(j:j+3,j-4:j-1)=a;
end if
end do
end do
end subroutine hmatr
end
出错信息:
1)Error: The shape matching rules of actual arguments and dummy arguments have been violated. [H0]
call hmatr(h0,n)
-----------^
2)E:\matlabxuexi\yyuu.f90(36) : Error: A constant or named constant is required in this context.
c=((/w,t*cmplx(exp(-fi*(-pi+2*pi/3*f*(1.5*n0+1/4)))),0,0,t*exp(fi*(-pi+2*pi/3*f*(1.5*n0+1/4))),w,t,0,0,t,w,t*exp(fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),0,0,t*exp(-fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),w/),(/4,4/))
---------^
3)E:\matlabxuexi\yyuu.f90(36) : Error: An INTEGER or REAL data type is required in this context.
c=((/w,t*cmplx(exp(-fi*(-pi+2*pi/3*f*(1.5*n0+1/4)))),0,0,t*exp(fi*(-pi+2*pi/3*f*(1.5*n0+1/4))),w,t,0,0,t,w,t*exp(fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),0,0,t*exp(-fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),w/),(/4,4/))
---------^
4)E:\matlabxuexi\yyuu.f90(39) : Error: The syntax of this substring is invalid. [H0]
h0(j:j+3,j:j+3)=c
-------^
Error executing df.exe.
yyuu.obj - 4 error(s), 0 warning(s)
思路:在外部定义一系列变量,t,w,f,pi为实型,fi为复型;矩阵h0为复型,要求它的特征值,h0由内部子程序调用得到,它又由几个小矩阵:c,a,b组合得到。首先将h0定义为全0矩阵,然后再对它内部片段矩阵赋值,c,a,b按照一定顺序排列在h0里面,得到h0的值后将其传回主程序求特征值。大家能否帮忙看下,不知道h0定义为复型好不好啊
program main
use IMSL
implicit none
real,parameter::pi=3.1415927
complex,parameter::fi=(0.0,1.0)
complex q
real t,f,w
complex, allocatable::h0(:,:)
real, allocatable:: eigenvalue(:) !特征值的矩阵
integer :: i,n
read*,n
allocate(h0(4*n,4*n))
allocate(eigenvalue(n))
w=0.0
t=1.0
f=0.25
call hmatr(h0,n)
eigenvalue=eig(h0)
do i=1,4*n
write(*,"('eigenvalue=',f10.7)")eigenvalue(i)
! write(*,"('eigenvector=['3(f5.2'')']')")eigenvector(:,i)
end do
stop
contains
subroutine hmatr(h0,n)
integer n,i,j,n0
complex h0
complex,dimension(:,:)::c(4,4),a(4,4),b(4,4)
h0=0.0
a=reshape((/0.0,0.0,0.0,t,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0/),(/4,4/))
b=transpose(a)
do n0=1,2*n-1,2
c=((/w,t*cmplx(exp(-fi*(-pi+2*pi/3*f*(1.5*n0+1/4)))),0,0,t*exp(fi*(-pi+2*pi/3*f*(1.5*n0+1/4))),w,t,0,0,t,w,t*exp(fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),0,0,t*exp(-fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),w/),(/4,4/))
j=2*n0-1
do j=1,4*n-3,4
h0(j:j+3,j:j+3)=c
if(j==1) then
h0(j:j+3,j+4:j+7)=b;
h0(j:j+3,4*n-3:4*n)=a;
else if(j>=5.and.j<4*n-3) then
h0(j:j+3,j+4:j+7)=b;
h0(j:j+3,j-4:j-1)=a;
else
h0(4*n-3:4*n,1:4)=b;
h0(j:j+3,j-4:j-1)=a;
end if
end do
end do
end subroutine hmatr
end
出错信息:
1)Error: The shape matching rules of actual arguments and dummy arguments have been violated. [H0]
call hmatr(h0,n)
-----------^
2)E:\matlabxuexi\yyuu.f90(36) : Error: A constant or named constant is required in this context.
c=((/w,t*cmplx(exp(-fi*(-pi+2*pi/3*f*(1.5*n0+1/4)))),0,0,t*exp(fi*(-pi+2*pi/3*f*(1.5*n0+1/4))),w,t,0,0,t,w,t*exp(fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),0,0,t*exp(-fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),w/),(/4,4/))
---------^
3)E:\matlabxuexi\yyuu.f90(36) : Error: An INTEGER or REAL data type is required in this context.
c=((/w,t*cmplx(exp(-fi*(-pi+2*pi/3*f*(1.5*n0+1/4)))),0,0,t*exp(fi*(-pi+2*pi/3*f*(1.5*n0+1/4))),w,t,0,0,t,w,t*exp(fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),0,0,t*exp(-fi*(-pi+2*pi/3*f*(1.5*(n0+1)+1/4))),w/),(/4,4/))
---------^
4)E:\matlabxuexi\yyuu.f90(39) : Error: The syntax of this substring is invalid. [H0]
h0(j:j+3,j:j+3)=c
-------^
Error executing df.exe.
yyuu.obj - 4 error(s), 0 warning(s)