回 帖 发 新 帖 刷新版面

主题:[讨论]关于数据统计

关于数据统计
现在有一组数据,我想统计下在两个数字间隔内有多少个数据。数据如下:

eigenvalue=  -2.59461975097656     
 eigenvalue=  -2.59461951255798     
 eigenvalue=  -2.59461903572083     
 eigenvalue=  -2.59461879730225     
 eigenvalue=  -2.58745384216309     
 eigenvalue=  -2.58745336532593     
 eigenvalue=  -2.58745312690735     
 eigenvalue=  -2.58745288848877     
 eigenvalue=  -1.87168383598328     
 eigenvalue=  -1.87168371677399     
 eigenvalue=  -1.87168371677399     
 eigenvalue=  -1.87168347835541     
 eigenvalue=  -1.80774712562561     
 eigenvalue=  -1.80774688720703     
 eigenvalue=  -1.80774688720703     
 eigenvalue=  -1.80774676799774     
 eigenvalue=  -1.41421377658844     
 eigenvalue=  -1.41421353816986     
 eigenvalue=  -1.41421353816986     
 eigenvalue=  -1.41421341896057     
 eigenvalue=  -1.30447649955750     
 eigenvalue=  -1.30447638034821     
 eigenvalue=  -1.30447638034821     
 eigenvalue=  -1.30447626113892     
 eigenvalue= -0.316583961248398     
 eigenvalue= -0.316583901643753     
 eigenvalue= -0.316583812236786     
 eigenvalue= -0.316583722829819     
 eigenvalue= -2.427690048989462E-007
 eigenvalue= -1.448813407023408E-007
 eigenvalue= -4.662113894937647E-008
 eigenvalue= -2.762132211842072E-008
 eigenvalue=  2.762132034206388E-008
 eigenvalue=  4.662114605480383E-008
 eigenvalue=  1.448813691240503E-007
 eigenvalue=  2.427690048989462E-007
 eigenvalue=  0.316583663225174     
 eigenvalue=  0.316583782434464     
 eigenvalue=  0.316583901643753     
 eigenvalue=  0.316583961248398     
 eigenvalue=   1.30447638034821     
 eigenvalue=   1.30447649955750     
 eigenvalue=   1.30447649955750     
 eigenvalue=   1.30447673797607     
 eigenvalue=   1.41421353816986     
 eigenvalue=   1.41421365737915     
 eigenvalue=   1.41421377658844     
 eigenvalue=   1.41421389579773     
 eigenvalue=   1.80774664878845     
 eigenvalue=   1.80774712562561     
 eigenvalue=   1.80774712562561     
 eigenvalue=   1.80774724483490     
 eigenvalue=   1.87168335914612     
 eigenvalue=   1.87168371677399     
 eigenvalue=   1.87168383598328     
 eigenvalue=   1.87168395519257     
 eigenvalue=   2.58745336532593     
 eigenvalue=   2.58745360374451     
 eigenvalue=   2.58745384216309     
 eigenvalue=   2.58745455741882     
 eigenvalue=   2.59461951255798     
 eigenvalue=   2.59461951255798     
 eigenvalue=   2.59461975097656     
 eigenvalue=   2.59462022781372     

给定一个参数Ef,让它从-2.6变化到2.6,每隔0.01变化一次,看下再每个间隔内有多少数据。比如在-2.6到-2.59之间,数据数为0;在-2.59到-2.58之间,数据数为4;在-2.58到-2.57之间数据数为4,等等。
我是这样做的,但是没能通过 程序。定义一个数组ds存储数据数,一个数组Ef存储数据间隔。


integer,dimension(:)::ds(1000)  !!ds定义的大些
real,dimension(:)::Ef(1000)  !Ef定义的也大些,便于存放较多数据

ds=0
 do j=1,4*m*n
  do i=1,520
    Ef(i)=2.6-0.01*i
   if(Ef(i)<=eigenvalue(j)<Ef(i+1)) then
   ds(i)=ds(i)+1
    
   end if
   
   open(10,file='taimidu.txt')
     write(10,*) Ef ds(i)
   close(10)
   end do
 end do

再把程序贴上来吧:
program main
  use IMSL
!  use linear_operators
  implicit none
  real, parameter::pi=3.14159265
  complex, parameter:: fi=(0.0, 1.0)
  real t,f,w,temp

  integer,dimension(:)::ds(1000)
  real,dimension(:)::Ef(100)
  complex*8,allocatable::h(:,:)
  complex*8,allocatable::h0(:,:)
  complex*8,allocatable::r0(:,:)
  complex*8,allocatable::l0(:,:)
  
  complex*8,allocatable::eigenvector(:,:)


  real*8, allocatable:: eigenvalue(:)  !特征值的矩阵
  integer ::i,n,m,j,p
  open(1,file='hmat.txt')
  n=4
  m=4 
  
  allocate(h(4*m*n,4*m*n))
  allocate(h0(4*n,4*n),r0(4*n,4*n),l0(4*n,4*n))
  allocate(eigenvalue(4*n*m)) 
  allocate(eigenvector(4*n*m,4*m*n))

  w=0.0
  t=1.0
  f=0.25

  call hmatr(h, n,m)  
 do  i=1,4*n*m
   do j=1,4*n*m

  write(1,*) h(j,i)

   end do
 end do
