HouseHolder Transformation-QR分解

时间:2018-06-03 17:24:56

标签: matrix fortran qr-decomposition

我正在进行QR分解,代码在这里工作,但我的问题是,例如,有一个数组dimension(6,4),但我想分解dimension(6,2)。我使用子程序(dgeqrf)所以我应该使用不同的子程序吗?该子程序采用整个矩阵,但我想给出不同的列大小,因为我可以分解矩阵(6,2)。我分享了此计划的当前结果,但我希望(6,2)尺寸分解不是(6,4)尺寸

!Current result:          but I want:
! x x x x                  x x x x
! 0 x x x                  0 x x x
! 0 0 x x                  0 0 x x
! 0 0 0 x                  0 0 x x
! 0 0 0 0                  0 0 x x
! 0 0 0 0                  0 0 x x

 program decomposition

 !CONTAINS
 !subroutine Qrdecomposition(A_mat, R)

 real(8),dimension(6,4)   :: A_mat    
 !real,dimension(2,2),intent(inout)
 real(8),dimension(6,4)   :: R        
 !real,dimension(2,2),intent(out)
 real(8),dimension(6,4)                  :: A
 integer                              :: M,N,LDA,LWORK,INFO,i,j
 real(8),allocatable, dimension(:,:)     :: TAU
 real(8),allocatable, dimension(:,:)     :: WORK
 external   dgeqrf
 M=6
 N=4
 LDA=6
 LWORK=4
 INFO=0
 A_mat(1,:)=[2,1,2,6 ]
 A_mat(2,:)=[10,4,3,2]
 A_mat(3,:)=[1,3,2,9]
 A_mat(4,:)=[8,9,2,7]
 A_mat(5,:)=[9,5,9,4]
 A_mat(6,:)=[9,10,6,6]

A=A_mat

allocate(tau(M,N), work(M,N))
call dgeqrf(M,N,A,LDA,TAU,WORK,LWORK,INFO)
R=A
R(:,:)=0
do i=1,6
do j=i,4
    R(i,j)=A(i,j)
end do
end do

print *,R

!end subroutine Qrdecomposition
end program decomposition 
!Input
!A =
! 2     1     2     6
!10     4     3     2
! 1     3     2     9
! 8     9     2     7
! 9     5     9     4
! 9    10     6     6
 !The result should be like that
 !  -18.193      -13.851      -10.278      -10.278
 !       0        6.336     0.099656       6.5706
 !       0            0      0.64881       5.2419
 !       0            0       -3.887      -3.5114
 !       0            0       4.0589      -1.1447
 !       0            0      -0.5819      -5.6624

0 个答案:

没有答案