Autor Beitrag
Molzer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: So 09.11.08 20:14 
Hallo!
Habe Probleme mit meiner KGl.

meine fehlermeldung ist
"ungültige gleitkommaoperation"
hat das damit zutun, dass ich real werte habe?


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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
  var
    x: array[1..6of Real;
    y: array[1..5of Real;
    a,b,c,d: Real;
    p,q,dis,u,v,fi: Real;
    Spruch: String ;

procedure TForm2.BtBerClick(Sender: TObject);
begin
      try
      a:=StrtoFloat(eda.Text);
      b:=StrtoFloat(edb.Text);
      c:=StrtoFloat(edc.Text);
      d:=StrtoFloat(edd.Text);

      except
      if (eda.Text='')or(edb.Text='')or(edc.Text='')or(edd.Text='')
      then showmessage ('Bitte alle Werte eingeben')

      end;

      if a= 0 then Spruch := 'Das ist keine Gleichung 3.Grades !!!'

      else begin
      p:= (3*c*a-b*b)/3*sqr(a);
      q:= (2*power(b,3)-9*a*b*c+27*a*a*d)/27*a*a*a;
      dis:= (q/2)*(q/2)+(p/3)*(p/3);

      if dis > 0 then begin
      u:= power(-q/2+sqrt(d),1/3);
      v:= power(-q/2-sqrt(d),1/3);

      y[1]:= u+v;
      y[2]:=(-(u+v/2)+(u-v/2))/(sqrt(3));
      y[3]:=(-(u+v/2)-(u-v/2))/(sqrt(3));
      x[1]:=y[1]-(b/(3*a));
      x[2]:=y[2]-(b/(3*a));
      x[3]:=y[3]-(b/(3*a));

      if dis>0 then Spruch :=
         'x1='+floattostr(x[1])+
         'x2='+floattostr(x[2])+
         'x3='+floattostr(x[3]);
      end

      else begin
      if dis<0 then
        fi:= arctan((sqrt(((p/3)*(p/3)*(p/3))-((q/2)*(q/2))))/(-q/2));
        y[4]:=2*sqrt(p/3)*(cos(fi/3));
        y[5]:=-2*sqrt(p/3)*(cos(fi/3-pi/3));
        x[4]:=y[4]-(b/(3*a));
        x[5]:=y[5]-(b/(3*a));
        x[6]:=y[5]-(b/(3*a));

        if dis<0 then Spruch :=
         'x1='+floattostr(x[4])+
         'x2='+floattostr(x[5])+
         'x3='+floattostr(x[6]);

      end
      end;
      Memo.Lines.Add (Spruch);

end;

procedure TForm2.BtEClick(Sender: TObject);
begin
  close //Programm wird beendet
end;

procedure TForm2.BtNGClick(Sender: TObject);
begin
        Eda.Text := '';
        Edb.Text := '';
        Edc.Text := '';
        Edd.Text := '';
end;

end.


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

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: So 09.11.08 20:56 
Wo kommt denn der Fehler??
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: So 09.11.08 20:57 
Ist sicher gestellt, dass bei den Rechenoperationen der Quotient ungleich Null ist, oder der Term unter der Wurzel nicht negativ?

_________________
We are, we were and will not be.
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 09.11.08 21:06 
-> Suche in: Delphi-Forum, Delphi-Library VARCMPLX
-> Suche in: Delphi-Forum, Delphi-Library COMPLEX

@Gausi: Ist bei kubischen Gleichungen doch dachte ich nicht der Fall?
@Molzer: Doch, ich glaube genau daran liegt es.
Molzer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: So 09.11.08 21:43 
danke ich probier mal!
Molzer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: So 16.11.08 00:17 
Nochmal ich!

Wenn D<0 stimmt mein Programm, aber wenn D=0 oder D>0 stimmen sie nicht..

:<




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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    LbUeberschrift: TLabel;
    Eda: TEdit;
    Edb: TEdit;
    Edc: TEdit;
    Edd: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    BtBer: TButton;
    BtNG: TButton;
    BtE: TButton;
    Memo: TMemo;
    Lbx: TLabel;
    procedure BtEClick(Sender: TObject);
    procedure BtBerClick(Sender: TObject);
    procedure BtNGClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

  var
    x: array[1..6of Real;
    y: array[1..6of Real;
    a,b,c,d,hu,hv: Real;
    p,q,dis,u,v,fi: Real;
    Spruch: String ;

procedure TForm2.BtBerClick(Sender: TObject);
begin
      memo.clear;
      try
      a:=StrtoFloat(eda.Text);
      b:=StrtoFloat(edb.Text);
      c:=StrtoFloat(edc.Text);
      d:=StrtoFloat(edd.Text);

      except
      if (eda.Text='')or(edb.Text='')or(edc.Text='')or(edd.Text='')
      then showmessage ('Bitte alle Zahlenwerte eingeben')

      end;
      if a= 0 then Spruch := 'Das ist keine Gleichung 3.Grades !!!'

      else begin
      p:= ((3*c*a)-(b*b))/(3*sqr(a));
      q:= ((2*b*b*b)-(9*a*b*c)+(27*sqr(a)*d))/(27*a*a*a);
      dis:= ((q/2)*(q/2))+((p/3)*(p/3)*(p/3));
      end;

      if (dis>0)or(dis=0)
        then begin
        hu:= (-q/2)+sqrt(dis);
        hv:= (-q/2)-sqrt(dis);
          if hu<0 then begin
          u:=Power((hu*(-1)),(1/3));
          u:=u*(-1);
          end
          else u:=power((hu),(1/3));
            if hv<0 then begin
            v:=Power((hv*(-1)),(1/3));
            v:=v*(-1);
            end
            else v:=Power((hv),(1/3));
            end
      else
      y[1]:= u+v;
      y[2]:=(u-v/2)/(sqrt(3));
      y[3]:=-(u+v/2);

      x[1]:=y[1]-(b/(3*a));
      x[2]:=y[3]-((b/(3*a)));
      x[3]:=y[3]-((b/(3*a)));

      if dis>0 then
         begin
         memo.lines.add('x1='+floattoStrf(x[1],ffNumber,8,4));
         memo.lines.add('x2='+floattoStrf(x[2],ffNumber,8,4)+ FloattoStrf(y[3],ffNumber,8,4)+'i');
         memo.lines.add('x3='+floattoStrf(x[3],ffNumber,8,4)+ FloattoStrf(y[3],ffNumber,8,4)+'i');
         end

      else begin
         memo.lines.add('x1='+floattoStrf(x[1],ffNumber,8,4));
         memo.lines.add('x2='+floattoStrf(x[2],ffNumber,8,4));
         memo.lines.add('x3='+floattoStrf(x[3],ffNumber,8,4));
      end;
        if dis<0 then begin
        memo.clear;
        if p<0 then p:= p*(-1);
        fi:= arctan((sqrt(((p/3)*(p/3)*(p/3))-((q/2)*(q/2))))/(-q/2));
        y[4]:=2*sqrt(p/3)*(cos(fi/3));
        y[5]:=-2*sqrt(p/3)*(cos(fi/3-pi/3));
        y[6]:=-2*sqrt(p/3)*(cos(fi/3+pi/3));
        x[4]:=y[4]-(b/(3*a));
        x[5]:=y[5]-(b/(3*a));
        x[6]:=y[6]-(b/(3*a));
        end;

        if dis<0 then begin
         memo.lines.add('x1='+floattostrf(x[4],ffNumber,10,2));
         memo.lines.add('x2='+floattostrf(x[5],ffNumber,10,2));
         memo.lines.add('x3='+floattostrf(x[6],ffNumber,10,2));

       end;
      end;
procedure TForm2.BtEClick(Sender: TObject);
begin
  close //Programm wird beendet
end;

procedure TForm2.BtNGClick(Sender: TObject);
begin
        memo.clear;
        Eda.Text := '';
        Edb.Text := '';
        Edc.Text := '';
        Edd.Text := '';
end;

end.


Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 16.11.08 00:36 
Setz mal deinen Code bitte zwecks besserer Lesbarkeit in Delphi-Tags, also <span class="inlineSyntax"><span class="codecomment">{PROTECTTAG616b959e776567d8c32a37eab8a85c93}</span></span> außen rum.
Molzer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: So 16.11.08 18:19 
Wurde gemacht!