unit
Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Math;
type
TfrmMain =
class
(TForm)
edtX: TLabeledEdit;
lblResult: TLabel;
btnCalc: TButton;
function
Summ(x:
Extended
):
Extended
;
function
Fact(n:
integer
):
integer
;
procedure
btnCalcClick(Sender: TObject);
private
public
end
;
var
frmMain: TfrmMain;
x:
extended
;
implementation
{$R *.dfm}
procedure
TfrmMain
.
btnCalcClick(Sender: TObject);
begin
try
x := strtofloat(edtX
.
Text);
lblResult
.
Caption :=
'erf(x) = '
+ floattostr(summ(x));
except
lblResult
.
Caption :=
'Ошибка!'
;
end
;
end
;
function
TfrmMain
.
Fact(n:
integer
):
Integer
;
begin
if
n >
1
then
Result := n * Fact(n -
1
)
else
Result :=
1
;
end
;
function
TfrmMain
.
Summ(x:
Extended
):
Extended
;
var
n:
Integer
;
begin
Result :=
0
;
for
n :=
0
to
33
do
Result := Result + power( -
1
, n) * power(x,
2
*n +
1
)/(fact(n) * (
2
*n +
1
));
Result := Result *
2
/ sqrt(pi);
end
;
end
.