Autor Beitrag
drummerbjoern
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mi 31.05.06 19:41 
Hey! ich hab ein delphi programm programmiert mit dem man pi berecdhnen kann! allerdings funktioniert es nicht richtig! könnt ihr mir sagen was ich verändern oder ergänzen muss?? Außerdemm weiß ich nicht womit und wie ich pi ausgeben kann! wäre euch sehr dankbar!
drummerbjoern
PS. ich übermittelden kompletten Quelltext!
PPS. Wäre um erklärungen dankbar!


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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    e_ergebnis: TEdit;
    procedure ende(Sender: TObject);
    procedure rechnen(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ende(Sender: TObject);
begin
close
end;

procedure TForm1.rechnen(Sender: TObject);

 function PiArchimedes(Schritte:integer):extended;
 var
   anzahl, i :integer;
   s,x,y     :extended;
 begin
   anzahl:=2;
   s:=sqrt(2);
   for i:=1 to schritte do
   begin
     anzahl:=anzahl*2;
     x:= sqrt(1-(1/2*s)*(1/2*s));
     y:=1-x;
     s:=sqrt((1/2*s)*(1/2*s)+y*y);
     result:=s*anzahl;
   end;

    end;
    end;
end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 31.05.06 19:44 
hat delphi "pi" nicht als konstante???

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mi 31.05.06 19:55 
user profile iconelundril hat folgendes geschrieben:
hat delphi "pi" nicht als konstante???


sicher, aber hier gehts darum das mal selber zu machen :wink:
(und das wohl noch mit beliebig vielen nachkommastellen)

_________________
Delphi: XE - OS: Windows 7 Professional x64
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Mi 31.05.06 20:09 
user profile iconHorschdware hat folgendes geschrieben:

(und das wohl noch mit beliebig vielen nachkommastellen)


Wohl eher nicht sqrt extended etc. Alle mit Fehlern behaftet. Multiplikationen Fehlerrechnung => ungenau
Die Konstante wird sehr viel genauer sein.
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: Mi 31.05.06 20:53 
user profile iconAllesquarks hat folgendes geschrieben:

Die Konstante wird sehr viel genauer sein.

... und falls dir das immer noch zu ungenau sein sollte, kannst du dir ja hier eine pdf mit 10 Mio. Nachkommastellen runterladen :mrgreen:

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Do 01.06.06 07:33 
ist zwar jetzt nicht geprüft aber ich glaube so is richtig :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function PiArchimedes(Schritte:integer):extended;
 var
  a,                     { Umfang des umschreibenden n-Ecks }
  b : extended;          { Umfang des einbeschriebenen n-Ecks }
  i : Integer;
  
begin
  a := 2*sqrt(3);        { Startwerte }
  b := 3;
   for i:=1 to schritte do
   begin
    a := 2*a*b/(a+b);
    b := sqrt(a*b);
  end;
result := b;
end;


Ausgabe :

ausblenden Delphi-Quelltext
1:
Showmessage("PI : " + FloattoStr(PiArchimedes(20));					
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 01.06.06 10:35 
um das jetzt nicht völlig runterzumachen: Is ne nette idee!! apropos Mathematik: weis jemand nen Algo um wurzeln zu ziehen!!

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
DerDepp
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 21



BeitragVerfasst: Do 01.06.06 10:41 
Schau mal bei wikipedia unter Wurzel nach, dort wird ihnen geholfen!
Mahlzeit DeDe