Thema: Delphi IntervallSchachtelung

Einzelnen Beitrag anzeigen

Benutzerbild von glkgereon
glkgereon

Registriert seit: 16. Mär 2004
2.287 Beiträge
 
#1

IntervallSchachtelung

  Alt 19. Dez 2004, 13:47
moin

ich hab (versucht) ein programm zu schreiben welches eine wurzel mit hilfe einer intervallschachtelung berechnet...

aber irgendwie klappt das nicht so richtig...
hat einer von euch da Quelltexte wies geht?

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var Zahl, i:Integer;
    RootMin, RootMax, RealRoot, Genauigkeit, AktGenau, Stelle:Extended;

begin
  ListBox1.Clear;
  Zahl:=JvIntegerEdit1.Value;
  RealRoot:=sqrt(Zahl);
  for i:=0 to Zahl do if sqr(i+1)>zahl then break;
  RootMin:=i;
  ListBox1.Items.Add('Minimum: '+FormatFloat('000.0000000000',RootMin));
  for i:=zahl downto 0 do if sqr(i-1)<zahl then break;
  RootMax:=i;
  ListBox1.Items.Add('Maximum: '+FormatFloat('000.0000000000',RootMax));
  AktGenau:=1;
  Stelle:=1;
  Genauigkeit:=0.0001;
  ListBox1.Items.Add(FormatFloat('000.0000000000',RootMin / Stelle)+' <= '+FormatFloat('000.0000000000',RealRoot)+' <= '+FormatFloat('000.0000000000',RootMax / Stelle));
  while (AktGenau>Genauigkeit) and (RootMax-RootMin>Genauigkeit) do
    begin
    while RootMax-RootMin>AktGenau do
      begin
      if sqr((RootMax+RootMin) / 2)>zahl
      then RootMax:=RootMax - 1
      else RootMin:=RootMin + 1;
      ListBox1.Items.Add(FormatFloat('000.0000000000',RootMin / Stelle)+' <= '+FormatFloat('000.0000000000',RealRoot)+' <= '+FormatFloat('000.0000000000',RootMax / Stelle));
      Application.ProcessMessages;
      end;
    if (RootMin=RealRoot) or (RootMax=RealRoot) then break;
    Stelle:=Stelle * 10;
    RootMax:=RootMax * 10;
    RootMin:=RootMin * 10;
    end;
end;
»Unlösbare Probleme sind in der Regel schwierig...«
  Mit Zitat antworten Zitat