[Fortran] 纯文本查看 复制代码
do i=1,200,1
R(1,1)=sqrt(dot_product(A(:,1),A(:,1)))!用Gram_Schmidt分解求QR分解
Q(:,1)=A(:,1)/R(1,1)
do k=2,N,1
forall(j=1:k-1) R(j,k)=dot_product(Q(:,j),A(:,k))
Temp=A(:,k)
do j=1,k-1!此处使用Forall会产生一个警告
Temp=Temp-Q(:,j)*R(j,k)
end do
R(k,k)=sqrt(dot_product(Temp,Temp))
Q(:,k)=Temp/R(k,k)
end do
A=matmul(R,Q)!分解完成,开始迭代
end do
[Fortran] 纯文本查看 复制代码
implicit none
real::P_reaArr_A(:,:),EigenValue(:)
real::R(N,N)
real,allocatable::A(:,:),Q(:,:),Temp(:)
real::Err,ds
integer::i,j,k,N,Error
Err=1E-6
N=size(P_reaArr_A,1)
allocate(A(N,N),stat=Error)
allocate(Q(N,N),stat=Error)
!allocate(R(N,N),stat=Error)
!write(*,*) Error
allocate(Temp(N),stat=Error)
A=P_reaArr_A