Program Polinomial Java

Nah saat ini saya akan mencoba membuat program regresi polinomial yang sebenarnya program ini saya buat untuk menyelesaikan tugas kuliah Metode Numerik..
langsung ajah ke source code.a....

public class polinomial {
    public static void main (String[]args){
        Scanner in = new Scanner(System.in);
        double x[] = new double[20];
        double y[] = new double[20];
        double x_y[] = new double[20];
        double x_x_y[] = new double [20];
        double x_x[] = new double [20];
        double x_x_x[] = new double [20];
        double x_x_x_x[] = new double [20];
        double x_total=0;
        double y_total=0;
        double xy_total=0;
        double xxy_total=0;
        double xx_total=0;
        double xxx_total=0;
        double xxxx_total=0;
        int n;


        //banyak x dan y; x=y
        System.out.print("Masukkan Nilai x dan y = ");
        n=in.nextInt();



        //input x
        for(int i=1;i<=n;i++){
            System.out.print("x-"+i+" = ");
            x[i]=in.nextDouble();
            x_total=x_total+x[i];
        }


        //input y
        for(int j=1;j<=n;j++){
            System.out.print("y-"+j+" = ");
            y[j]=in.nextDouble();
            y_total=y_total+y[j];
        }


        //proses perhitungan Sigma 
        for(int k=1;k<=n;k++){
            x_y[k]=x[k]*y[k];
            x_x_y[k]=x[k]*x[k]*y[k];
            x_x[k]=x[k]*x[k];
            x_x_x[k]=x[k]*x[k]*x[k];
            x_x_x_x[k]=x[k]*x[k]*x[k]*x[k];
            
            xy_total=xy_total+x_y[k];
            xxy_total=xxy_total+x_x_y[k];
            xx_total=xx_total+x_x[k];
            xxx_total=xxx_total+x_x_x[k];
            xxxx_total=xxxx_total+x_x_x_x[k];
        }


        System.out.println("------Hasil Perhitungan Rumus Sigma-------");
        System.out.println("n \t= "+n);
        System.out.println("Zx \t= "+x_total);
        System.out.println("Zy \t= "+y_total);
        System.out.println("Zx^2 \t= "+xx_total);
        System.out.println("Zx^3 \t= "+xxx_total);
        System.out.println("Zx^4 \t= "+xxxx_total);
        System.out.println("Zxy \t= "+xy_total);
        System.out.println("Zx^2y \t= "+xxy_total);


        //hitung determinan
        double det = ((n*xx_total*xxxx_total)+(x_total*xxx_total*xx_total)+(xx_total*x_total*xxx_total))-
                     ((x_total*x_total*xxxx_total)+(n*xxx_total*xxx_total)+(xx_total*xx_total*xx_total));
        System.out.println("Hasil Determinan \t= "+det);
        double detA1 = ((y_total*xx_total*xxxx_total)+(x_total*xxx_total*xxy_total)+(xx_total*xy_total*xxx_total))-
                       ((x_total*xy_total*xxxx_total)+(y_total*xxx_total*xxx_total)+(xx_total*xx_total*xxy_total));
        System.out.println("Hasil Determinan A1 \t= "+detA1);
        double detA2 = ((n*xy_total*xxxx_total)+(y_total*xxx_total*xx_total)+(xx_total*x_total*xxy_total))-
                       ((y_total*x_total*xxxx_total)+(n*xxx_total*xxy_total)+(xx_total*xy_total*xx_total));
        System.out.println("Hasil Determinan A2 \t= "+detA2);
        double detA3 = ((n*xx_total*xxy_total)+(x_total*xy_total*xx_total)+(y_total*x_total*xxx_total))-
                       ((x_total*x_total*xxy_total)+(n*xy_total*xxx_total)+(y_total*xx_total*xx_total));
        System.out.println("Hasil Determinan A3 \t= "+detA3);


        //pencarian Fungsi Rumus Polinomial
        double A0 = detA1 / det;
        System.out.println("A0 \t= "+A0);
        double A1 = detA2 / det;
        System.out.println("A1 \t= "+A1);
        double A2 = detA3 / det;
        System.out.println("A2 \t= "+A2);
        System.out.println("Rumus Fungsi Polinomial = "+A0+" + "+A1+"x + "+A2+"x^2");


        //menghitung fungsi polinomial dalam range x data dummy
        System.out.print("masukkan jumlah x = ");
        int m = in.nextInt();
        double x2[] = new double[20];
        double y_hasil;
        for(int a=1;a<=m;a++){
            System.out.print("x-"+a+" = ");
            x2[a]=in.nextDouble();
        }


// hasil dimasukkan ke dalam tabel       System.out.println("====================================================");
        System.out.println("| x\t |\t y \t|");
        System.out.println("====================================================");
        for(int b=1;b<=m;b++){
            y_hasil = A0+(A1*x2[b])+A2*x2[b]*x2[b];
            System.out.println("|" + x2[b] + "\t|\t"+y_hasil+"\t|");
        }
        System.out.println("====================================================");
    }
}


nah untuk hasil running program.a, display.a seperti berikut ini : 


selamat mencoba, semoga sukses dan semoga bermanfaat...
^_^

2 komentar:

Blog27999 mengatakan...

If you're attempting to lose pounds then you absolutely have to jump on this totally brand new personalized keto meal plan.

To create this service, certified nutritionists, fitness couches, and top chefs have joined together to provide keto meal plans that are effective, painless, cost-efficient, and delicious.

Since their grand opening in January 2019, hundreds of individuals have already transformed their body and well-being with the benefits a certified keto meal plan can offer.

Speaking of benefits: clicking this link, you'll discover 8 scientifically-confirmed ones offered by the keto meal plan.

Blogger mengatakan...

If you're trying hard to lose fat then you absolutely have to start using this brand new custom keto meal plan diet.

To create this keto diet service, certified nutritionists, personal trainers, and professional chefs united to provide keto meal plans that are productive, decent, economically-efficient, and delicious.

Since their first launch in early 2019, 1000's of individuals have already completely transformed their figure and health with the benefits a certified keto meal plan diet can provide.

Speaking of benefits; in this link, you'll discover 8 scientifically-tested ones given by the keto meal plan diet.

Posting Komentar