Autor Beitrag
erikh112
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

WIN 2000

BeitragVerfasst: Fr 14.07.06 20:41 
hallo gemeinde,

habe folgendes Problem:

Ich rechnen einen Wert aus in einer Real-Variable, danach will ich diesen in ein Stringgrid schreiben.
Allerdings steigt delphi bei der berechnung schon aus, ich vermute, dass der errechnete wert bereits zu groß ist.
(Meldung: Ungültige Gleitkommaoperation!, dabei markiert er einen sehr komplexe formel.)

Habt ihr da ein Tip?
Bisher dachte ich es reicht, das endergebnis beim umwandeln zu runden, aber das schein wohl zu spät zu sein...

Hoffe ihr könnt mir weiterhelfen.

Danke

Gruß

E
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Fr 14.07.06 20:46 
Hallo erikh112
Allgemein poste bitte mal den betreffenden Code
Mein Tipp ist die Formeln auf mehrere Zeilen aufzuteilen. Nutze Zusatzvariblen für Zwischenergebenisse.
aus z.B.

ausblenden Quelltext
1:
aZahl:=e*(t/z);					


wird

ausblenden Quelltext
1:
2:
a1:=t/z;
aZahl:=e*a1;
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 14.07.06 20:47 
Also mit der Rundung hat dein Problem nichts zu tun. Wie sieht den die berechnung aus?

_________________
Markus Kinzler.
erikh112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

WIN 2000

BeitragVerfasst: Fr 14.07.06 21:23 
so sieht die funktion aus:
ausblenden 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:
 function berechnung_winkel_alpha(a,b,c,d,e,r,cf,l0,m,N: real):real;
    var g: real;
    begin
    g:=9.81;
    alpha:=-1*(pi/4);
    alpha_schritt:=(pi/36000);

    r12:=sqrt(a*a+b*b+c*c-2*b*c*cos(alpha)+2*a*c*sin(alpha));

    alt:=((c*cf)/r12)*((r12-l0)*(r12-l0)*(r12-l0))*(a*cos(alpha)+b*sin(alpha))+((N*e-d*m*g)*cos(alpha))-(N*r*sin(alpha));
     --> danach steigt er aus!!!

    repeat

    alpha:=alpha+alpha_schritt;

    r12:=sqrt(a*a+b*b+c*c-2*b*c*cos(alpha)+2*a*c*sin(alpha));

    neu:=((c*cf)/r12)*((r12-l0)*(r12-l0)*(r12-l0))*(a*cos(alpha)+b*sin(alpha))+((N*e-d*m*g)*cos(alpha))-(N*r*sin(alpha));

    until alt*neu<0;

    berechnung_winkel_alpha:=alpha*(180/pi)*(-1);


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 14.07.06 21:28 
Um die Genauigkeit zu erhöhen würde ich statt Real Extended nehmen.
Versuche mal die Berechnung in mehrere Teilschritte zu zerlegen.
Welchen Typ hat alt/neu?

_________________
Markus Kinzler.
erikh112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

WIN 2000

BeitragVerfasst: Sa 15.07.06 18:58 
alt und neu sind auch real-typen.

Jetzt klappt die berechnung mit den extended typen. danke, allerdings steigt das programm immernoch beim eintragen in die string grid aus..

folgendes ist gecoded:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
zwischenwert : extended;
begin
    N:=StrtoFloat(E_N.Text);
    kraft_start:=0;
    kraft_schritt:=N/100;

    Form2.stringgrid1.rowcount:=102;

    for i:=1 to 100 do
    N:=kraft_start;
    Form2.Stringgrid1.Cells[0,2]:=Floattostr(kraft_start+i*kraft_schritt);
    zwischenwert:=berechnung_winkel_alpha(a,b,c,d,e,r,cf,l0,m,N);
    Form2.Stringgrid1.Cells[1,i]:=FloattostrF(zwischenwert,ffFixed,10,2);
    N:=(kraft_start+i*kraft_schritt);
    Form2.show;
end;


weiß jemand woran es liegt??
danke

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 15.07.06 20:44 
Was für ein Fehler kommt?
Vielleicht liegt es an den Grenzen.
Wie groß ist das stringGrid (.ColCount/.RowCount)?

Noch ein paar Anmerkungen, du verwendest globale variablen, das ist gefährlich.
Verwende bitte die Delhpi-Tags, dann ist der Code besser lesbar.

_________________
Markus Kinzler.
erikh112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

WIN 2000

BeitragVerfasst: So 16.07.06 16:34 
danke problem hat sich erledigt.. manchmal soll auch viel probieren helfen ;) einen schönen tag noch