так ні
так ні
так ні
так ні
С Лiстiнг програми
unit funct;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls, Math;
const
a = 0;
b = 6;
type
one_array = array of real;
Parametrs = record
nSimp, nTrap:integer;
end;
function y(x:real):real;
function first(x1,x2:real):real;
procedure setN(nG, nT, nS:integer);
procedure createGrid;
procedure createGridOfInt;
function integralSimpsona(aSim,bSim:real):real;
function integralTrapeciay(aTrap,bTrap:real):real;
function FullIntegral(aFull,bFull:real):real;
var
Xgrid:one_array; GridOfInt:one_array; nGrid, nSim, nTrap:integer;
implementation
//--------------------------------------------------------------
function y(x:real):real;
begin
Result:=2*arctan(x)-11*Power(3,(-x))+5;
end;
//--------------------------------------------------------------
function first(x1,x2:real):real;
begin
result:=5*x2+2*x2*ArcTan(x2)+11*Power(3,(-x2))/Ln(3)-Ln(1+x2*x2)-(5*x1+2*x1*ArcTan(x1)+11*Power(3,(-x1))/Ln(3)-Ln(1+x1*x1));
|
|
end;
//--------------------------------------------------------------
procedure setN(nG, nT, nS:integer);
begin
nGrid:=nG; nSim:=nS; nTrap:=nT;
end;
//--------------------------------------------------------------
procedure createGrid;
var i:integer; h:real;
begin
h:=(b-a)/nGrid;
SetLength(Xgrid,nGrid+1);
for i:=0 to nGrid do
Xgrid[i]:=a+h*i;
end;
//--------------------------------------------------------------
procedure createGridOfInt;
var i, n:integer;
begin
n:=High(Xgrid);
SetLength(GridOfInt,n+1);
for i:=1 to n do
GridOfInt[i]:=integralSimpsona(a,Xgrid[i]);
end;
//--------------------------------------------------------------
function integralSimpsona(aSim,bSim:real):real;
var X:one_array; i:integer; sum1, sum2, h:real;
begin
if(aSim<>bSim)then
begin
h:=(bSim-aSim)/nSim;
SetLength(X,nSim+1);
for i:=0 to nSim do
X[i]:=aSim+h*i;
sum1:=0;
sum2:=0;
for i:=1 to (nSim div 2) do
sum1:=sum1+y(X[2*i-1]);
for i:=1 to ((nSim div 2)-1) do
sum2:=sum2+y(X[2*i]);
Result:=(bSim-aSim)*(y(X[0])+y(X[nSim])+4*sum1+2*sum2)/(3*nSim);
end
else
Result:=0;
end;
//--------------------------------------------------------------
function integralTrapeciay(aTrap,bTrap:real):real;
var i:integer; sum, h:real; X:one_array;
begin
h:=(bTrap-aTrap)/nTrap;
SetLength(X,nTrap+1);
for i:=0 to nTrap do
X[i]:=aTrap+h*i;
sum:=(y(X[0])+y(X[nTrap]))/2;
for i:=1 to (nTrap-1) do
sum:=sum+y(X[i]);
Result:=sum*h;
end;
//--------------------------------------------------------------
function FullIntegral(aFull,bFull:real):real;
var z1, z2, z3, raznost:real; i, ai, bi:integer;
begin
if(aFull<>bFull)then
begin
for i:=0 to (High(Xgrid)-1) do
begin
if((Xgrid[i]<=aFull)and(aFull<=Xgrid[i+1]))then ai:=i;
if((Xgrid[i]<=bFull)and(bFull<=Xgrid[i+1]))then bi:=i;
end;
raznost:=GridOfInt[ai]+integralTrapeciay(Xgrid[ai],aFull);
Result:=GridOfInt[bi]+integralTrapeciay(Xgrid[bi],bFull)-raznost;
end
else
Result:=0;
end;
//--------------------------------------------------------------
end.
unit UnitMAIN;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, jpeg, ExtCtrls, StdCtrls, funct;
type
TForm1 = class(TForm)
Image1: TImage; Image2: TImage; Button1: TButton; Image3: TImage; Edit1: TEdit; Edit2: TEdit;
Label1: TLabel; Label2: TLabel; Label3: TLabel; Memo1: TMemo; Panel1: TPanel; Button2: TButton;
Button3: TButton; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Edit3: TEdit;
Edit4: TEdit; Edit5: TEdit; Label8: TLabel;
procedure Button1Click(Sender: TObject);
|
|
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer; intF, intS, intT, intR, L,R:real; file1:TextFile;
begin
L:=StrToFloat(Edit1.Text); R:=StrToFloat(Edit2.Text);
if(((0<=L)and(L<=6))and(((0<=R)and(R<=6))))
then
begin
createGrid;
createGridOfInt;
intF:=FullIntegral(L,R);
Label1.Caption:=FloatToStr(intF);
intS:=integralSimpsona(L,R);
intT:=integralTrapeciay(L,R);
intR:=first(L,R);
AssignFile(file1,'Result.txt');
Rewrite(file1);
writeln(file1,'Дйствительное значение интеграла ',intR:17:15);
writeln(file1,'Значение интеграла по формуле (1) ',intF:17:15,' Расность по модулю ',abs(intF-intR):17:15);
writeln(file1,'Значение интеграла по формуле трапеций ',intT:17:15,' Расность по модулю ',abs(intT-intR):17:15);
writeln(file1,'Значение интеграла по формуле Симпсона ',intS:17:15,' Расность по модулю ',abs(intS-intR):17:15);
CloseFile(file1);
Memo1.Lines.LoadFromFile('Result.txt');
end
else ShowMessage('граници должна быть в пределах от 0 до 6');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Panel1.Visible:=true; Button2.Visible:=false;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Panel1.Visible:=false; Button2.Visible:=true;
setN(StrToInt(Edit5.Text),StrToInt(Edit3.Text),StrToInt(Edit4.Text));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
setN(StrToInt(Edit5.Text),StrToInt(Edit3.Text),StrToInt(Edit4.Text));
end;
end.