[Fortran] 纯文本查看 复制代码
program main
implicit none
double precision matrix(3,3),T(3,3),c,s,kexi,toll,eak
integer i,j,m,n
parameter (toll=0.000001)
Matrix(1,1)=1
matrix(1,2)=2
matrix(2,1)=2
matrix(1,3)=3
matrix(3,1)=3
matrix(2,2)=4
matrix(2,3)=5
matrix(3,2)=5
matrix(3,3)=6
Do i=1,3
Do j=1,3
T(i,j)=matrix(i,j)
end do
end do
C
Do i=1,100
call subroutine E_k(eak,T)
if (eak.gt.toll) then
call subroutine maxmatrix(m,n)
kexi=0.5*atan(2*T(m,n)/T(m,m)-T(n,n))
c=cos(kexi)
s=sin(kexi)
T(m,m)=c
T(n,n)=c
T(m,n)=s
T(m,n)=-s
end if
end do
write(*,*) T
pause
end program main
C
C
subroutine E_k(eak)
implicit none
double precision a1,a2,a3,eak,T(3,3)
a1=T(2,1)**2
a2=T(3,1)**2
a3=T(3,2)**2
eak=a1+a2+a3
end subroutine
C
subroutine maxmatrix(m,n,T)
implicit none
double precision a,b,c,maxT,T(3,3)
integer m,n
a=T(2,1)
b=T(3,1)
c=T(3,2)
if (a.ge.b) then
if (a.ge.c)then
maxT=a
m=2
n=1
else
maxT=c
m=3
n=2
end if
else
if (b.ge.c)then
maxT=b
m=3
n=1
else
maxT=c
m=3
n=2
end if
end if
end subroutine