第1个回答 推荐于2018-03-14
以下是约当消去法解方程组,供参考。
c 约当削去法解线性方程
c program jordan
real a(5,6)
data a/1,0,6,0,0,
1 0,1,0,0,0,
1 0,0,1,0,0,
1 0,0,0,1,0,
1 0,0,0,0,1,
1 1,1,7,1,1/
write(*,100)((a(i,j),j=1,6),i=1,5)
write(*,*)
call jordan(a,5,6)
write(*,100)(a(i,6),i=1,5)
100 format(1x,6f10.4)
c READ(*,*)
end
c**********************************************************
C选列主元的约当削去法子程序
subroutine jordan(A,N,M)
real A(N,M)
do 10 K=1,N
big=abs(A(K,K))
L=K
do 5 J=K+1,N
if (abs(A(J,K)).GT.big) L=J
5 CONTINUE
IF (L.NE.K) THEN
DO 15 J=K,N+1
R=A(K,J)
A(K,J)=A(L,J)
A(L,J)=R
15 CONTINUE
ENDIF
DO 20 J=N+1,K,-1
20 A(K,J)=A(K,J)/A(K,K)
DO 40 I=1,N
IF (I.NE.K) THEN
DO 30 J=N+1,K,-1
30 A(I,J)=A(I,J)-A(I,K)*A(K,J)
ENDIF
40 CONTINUE
write(*,100)((a(iI,jJ),jJ=1,6),iI=1,5)
WRITE(*,*)
10 CONTINUE
100 format(1x,6f10.4)
return
END
c*********************************************************
c不选主元的约当削去法子程序
subroutine jor10(a,n,m)
dimension a(n,m)
do 10 k=1,n
do 20 j=n+1,k,-1
20 a(k,j)=a(k,j)/a(k,k)
do 40 i=1,n
if (i.ne.k) then
do 30 j=n+1,k,-1
30 a(i,j)=a(i,j)-a(i,k)*a(k,j)
endif
40 continue
10 continue
return
end本回答被网友采纳