Autor Beitrag
Ivo@CoMRoK
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Di 07.02.06 18:52 
Hi!
Ich hab mal was geproggt mit monte-carlo, zum Pi ausrechnen.
Nun hab ich mir gedacht ich mach des mal ohne Zufallszahlen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Label2: TLabel;
    Edit2: TEdit;
    ProgressBar1: TProgressBar;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  z: Extended;
  k,n,t: LongInt;
  Text: String;
  x,y: Real;
  a: Single;

implementation

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
begin
  t := 0;
  n := 0;
  x := 0.01;
  y := 0.01;
  repeat
    repeat
      if x*x + y*y <= 1 then inc(t);
      x := x + 0.01;
    until x = 1;
    y := y + 0.01;
    x := 0;
    inc(n);
  until y = 1;
  z := 4*t/n;
  Edit2.Text := 'Pi = ' + FloatToStrF(z,ffFixed,18,18);
end;

end.


Aber das hängt sich auf. Ich hab schon geguckt, find den Fehler aber nicht.
Könnt ihr mir helfen?
DhÄnX

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Di 07.02.06 18:56 
ich würde mal prüfen ob du da keine endlosschleife produzierst, vlt wird x oder y nie 1, oder braucht halt a**** lange ;-)
Ivo@CoMRoK Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Di 07.02.06 18:59 
Ja des 0.01 = 0,100000000000023!!!
Hatte ich schomma , hatte StrToInt(0,1) und habs ez mit 0.01 gemacht wie krieg ichn des hin das des GENAU 0,01 ist :?:

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 07.02.06 19:35 
Gar nicht. Floats sollten nie mit = verglichen werden. Nimm als Abbruchbedingungen in den Schleifen besser {bzw. y} >= 1;

_________________
We are, we were and will not be.
Ivo@CoMRoK Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Di 07.02.06 20:15 
ja ich war grad bei E-Gitarre komm ins Zimmer und denk ich Idiot!!! Machs doch einfach mit >=!!!
Aber das dauert trotdem total lange :?: Keine Ahnung ich werd nochma zeile für zeile überprüfen!
DäNx

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
Ivo@CoMRoK Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Di 07.02.06 20:30 
okay ich hatte den jetzt 10 min laufen und nix is passiert (3Ghz).

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 07.02.06 20:42 
hmmm. Hiermit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.Button1Click(Sender: TObject);
begin
  t := 0;
  n := 0;
  x := 0.01;
  y := 0.01;
  repeat
    repeat
      if x*x + y*y <= 1 then inc(t);   
      x := x + 0.0001;
    until x >= 1;
    y := y + 0.0001;
    x := 0;
    inc(n);
  until y >= 1;
  z := 4*t/n;
  Edit2.Text := 'Pi = ' + FloatToStrF(z,ffFixed,18,18);
end;
bekomme ich in ca. 5 Sekunden (man beachte das Inkrement!):
Project1 hat folgendes geschrieben:
Pi = 31330,032521967478000000

Hast du beide > durch >= ersetzt?

_________________
We are, we were and will not be.
Ivo@CoMRoK Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Di 07.02.06 20:46 
Omfg! Gott bin ich blöd :shock: !
ICh habs nur bei dem einen Gemacht! :oops:
Danke für den Hinweis

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
Ivo@CoMRoK Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Mi 08.02.06 12:14 
Geht doch net!

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 08.02.06 12:16 
Was geht nicht?

_________________
We are, we were and will not be.
Ivo@CoMRoK Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Fr 10.02.06 13:33 
also es geht schon nur krieg ich da 33,333333333333337600 als Wert und soweit ich weiß is des net Pi.

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.