拿来即用的求矩阵特征值的fortran程序
摘自宋叶志《Fortran科学计算与工程》
! -----------------------------------------------
! input: A(n,n)为输入的n*n的矩阵,tol是迭代停止的阈值
! output: namda为主特征值,u(n)为输入矩阵的n个特征值
! -----------------------------------------------
subroutine solveqr(A,n,namda,u,tol)
implicit real*8 (a-h,o-z)
integer :: n,i,k
real*8 :: A(n,n),u(n),u0(n),v(n),m0,m1,namda
u0(:) = 1.0d0 !迭代的初始向量
u = u0
m0 = 0.0d0
do k = 1,500 !设置最大迭代次数
v = matmul(A,u)
call max_rou(v,n,m1)
u = v/m1
if(dabs(m1-m0)<tol) exit
m0 = m1
end do
namda = m1
end subroutine
subroutine max_rou(r,n,ma)
implicit real*8 (a-h,o-z)
integer :: n,i,k
real*8 :: r(n),ma
ma = dabs(r(1))
do i = 2,n
if(dabs(r(i))>ma) then
ma = dabs(r(i))
k = i
end if
end do
ma = r(k)
end subroutine
标签:特征值,end,矩阵,u0,fortran,m1
From: https://www.cnblogs.com/liangxuran/p/17719101.html