Algoritma dan Pemrograman: Implementasi Metode Invers Gauss Jordan
Table of Contents
Dan ini penerapannya dalam pemrograman java
/** * * @author ABD. CHARIS FAUZAN */ public class InversGaussJordan { double A[][] = { {1, 1 , 1}, {1, 2, -1}, {2, 1, 2} }; double B[][] = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }; boolean lanjutkan = true; int n = B.length; double X[] = new double[n]; double m = 0; double jumB = 0; private InversGaussJordan() { System.out.println(""); System.out.println("Matriks awal :"); printMatriks(); for (int i = 0; i < B.length; i++) { if (A.length != A[i].length) { lanjutkan = false; } } if (!lanjutkan) { return; } for (int row = 0; row < n; row++) { double tampung = A[row][row]; for (int col = 0; col < n; col++) { A[row][col] /= tampung; B[row][col] /= tampung; } for (int i = 0; i < n; i++) { if (i != row) { m = A[i][row]; for (int col = 0; col < n; col++) { A[i][col] -= m * A[row][col]; B[i][col] -= m * B[row][col]; } } } } System.out.println("Hasil Invers: "); printMatriks(); } public static void main(String[] args) { new InversGaussJordan(); } private void printMatriks() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.print(A[i][j] + "\t"); } System.out.print("|\t"); for (int j = 0; j < n; j++) { System.out.print(B[i][j] + "\t"); } System.out.println(""); } } }
Tampilan ketika program dijalankan :
Post a Comment