Реферат: Теорія імовірностей та математична статистика
Дискрентна вибірка 1,0,-1,2,3,2,3,-1,0,5,4. Результат:
Графіки:
Текст програми (Object Pascal Delphi 4 з застосуванням технології ActiveX):
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
ComboBox3: TComboBox;
Label1: TLabel;
Edit1: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;n:integer; typ:boolean;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
i:=30;n:=30;
while (StringGrid1.Cells[i,0]='') do begin
n:=n-1;
i:=i-1;
end;
typ:=true;
if Combobox3.ItemIndex=1 then typ:=false;
Form1.Visible:=false;
Form2.Showmodal;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm2 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit5: TEdit;
Label1: TLabel;
Button3: TButton;
Label2: TLabel;
Edit4: TEdit;
Label3: TLabel;
Edit6: TEdit;
Memo1: TMemo;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit8: TEdit;
Label8: TLabel;
Edit9: TEdit;
Label9: TLabel;
Edit10: TEdit;
Label10: TLabel;
Edit11: TEdit;
Label4: TLabel;
Edit7: TEdit;
Label11: TLabel;
Edit12: TEdit;
Label12: TLabel;
Edit13: TEdit;
Label13: TLabel;
Edit14: TEdit;
Label14: TLabel;
Edit15: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2; xi,ni,wi:variant;m,r:integer;sx,s,ser:double;
implementation
uses main, Unit3;
{$R *.DFM}
procedure TForm2.Button2Click(Sender: TObject);
begin
halt;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Form2.Close;
Form1.Visible:=true;
end;
procedure TForm2.FormActivate(Sender: TObject);
var sn,i,j,k:integer;p,w,v,t:variant;dx,tx:double;
s1,s2,s3:string;
begin
v := VarArrayCreate([0,n], varDouble);
p := VarArrayCreate([0,n], varDouble);
m:=0;
for i:=1 to n do begin
v[i]:=Form1.StringGrid1.Cells[i,0];
p[i]:=Form1.StringGrid1.Cells[i,0];
end;
{sorting}
k:=n;
while k<>0 do begin
for i:=n-1 downto 1 do
if v[i]>v[i+1] then begin
t:=v[i]; v[i]:=v[i+1]; v[i+1]:=t;
end;
k:=k-1;
end;
{об'єм вибірки}
xi:=n;
edit5.Text:=xi;
if typ=true then begin
w := VarArrayCreate([0,n], varDouble);
for i:=1 to n do
w[i]:=Form1.StringGrid1.Cells[i,0];
{об'єм ряду вибірки}
for i:=1 to n do
if w[i]<>-666 then begin
m:=m+1;
if i<>n then
for j:=i+1 to n do
if w[i]=w[j] then
w[j]:=-666;
end;
xi := VarArrayCreate([0,m], varDouble);
ni := VarArrayCreate([0,m], varInteger);
wi := VarArrayCreate([0,m], varDouble);
sn:=0;
sx:=0;
k:=0;
for i:=1 to n do
if v[i]<>-666 then begin
k:=k+1;
xi[k]:=v[i];
ni[k]:=1;
if i<>n then
for j:=i+1 to n do
if xi[k]=v[j] then begin
ni[k]:=ni[k]+1;
v[j]:=-666;
end;
end;
sn:=0;sx:=0;
for i:=1 to m do begin
sn:=sn+ni[i];
sx:=sx+xi[i];
end;
s:=sx/m;
for i:=1 to m do
wi[i]:=ni[i]/sn;
{moda}
t:=ni[1];
for i:=1 to m do
if t<=ni[i] then begin
t:=ni[i];
k:=i;
end;
Edit4.text:='{';
for i:=1 to m do
if t=ni[i] then begin
w:=xi[i];s1:=w;
Edit4.text:=Edit4.Text + s1;
if k<>i then Edit4.Text:=Edit4.Text + ','
else Edit4.Text:=Edit4.Text + '}';
end;
{mediana}
if m mod 2<>0 then begin
t:=(m+1)/2; t:=xi[t];
Edit6.Text:=t;
end
else begin
t:=m/2;k:=t;
t:=xi[k];
s1:=t;
t:=xi[k+1];
s2:=t;
Edit6.Text:='[' + s1 + ',' + s2 + ']';
end;
{Середнє}
ser:=0;
for i:=1 to n do
ser:=ser+p[i];
ser:=ser/n;
t:=ser; Edit15.Text:=t;
{Deviacia}
tx:=0;
for i:=1 to n do
tx:=tx+(p[i]-ser)*(p[i]-ser);
t:=tx;
Edit8.Text:=t;
{Variansa}
if n<>1 then sx:=tx/(n-1);t:=sx;
Edit9.Text:=t;
sx:=0;
{momenty}
for i:=1 to n do {1}
sx:=sx+p[i]-ser;
sx:=sx/n;
t:=sx;
Edit7.Text:=t;
tx:=tx/n;t:=tx; {2}
Edit12.Text:=t;
sx:=0;
for i:=1 to n do {3}
sx:=sx+(p[i]-ser)*(p[i]-ser)*(p[i]-ser);
sx:=sx/n;
t:=sx;
Edit13.Text:=t;
{Assymetrija}
if tx<>0 then sx:=sx/(sqrt(tx)*sqrt(tx)*sqrt(tx));
t:=sx;
Edit10.Text:=t;
sx:=0;
for i:=1 to n do {4}
sx:=sx+(p[i]-ser)*(p[i]-ser)*(p[i]-ser)*(p[i]-ser);
sx:=sx/n;
t:=sx;
Edit14.Text:=t;
{Eksces}
if tx<>0 then sx:=sx/(tx*tx)-3;
t:=tx;
Edit11.Text:=t;
{rozpodil function}
s2:=xi[1]; sx:=0;
Memo1.lines[0]:='0, x<' + s2;
for i:=1 to m-1 do begin
sx:=sx+wi[i];
t:=sx;
s1:=t;
s2:=xi[i];
s3:=xi[i+1];
Memo1.lines[i]:=s1 + ', ' + s2 + '=<x<' + s3;
end;
s2:=xi[m];
Memo1.lines[m]:='1, x>=' + s2;
for i:=1 to m do begin
Form2.StringGrid1.Cells[i,0]:=xi[i];
Form2.StringGrid1.Cells[i,1]:=ni[i];
Form2.StringGrid1.Cells[i,2]:=wi[i];
end;
end
else begin
sx:=v[n]-v[1];
i:=1;
r:=1;
while i<n do begin
i:=2*i;
r:=r+1;
end;
sx:=sx/(r-1)-0.2;
xi := VarArrayCreate([0,r-1], varDouble);
ni := VarArrayCreate([0,r-1], varInteger);
wi := VarArrayCreate([0,r-1], varDouble);
w := VarArrayCreate([0,r-1], varVariant);
xi[1]:=v[1]-0.2; s1:=xi[1];s2:=v[1]+sx;
Form2.StringGrid1.Cells[1,0]:='[' + s1 + ';' + s2 + ')';
xi[r-1]:=v[n]-sx; s1:=xi[r-1];
s2:=v[n]+0.2;
Form2.StringGrid1.Cells[r-1,0]:='[' + s1 + ';' + s2 + ']';
for i:=2 to r-2 do begin
xi[i]:=xi[i-1]+sx; s1:=xi[i]; s2:=xi[i]+sx;
Form2.StringGrid1.Cells[i,0]:='[' + s1 + ';' + s2 + ']';
end;
i:=1;j:=1;
while i<n do begin
if v[i]<xi[j]+sx then begin
ni[j]:=ni[j]+1;
i:=i+1;
end
else if j<=r-1 then j:=j+1;
end;
ni[r-1]:=ni[r-1]+1;
sn:=0;
for i:=1 to r-1 do begin
sn:=sn+ni[i];
Form2.StringGrid1.Cells[i,1]:= ni[i];
end;
for i:=1 to r-1 do begin
w[i]:=Form2.StringGrid1.Cells[i,0];
wi[i]:=ni[i]/sn;
Form2.StringGrid1.Cells[i,2]:= wi[i];
end;
{moda}
t:=ni[1];
for i:=1 to r-1 do
if t<=ni[i] then begin
t:=ni[i];
k:=i;
end;
Edit4.text:='{';
for i:=1 to r-1 do
if t=ni[i] then begin
s1:=xi[i]+sx/2;
Edit4.text:=Edit4.Text + s1;
if k<>i then Edit4.Text:=Edit4.Text + ','
else Edit4.Text:=Edit4.Text + '}';
end;
{mediana}
if r-1 mod 2<>0 then begin
t:=r/2; s1:=w[t];
Edit6.Text:=s1;
end
else begin
t:=(r-1)/2;
s1:=xi[t+1]+sx-sx/2;
s2:=xi[t+1]+sx+sx/2;
Edit6.Text:='[' + s1 + ';' + s2 + ']';
end;
{rozpodil function}
s2:=xi[1]; w[1]:=0;
Memo1.lines[0]:='0, x<' + s2;
for i:=1 to r-1 do begin
w[1]:=w[1]+wi[i];
t:=w[1];