close(1)


  eigenvalue=eig(h,w=eigenvector) 
  
  open(10,file='eeig.txt')
  do j=1,4*n*m-1
     p=j
    do i=j+1,4*m*n
       if(eigenvalue(i)<eigenvalue(p)) p=i
    end do
     temp=eigenvalue(j)
     eigenvalue(j)=eigenvalue(p)
     eigenvalue(p)=temp
  end do
  
  do i=1,4*m*n
 
   write(10,*) 'eigenvalue=',eigenvalue(i)
   end do
  close(10)
ds=0
 do j=1,4*m*n
  do i=1,51
    Ef(i)=2.6-0.1*i
   if(Ef(i)<=eigenvalue(j)<Ef(i+1)) then
   ds(i)=ds(i)+1
    
   end if
   
   open(10,file='taimidu.txt')
     write(10,*) Ef ds(i)
   close(10)
   end do
 end do
 

 stop
 contains
   subroutine hmatr(h,n,m) 
   integer n,m
   complex h(4*m*n,4*m*n)
   complex h0(4*n,4*n)
   complex r0(4*n,4*n)
   complex l0(4*n,4*n)

   integer:: j,n0,x
   complex:: c(4,4),a(4,4),b(4,4),r(4,4),l(4,4)
 
   h0=0.0
   a=0.0
   b=0.0
   h=0.0
   r0=0.0
   l0=0.0
   a(1, 4)=t
   b=transpose(a)
   c=0.0
   r=0.0
   l=0.0

   
      n0=1
   do while(n0<=2*n-1)

      r(2,1)=t*exp(fi*(pi-2.0*pi*f/3.0*(3.0*n0/2.0+0.25)))
      r(3,4)=t*exp(fi*(pi-2.0*pi*f/3.0*(3.0*(n0+1)/2.0+0.25)))
      l(1,2)=t*exp(-fi*(pi-2.0*pi*f/3.0*(3.0*n0/2.0+0.25)))!conjg(r0(2,1))
      l(4,3)=t*exp(-fi*(pi-2.0*pi*f/3.0*(3.0*(n0+1)/2.0+0.25)))!conjg(r0(3,4))


      r0(2*n0,2*n0-1)=r(2,1)
      r0(2*n0+1,2*n0+2)=r(3,4)
      l0(2*n0-1,2*n0)=l(1,2)
      l0(2*n0+2,2*n0+1)=l(4,3)


      c(1,1)=w
      c(2, 1) = t*exp(fi*(-pi+2.0*pi/3.0*f*(1.5*n0+0.25))) 
      c(1, 2) = t*exp(-fi*(-pi+2.0*pi/3.0*f*(1.5*n0+0.25)))
      
      c(2, 2) = w
      c(2, 3) = t
      c(3, 2) = t
      c(3, 3) = w
      c(3, 4) = t*exp(fi*(-pi+2.0*pi/3.0*f*(1.5*(n0+1)+0.25)))
      c(4, 3) = t*exp(-fi*(-pi+2.0*pi/3.0*f*(1.5*(n0+1)+0.25)))
      c(4, 4) = w
    

       h0(2*n0-1,2*n0-1)=c(1,1)
       h0(2*n0,2*n0-1)=c(2,1)
       h0(2*n0-1,2*n0)=c(1,2)
       h0(2*n0,2*n0)=c(2,2)
       h0(2*n0,2*n0+1)=c(2,3)
       h0(2*n0+1,2*n0)=c(3,2)
       h0(2*n0+1,2*n0+1)=c(3,3)
       h0(2*n0+1,2*n0+2)=c(3,4)
       h0(2*n0+2,2*n0+1)=c(4,3)
       h0(2*n0+2,2*n0+2)=c(4,4)   

       if(2*n0-1==1) then

        h0(2*n0-1:2*n0+2,2*n0+3:2*n0+6)=b
        h0(2*n0-1:2*n0+2,4*n-3:4*n)=a

         else if(2*n0-1<4*n-3)  then

          h0(2*n0-1:2*n0+2,2*n0+3:2*n0+6)=b
          h0(2*n0-1:2*n0+2,2*n0-5:2*n0-2)=a

         else 

            h0(4*n-3:4*n,1:4)=b
            h0(2*n0-1:2*n0+2,2*n0-5:2*n0-2)=a
       end if

       n0=n0+2


   end do

 do x=1,4*(m-1)*n+1,4*n
     h(x:x+4*n-1,x:x+4*n-1)=h0
        if( x==1) then
          h(x:x+4*n-1,x+4*n:8*n)=r0
          h(x:x+4*n-1,(m-1)*4*n+1:m*4*n)=l0
        elseif( x>=4*n+1 .and. x<4*(m-1)*n+1) then
          h(x:x+4*n-1,x+4*n:x+8*n-1)=r0
          h(x:x+4*n-1,x-4*n:x-1)=l0
        else
          h(x:x+4*n-1,1:4*n)=r0
          h(x:x+4*n-1,x-4*n:x-1)=l0
        end if
  
  end do


   end subroutine hmatr
 end program main

回复列表 (共11个回复)

11 楼

解决了,多谢啊

我来回复

您尚未登录,请登录后再回复。点此登录或注册