Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Quadratische und Lineare Funktion (https://www.delphipraxis.net/14200-quadratische-und-lineare-funktion.html)

ichbins 31. Okt 2005 18:27

Re: Quadratische und Lineare Funktion
 
ne, math brauchst du für power und min/max. sqrt is noch in system.

eine Möglichkeit die fehler abzufangen:
Delphi-Quellcode:
var
  a,b,c,d:extended;
begin
  a:=StrToFloat(Ea.Text);
  b:=StrToFloat(Eb.Text);
  c:=StrToFloat(Ec.Text);
  d:=b*b-4*a*c;
  if d<0 then begin
    messagedlg('Radikant kleiner Null -> keine schnittstellen');
    exit;
  end;
  if d=0 then begin
    showmessage('Eine Schnittstelle: '+floattostr(-b / (2 * c)));
    exit;
  end;
  if d>0 then begin
    showmessage('2 Schnittstellen: '#13'1. = '+floattostr(( (-b) + (sqrt( (b*b) - (4 * a * c))) ) / (2 * c))+#13'2. = '+floattostr(( (-b) - (sqrt( (b*b) - (4 * a * c))) ) / (2 * c)));
  end;

alzaimar 31. Okt 2005 19:40

Re: Quadratische und Lineare Funktion
 
Absolut korrekt. Eine Kleinigkeit. d=0 wird wohl nie zutreffen, da es sich um Gleitkommazahlen handelt. Vergleiche lieber so:
Delphi-Quellcode:
If Abs (d) < 1E-8

Khabarakh 31. Okt 2005 21:39

Re: Quadratische und Lineare Funktion
 
Wenn die Diskriminante ("so ziemlich") 0 ist, sollte man die Wurzel gleich durch 0 ersetzen. Sonst wirft sqrt noch eine Exception, weil d vielleicht doch -1E-10 ist.

PS: Heißt der Nenner nicht 2a :zwinker: ?


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:07 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz