Sabtu, 19 November 2016

Program Delphi Mencari Persamaan Regresi atau Penghampiran Fungsi Menggunakan Metode Kuadrat Terkecil

procedure TMetodeKuadtratTerkecil.Panel2Click(Sender: TObject);
var
JmlX,JmlY,Mean,JmlXiM,JmlXiM2,JmlYXM,DenomA0,PembilangA0,a0,PembilangA1,DenomA1,a1 : real;
i,j,n,m : integer;
x,y,XiM,XiM2,YXM : array[0..100] of real;


begin
for i:=1 to listbox1.Count do x[i]:=strtofloat(listbox1.Items[i-1]);
for j:=1 to listbox2.Count do y[j]:=strtofloat(listbox2.Items[j-1]);
JmlX:=0;
JmlY:=0;
for i:=1 to listbox1.count do JmlX:=JmlX+x[i];
for j:=1 to listbox2.Count do JmlY:=JmlY+y[j];
n:=listbox1.Count;
Mean:=JmlX/n;
for i:=1 to n do
begin
XiM[i]:=x[i]-Mean;
XiM2[i]:=Sqr(XiM[i]);
YXM[i]:=(y[i])*(XiM[i]);
Listbox4.Items.add(floattostr(XiM2[i]));
Listbox5.Items.Add(Floattostr(YXM[i]));
Listbox3.Items.add(floattostr(XiM[i]));
end;

JmlXiM2:=0;
JmlXiM:=0;
JmlYXM:=0;
for i:=1 to listbox4.Count do
begin
JmlXiM2:=JmlXiM2+XiM2[i];
end;

For i:=1 to listbox3.Count do
begin
JmlXiM:=JmlXiM+XiM[i];
end;

For i:=1 to listbox5.Count do
begin
JmlYXM:=JmlYXM+YXM[i];
end;

PembilangA0:=JmlY*JmlXim2-JmlXim*JmlYXM;
DenomA0:=n*JmlXiM2;
a0:=PembilangA0/DenomA0;
edit8.text:=floattostr(a0);

PembilangA1:=n*JmlYXM;
DenomA1:=JmlXiM2;
a1:=PembilangA1/DenomA1;
edit9.Text:=floattostr(a1);

end;



procedure TMetodeKuadtratTerkecil.Panel3Click(Sender: TObject);
begin
edit1.Text:=' ';
edit2.Text:=' ';
edit8.Text:=' ';
edit9.Text:=' ';
listbox1.Items.Clear;
listbox2.Items.Clear;
listbox3.Items.Clear;
listbox4.Items.Clear;
listbox5.Items.Clear;
end;

procedure TMetodeKuadtratTerkecil.Panel4Click(Sender: TObject);
begin
close;
end;

end.

0 komentar:

Posting Komentar