Skip to content Skip to sidebar Skip to footer

Algoritma dan Pemrograman Penentuan Akar Menggunakan Metode False Position

Metode false position adalah pengembangan dari metode bisection yang telah saya jelaskan sebelumnya. Berikut ini adalah algoritma metode false position yang saya gambarkan dalam bentuk flowchart

Kemudian, untuk mengimplementasikan flowchart diatas, maka saya buat pemrogramannya pada java seperti ini, 



/**
 *
 * @author CHARIS
 */
public class FP {

    private double Es = 2;
    double Ea = 0.0;
    private double xl = -1;
    private double xu, xu2 = 0;
    private double x;
    private double xr, xr1, xr2;
    int iterasi = 0;
    
    public double XL(double a) {
        xl = a;
        return xl;
    }
    public double XU(double b) {
        xu = b;
        return xu;
    }
    public double fungsiX(double X) {
        x = X * Math.exp(-X) + 1;
        return x;
    }
    public double XR(double Xu, double Xl) {
        xr = Xu - (fungsiX(Xu) * (Xl - Xu) / (fungsiX(Xl) - (fungsiX(Xu))));
        return xr;
    }

    public void jalankan() {
        do {
            if (iterasi == 0) {
                System.out.println("Iterasi   : " + iterasi + " ");
//                System.out.print("xl          : " + xl + " ");
                System.out.print("xu   : " + xu + " ");
                System.out.print("fungsi(xl)  : " + fungsiX(xl) + " ");
//                System.out.print("fungsi(xu)  : " + fungsiX(xu) + " ");
                System.out.println("xr  : " + XR(XU(xu), XL(xl)) + " ");
//                System.out.print("fungsi(xr)  : " + fungsiX(XR(XU(xu), XL(xl))) + " ");
            } else if (iterasi > 0) {
                xu2 = xr;
                xr1 = xu - (fungsiX(xu) * (xl - xu) / (fungsiX(xl) - fungsiX(xu)));
                xr2 = xu2 - (fungsiX(xu2) * (xl - xu2) / (fungsiX(xl) - fungsiX(xu2)));
                System.out.println("Iterasi   : " + iterasi);
//                System.out.print("xl          : " + xl + " ");
                System.out.print("xu   : " + xu2 + " ");
                System.out.print("fungsi(xl)  : " + fungsiX(xl) + " ");
//                System.out.print("fungsi(xu)  : " + fungsiX(xu2) + " ");
                System.out.print("xr   : " + XR(XU(xu2), XL(xl)) + " ");
//                System.out.print("fungsi(xr)  : " + fungsiX(XR(XU(xu2), XL(xl))) + " ");

                Ea = Math.abs((xr2 - xr1) / xr2) * 100;
                System.out.println("|Ea|   : " + Ea);

                if (Ea < Es) {
                    System.out.println("Berhenti");
                    double akar = xr2;
                    System.out.println("Akar : " + akar);
                    break;
                }
            }
            iterasi++;
        } while (true);
    }

    public static void main(String[] args) {
        FP P = new FP();
        P.jalankan();
    }
}


Hasil dari pemrograman diatas adalah :


Post a Comment for "Algoritma dan Pemrograman Penentuan Akar Menggunakan Metode False Position"