Algoritma dan Pemrograman Penentuan Akar Menggunakan Metode Bisection

Setelah membahas bagaimana menentukan akar menggunakan metode tabel, kini saatnya kita membahas metode yang lebih simpel dan efisien bernama metode bisection


berikut ini adalah source code dari metode bisection yang saya tulis menggunakan pemrograman java :

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

    double xl = -1, xl2 = 0;
    double xu, xu2 = 0;
    double fungsiX;
    double Es = 2;
    double Ea = 100;
    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) {
        fungsiX = x * Math.exp(-x) + 1;
        return fungsiX;
    }

    public double XR(double xl, double xu) {
        xr = (xl + xu) / 2;
        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("xr : " + XR(xl, xu) + " ");
                System.out.print("fungsiXL : " + fungsiX(xl) + " ");
                System.out.println("fungsiXR : " + fungsiX(XR(xl, xu)) + " ");
            }
            if (iterasi > 0) {
                if (fungsiX(xl) * fungsiX(XR(xl, xu)) < 0) {
                    xu2 = XR(xl, xu);
                    System.out.println("Iterasi : " + iterasi + " ");
                    System.out.print("xl : " + xl + " ");
                    System.out.print("xu : " + xu2 + " ");
                    System.out.print("xr : " + XR(xl, xu2) + " ");
                    System.out.print("fungsiXL : " + fungsiX(xl) + " ");
                    System.out.print("fungsiXR : " + fungsiX(XR(xl, xu2)) + " ");
                    xr1 = (xl + xu) / 2;
                    xr2 = (xl + xu2) / 2;
                    xu = xu2;
                    Ea = Math.abs((xr2 - xr1) / xr2) * 100;
                    System.out.println("Ea : " + Ea);
                } else if (!(fungsiX(xl) * fungsiX(XR(xl, xu)) < 0)) {
                    xl2 = XR(xl, xu);
                    System.out.println("Iterasi : " + iterasi + " ");
                    System.out.print("xl : " + xl2 + " ");
                    System.out.print("xu : " + xu + " ");
                    System.out.print("xr : " + XR(xl2, xu) + " ");
                    System.out.print("fungsiXL : " + fungsiX(xl2) + " ");
                    System.out.print("fungsiXR : " + fungsiX(XR(xl2, xu)) + " ");
                    xr1 = (xl + xu) / 2;
                    xr2 = (xl2 + xu2) / 2;
                    xl = xl2;
                    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) {
        Bisection Bi = new Bisection();
        Bi.jalankan();
    }
}

Program diatas engahasilkan output berupa penentuan akar ketika Error Stopping (Es) telah terpenuhi


Subscribe to receive free email updates:

0 Response to "Algoritma dan Pemrograman Penentuan Akar Menggunakan Metode Bisection"

Post a Comment

Terima Kasih Telah Berkunjung, Silakan Berkomentar...
Kritik dan Saran Teman-Teman Sangat Memotivasi Saya (^_^)