Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tabulasi;
- import java.util.Scanner;
- import java.math.*;
- /**
- *
- * @author surya
- */
- public class Tabulasi {
- private static float x1,x2,x,xa,xb,h,y,y1,y2,ya,yb;
- private static int i,j,k;
- private static String tampung,x1k,x2k;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner datain = new Scanner (System.in);
- do{
- System.out.print("Masukkan batas atas = ");
- x1 = datain.nextInt();
- y1 = x1*x1*x1-7*x1+1;
- System.out.print("Masukkan batas bawah = ");
- x2 = datain.nextInt();
- y2 = x2*x2*x2-7*x2+1;
- }while ((y1*y2)>=0);
- k=0;
- do {
- k= k+1;
- if(x1>x2){
- xa=x1;
- xb=x2;
- }else{
- xa=x2;
- xb=x1;
- }
- h=(xa-xb)/10;
- i=0;
- do{
- i=i+1;
- x=xb+h*i;
- ya=x*x*x+7*x-1;
- yb=(x-h)*(x-h)*(x-h)-7*(x-h)+1;
- }while ((ya*yb)>0);
- x1=x;
- x2=x-h;
- tampung="Tabulasi ke-"+k+"\n";
- tampung+="----------------------------------------"+"\n";
- tampung+="n x f(x) error "+"\n";
- tampung+="----------------------------------------"+"\n";
- while (j<=9){
- x = xb + h * (j - 1);
- y = x * x * x - 7 * x + 1;
- tampung+=""+j+" :: "+x+" :: "+y+" :: "+Math.abs(y)+" :: "+"\n";
- j++;
- }
- j=10;
- while(j<=11){
- x = xb + h * (j - 1);
- y = x * x * x - 7 * x + 1;
- tampung+=""+j+" :: "+x+" :: "+y+" :: "+Math.abs(y)+" :: "+"\n";
- j++;
- }
- tampung+="-------------------------------------------";
- } while (Math.abs((y))<10e-8);
- tampung+="Akar pendekatan = "+x+"\n";
- tampung+="Error = "+Math.abs(y)+"\n";
- System.out.print(tampung);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement