* Methode de factorisation L.U (sans change de lignes) C **************************************** REAL A(20,21),X(20),Y(20) OPEN (1,FILE='LU.DON',ACCESS='SEQUENTIAL',STATUS='OLD') READ(1,*) N N1=N+1 READ(1,*) ((A(I,J),J=1,N1),I=1,N) CLOSE(1,STATUS='KEEP') OPEN (1,FILE='LU.DAT',ACCESS='SEQUENTIAL',STATUS='UNKNOWN') WRITE(1,100)N 100 FORMAT(T15,'Systme linaire d''ordre ',I4) WRITE(1,*) WRITE(1,*) 'Matrice' DO 150 I=1,N 150 WRITE(1,400)(A(I,J),J=1,N) 400 FORMAT(4E17.7) WRITE(1,*) WRITE(1,*)' Second membre ' WRITE(1,400)(A(I,N1),I=1,N) DO 1 K=1,N-1 C C Elimination de X(k) C 3 PIVOT=1./A(K,K) DO 1 I=K+1,N S=A(I,K) IF(S.EQ.0)GOTO 1 S=PIVOT*S A(I,K)=S DO 9 J=K+1,N 9 A(I,J)=A(I,J)-S*A(K,J) 1 CONTINUE C DO 550 I=1,N 550 WRITE(1,400)(A(I,J),J=1,N)
C Matrices L et U de la factorisation WRITE(1,*) WRITE(1,*) 'Matrices L et U' DO 151 I=1,N DO 152 J=1,N Y(J)=0 152 X(J)=0 X(I)=1. IF(I.EQ.1)GOTO 157 DO 153 J=1,I-1 153 X(J)=A(I,J) 157 DO 154 J=I,N 154 Y(J)=A(I,J) 151 WRITE(1,500)(X(J),Y(J),J=1,N) 500 FORMAT(1X,6E13.6) WRITE(1,*) C C Rsolution du systme triangulaire L.Y=B C IF(A(N,N).EQ.0)GOTO 1000 c WRITE(1,*) c WRITE(1,*)'Solution' Y(1)=A(1,N1) DO 155 I=2,N S=A(I,N1) DO 156 J=1,I-1 156 S=S-A(I,J)*Y(J) 155 Y(I)=S C C Rsolution du systme U.X=Y X(N)=A(N,N1)/A(N,N) DO 7 K=N-1,1,-1 S=A(K,N1) DO 8 J=K+1,N 8 S=S-A(K,J)*X(J) 7 X(K)=S/A(K,K) WRITE(1,200) 200 FORMAT(T30,19('*')) DO 4 I=1,N 4 WRITE(1,300) X(I) 300 FORMAT(T30,'*',T32,E14.7,T48,'*') WRITE(1,200) GOTO 2000 1000 WRITE(1,*)' Systme singulier det A = 0' 2000 CLOSE(1,STATUS='KEEP') END
Marsh Posté le 24-03-2007 à 18:42:08
le programme que j'ai fais ne donne pas les bon resultat quelqu'un peut-il m'aider:
fichier d'entree
3
3. 2. 7.
1. 3. 2. 13.
1. 3. 11.
* Methode de factorisation L.U (sans change de lignes)
C ****************************************
REAL A(20,21),X(20),Y(20)
OPEN (1,FILE='LU.DON',ACCESS='SEQUENTIAL',STATUS='OLD')
READ(1,*) N
N1=N+1
READ(1,*) ((A(I,J),J=1,N1),I=1,N)
CLOSE(1,STATUS='KEEP')
OPEN (1,FILE='LU.DAT',ACCESS='SEQUENTIAL',STATUS='UNKNOWN')
WRITE(1,100)N
100 FORMAT(T15,'Systme linaire d''ordre ',I4)
WRITE(1,*)
WRITE(1,*) 'Matrice'
DO 150 I=1,N
150 WRITE(1,400)(A(I,J),J=1,N)
400 FORMAT(4E17.7)
WRITE(1,*)
WRITE(1,*)' Second membre '
WRITE(1,400)(A(I,N1),I=1,N)
DO 1 K=1,N-1
C
C Elimination de X(k)
C
3 PIVOT=1./A(K,K)
DO 1 I=K+1,N
S=A(I,K)
IF(S.EQ.0)GOTO 1
S=PIVOT*S
A(I,K)=S
DO 9 J=K+1,N
9 A(I,J)=A(I,J)-S*A(K,J)
1 CONTINUE
C
DO 550 I=1,N
550 WRITE(1,400)(A(I,J),J=1,N)
C Matrices L et U de la factorisation
WRITE(1,*)
WRITE(1,*) 'Matrices L et U'
DO 151 I=1,N
DO 152 J=1,N
Y(J)=0
152 X(J)=0
X(I)=1.
IF(I.EQ.1)GOTO 157
DO 153 J=1,I-1
153 X(J)=A(I,J)
157 DO 154 J=I,N
154 Y(J)=A(I,J)
151 WRITE(1,500)(X(J),Y(J),J=1,N)
500 FORMAT(1X,6E13.6)
WRITE(1,*)
C
C Rsolution du systme triangulaire L.Y=B
C
IF(A(N,N).EQ.0)GOTO 1000
c WRITE(1,*)
c WRITE(1,*)'Solution'
Y(1)=A(1,N1)
DO 155 I=2,N
S=A(I,N1)
DO 156 J=1,I-1
156 S=S-A(I,J)*Y(J)
155 Y(I)=S
C
C Rsolution du systme U.X=Y
X(N)=A(N,N1)/A(N,N)
DO 7 K=N-1,1,-1
S=A(K,N1)
DO 8 J=K+1,N
8 S=S-A(K,J)*X(J)
7 X(K)=S/A(K,K)
WRITE(1,200)
200 FORMAT(T30,19('*'))
DO 4 I=1,N
4 WRITE(1,300) X(I)
300 FORMAT(T30,'*',T32,E14.7,T48,'*')
WRITE(1,200)
GOTO 2000
1000 WRITE(1,*)' Systme singulier det A = 0'
2000 CLOSE(1,STATUS='KEEP')
END