Advertisement
pendekar_langit

tabulasi

Nov 26th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.53 KB | None | 0 0
  1. program HelloWorld;
  2. label ulang;
  3. var x,x1,x2,xa,xb,xc,y,y1,y2,ya,yb:real;
  4.     i,j,k:integer;
  5.     ab:char;
  6. begin
  7.      ulang:
  8.      writeln('Tentukan akar penyelesaian dengan metode tabulasi dari f(x)=x^3-7x+1');
  9.      writeln;
  10.      write('Masukkan nilai x1 = ');
  11.      readln(x1);
  12.      y1 := x1 * x1 * x1 - 7 * x1 + 1;
  13.      writeln('  f(',x1:0:2,') = ',y1:0:4);
  14.      repeat
  15.      begin
  16.           write('Masukkan nilai x2 = ');
  17.           readln(x2);
  18.           y2 := x2 * x2 * x2 - 7 * x2 + 1;
  19.           writeln('  f(',x2:0:2,') = ',y2:0:4);
  20.           writeln;
  21.           writeln('Syarat (x1 * x2) < 0');
  22.           write('x1 * x2 = ',y1 * y2:0:5);
  23.           if (y1 * y2) < 0 then write('Nilai OK')
  24.           else write('Nilai tidak sesuai');
  25.           readln;
  26.      end;
  27.      until (y1 * y2) < 0;
  28.      k := 0;
  29.      repeat
  30.      begin
  31.           k := k + 1;
  32.           if x1 > x2 then
  33.           begin
  34.                xa := x1;
  35.                xb := x2;
  36.           end
  37.           else
  38.           begin
  39.                xa := x2;
  40.                xb := x1;
  41.           end;
  42.           xc := (xa - xb) / 10;
  43.           i := 0;
  44.           repeat
  45.           begin
  46.                i := i + 1;
  47.                x := xb + xc * i;
  48.                ya := x * x * x - 7 * x + 1;
  49.                yb := (x - xc) * (x - xc) * (x - xc) - 7 * (x - xc) + 1;
  50.           end;
  51.           until (ya * yb) < 0;
  52.           x1 := x;
  53.           x2 := x - xc;
  54.           writeln('Tabulasi ke-',k);
  55.           writeln('--------------------------------------------------------');
  56.           writeln('n             x               f(x)           error      ');
  57.           writeln('--------------------------------------------------------');
  58.           for j := 1 to 9 do
  59.           begin
  60.                x := xb + xc * (j - 1);
  61.                y := x * x * x - 7 * x + 1;
  62.                writeln('',j,' ::',x,' ::',y,' ::',abs(y),' ::');
  63.           end;
  64.           for j := 10 to 11 do
  65.           begin
  66.                x := xb + xc * (j - 1);
  67.                y := x * x * x - 7 * x + 1;
  68.                writeln('',j,' ::',x,' ::',y,' ::',abs(y),' ::');
  69.           end;
  70.           writeln('--------------------------------------------------------');
  71.      end;
  72.      readln;
  73.      until abs(y) < 10e - 8;
  74.      writeln('Akar pendekatannya adalah x = ',x);
  75.      writeln('Error = ',abs(y));
  76.      writeln;
  77.      write('Apakah anda ingin mengulangi? (Y/T) : ');
  78.      readln(ab);
  79.      if (ab = 'y') or (ab = 'Y') then
  80.      begin
  81.           goto ulang;
  82.      end
  83. else
  84.  
  85. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement