Subscribe For Free Updates!

We'll not spam mate! We promise.

Coding Java Metode Gaus Jordan

package program;
import java.text.DecimalFormat;
public class metodeGauss {
    public static void main(String[] args) {
     DecimalFormat set = new DecimalFormat("0.00");
        double penyebut = 0;
System.out.println("Bentuk Persamaan");
System.out.println("----------------");
 double [ ] [ ]  mat1 = {
    {5,  3,  -45,  8,  5 },
    {4,  45,  -3,  5,  51},
    {1,  3,  -2,  10,  20},
    {5, -45,  48, 5,  26}
};
    for ( int i = 0 ; i < mat1.length ; i + + ) {
        penyebut = mat1  [ i ] [ i ] ;
            for ( int j = 0 ;  j < = mat1.length ; j + + ) {
                System.out.print ( set.format ( mat1 [ i ] [ j ] ) + " \ t " )  ;
        }
    System.out.print(" ");
    System.out.println("penyebut : "+set.format(penyebut ) ) ;
    }
        System.out.println("");
        System.out.println("==================================================================================");
        System.out.println("");
        System.out.println("Hasil eliminasi tahap awal");
        System.out.println("--------------------------");

        double [ ] [ ]  mat2 = new double  [ 4 ] [ 5 ] ;
mat2 [ 0 ] [ 0 ] = mat1 [ 0 ] [ 0 ] ;  mat2 [ 0 ] [ 1 ] = mat1 [ 0 ] [ 1 ] ;  mat2 [ 0 ] [ 2 ] = mat1 [ 0 ] [ 2 ] ;  mat2 [ 0 ] [ 3 ] = mat1 [ 0 ] [ 3 ] ;  mat2 [ 0 ] [ 4 ] = mat1 [ 0 ] [ 4 ] ;

mat2 [ 1 ] [ 0 ] = mat1 [ 1 ] [ 0 ] - ( mat1 [ 1 ] [ 0 ] / mat1 [ 0 ] [ 0 ] ) * mat1 [ 0 ] [ 0 ] ; mat2 [ 1 ] [ 1 ] = mat1 [ 1 ] [ 1 ] - ( mat1 [ 1 ] [ 0 ] / mat1 [ 0 ] [ 0 ] ) * mat1 [ 0 ] [ 1 ] ; mat2  [ 1 ] [ 2 ] = mat1 [ 1 ] [ 2 ] - ( mat1 [ 1 ] [ 0 ] / mat1 [ 0 ] [ 0 ] ) * mat1 [ 0 ] [ 2 ] ;
mat2 [ 1 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3 ] - ( mat1 [ 3 ] [ 0 ] / mat1 [ 0 ] [ 0 ] ) * mat1 [ 0 ] [ 3 ] ;   mat2 [ 3 ] [ 4 ] = mat1 [ 3 ] [ 4 ] - ( mat1 [ 3 ] [ 0 ] / mat1 [ 0 ] [ 0 ] ) * mat1 [ 0 ] [ 4 ] ;

 for ( int i = 0 ; i < mat2.length ; i + + ) {
        penyebut = mat2  [ i ] [ i ] ;
            for ( int j = 0 ;   j < = mat2.length ; j + + ){
                System.out.print (set.format (mat2 [ i ] [ j ] ) + " \ t " );
        }
    System.out.print(" ");
    System.out.println("penyebut : "+set.format (penyebut) );
    }
        System.out.println("");
        System.out.println("==================================================================================");
        System.out.println("");
        System.out.println("Hasil eliminasi tahap kedua");
        System.out.println("---------------------------");

         double [ ] [ ]   mat3 = new double [ 4 ] [ 5 ] ;
mat3 [ 0 ] [ 0 ] =  mat2 [ 0 ] [ 0 ] ; mat3 [ 0 ] [ 1 ] = mat2 [ 0 ] [ 1 ] ; mat3 [ 0 ] [ 2 ] = mat2 [ 0 ] [ 2 ] ;  mat3 [ 0 ] [ 3 ] = m at2 [ 0 ] [ 3 ] ;  mat3 [ 0 ] [ 4 ] = m a t 2 [ 0 ] [ 4 ] ;

m a t 3   [ 1 ] [ 0 ] = m a t 2 [ 1 ] [ 0 ] ;   m a t3   [ 1 ] [ 1 ] = m a t 2 [ 1 ] [ 1 ] ;   m a t 3   [ 1 ] [ 2 ] = m a t 2 [ 1 ] [ 2 ] ;   m a t 3   [ 1 ] [ 3 ] = m a t 2 [ 1 ] [ 3 ] ;   m a t 3 [ 1 ] [ 4 ] = m a t 2 [ 1 ] [ 4 ] ;

m a t 3   [ 2 ] [ 0 ] = m a t 2   [ 2 ] [ 0 ] ;   m a t 3   [ 2 ] [ 1 ] = m a t 2 [ 2 ] [1 ] - ( ma t 2 [ 2 ] [ 1 ] / m a t 2 [ 1 ] [ 1 ] ) * m a t 2 [ 1 ] [ 1 ] ;   m a t 3   [ 2 ] [ 2 ] = m a t 2 [ 2 ] [ 2 ] - ( m a t 2 [ 2 ] [ 1 ] / m a t 2 [ 1 ] [ 1 ] ) * m a t 2 [ 1 ] [ 2 ]  ;
 m a t 3   [ 2 ] [ 3 ] = m a t 2 [ 2 ] [ 3 ] - ( m a t 2 [ 2 ] [ 1 ] / m a t 2 [ 1 ] [ 1 ] ) * m a t 2 [ 1 ] [ 3 ] ;   m a t 3   [ 2 ] [ 4 ] = m a t 2 [ 2 ] [ 4 ] - ( m a t 2 [ 2 ] [ 1 ] / m a t 2  [ 1 ] [  1 ] ) * m a t 2 [ 1 ] [ 4 ] ;

 mat3 [ 3 ] [ 0 ] = mat2 [ 2 ] [ 0 ] ; mat3 [ 3 ] [ 1 ] = mat2 [ 3 ] [ 1 ] - ( mat2 [ 3 ] [ 1 ] / mat2 [ 1 ] [ 1 ]  ) * mat2 [ 1 ] [ 1 ] ; mat3 [ 3 ][ 2 ] = mat2 [ 3 ] [ 2 ] - ( mat2 [ 3 ] [ 1 ] / mat2 [ 1 ] [ 1 ] ) * mat2 [ 1 ] [ 2 ] ;
mat3 [ 3 ][ 3 ] = mat2 [ 3 ] [ 3 ] - ( mat2 [ 3 ] [ 1 ] / mat2 [ 1 ] [ 1 ] ) * mat2 [ 1 ] [ 3 ] ; mat3  [ 3 ] [ 4 ] = mat2 [ 3 ] [ 4 ] - ( mat2 [ 3 ] [ 1 ] / mat2 [ 1 ] [ 1 ] )  * mat2 [ 1 ] [ 4 ] ;

 for ( int i = 0 ; i < mat3.length ; i + + ) {
        penyebut = mat3  [ i ] [ i ] ;
            for ( int j = 0 ; j < = mat3.length ; j + + ) {
                System.out.print ( set.format ( mat3 [ i ] [ j ] ) + " \ t " ) ;
         }
    System.out.print(" ");
    System.out.println (" penyebut : " + set.format ( penyebut ) );
    }
        System.out.println("");
        System.out.println("==================================================================================");
        System.out.println("");
        System.out.println("Hasil eliminasi tahap ketiga");
        System.out.println("----------------------------");

          double [ ] [ ] mat4 = new double [ 4 ] [ 5 ]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; j + + ) {
                System.out.print(set.format(mat4 [ i ] [ j ] ) + " \t " ) ;
        }
    System.out.print(" ");
    System.out.println("penyebut : "+ set.format (penyebut) ) ;
    }
        System.out.println("");
        System.out.println("==================================================================================");
        System.out.println("");

        System.out.println("5x1 + 3x2 - 45x3 + 8x4 = 5");
        System.out.println(" 42,6x2 + 33x3 - 1,4x4 = 47");
        System.out.println("       5,14x3 + 8,48x4 = 16,35");
        System.out.println("            - 219,29x4 = -340,13");
        System.out.println("");
        System.out.println("Maka nilai x1, x2, x3, dan x4 adalah :");
        System.out.println("");
        System.out.println("x1 = 3,712872844 ");
        System.out.println("x2 = 0,672427929 ");
        System.out.println("x3 = 0,62200127 ");
        System.out.println("x4 = 1,55105112 ");
}
 }

Socializer Widget By Blogger Yard
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 komentar:

Post a Comment