HOW TO CONVERT FORTRAN CODE TO MATLAB?

4 views (last 30 days)
Ahmad Fakih
Ahmad Fakih on 10 Oct 2022
Answered: KSSV on 10 Oct 2022
PROGRAM LU_DECOMPOSITION
DIMENSION A(10,11), B(10), Y(10), X(10)
REAL MJI
WRITE(*,*)
WRITE(*,*) '==> FAKTORISASI MATRIK: LU DECOMPOSITION <=='
WRITE(*,*)
/*LANGKAH 1: MEMASUKKAN NILAI ELEMEN-ELEMEN MATRIK A DAN VEKTOR B
WRITE (*,'(1X,A)') 'JUMLAH PERSAMAAN ?'
READ (*,*) N
WRITE(*,*)
WRITE(*,*)'MASUKKAN ELEMEN-ELEMEN MATRIKS A'
DO 50 I = 1,N
DO 60 J = 1,N
WRITE (*,'(1X,A,I2,A,I2,A)') 'A(',I,',',J,') = '
READ (*,*) A(I,J)
60 CONTINUE
WRITE (*,'(1X,A,I2,A)') 'B(',I,') ? '
READ (*,*) B(I)
WRITE (*,*)
50 CONTINUE
WRITE (*,*)
/*MENAMPILKAN MATRIKS A
WRITE (*,'(1X,A)') 'MATRIKS A:'
DO 110 I = 1,N
WRITE (*,6) (A(I,J),J=1,N)
110 CONTINUE
WRITE (*,*)
/*LANGKAH 2: MEMERIKSA ELEMEN-ELEMEN PIVOT
NN = N-1
DO 10 I=1, NN
/*LANGKAH 3: MENDEFINISIKAN P
P = INTEGER (I)
100 IF (((ABS(A(P,I))).GE.1.0E-20) .OR. (P.GT.N)) GOTO 200
P = P+1
GOTO 100
200 IF(P.EQ.N+1)THEN
/*MENAMPILKAN PESAN TIDAK DAPAT DIFAKTORKAN
WRITE(*,8)
GOTO 400
END IF
/*LANGKAH 4: PROSES TUKAR POSISI
IF(P.NE.I) THEN
DO 20 JJ=1,N
C = A(I,JJ)
A(I,JJ) = A(P,JJ)
A(P,JJ) = C
20 CONTINUE
END IF
/*LANGKAH 5: PERSIAPAN PROSES TRIANGULARISASI
JJ = I+1
DO 30 J=JJ,N
/*LANGKAH 6: TENTUKAN MJI
MJI = A(J,I)/A(I,I)
/*LANGKAH 7: PROSES TRIANGULARISASI
DO 40 K=JJ,N
A(J,K) = A(J,K)-MJI*A(I,K)
40 CONTINUE
/*LANGKAH 8: MENYIMPAN MJI KE A(J,I)
A(J,I) = MJI
30 CONTINUE
10 CONTINUE
/*MENAMPILKAN MATRIKS LU
WRITE (*,'(1X,A)') 'MATRIKS LU:'
DO 120 I = 1,N
WRITE (*,6) (A(I,J),J=1,N)
120 CONTINUE
WRITE (*,*)
/*LANGKAH 9: SUBSTITUSI-MAJU
Y(1) = B(1)
DO 15 I=2,N
SUM = 0.0
DO 16 J=1,I-1
SUM = SUM+A(I,J)*Y(J)
16 CONTINUE
Y(I) = B(I)-SUM
15 CONTINUE
/*MENAMPILKAN VEKTOR Y
WRITE (*,'(1X,A)') 'VEKTOR Y:'
DO 138 I =1,N
WRITE (*,6) Y(I)
138 CONTINUE
WRITE (*,*)
/*LANGKAH 10: SUBSTITUSI-MUNDUR
X(N) = Y(N)/A(N,N)
DO 24 K=1, N-1
I = N-K
JJ = I+1
SUM = 0.0
DO 26 KK=JJ,N
SUM = SUM+A(I,KK)*X(KK)
26 CONTINUE
X(I) = (Y(I)-SUM)/A(I,I)
24 CONTINUE
/*LANGKAH 11: MENAMPILKAN SOLUSI DAN SELESAI
WRITE (*,'(1X,A)') 'SOLUSI:'
DO 18 I = 1,N
WRITE (*,'(1X,A,I2,A,F14.8)') 'X(',I,') = ',X(I)
18 CONTINUE
WRITE(*,*)
WRITE(*,*) 'SELESAI ---> SUKSES'
WRITE(*,*)
400 CONTINUE
6 FORMAT(1X,5(F14.8))
8 FORMAT(1X,'TIDAK DAPAT DIFAKTORKAN')
END

Accepted Answer

KSSV
KSSV on 10 Oct 2022
The code says it LU decomposition. SEarch in google and file exchange you will get many codesw riteen and submitted.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!