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 public end;
var Form2: TForm2;
implementation
{$R *.dfm}
var x: array[1..6] of Real; y: array[1..6] of 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 end;
procedure TForm2.BtNGClick(Sender: TObject); begin memo.clear; Eda.Text := ''; Edb.Text := ''; Edc.Text := ''; Edd.Text := ''; end;
end. |