Abt. BISECTION-Algorithmus
===================
Bei der rechnerischen Lösung einer u.U. sehr komplizierten Gleichung 'F(x)=Vorgabewert', also der Suche all jener x-Werte, bei denen die Gleichung erfüllt bzw. 'wahr' ist, ordnet man üblicherweise die Gleichung um zu f(x) - Vorgabewert = 0 und sucht nach den Nullstellen. Das BISECTION(= Unterteilungs-)Verfahren war dabei einer der allerersten erfolgreich angewendeten Computeralgorithmen, und hat sich bis heute als sehr robuste
Methode bewährt, soll heißen: Das Verfahren liefert - abhängig vom angebenen Suchbereich - mit Sicherheit genau einen exakten Nulldurchgang der Funktion als Lösung, falls eine solche Lösung existiert. Weiterer Vorteil: Die gefundenen Lösungen gelten als "technisch stabil".
Dies Stabilität wird aus Sicht der Mathematik-Puristen allerdings duch einen Nachteil erkauft: Es werden nur Lösungen gefunden, die die x-Achse tatsächlich schneiden, also in der Nähe der Lösungspunkte sowohl positive als auch negative y-Achsenwerte besitzen. Mit anderen Worten: Der Algorithmus kann keine Lösungen ermitteln, die durch bloße Berührung der x-Achse
nur von oben oder nur von unten *) gegeben wären.
Gruss
P.S.: *) In solchen Fällen wäre Verfahren wie "Regula falsi" oder "Newton-Raphson" geeigneter, beide haben allerdings auch wieder ihre Vor- und Nachteile. Achtung, die untenstehende Variante ist der reinste
GOTO-Friedhof!
' ACM TOMS Algorithm 4 'BISECTION'
'{Depending on 4 start parameters, BISEC finds one x where Function y=F(x)=0
' Original Fortran Source by S. Gorn from http://www.netlib.org/toms/4.gz
' (C) Feb.1960 by ACM-TOMS Association of Computing Machinery
' ----------------------------------------------------------------------------
' (D) Demo-Migration to XProfan-11.2a in 2014-11 by P.Specht, Vienna (Austria)
' Es bestehen Urheberrechte Dritter! No Warranty Whatsoever! Ohne jede Gewähr!
' ----------------------------------------------------------------------------
' Description (F99): Date: Sun, 12 Feb 95 18:54:30 +0000
' Here is a transcription of algorithm #4 from Collected Algorithms
' from ACM. I had to modify some characters to make it fit into ASCII,
' specially the multiplicative operator has become * and greek letters
' are substituted by their equivalent names.
' Jose R. Valverde, European Bioinformatics Institute, txomsy@ebi.ac.uk
' ------------------------------------------------------------------------------
' Original Algorithm 4: BISECTION ROUTINE
' by S. Gorn, Univeristy of Pennsylvania Computer Center, Philadelphia, Pa.
' ------------------------------------------------------------------------------
' Comment: This procedure evaluates a function at the end-points
' of a real interval, switching to an error exit (fools
' exit) FLSXT if there is no change of sign. Otherwise
' it finds a root by iterated bisection and evaluation
' at the midpoint, halting if either the value of the
' function is less than the free variable epsilon, or two
' successive approximations of the root differ by less
' than epsilon1. Epsilon should be chosen of the order of
' error in evaluating the function (otherwise time would be
' wasted), and epsilon1 of the order of desired accuracy.
' Epsilon1 must not be less than two units in the last place
' carried by the machine or else indefinite cycling will
' occur due to roundoff on bisection. Although this
' method is of 0 order, and therefore among the slow-
' est, it is applicable to any continuous function. The
' fact that no differentiability conditions have to be
' checked makes it, therefore, an 'old work-horse'
' among routines for finding real roots which have
' already been isolated. The free varaibles y1 and y2
' are (presumably) the end-points of an interval within
' which there is an odd number of roots of the real function F.
' Alpha is the temporary exit fot the evaluation of F.;
'---------------------------------------------------------------
'---------------------------------------------------------------
' CERTIFICATION OF ALGORITHM 4
' BISECTION ROUTINE (S. Gorn, _Comm._ACM_, March 1960), Program by
' Patty Jane Rader,* Argonne National Laboratory, Argonne, Illinois
'
' Bisec was coded for the Royal Precision LGP-30 computer, using inter-
' pretive floating point system (24.2) with 28 bits of significance.
'
' The following minor correction was found necessary.
' alpha: go to gamma[1] should be go to gamma[i]
' After this correction was made, the program ran smoothly for
' F(x) = cos x, using the following parameters:
'---------------------------------------------------------------
' y1 y2 Epsilon Epsilon1 Results
'---------------------------------------------------------------
' 0 1 .001 .001 FLSXT
' 0 2 .001 .001 1.5703
' 1.5 2 .001 .001 1.5703
' 1.55 2 .1 .1 1.5500
' 1.5 2 .001 .1 1.5625
'---------------------------------------------------------------
' These combinations test all loops of the program.
' *) Work supported by the U. S. Atomic Energy Commission.
'}
'---------------------------------------------------------------
'{TESTPROGRAMM
CLS
Font 2
Set("decimals",15)
print "\n Berechnete Testwerte bitte mit den im Kommentar"
print " angegebenen Tabellenresultaten vergleichen: \n"
print " ";format$("%g",BiSec(0,1,0.001,0.001))
print " ";format$("%g",BiSec(0,2,0.001,0.001))
print " ";format$("%g",BiSec(1.5,2,0.001,0.001))
print " ";format$("%g",BiSec(1.55,2,0.1,0.1))
print " ";format$("%g",BiSec(1.5,2,0.001,0.1))
Waitinput
END
'}-------------------------------------------------------------------------
'Function F(x) HIER EINPORGRAMMIEREN!
proc F :parameters x!
return cos(x!)
endproc
'-------------------------------------------------------------------------
'Bisec Routine:
proc BISEC :parameters y1!,y2!,epsilon!,epsilon1!
declare x!,f!,f1!,i&,j&,k&,FLSXT!
FLSXT!=-999999999 'bedeutet ERROR, keine Nullstelle in diesem Bereich
Bisec:
i&=1:j&=1:k&=1:x!=y2!
Alpha:
f!=F(x!) : case abs(f!)<=epsilon!:return x!
if i&=1:goto "First_val" : elseif i&=2:goto "Succ_val" :endif
First_val:
i&=2 : f1!=f! : x!=y1!
goto "Alpha"
Succ_val:
if (f!*f1!)>=0
if j&=1: Print "Keine Nullstelle in diesem Bereich! Error ";:return FLSXT!
elseif j&=2: goto "Reg_delta"
endif
endif
if k&=1:goto "Sec_val" : elseif k&=2:goto "Reg_etha" :endif
Sec_val:
j&=2:k&=2
Midpoint:
x!=(y1!+y2!)/2
goto "Alpha"
Reg_delta:
y2!=x!
Precision:
case (abs(y1!-y2!)>=epsilon1!):goto "Midpoint"
return x!
Reg_etha:
y1!=x!
goto "Precision"
EndProc
Alles anzeigen