Autor Beitrag
onkeleule44
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 06.05.05 15:07 
Hallo,
folgende Schleife habe ich eingefügt:

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:
procedure TForm23.Button1Click(Sender: TObject);
var a,b,c,d: real;
    k,n: integer;
    function fexp (x, y: real) : real;
    begin
         result := exp (y*ln(x));
    end;

begin
     a := StrToFloat (DBEdit4.Text);
     b := StrToFloat (DBEdit10.Text);
     c := StrToFloat (DBEdit8.Text);
     d := 0;
     k := 0;

     if (DBEdit4.Text = '') or
        (DBEdit8.Text = '') or
        (DBEdit10.Text = '') then
        begin
             beep;
             exit;
        end;

     screen.Cursor := crHourGlass;

     DBEdit9.Text := '';

     while (d <= 1)and (DBEdit9.Text = '') do
     begin
          inc (k);
          d :=  (1/a) + (1/b)*(1/(1+c))*(1/fexp(1-d, c));
          application.ProcessMessages;
     end;

     screen.Cursor := crDefault;

     DBEdit9.Text := IntToStr (k);
end;
Leider bleibt die Schleife beim Einsetzen schon bei kleineren Werten (unter 20) hängen und läuft unendlich. Habe über Excel das simuliert und irgendwann wird immer wieder der gleiche Wert in die Formel eingesetzt, ´so dass sie nie enden kann.

Weiß jemand woran das liegt und wie man so was beheben kann?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 15:10 
ähm benutz mal bitte die delphi tags, danke
onkeleule44 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 06.05.05 15:19 
Sorry, aber dir gegenüber sitzt ein Laie.

Was meinst du mit Delphi-Tags? Kannst du mir das genauer erklären?
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 15:24 
forenregeln lesen :D
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:
procedure TForm23.Button1Click(Sender: TObject); 
var a,b,c,d: real; 
k,n: integer; 
function fexp (x, y: real) : real; 
begin 
result := exp (y*ln(x)); 
end; 

begin 
a := StrToFloat (DBEdit4.Text); 
b := StrToFloat (DBEdit10.Text); 
c := StrToFloat (DBEdit8.Text); 
d := 0; 
k := 0; 

if (DBEdit4.Text = '') or 
(DBEdit8.Text = '') or 
(DBEdit10.Text = '') then 
begin 
beep; 
exit; 
end; 

screen.Cursor := crHourGlass; 

DBEdit9.Text := ''; 

while (d <= 1)and (DBEdit9.Text = '') do 
begin 
inc (k); 
d := (1/a) + (1/b)*(1/(1+c))*(1/fexp(1-d, c)); 
application.ProcessMessages; 
end; 

screen.Cursor := crDefault; 

DBEdit9.Text := IntToStr (k); 
end;

auf den delphi button klicken, code einfügen und nochmal draufklicken, sieht doch viel besser aus, oder net ?
onkeleule44 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 06.05.05 15:32 
Jau, recht hast du!
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 15:39 
also eigentlich läuft die ja solange weiter, wie im edit nichts steht, ok application.prcoessmessages ist drin, probiers aber lieber mal mit ner repeat schleife.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
repeat
  if DBEdit9.text = '' then
    begin
      inc (k);   
      d := (1/a) + (1/b)*(1/(1+c))*(1/fexp(1-d, c));   
      application.ProcessMessages; 
    end;
until d > 1;



oder der fehler liegt in der rechnung, sodass d nie größer als 1 wird :idea:
^
|- halte ich für am wahrscheinlichsten :!:
onkeleule44 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Sa 07.05.05 21:48 
Hallo,

das hat leider auch nicht funktioniert, schade!

Hat jemand ne andere Idee, wie das Problem zu lösen ist?

Mal ganz allgemein: Es muss doch auch möglich sein mit unglaublich kleinen und großen Zahlen Rechnungen durchführen zu können.

Wäre um weitere Hilfe oder Anregungen dankbar!
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mo 09.05.05 15:37 
Titel: hmm,
das Problem liegt einfach an der Genauigkeit bzw. an der Anzahl der Nachkommastellen. Wenn du dein Programm durchtraced dann wirst du sehen dass der Wert der zu d dazuaddiert wird immer kleiner wird und irgendwann läuft er einfach aus der rechengenauigkeit raus und es wird nichtsmehr addiert.

_________________
mfg. Joel
onkeleule44 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Di 10.05.05 13:47 
Okay, habe es jetzt nochmal in alle Einzelteile zerpflückt und kann das Problem umgehen, da es sich nur um eine Teilformel handelt.

Ich muss den berechneten Wert jetzt einfach nur mal die Anzahl der Rechenschritte nehmen und dann wieder einsetzen.

Also D1= (.....) mal 1 für ersten Rechenschritt.


Lautet dann meine Formel einfach

D:= (.........) *k

oder wie muss ich das schreiben?