home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
zkuste
/
matemat
/
Vyssi
/
MATH2.ZIP
/
exmpl-1
/
pas
/
frmcent.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-01-06
|
4KB
|
133 lines
unit Frmcent;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, RChart, ExtCtrls, NumLab;
{===========================================================
Please note, that the program FINDCENT uses the units RChart
and NumLab, which are not supplied with the MATH2 package. If
you don't have them, you can download them from the following
WWW site: http://qspr03.tuwien.ac.at/lo/
===========================================================}
type
TForm1 = class(TForm)
Panel1: TPanel;
RChart1: TRChart;
BButExit: TBitBtn;
BButCreateD: TBitBtn;
BButCalcCent: TBitBtn;
NLabProcCnt: TNumLab;
procedure BButExitClick(Sender: TObject);
procedure BButCreateDClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BButCalcCentClick(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
Matrix, math2;
const
NData = 200; { number of data points }
NCenters = 10; { number of centers }
var
Data : TMatrix; { data matrix }
Centers : TMatrix; { calculated centers }
(*********************************************************)
procedure TForm1.BButExitClick(Sender: TObject);
(*********************************************************)
begin
close;
end;
(*********************************************************)
procedure TForm1.BButCreateDClick(Sender: TObject);
(*********************************************************)
var
i : integer;
begin
RChart1.ClearGraf;
RChart1.DataColor := clBlack;
for i:=1 to NData div 2 do
begin
Data.Elem[1,i] := 0.05*RChart1.RangeHiX+0.9*RChart1.RangeHiX*random;
Data.Elem[2,i] := 0.05*RChart1.RangeHiY+0.9*RChart1.RangeHiY*random;
RChart1.MarkAt (Data.Elem[1,i],Data.Elem[2,i],7);
end;
for i:=NData div 2 to NData-20 do
begin
Data.Elem[1,i] := 0.15*RChart1.RangeHiX+0.4*RChart1.RangeHiX*random;
Data.Elem[2,i] := 0.15*RChart1.RangeHiY+0.4*RChart1.RangeHiY*random;
RChart1.MarkAt (Data.Elem[1,i],Data.Elem[2,i],7);
end;
for i:=NData-20 to NData do
begin
Data.Elem[1,i] := 0.25*RChart1.RangeHiX+0.2*RChart1.RangeHiX*random;
Data.Elem[2,i] := 0.25*RChart1.RangeHiY+0.2*RChart1.RangeHiY*random;
RChart1.MarkAt (Data.Elem[1,i],Data.Elem[2,i],7);
end;
RChart1.SHowGraf;
end;
(*********************************************************)
procedure TForm1.FormCreate(Sender: TObject);
(*********************************************************)
begin
Data := TMatrix.Create (2,NData);
Data.Fill (0);
Centers := TMatrix.Create (2,NCenters);
Centers.Fill (0);
end;
(*********************************************************)
procedure ShowProgress (cnt: longint); far;
(*********************************************************)
begin
Form1.NLabProcCnt.Value := 100*(cnt/NData);
end;
(*********************************************************)
procedure TForm1.BButCalcCentClick(Sender: TObject);
(*********************************************************)
var
MeanDist : double;
i : integer;
begin
ProcStat := 0;
MathFeedbackProc := ShowProgress;
NLabProcCnt.LeftText := '... calculating';
NLabProcCnt.RightText := '% done';
NLabProcCnt.Visible := true;
FindCenters (Data, 1, Data.NrOfRows, NCenters, Centers, MeanDist); { mean distance }
RChart1.DataColor := clRed;
for i:=1 to NCenters do
RChart1.MarkAt (Centers.Elem[1,i],Centers.Elem[2,i],12);
RChart1.SHowGraf;
MathFeedbackProc := NIL;
NLabProcCnt.Visible := false;
end;
end.