- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
- */
- package pbo;
- import java.util.Scanner;
- /**
- *
- * @author ADVAN
- */
- public class Numerik3 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Mencari akar persamaan Dengan Metode Bagi dua/ Biseksi");
- System.out.print("\nMasukkan batas bawah: ");
- double xb = scanner.nextDouble();
- System.out.print("Masukkan batas atas: ");
- double xa = scanner.nextDouble();
- double fxb = Math.exp(-5 * xb * xb);
- double fxa = Math.exp(-5 * xa * xa);
- System.out.printf("\nnilai fungsi pada batas bawah f(%.4f) = %.4f%n", xb, fxb);
- System.out.printf("nilai fungsi pada batas atas f(%.4f) = %.4f%n", xa, fxa);
- System.out.print("\nMasukkan error: ");
- double e = scanner.nextDouble();
- System.out.print("Masukkan iterasi maksimum: ");
- int n = scanner.nextInt();
- if (fxb * fxa > e) {
- System.out.println("\nTidak ada akar pada selang tersebut!!!");
- System.out.print("\nMasukkan batas atas (xa) dan batas bawah (xb) baru: ");
- // Untuk sementara, saya tidak menangani ulangannya
- } else {
- System.out.println("\nPemilihan batas atas (xa) dan Batas bawah (xb) tepat");
- System.out.println("Akar diantara xa dan xb");
- }
- int kondisi = 1;
- double error = Math.abs(xa - xb);
- System.out.println("\nIterasi xb xc xa f(xb) f(xc) f(xa) error");
- for (int i = 1; kondisi != 0 && i <= n; i++) {
- double xc = (xb + xa) / 2.0;
- double fxc = Math.exp(-5 * xc * xc);
- error = Math.abs(xa - xb);
- System.out.printf("%7d %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f%n", i, xb, xc, xa, fxb, fxc, fxa, error);
- if (error < e || i >= n)
- kondisi = 0;
- else if (fxb * fxc > 0) {
- xb = xc;
- fxb = fxc;
- } else {
- xa = xc;
- fxa = fxc;
- }
- }
- if (kondisi == 0)
- System.out.printf("\nAkar ditemukan: %.4f\n", (xb + xa) / 2.0);
- }
- }
[text] a
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: