You are on page 1of 6

unit Uintegrasi;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Menus;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Ulang1: TMenuItem;
Close1: TMenuItem;
Lfungsi: TLabel;
Lorde: TLabel;
Lreferensi: TLabel;
Em: TEdit;
ComboBox1: TComboBox;
Stgreferensi: TStringGrid;
ListBox1: TListBox;
Stgpolinom: TStringGrid;
Eordepolinom: TEdit;
Lpangkat: TLabel;
Ljudul: TLabel;
Lnama: TLabel;
IntegrasiTrapesium1: TMenuItem;
IntegrasiSimpson1: TMenuItem;
unggal1: TMenuItem;
Bersegmen1: TMenuItem;
N13Tunggal1: TMenuItem;
N13Bersegmen1: TMenuItem;
N381: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure StgpolinomClick(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Ulang1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure unggal1Click(Sender: TObject);
procedure Bersegmen1Click(Sender: TObject);
procedure N13Tunggal1Click(Sender: TObject);
procedure N13Bersegmen1Click(Sender: TObject);
procedure N381Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
m,n,k: integer;
xp,a,hslintegrasi,h,jml,fxx,jml1,jml2:real;
x, fx: array [0..1000] of real;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);


begin
Eordepolinom.Enabled:=False;
Stgpolinom.Enabled:=False;
Lpangkat.Enabled:=False;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);


begin
if ComboBox1.ItemIndex=3 then
begin
Eordepolinom.Enabled:=True;
Stgpolinom.Enabled:=True;
Lpangkat.Enabled:=True;
end;
end;

procedure TForm1.StgpolinomClick(Sender: TObject);


begin
k:=StrToInt(Eordepolinom.text);
Stgpolinom.ColCount:=k +1;
end;

function Xpangkat(x:real;z:integer):real;
var i:integer;
hasil:real;
begin
hasil:=1;
if z=0 then hasil:=1 else
if z>0 then
begin
for i:=1 to z do
hasil:=hasil*x;
end else
for i:=1 to abs(z) do
hasil:=hasil*x;
if z<0 then hasil:=1/hasil;
result:=hasil;
end;

function Lix(i:integer; xp:real):real;


var j:integer;
hasil:real;
begin
hasil:=1;
for j:=0 to m do
if j<>i then hasil:=hasil*((xp-x[j])/(x[i]-x[j]));

result:=hasil;
end;

procedure BacaFungsi(var fungsi:real; xj:real);


var j:Integer;
begin
if Form1.ComboBox1.ItemIndex = 0 then
fungsi:=Ln(xj)
else
if Form1.ComboBox1.ItemIndex = 1 then
fungsi:=Exp(xj)
else
if Form1.ComboBox1.ItemIndex = 2 then
fungsi:=Ln(xj)/ln(10)
else
if Form1.ComboBox1.ItemIndex = 3 then
begin
fungsi := 0;
for j := 0 to k do
begin
a := StrToFloat(Form1.Stgpolinom.Cells[j,0]);
fungsi := fungsi + a * xPangkat(xj,k-j);
end
end
else
if Form1.ComboBox1.ItemIndex = 4 then
fungsi:=Sin(xj/180*pi)
else
if Form1.ComboBox1.ItemIndex = 5 then
fungsi:=Cos(xj/180*pi)
else
begin
ShowMessage('Fungsi belum diisikan.');
exit;
end;
end;

procedure TForm1.Ulang1Click(Sender: TObject);


var i:Integer;
begin
ComboBox1.ItemIndex:=-1;
ComboBox1.Text:='Tipe';
ListBox1.Clear;

em.Clear;
Eordepolinom.Clear;

Stgreferensi.ColCount:=2;
for i:=0 to m-1 do
Stgreferensi.Cells[i,0]:='';

Stgpolinom.ColCount:=2;
for i:=0 to k-1 do
Stgpolinom.Cells[i,0]:='';

Eordepolinom.Enabled:=False;
Stgpolinom.Enabled:=False;
Lpangkat.Enabled:=False;
Lorde.Enabled:=True;
Em.Enabled:=True;
Lreferensi.Enabled:=True;
Stgreferensi.Enabled:=True;
end;

procedure TForm1.Close1Click(Sender: TObject);


begin
Close;
end;

procedure TForm1.unggal1Click(Sender: TObject);


