package program;
import java.text.DecimalFormat;
public class gausbiasa {
double penyebut,pembilang;
int pembagi=1;
DecimalFormat des = new DecimalFormat("0.00");
double matrik[][] = {
{6,3,46,8,80},
{4,46,3,6,45},
{1,3,2,12,30},
{11,-3,20,12,33}};
double[] hasil=new double[matrik.length];//array x1,x2,...xn
//method untuk menampilkan matrik
void tampilArray(double[][] matrik){
for(int l=0;l for(int m=0;m<=matrik.length;m++){
System.out.print(des.format(matrik[l][m])+"\t");
}
System.out.println("");
}
System.out.println("");
}
void proses(){
//menampilkan matrik awal
tampilArray(matrik);
//proses perhitungan gauss
for(int i=0;i penyebut=matrik[i][i];
for(int j=(i+1);j pembilang=matrik[j][i];
for(int k=0;k<=matrik.length;k++){
matrik[j][k]=matrik[j][k]-(pembilang/penyebut*matrik[i][k]);
}
}
//menampilkan matrik tiap perubahan
tampilArray(matrik);
}
//proses penyulihan mundur
double atas;
for(int i=hasil.length-1;i>=0;i--){
atas=matrik[i][hasil.length];
for(int j=hasil.length-1;j>=0;j--){
if(j==i)
pembagi=i;
else
atas=atas-matrik[i][j]*hasil[j];
}
hasil[i]=atas/matrik[pembagi][pembagi];
System.out.println("x"+(i+1)+" : "+des.format(hasil[i]));
}
}
public static void main(String[] args) {
gausbiasa mg = new gausbiasa();
mg.proses();
}
}
versi saya biar lebih gampang brow
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 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][3]=mat1[1][3]-(mat1[1][0]/mat1[0][0])*mat1[0][3]; mat2 [1][4]=mat1[1][4]-(mat1[1][0]/mat1[0][0])*mat1[0][4];
mat2 [2][0]=mat1[2][0]-(mat1[2][0]/mat1[0][0])*mat1[0][0]; mat2 [2][1]=mat1[2][1]-(mat1[2][0]/mat1[0][0])*mat1[0][1]; mat2 [2][2]=mat1[2][2]-(mat1[2][0]/mat1[0][0])*mat1[0][2];
mat2 [2][3]=mat1[2][3]-(mat1[2][0]/mat1[0][0])*mat1[0][3]; mat2 [2][4]=mat1[2][4]-(mat1[2][0]/mat1[0][0])*mat1[0][4];
mat2 [3][0]=mat1[3][0]-(mat1[3][0]/mat1[0][0])*mat1[0][0]; mat2 [3][1]=mat1[3][1]-(mat1[3][0]/mat1[0][0])*mat1[0][1]; mat2 [3][2]=mat1[3][2]-(mat1[3][0]/mat1[0][0])*mat1[0][2];
mat2 [3][3]=mat1[3][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 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]=mat2[0][3]; mat3[0][4]=mat2[0][4];
mat3 [1][0]=mat2[1][0]; mat3 [1][1]=mat2[1][1]; mat3 [1][2]=mat2[1][2]; mat3 [1][3]=mat2[1][3]; mat3 [1][4]=mat2[1][4];
mat3 [2][0]=mat2 [2][0]; mat3 [2][1]=mat2[2][1]-(mat2[2][1]/mat2[1][1])*mat2[1][1]; mat3 [2][2]=mat2[2][2]-(mat2[2][1]/mat2[1][1])*mat2[1][2];
mat3 [2][3]=mat2[2][3]-(mat2[2][1]/mat2[1][1])*mat2[1][3]; mat3 [2][4]=mat2[2][4]-(mat2[2][1]/mat2[1][1])*mat2[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 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];
mat4 [0][0]= mat3[0][0]; mat4 [0][1]=mat3[0][1]; mat4[0][2]=mat3[0][2]; mat4[0][3]=mat3[0][3]; mat4[0][4]=mat3[0][4];
mat4 [1][0]=mat3[1][0]; mat4 [1][1]=mat3[1][1]; mat4 [1][2]=mat3[1][2]; mat4 [1][3]=mat3[1][3]; mat4 [1][4]=mat3[1][4];
mat4 [2][0]=mat3 [2][0]; mat4 [2][1]=mat3[2][1]; mat4 [2][2]=mat3[2][2]; mat4 [2][3]=mat3[2][3]; mat4 [2][4]=mat3[2][4];
mat4 [3][0]=mat3 [2][0]; mat4 [3][1]=mat3[3][1]; mat4 [3][2]=mat3[3][2]-(mat3[3][2]/mat3[2][2])*mat3[2][2];
mat4 [3][3]=mat3[3][3]-(mat3[3][2]/mat3[2][2])*mat3[2][3]; mat4 [3][4]=mat3[3][4]-(mat3[3][2]/mat3[2][2])*mat3[2][4];
for (int i=0;i penyebut =mat4 [i][i];
for (int j=0; j<=mat4.length;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 ");
}
}
import java.text.DecimalFormat;
public class gausbiasa {
double penyebut,pembilang;
int pembagi=1;
DecimalFormat des = new DecimalFormat("0.00");
double matrik[][] = {
{6,3,46,8,80},
{4,46,3,6,45},
{1,3,2,12,30},
{11,-3,20,12,33}};
double[] hasil=new double[matrik.length];//array x1,x2,...xn
//method untuk menampilkan matrik
void tampilArray(double[][] matrik){
for(int l=0;l
System.out.print(des.format(matrik[l][m])+"\t");
}
System.out.println("");
}
System.out.println("");
}
void proses(){
//menampilkan matrik awal
tampilArray(matrik);
//proses perhitungan gauss
for(int i=0;i
for(int j=(i+1);j
for(int k=0;k<=matrik.length;k++){
matrik[j][k]=matrik[j][k]-(pembilang/penyebut*matrik[i][k]);
}
}
//menampilkan matrik tiap perubahan
tampilArray(matrik);
}
//proses penyulihan mundur
double atas;
for(int i=hasil.length-1;i>=0;i--){
atas=matrik[i][hasil.length];
for(int j=hasil.length-1;j>=0;j--){
if(j==i)
pembagi=i;
else
atas=atas-matrik[i][j]*hasil[j];
}
hasil[i]=atas/matrik[pembagi][pembagi];
System.out.println("x"+(i+1)+" : "+des.format(hasil[i]));
}
}
public static void main(String[] args) {
gausbiasa mg = new gausbiasa();
mg.proses();
}
}
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
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][3]=mat1[1][3]-(mat1[1][0]/mat1[0][0])*mat1[0][3]; mat2 [1][4]=mat1[1][4]-(mat1[1][0]/mat1[0][0])*mat1[0][4];
mat2 [2][0]=mat1[2][0]-(mat1[2][0]/mat1[0][0])*mat1[0][0]; mat2 [2][1]=mat1[2][1]-(mat1[2][0]/mat1[0][0])*mat1[0][1]; mat2 [2][2]=mat1[2][2]-(mat1[2][0]/mat1[0][0])*mat1[0][2];
mat2 [2][3]=mat1[2][3]-(mat1[2][0]/mat1[0][0])*mat1[0][3]; mat2 [2][4]=mat1[2][4]-(mat1[2][0]/mat1[0][0])*mat1[0][4];
mat2 [3][0]=mat1[3][0]-(mat1[3][0]/mat1[0][0])*mat1[0][0]; mat2 [3][1]=mat1[3][1]-(mat1[3][0]/mat1[0][0])*mat1[0][1]; mat2 [3][2]=mat1[3][2]-(mat1[3][0]/mat1[0][0])*mat1[0][2];
mat2 [3][3]=mat1[3][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
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]=mat2[0][3]; mat3[0][4]=mat2[0][4];
mat3 [1][0]=mat2[1][0]; mat3 [1][1]=mat2[1][1]; mat3 [1][2]=mat2[1][2]; mat3 [1][3]=mat2[1][3]; mat3 [1][4]=mat2[1][4];
mat3 [2][0]=mat2 [2][0]; mat3 [2][1]=mat2[2][1]-(mat2[2][1]/mat2[1][1])*mat2[1][1]; mat3 [2][2]=mat2[2][2]-(mat2[2][1]/mat2[1][1])*mat2[1][2];
mat3 [2][3]=mat2[2][3]-(mat2[2][1]/mat2[1][1])*mat2[1][3]; mat3 [2][4]=mat2[2][4]-(mat2[2][1]/mat2[1][1])*mat2[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
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];
mat4 [0][0]= mat3[0][0]; mat4 [0][1]=mat3[0][1]; mat4[0][2]=mat3[0][2]; mat4[0][3]=mat3[0][3]; mat4[0][4]=mat3[0][4];
mat4 [1][0]=mat3[1][0]; mat4 [1][1]=mat3[1][1]; mat4 [1][2]=mat3[1][2]; mat4 [1][3]=mat3[1][3]; mat4 [1][4]=mat3[1][4];
mat4 [2][0]=mat3 [2][0]; mat4 [2][1]=mat3[2][1]; mat4 [2][2]=mat3[2][2]; mat4 [2][3]=mat3[2][3]; mat4 [2][4]=mat3[2][4];
mat4 [3][0]=mat3 [2][0]; mat4 [3][1]=mat3[3][1]; mat4 [3][2]=mat3[3][2]-(mat3[3][2]/mat3[2][2])*mat3[2][2];
mat4 [3][3]=mat3[3][3]-(mat3[3][2]/mat3[2][2])*mat3[2][3]; mat4 [3][4]=mat3[3][4]-(mat3[3][2]/mat3[2][2])*mat3[2][4];
for (int i=0;i
for (int j=0; j<=mat4.length;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 ");
}
}
men kok eror sih gwa pake notpad
ReplyDeletecoba yang koding yg for itu di isi.
ReplyDeletefor (int i=0;i penyebut =mat4 [i][i];
isi dengan <
jadi
for (int i=0;i < penyebut =mat4 [i][i];