Главная страница Случайная страница КАТЕГОРИИ: АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника |
Приклади роботи програми для неперервної змінної⇐ ПредыдущаяСтр 22 из 22
Код програми: unit Stat; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, TeEngine, Series, TeeProcs, Chart, ArrowCha, jpeg, About, Grids, Math, ComCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; OpenDialog1: TOpenDialog; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton; RadioGroup1: TRadioGroup; RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; RadioButton4: TRadioButton; RadioGroup2: TRadioGroup; RadioButton5: TRadioButton; RadioButton6: TRadioButton; RadioButton7: TRadioButton; RadioButton8: TRadioButton; Bevel1: TBevel; Bevel2: TBevel; Button9: TButton; Bevel3: TBevel; Bevel4: TBevel; Button10: TButton; Button11: TButton; Button12: TButton; Button13: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; Memo2: TMemo; Memo3: TMemo; Edit9: TEdit; Edit10: TEdit; Image2: TImage; Button14: TButton; Image3: TImage; StringGrid1: TStringGrid; Button15: TButton; Button16: TButton; StringGrid2: TStringGrid; Image5: TImage; Edit11: TEdit; Edit12: TEdit; Label5: TLabel; Label6: TLabel; Button17: TButton; Label7: TLabel; Label8: TLabel; MemoRiad: TMemo; Button18: TButton; Label9: TLabel; Label1: TLabel; Label10: TLabel; Label2: TLabel; Label3: TLabel; Label11: TLabel; Label12: TLabel; Edit13: TEdit; Edit14: TEdit; Button19: TButton; Edit15: TEdit; Label4: TLabel; Edit16: TEdit; Edit17: TEdit; Button20: TButton; Edit18: TEdit; Label13: TLabel; Label14: TLabel; Label15: TLabel; RichEdit3: TRichEdit; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button13Click(Sender: TObject); procedure Button12Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button10Click(Sender: TObject); procedure RadioButton5Click(Sender: TObject); procedure RadioButton6Click(Sender: TObject); procedure RadioButton7Click(Sender: TObject); procedure RadioButton8Click(Sender: TObject); procedure RadioButton1Click(Sender: TObject); procedure RadioButton2Click(Sender: TObject); procedure RadioButton3Click(Sender: TObject); procedure RadioButton4Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button14Click(Sender: TObject); procedure Button15Click(Sender: TObject); procedure Button16Click(Sender: TObject); procedure Button17Click(Sender: TObject); procedure Button18Click(Sender: TObject); procedure Button19Click(Sender: TObject); procedure Button20Click(Sender: TObject); procedure Image5Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; n, quantity, r, int, size: integer; sum, max, rizn, rozmah: real; variable: array[1..100] of real; x: array[1..100] of real; xi: array[1..100] of real; z: array[1..100] of real; nju: array[1..100] of real; njuz: array[1..100] of real; ser_vyb, mediana, devia, varianca, standart, variacija, pmom1, pmom2, pmom3, pmom4, cmom1, cmom2, cmom3, cmom4, asum, eksc: real; f: textFile; s, vlast: string;
implementation uses Graphs;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject); begin Close; end;
procedure TForm1.Button1Click(Sender: TObject); var j, i, q, Ex: integer; temp: real; begin OpenDialog1.Filter: ='Текстові файли|*.txt|'; if OpenDialog1.Execute and FileExists(OpenDialog1.FileName) then try begin assignfile(f, OpenDialog1.FileName); reset(f); readln(f, quantity); readln(f, vlast); for j: =1 to quantity do begin readln(f, variable[j]); end; end; closefile(f); except on EInOutError do ShowMessage('Error!! '); end; for i: =1 to quantity-1 do begin for j: =1 to quantity-i do begin if variable[j] > variable[j+1] then begin temp: =variable[j+1]; variable[j+1]: =variable[j]; variable[j]: =temp; end; end; end; j: =1; for i: =1 to quantity do begin nju[i]: =1; end; for i: =1 to (quantity-1) do begin if (variable[i]=variable[i+1]) then begin nju[j]: =nju[j]+1; x[j]: =variable[i]; end else begin j: =j+1; x[j]: =variable[i+1]; end; end; size: =j; for i: =1 to size do begin sum: =sum+x[i]; end; rozmah: =x[size]-x[1]; //================================= if vlast='n' then begin q: =2; r: =0; while (quantity> q) do begin q: =q*2; r: =r+1; end; int: =r+1; rizn: =rozmah/int; z[1]: =x[1]+rizn/2; for i: =2 to int do z[i]: =z[i-1]+rizn; j: =1; for i: =1 to int do njuz[i]: =0; while (j< int) do begin for i: =1 to quantity do begin if (((z[j]-rizn/2)-1e-4< =variable[i])and(variable[i]< (z[j]+rizn/2))) then njuz[j]: =njuz[j]+1; end; j: =j+1; end;
for i: =1 to quantity do begin if (((z[int]-rizn/2)< =variable[i])and(variable[i]< =(z[int]+rizn/2+1e-4))) then njuz[int]: =njuz[int]+1; end;
end; //================================= button3.Enabled: =true; button4.Enabled: =true; button5.Enabled: =true; button6.Enabled: =true; button7.Enabled: =true; button8.Enabled: =true; button9.Enabled: =true; button10.Enabled: =true; button11.Enabled: =true; button12.Enabled: =true; button13.Enabled: =true; button15.Enabled: =true; button16.Enabled: =true; //Existing poriadok Ex: =100 div quantity; Label8.Caption: = ' '+ IntToStr(Ex) +' '; //Edit13.Text: = IntToStr(Ex); //=========================== moda max: =nju[1]; for i: =2 to size do begin if max< nju[i] then begin max: =nju[i]; end; end; //========================== mediana if (quantity mod 2)< > 0 then begin i: =quantity div 2; mediana: =variable[i+1]; end else begin i: =quantity div 2; mediana: =(variable[i] + variable [i+1])/2; end; //========================== serednie if vlast='n' then begin for i: =1 to int do ser_vyb: =ser_vyb+z[i]*njuz[i]; end else begin for i: =1 to size do ser_vyb: =ser_vyb+x[i]*nju[i]; end; ser_vyb: =ser_vyb/quantity; //========================= deviacija if vlast< > 'n' then begin for i: =1 to size do devia: =devia+nju[i]*sqr(x[i]-ser_vyb); end else begin for i: =1 to int do devia: =devia+njuz[i]*sqr(z[i]-ser_vyb); end; //========================= variansa varianca: =(1/(quantity-1))*devia; //========================= standart standart: =sqrt(varianca); //========================= variacija variacija: =standart/ser_vyb; //========================= po4atkovi momenty //1 if vlast< > 'n' then begin for i: =1 to size do pmom1: =pmom1+x[i]*nju[i]; end else begin for i: =1 to int do pmom1: =pmom1+z[i]*njuz[i]; end; pmom1: =pmom1/quantity; //2 if vlast< > 'n' then begin for i: =1 to size do pmom2: =pmom2+sqr(x[i])*nju[i]; end else begin for i: =1 to int do pmom2: =pmom2+sqr(z[i])*njuz[i]; end; pmom2: =pmom2/quantity; //3 if vlast< > 'n' then begin for i: =1 to size do pmom3: =pmom3+sqr(x[i])*x[i]*nju[i]; end else begin for i: =1 to int do pmom3: =pmom3+sqr(z[i])*z[i]*njuz[i]; end; pmom3: =pmom3/quantity; //4 if vlast< > 'n' then begin for i: =1 to size do pmom4: =pmom4+sqr(x[i])*sqr(x[i])*nju[i]; end else begin for i: =1 to int do pmom4: =pmom4+sqr(z[i])*sqr(z[i])*njuz[i]; end; pmom4: =pmom4/quantity; //centralni momenty //1 if vlast< > 'n' then begin for i: =1 to size do cmom1: =cmom1+(x[i]-ser_vyb)*nju[i]; end else begin for i: =1 to int do cmom1: =cmom1+(z[i]-ser_vyb)*njuz[i]; end; cmom1: =cmom1/quantity; //2 if vlast< > 'n' then begin for i: =1 to size do cmom2: =cmom2+sqr(x[i]-ser_vyb)*nju[i]; end else begin for i: =1 to int do cmom2: =cmom2+sqr(z[i]-ser_vyb)*njuz[i]; end; cmom2: =cmom2/quantity; //3 if vlast< > 'n' then begin for i: =1 to size do cmom3: =cmom3+sqr(x[i]-ser_vyb)*(x[i]-ser_vyb)*nju[i]; end else begin for i: =1 to int do cmom3: =cmom3+sqr(z[i]-ser_vyb)*(z[i]-ser_vyb)*njuz[i]; end; cmom3: =cmom3/quantity; //4 if vlast< > 'n' then begin for i: =1 to size do cmom4: =cmom4+sqr(x[i]-ser_vyb)*sqr(x[i]-ser_vyb)*nju[i]; end else begin for i: =1 to int do cmom4: =cmom4+sqr(z[i]-ser_vyb)*sqr(z[i]-ser_vyb)*njuz[i]; end; cmom4: =cmom4/quantity; //exces eksc: =cmom4/sqr(cmom2)-3; //asymetria asum: =cmom3/sqrt(cmom2*cmom2*cmom2); end;
function realtostr(x: real): string; var r: string; a, b: integer; begin s: =''; a: =trunc(x*100); b: =a mod 100; a: =a div 100; s: =inttostr(a); if(b> 0) then s: =s+'.'+inttostr(b); result: =s; end;
procedure TForm1.Button3Click(Sender: TObject); var nn, i, j, k: integer; rozmah, a, h, kilk: real; begin
if vlast='n' then begin with Form1.RichEdit3 do begin Text: =Text+'-----------------'+#13; Text: =Text+'| Z || nju |'+#13; Text: =Text+'-----------------'+#13; for i: =1 to int do Text: =Text+'| '+realToStr(z[i])+' | '+IntToStr(trunc(njuz[i]))+' |'+#13; Text: =Text+'------------------'+#13; Text: =Text+'Suma: '+IntToStr(quantity); end; end; if vlast='d' then begin StringGrid2.ColCount: =size+2; StringGrid2.Cells[0, 0]: ='x'; StringGrid2.Cells[0, 1]: ='nuj'; for i: =1 to size do begin StringGrid2.Cells[i, 0]: =realToStr(x[i]); StringGrid2.Cells[i, 1]: =realToStr(nju[i]); end; StringGrid2.Cells[size+1, 0]: ='sum'; StringGrid2.Cells[size+1, 1]: =IntToStr(quantity); end; end;
procedure TForm1.Button6Click(Sender: TObject); var i: integer; begin Edit3.Clear; Edit3.Text: =FloatToStr(ser_vyb); end;
procedure TForm1.Button5Click(Sender: TObject); var i: integer; begin Edit2.Clear; Edit2.Text: =FloatToStr(mediana); end;
procedure TForm1.Button9Click(Sender: TObject); var i: integer; begin Edit4.Clear; Edit4.Text: =FloatToStr(devia); end;
procedure TForm1.Button11Click(Sender: TObject); begin Edit6.Clear; Edit6.Text: =FloatToStr(varianca); end;
procedure TForm1.Button13Click(Sender: TObject); begin Edit7.Clear; Edit7.Text: =FloatToStr(standart); end;
procedure TForm1.Button12Click(Sender: TObject); begin Edit8.Clear; Edit8.Text: =FloatToStr(variacija); end;
procedure TForm1.Button4Click(Sender: TObject); var i: integer; begin Edit1.Clear; for i: =1 to size do begin if max=nju[i] then begin Edit1.Text: = Edit1.Text+FloatToStr(x[i])+' '; end; end; end; procedure TForm1.Button10Click(Sender: TObject); begin Edit5.Clear; Edit5.Text: =FloatToStr(rozmah); end;
procedure TForm1.RadioButton5Click(Sender: TObject); var i: integer; begin Form1.Memo2.Lines.Text: =Form1.Memo2.Lines.Text+'1-ий початковий момент: '+FloatToStr(pmom1)+#13; end; procedure TForm1.RadioButton6Click(Sender: TObject); var i: integer; begin Form1.Memo2.Lines.Text: =Form1.Memo2.Lines.Text+'2-ий початковий момент: '+FloatToStr(pmom2)+#13; end; procedure TForm1.RadioButton7Click(Sender: TObject); var i: integer; begin Form1.Memo2.Lines.Text: =Form1.Memo2.Lines.Text+'3-ій початковий момент: '+FloatToStr(pmom3)+#13; end; procedure TForm1.RadioButton8Click(Sender: TObject); var i: integer; begin Form1.Memo2.Lines.Text: =Form1.Memo2.Lines.Text+'4-ий початковий момент: '+FloatToStr(pmom4)+#13; end;
procedure TForm1.RadioButton1Click(Sender: TObject); var i: integer; begin Form1.Memo3.Lines.Text: =Form1.Memo3.Lines.Text+'1-ий центральний момент: '+FloatToStr(cmom1)+#13; end; procedure TForm1.RadioButton2Click(Sender: TObject); var i: integer; begin Form1.Memo3.Lines.Text: =Form1.Memo3.Lines.Text+'2-ий центральний момент: '+FloatToStr(cmom2)+#13; end; procedure TForm1.RadioButton3Click(Sender: TObject); var i: integer; begin Form1.Memo3.Lines.Text: =Form1.Memo3.Lines.Text+'3-ій центральний момент: '+FloatToStr(cmom3)+#13; end; procedure TForm1.RadioButton4Click(Sender: TObject); var i: integer; begin Form1.Memo3.Lines.Text: =Form1.Memo3.Lines.Text+'4-ий центральний момент: '+FloatToStr(cmom4)+#13; end; procedure TForm1.Button7Click(Sender: TObject); begin Edit10.Clear; Edit10.Text: =FloatToStr(asum); end; procedure TForm1.Button8Click(Sender: TObject); begin Edit9.Clear; Edit9.Text: =FloatToStr(eksc); end; procedure TForm1.Button14Click(Sender: TObject); begin AboutBox.Show; end; procedure TForm1.Button15Click(Sender: TObject); var h, i: integer; begin h: =0; if vlast< > 'n' then begin StringGrid1.RowCount: =size+1; StringGrid1.Cells[0, 0]: ='0'; StringGrid1.Cells[1, 0]: ='x < '+realToStr(x[1]); for i: =1 to size-1 do begin h: =h+trunc(nju[i]); StringGrid1.Cells[0, i]: =IntToStr(h)+'/'+IntToStr(quantity); StringGrid1.Cells[1, i]: =realToStr(x[i])+'< =x< '+realToStr(x[i+1]); end; StringGrid1.Cells[0, size]: ='1'; StringGrid1.Cells[1, size]: ='x> ='+realToStr(x[size]); end else begin StringGrid1.RowCount: =int+1; StringGrid1.Cells[0, 0]: ='0'; StringGrid1.Cells[1, 0]: ='z < '+realToStr(z[1]); for i: =1 to int-1 do begin h: =h+trunc(njuz[i]); StringGrid1.Cells[0, i]: =IntToStr(h)+'/'+IntToStr(quantity); StringGrid1.Cells[1, i]: =realToStr(z[i])+'< =z< '+realToStr(z[i+1]); end; StringGrid1.Cells[0, int]: ='1'; StringGrid1.Cells[1, int]: ='z> ='+realToStr(z[int]); end; end;
procedure TForm1.Button16Click(Sender: TObject); var t: TForm3; begin t: =TForm3.Create(Application); t.Show; end;
procedure TForm1.Button17Click(Sender: TObject); var q, g, l1: integer; begin l1: =100 div quantity; if Edit11.Text='' then ShowMessage('vvedit porjadok') else begin g: =StrToint(Edit11.Text); q: =g div l1; if (g mod l1)=0 then begin Edit12.Text: =realToStr((variable[q])); Label6.Caption: ='x ['+IntToStr(q)+']'; end else ShowMessage('Takogo kvantulja ne isnyje'); end; end; procedure TForm1.Button18Click(Sender: TObject); var i, j, k: integer; min, mini, c, s, ss: real; begin for i: =1 to quantity-1 do begin min: =variable[i]; k: =i; for j: =i+1 to quantity do if variable[j]< min then begin min: =variable[j]; k: =j; end; c: =variable[i]; variable[i]: =variable[k]; variable[k]: =c; MemoRiad.Lines.Text: =MemoRiad.Lines.Text+' '+realToStr(variable[i]); end; end; procedure TForm1.Button19Click(Sender: TObject); var q, g, l1: integer; QQ, Q1, Q3: real; begin l1: =quantity div 4; if Edit13.Text='' then ShowMessage('vvedit porjadok') else begin g: =StrToint(Edit13.Text); if (g=1)or(g=2)or(g=3) then begin //if (g=2) then begin // у вибірці з н=50 q: =g * l1; end else ShowMessage('Takogo kvartulja ne isnyje'); //if (q mod 2)=0 if (Frac(q))=0 then begin Edit14.Text: =realToStr((variable[q])); end //Edit14.Text: =IntToStr((variable[q])); //Label13.Caption: ='x ['+IntToStr(q)+']'; end else ShowMessage('Takogo kvartulja ne isnyje'); end; //for (q=l1) and (q=3*l1) do begin q: =l1; Q1: = variable[q]; q: =3*l1; Q3: = variable[q]; QQ: = Q3-Q1; Edit15.Text: ='Q= Q3-Q1= ' +realToStr(QQ); end;
procedure TForm1.Button20Click(Sender: TObject); var q, g, l1: integer; DD, D1, D9: real; begin l1: =quantity div 10; if Edit16.Text='' then ShowMessage('vvedit porjadok') else begin g: =StrToint(Edit16.Text); if (g=1)or(g=2)or(g=3)or(g=4)or(g=5)or(g=6)or(g=7)or(g=8)or(g=9) then begin //if (g=2) then begin // у вибірці з н=50 q: =g * l1; end else ShowMessage('Takogo kvartulja ne isnyje'); if (Frac(q))=0 then begin Edit17.Text: =realToStr((variable[q])); end else ShowMessage('Takogo decylia ne isnyje'); end; q: =l1; D1: = variable[q]; q: =9*l1; D9: = variable[q]; DD: = D9-D1; Edit18.Text: ='D= D9-D1= ' +realToStr(DD); end; end. ////////////////////////////////////////////////////////////////// unit Graphs; interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart, ArrowCha, jpeg;
type TForm3 = class(TForm) Chart1: TChart; Series1: TLineSeries; Button1: TButton; Chart2: TChart; Button2: TButton; Series2: TArrowSeries; Chart3: TChart; Button3: TButton; Series3: TArrowSeries; Button4: TButton; Chart4: TChart; Series4: TBarSeries; Button5: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form3: TForm3; i: integer;
implementation uses Stat;
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject); begin Series1.Clear; if vlast< > 'n' then begin for i: =1 to size do Series1.AddXY(x[i], nju[i]); end else begin for i: =1 to int do Series1.AddXY(z[i], njuz[i]); end; end;
procedure TForm3.Button2Click(Sender: TObject); var h: real; begin Series2.Clear; h: =0; if vlast< > 'n' then begin Series2.AddArrow(x[1]-1, 0, x[1], 0); for i: =1 to size-1 do begin h: =h+nju[i]/quantity; Series2.AddArrow(x[i], h, x[i+1], h); end; Series2.AddArrow(x[size], 1, x[size]+1, 1); end else begin Series2.AddArrow(z[1]-1, 0, z[1], 0); for i: =1 to int-1 do begin h: =h+njuz[i]/quantity; Series2.AddArrow(z[i], h, z[i+1], h); end; Series2.AddArrow(z[int], 1, z[int]+1, 1); end; end;
procedure TForm3.Button3Click(Sender: TObject); begin Series3.Clear; for i: =1 to size do Series3.AddArrow(x[i], 0, x[i], nju[i]); end; function realtostr(x: real): string; var r: string; a, b: integer; begin s: =''; a: =trunc(x*100); b: =a mod 100; a: =a div 100; s: =inttostr(a)+'.'+inttostr(b); result: =s; end; procedure TForm3.Button4Click(Sender: TObject); begin Series4.Clear; for i: =1 to int do Series4.AddBar(njuz[i], realtostr(z[i]), clBlack); end; procedure TForm3.Button5Click(Sender: TObject); begin Close; end; procedure TForm3.FormCreate(Sender: TObject); begin if vlast='n' then begin Button4.Visible: =true; Chart4.Visible: =true; end; end; end.
|