unit montecarlo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
START: TButton;
ENDE: TButton;
procedure ENDEClick(Sender: TObject);
procedure STARTClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ENDEClick(Sender: TObject);
begin
close
end;
procedure TForm1.STARTClick(Sender: TObject);
var a,b,d,fi,f,xz,yxz,yz,ymax: real;
zaehler,i,n:integer;
begin
a:=StrToFloat(Edit2.Text);
b:=StrToFloat(Edit3.Text);
n:=StrToInt(Edit4.Text);
d:=b-a;
ymax:=a*exp(b)-b;
zaehler:=0;
xz:= Random;
yxz:=a*exp(xz)-xz;
for i:=1
to n
do
begin
zaehler:=0;
randomize;
xz:=Random;
if (xz>a)
and (xz<b)
then
yxz:=a*exp(xz)-xz;
randomize;
yz:=Random;
if (yz<=yxz)
then
zaehler:=zaehler+1;
end;
f:=zaehler/n;
fi:=(ymax*f*d)/n;
Edit5.Text := FloatToStr(fi);
Edit5.Text:= Format('
= %10.2f FE',[fi]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
end;
end.