
ProsedurMetodeBagi-Dua :
Misal dijamin bahwa f(x) adalah fungsi kontinyu pada
interval [a, b] dan f(a) f(b) < 0. Ini artinya bahwa f(x) paling
tidak harus memiliki akar pada
interval [a, b]. Kemudian definisikan titik tengah pada
interval [a, b] yaitu c :=
Contoh :
Carilah akar dari x3 + 4x2
– 10 = 0 pada interval [1, 2].
Penyelesaian :
Dalam penyelesaian ini saya akan menggunakan sampai iterasi
ke-10 dan menggunakan 5 angka dibelakang koma.
f(x) = x3 + 4x2
– 10
f(1) = (1)3 + 4(1)2
– 10 = -5
f(2) = (2)3 + 4(2)2
– 10 = 14
f(1.5) = (1.5)3 + 4(1.5)2
– 10 = 2.375
f(1.25) = (1.25)3 +
4(1.25)2 – 10 = -1.79687
f(1.375) = (1.375)3 +
4(1.375)2 – 10 = 0.16210
f(1.3125) = (1.3125)3 +
4(1.3125)2 – 10 = -0.84838
f(1.34375) = (1.34375)3 +
4(1.34375)2 – 10 = -0.35098
f(1.35938) = (1.35938)3 +
4(1.35938)2 – 10 = -0.09632
f(1.36719) = (1.36719)3 +
4(1.36719)2 – 10 = 0.03239
f(1.36329) = (1.36329)3 +
4(1.36329)2 – 10 = -0.03200
f(1.36524) = (1.36524)3 +
4(1.36524)2 – 10 = 0.000016
f(1.36426) = (1.36426)3 +
4(1.36426)2 – 10 = -0.01601
f(1.36329) = (1.36329)3 +
4(1.36329)2 – 10 = -0.00784
n
|
a
|
B
|
c = (a + b)/2
|
f(a)
|
f(b)
|
f(c)
|
f(a)f(c)
|
f(b)f(c)
|
1
2
3
4
5
6
7
8
9
10
|
1
1
1.25
1.25
1.3125
1.34375
1.35938
1.35938
1.36329
1.36329
|
2
1.5
1.5
1.375
1.375
1.375
1.375
1.36719
1.36719
1.36524
|
1.5
1.25
1.375
1.3125
1.34375
1.35938
1.36719
1.36329
1.36524
1.36426
|
-
-
-
-
-
-
-
-
-
-
|
+
+
+
+
+
+
+
+
+
+
|
+
-
+
-
-
-
+
-
+
-
|
-
+
-
+
+
+
-
+
-
+
|
+
-
+
-
-
-
+
-
+
-
|
Jadi akar yang diperoleh dari f(x) = x3
+ 4x2 – 10 menggunakan 10 iterasi adalah 1.36426
Pseducode
Program Metode Bisection
unit Unit1;
interface
uses
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Memo1: TMemo;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender:
TObject);
procedure Button2Click(Sender:
TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x1,x2,x3,y1,y2,y3:real;
i:integer;
pas:char;
implementation
{$R *.dfm}
//function x()
procedure
TForm1.Button1Click(Sender: TObject);
begin
x1:=StrToFloat(Edit1.Text);
y1:=x1*x1*x1+4*x1*x1-10;
Edit5.Text:=FloatToStr(y1);
x2:=StrToFloat(Edit2.Text);
y2:=x2*x2*x2+4*x2*x2-10;
Edit6.Text:=FloatToStr(y2);
Edit7.Text:=FloatToStr(y1*y2);
if (y1*y2)<0 then
Button2.Enabled:=true
else
Button2.Enabled:=false;
end;
procedure
TForm1.Button2Click(Sender: TObject);
begin
Memo1.Clear;
Memo1.Lines.Add('Iterasi |
x | f(x) |
error');
i:=2;
repeat
i:=i+1;
x3:=(x1+x2)/2;
y3:=x3*x3*x3+4*x3*x3-10;
if (y1*y3)<0 then
x2:=x3
else
x1:=x3;
if i<10 then
Memo1.Lines.Add(' '+IntToStr(i)+' |
'+FormatFloat('#,########0.00000000',x3)+'
| '+FormatFloat('#,########0.00000000',y3)+' |
'+FormatFloat('#,########0.00000000',abs(y3)))
else
Memo1.Lines.Add(IntToStr(i)+' |
'+FormatFloat('#,########0.00000000',x3)+'
| '+FormatFloat('#,########0.00000000',y3)+' | '+FormatFloat('#,########0.00000000',abs(y3)));
until abs(y3)<1E-07;
Edit3.Text:=FloatToStr(x3);
end;
end.
bro kalo download gimana kog bisa ke code.google.com?? hehehe :P
ReplyDeletehahahahahahah
ReplyDeletey masuk code.google.com dlu.
kemudian log in. ada disk 4 Gg yg bs kita gunakan disitu
Lihat di artikel di blogku ada cara upload di code google.com