unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Buttons, StdCtrls, Mask, ExtCtrls, Grids, TeEngine,
Series, TeeProcs, Chart, Math;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSt1: TTabSheet;
Panel2: TPanel;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
L3: TLabel;
L5: TLabel;
L6: TLabel;
L4: TLabel;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
Edit1: TEdit;
Chart1: TChart;
Series1: TBarSeries;
StringGrid1: TStringGrid;
BitBtn2: TBitBtn;
TabSheet1: TTabSheet;
StringGrid2: TStringGrid;
L10: TLabel;
L9: TLabel;
L8: TLabel;
L7: TLabel;
Chart2: TChart;
BarSeries2: TBarSeries;
GoOUT2: TBitBtn;
Panel4: TPanel;
L00: TLabel;
L15: TLabel;
L17: TLabel;
L18: TLabel;
L16: TLabel;
MaskEdit4: TMaskEdit;
Chart4: TChart;
BarSeries3: TBarSeries;
Panel3: TPanel;
L14: TLabel;
L13: TLabel;
L12: TLabel;
L11: TLabel;
Label15: TLabel;
Chart3: TChart;
BarSeries1: TBarSeries;
SpeedButton1: TSpeedButton;
SpeedButton3: TSpeedButton;
GroupBox2: TGroupBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
SpeedButton2: TSpeedButton;
SpeedButton4: TSpeedButton;
StringGrid4: TStringGrid;
StringGrid3: TStringGrid;
Edit3: TEdit;
GoOUT1: TBitBtn;
BitBtn1: TBitBtn;
Label14: TLabel;
L23: TLabel;
L24: TLabel;
L25: TLabel;
L26: TLabel;
L19: TLabel;
L20: TLabel;
L21: TLabel;
L22: TLabel;
procedure SpeedButton1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
|
|
procedure CheckBox4Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure GoOUT2Click(Sender: TObject);
procedure GoOUT1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Y,e,A,X:array[0..100]of extended;
t,k,i,n,r,nr:integer;
col:array[0..100]of integer;
j,LA:real;
implementation
{$R *.dfm}
procedure TForm1.SpeedButton1Click(Sender: TObject);
var s:string;
sum,mx,dx,sko:extended;
begin
y[0]:=StrToFloat(Trim(MaskEdit1.Text));
t:=StrToInt(Trim(MaskEdit2.Text));
k:=8*t-3;
Edit1.Text:=IntToStr(k);
for i:=1 to 100 do
y[i]:=k*y[i-1]-trunc(k*y[i-1]);
for i:=0 to 100 do
StringGrid1.Cells[0,i]:=FloatToStr(y[i]);
j:=0;r:=0;
while j<0.9 do
begin
for i:=0 to 100 do
if (y[i]>j) and (y[i]<j+0.1)then
inc(n);
col[r]:=n;n:=0;
j:=j+0.1;inc(r);
end;
for i:=0 to 9 do
Chart1.SeriesList[0].AddXY(i,col[i]/10,'',clred);
sum:=0;
for i:=0 to 100 do
sum:=sum+y[i];
mx:=sum/101;
L4.Caption:=FloatToStr(mx);
L3.Visible:=true;
sum:=0;
for i:=0 to 100 do
sum:=sum+sqr(y[i]-mx);
dx:=sum/100;
sko:=sqrt(dx);
L6.Caption:=FloatToStr(dx);
L5.Visible:=true;
L24.Caption:=FloatToStr(sko);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
L4.Caption:='';
L6.Caption:='';
L8.Caption:='';
L10.Caption:='';
Edit1.Text:='';
MaskEdit1.Text:='';
MaskEdit2.Text:='';
Chart1.SeriesList[0].clear;
Chart2.SeriesList[0].clear;
for i:=0 to 100 do
begin
Stringgrid1.Cells[0,i]:=FloatToStr(0);
Stringgrid2.Cells[0,i]:=FloatToStr(0);
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
var s:string;
sum,mx,dx:extended;
begin
if CheckBox1.Checked then Panel1.Visible:=true
else Panel1.Visible:=false;
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked then Panel2.Visible:=true
else Panel2.Visible:=false;
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
var s:string;
sum,mx,dx,sko:extended;
begin
for i:=0 to 100 do
begin
a[i]:=random(100000);
s:=FloatToStr(a[i]);
s:='0,'+s;
a[i]:=StrToFloat(Trim(s));
StringGrid2.Cells[0,i]:=FloatToStr(a[i]);
end;
j:=0;r:=0;
while j<0.9 do
begin
for i:=0 to 100 do
if (a[i]>j) and (a[i]<j+0.1)then inc(n);
col[r]:=n;n:=0;
j:=j+0.1;inc(r);
end;
for i:=0 to 9 do
Chart2.SeriesList[0].AddXY(i,col[i]/10,'',clblue);
sum:=0;
for i:=0 to 100 do
sum:=sum+a[i];
mx:=sum/101;
L8.Caption:=FloatToStr(mx);
L7.Visible:=true;
sum:=0;
for i:=0 to 100 do
sum:=sum+sqr(a[i]-mx);
dx:=sum/100;
L10.Caption:=FloatToStr(dx);
|
|
L9.Visible:=true;
sko:=sqrt(dx);
L26.Caption:=FloatToStr(sko);
end;
procedure TForm1.CheckBox4Click(Sender: TObject);
begin
if CheckBox4.Checked then Panel3.Visible:=true
else Panel3.Visible:=false;
end;
procedure TForm1.CheckBox3Click(Sender: TObject);
begin
if CheckBox3.Checked then Panel4.Visible:=true
else Panel4.Visible:=false;
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
var sum,mx,dx,sko:extended;
begin
LA:=StrToInt(Trim(Edit3.Text));
for i:=0 to 100 do
begin
e[i]:=-(1/LA)*ln(y[i]);
StringGrid3.Cells[0,i]:=FloatToStr(e[i]);
end;
sum:=0;
for i:=0 to 100 do
sum:=sum+e[i];
mx:=sum/101;
L12.Caption:=FloatToStr(mx);
L11.Visible:=true;
sum:=0;
for i:=0 to 100 do
sum:=sum+sqr(e[i]-mx);
dx:=sum/100;
sko:=sqrt(dx);
L14.Caption:=FloatToStr(dx);
L13.Visible:=true;
L22.Caption:=FloatToStr(sko);
j:=0;r:=0;
while j<3.5*sko do
begin
n:=0;
for i:=1 to 100 do
if (e[i]>j) and (e[i]<j+sko/5)then inc(n);
Chart3.SeriesList[0].AddXY(j,n/20*sko,'',clblue);
j:=j+sko/5;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Edit3.Text:='1';
L12.Caption:='';
L14.Caption:='';
L16.Caption:='';
L18.Caption:='';
Chart3.SeriesList[0].clear;
Chart4.SeriesList[0].clear;
for i:=0 to 100 do
begin
Stringgrid3.Cells[0,i]:=FloatToStr(0);
Stringgrid4.Cells[0,i]:=FloatToStr(0);
end;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
var sum,mx,dx,sko,ss,w:extended; j:integer;
begin
nr:=StrToInt(Trim(MaskEdit4.Text));
mx:=nr/2;
dx:=sqrt(nr)/(2*sqrt(3));
sko:=sqrt(dx);
L16.Caption:=FloatToStr(mx);
L18.Caption:=FloatToStr(dx);
L20.Caption:=FloatToStr(sko);
j:=0;
while j<100 do
begin
for i:=1 to 100 do
begin
y[i]:=k*y[i-1]-trunc(k*y[i-1]);
end; y[0]:=y[100];
sum:=0;
for i:=1 to nr do
sum:=sum+y[i];
x[j]:=sqrt(3)*(2/sqrt(nr)*sum-sqrt(nr))*dx+mx;
StringGrid4.Cells[0,j]:=FloatToStr(x[j]);
inc(j);
end;
j:=0;
{while j<2.5*sko do}
for j:=-9 to 9 do
begin
w:=mx+j*sko/5;
ss:=0;
for i:=1 to 100 do
if (x[i]>=w)and (x[i]<w+sko/5)then ss:=ss+1;
Chart4.SeriesList[0].AddXY(w,ss/(20*sko),'',clred);
end;
end;
procedure TForm1.GoOUT2Click(Sender: TObject);
begin
If CloseQuery then Close;
end;
procedure TForm1.GoOUT1Click(Sender: TObject);
begin
If CloseQuery then Close;
end;
end.
Результаты генерации последовательностей ПСЧ указанными выше методами приведены на экранной форме.
Как видно из первой экранной формы, оценки математического ожидания и дисперсии последовательности квазиравномерных ПСЧ, полученной методом Лемера, близки к математическому ожиданию (равному 0,5) и дисперсии (равной 1/12 или, округленно, 0,0833) равномерного распределения случайных чисел. Для последовательности квазиравномерных ПСЧ, полученной с помощью стандартного датчика Random, данные оценки несколько хуже.
На следующей экранной форме приведены результаты генерации последовательностей ПСЧ с квазинормальным и квазиэкспоненциальным законами распределения, полученных по приведенным выше соотношениям.