pasuka 发表于 2018-3-6 15:46:29

学客 发表于 2018-3-6 15:08
这样能对特征值进行从小到大顺序排序,但是特征向量不能进项从小打大排序,而是要随着特征值的顺序变化与之 ...

Orz。。。
特征值按照模的大小排序的同时,将对应的特征向量交换一下列或行的顺序呗

学客 发表于 2018-3-6 16:14:51

谢谢你,这个我知道

学客 发表于 2018-3-6 23:47:07

module qsort_c_module
      implicit none
      public :: QsortC
      private :: Partition
      contains
      recursive subroutine QsortC(A,B)
      real, intent(in out), dimension(:) :: A
      real, intent(in out), dimension(:,:) :: B
      integer :: iq
      if(size(A) > 1) then
      call Partition(A, iq, B)
      call QsortC(A(:iq-1),B(:,:iq-1))
      call QsortC(A(iq:),B(:,iq:))
      endif
      end subroutine QsortC
      subroutine Partition(A, marker, B)
      real, intent(in out), dimension(:) :: A
      real, intent(in out), dimension(:,:) :: B
      integer, intent(out) :: marker
      integer :: i, j
      real :: temp
      real ,dimension(1:size(A))::temb
      real :: x      ! pivot poin
      x = A(1)
      i= 0
      j= size(A) + 1
      do
          j = j-1
      do
      if (A(j) <= x) exit
      j = j-1
      end do
      i = i+1
      do
      if (A(i) >= x) exit
      i = i+1
      end do
      if (i < j) then
      ! exchange A(i) and A(j)
      temp = A(i)
      temb = B(:,i)
      A(i) = A(j)
      B(:,i)=B(:,j)
      A(j) = temp
      B(:,j)=temb
      elseif (i == j) then
      marker = i+1
      return
      else
      marker = i
      return
      endif
      end do
      end subroutine Partition
      end module qsort_c_module
      program www_fcode_cn
      use qsort_c_module
      implicit none
      integer, parameter :: r = 3
      real, dimension(1:r) :: myarray = (/0, 50, 20/)
      real, dimension(1:r,1:r) :: mb=(/1,2,3,4,5,6,7,8,9/)
      write(2,*) "原数组:", myarray
      write(2,'*') "原数组:", mb
      call QsortC(myarray,mb)
      write(2,*) "排序后:", myarray
      write(2,'*') "排序后:", mb
      end program www_fcode_cn

用这个修改后的快速排序法,排列特征值A,和特征向量B,出现了错误:
B排序输出后,出现了这样的数字:1.000000       2.000000       3.000000       7.000000   
   8.000000       9.000000       4.000000       5.000000   -1.5823616E-26
请问是哪里出错了,非常感谢
页: 1 [2]
查看完整版本: MKL求一般非对称矩阵特征值特征向量