24小时热门版块排行榜    

CyRhmU.jpeg
查看: 2761  |  回复: 23
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

maomao1210

金虫 (正式写手)

[交流] 【分享】暑假闲来无事,与虫虫共同进步已有17人参与

暑假闲来无事,
有对写学术型代码感兴趣的虫子可以一起共同进步

[ Last edited by maomao1210 on 2010-7-28 at 18:53 ]
回复此楼
已阅   关注TA 给TA发消息 送TA红花 TA的回帖

田山东

捐助贵宾 (著名写手)

高人能给指点下不?


小木虫(金币+0.5):给个红包,谢谢回帖交流
第一次编矩阵里有复数的程序!够烦人啊!
思路:在外部定义一系列变量,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)  
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)

[ Last edited by 田山东 on 2010-7-23 at 11:32 ]
everythinghasitsseason.enjoyyourlife.
6楼2010-07-23 11:30:13
已阅   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 maomao1210 的主题更新
信息提示
请填处理意见