var i:Integer;
begin
for i:=1 to 2 do
x[i]:=strtofloat(stgreferensi.Cells[i-1,0]);

for i:=1 to 2 do
BacaFungsi(fx[i],x[i]);

Hslintegrasi:=(x[2]-X[1])*(fx[2]+fx[1])/2;

ListBox1.Items.Add(' HASIL INTEGRASI TRAPESIUM TUNGGAL');


ListBox1.Items.Add('');
ListBox1.Items.Add('==> ' + FormatFloat('#.0000',hslintegrasi));
end;

procedure TForm1.Bersegmen1Click(Sender: TObject);


var i:integer;
begin
m:=StrToInt(Em.Text);

for i:=1 to 2 do
x[i]:=strtofloat(stgreferensi.Cells[i-1,0]);

h:=(X[2]-X[1])/m;

//cari Fx[2] dan Fx[1]


for i:=1 to 2 do
BacaFungsi(fx[i],x[i]);

//cari jumlah Fx[a+i*h]


jml:=0;
for i:=1 to m-1 do
begin
BacaFungsi(Fxx,(X[1]+i*h));
jml:=jml+Fxx;
end;

Hslintegrasi:=(Fx[1] + 2*jml + fx[2])*h/2;

ListBox1.Items.Add(' HASIL INTEGRASI TRAPESIUM BERSEGMEN');


ListBox1.Items.Add('');
ListBox1.Items.Add('==> ' + FormatFloat('#.0000',hslintegrasi));

end;

procedure TForm1.N13Tunggal1Click(Sender: TObject);


var i:Integer;
begin
for i:=1 to 2 do
x[i]:=strtofloat(stgreferensi.Cells[i-1,0]);

h:=(X[2]-X[1])/2;

for i:=1 to 2 do
BacaFungsi(fx[i],x[i]);

//baca f(1/2(x[2]+X[1]))
BacaFungsi(fxx,((x[2]+X[1])/2));

Hslintegrasi:=h/3*(fx[1]+4*Fxx+fx[2]);
ListBox1.Items.Add(' HASIL INTEGRASI SIMPSON 1/3 TUNGGAL');
ListBox1.Items.Add('');
ListBox1.Items.Add('==> ' + FormatFloat('#.0000',hslintegrasi));
end;

procedure TForm1.N13Bersegmen1Click(Sender: TObject);


var i:Integer;
begin
m:=StrToInt(Em.Text);

for i:=1 to 2 do
x[i]:=strtofloat(stgreferensi.Cells[i-1,0]);

h:=(X[2]-X[1])/m;

//cari Fx[2] dan Fx[1]


for i:=1 to 2 do
BacaFungsi(fx[i],x[i]);

//cari jumlah Fx[a+i*h] ganjil dan genap


jml1:=0;
jml2:=0;
for i:=1 to m-1 do
begin
BacaFungsi(Fxx,(X[1]+i*h));
if i mod 2 <> 0 then jml1:=jml1+Fxx;
if i mod 2 =0 then jml2:=jml2+fxx;
end;

Hslintegrasi:=(Fx[1] + 4*jml1 +2*jml2 + fx[2])*h/3;


//jika segmen ganjil
//if m mod 2 <> 0 then

ListBox1.Items.Add(' HASIL INTEGRASI SIMPSON 1/3 BERSEGMEN');


ListBox1.Items.Add('');
ListBox1.Items.Add('==> ' + FormatFloat('#.0000',hslintegrasi));
end;

procedure TForm1.N381Click(Sender: TObject);


var i:Integer;
f13, f23:Real;
begin
for i:=1 to 2 do
x[i]:=strtofloat(stgreferensi.Cells[i-1,0]);

h:=(X[2]-X[1])/3;

for i:=1 to 2 do
BacaFungsi(fx[i],x[i]);

//baca f(1/3(x[2]+X[1])) DAN f(1/3(x[2]+X[1]))


BacaFungsi(f13,(x[2]+x[1])/3);
BacaFungsi(f23,(x[2]+x[1])*2/3);

Hslintegrasi:=3*h/8*(fx[1]+3*f13+3*f23+fx[2]);

ListBox1.Items.Add(' HASIL INTEGRASI SIMPSON 3/8');


ListBox1.Items.Add('');
ListBox1.Items.Add('==> ' + FormatFloat('#.0000',hslintegrasi));
end;

end.