Zum Inhalt springen

Datei:Bisection method.gif

Aus MOOCsWiki Staging
Originaldatei (480 × 289 Pixel, Dateigröße: 841 KB, MIME-Typ: image/gif, Endlosschleife, 116 Bilder, 12 s)
Hinweis: Aufgrund technischer Beschränkungen werden Vorschaubilder hochauflösender GIF-Dateien wie dieser nicht animiert.

Diese Datei stammt aus Wikimedia Commons und kann von anderen Projekten verwendet werden. Die Beschreibung von deren Dateibeschreibungsseite wird unten angezeigt.

Beschreibung

Beschreibung
English: Finding the roots of a function is a very common problem in computational Physics, and the bisection method is a simple and effective (albeit far from optimal) way to do that. The idea is that you start by "bracketing" your root between a value where the function is negative and one where it is positive. You then take the midpoint between them, check if your function there is positive or negative and update the bracket.
Datum
Quelle https://mathstodon.xyz/@j_bertolotti/114834711962600450
Urheber Clodovendro
Genehmigung
(Weiternutzung dieser Datei)
https://mathstodon.xyz/@j_bertolotti/114533575175127912

Mathematica 14.0 code

f[x_] := Tan[x] - Sqrt[(8/x)^2 - 1];
negativebraket = 0.5;
positivebraket = 1.5;
bracketlist = {{negativebraket, positivebraket}};
Do[
 midpoint = Mean[{negativebraket, positivebraket}];
 tmp = Transpose[{{negativebraket, midpoint, positivebraket}, 
 Sign[f[#] & /@ {negativebraket, midpoint, positivebraket}]}];
 negativebraket = Sort[Select[tmp, #[[2]] < 0 &], #1[[2]] < #2[[2]] &][[1, 1]];
 positivebraket = Sort[Select[tmp, #[[2]] > 0 &], #1[[2]] < #2[[2]] &][[-1, 1]];
 AppendTo[bracketlist, {negativebraket, positivebraket}];
 , 30];
speedstep[t_] := t^2;
plot1[a_, b_, t_] := 
  Plot[f[x], {x, 0.5, \[Pi]/2}, PlotStyle -> Black, 
   AxesLabel -> {"z", 
     "tan(z)-\!\(\*SqrtBox[\(\*SuperscriptBox[\((\*SubscriptBox[\(z\),\
 \(0\)]/z)\), \(2\)] - 1\)]\)"}, LabelStyle -> {Bold, Black},
   Epilog -> {PointSize -> 0.02, Red, 
     Point[{{a + speedstep[t] ((a + b)/2 - a), 
        0}, {b + speedstep[t] ((a + b)/2 - b), 0}}], Gray, 
     Point[{{a, 0}, {b, 0}}], Opacity[0.3], 
     Rectangle[{-10, -100}, {a, 100}], Rectangle[{b, -100}, {10, 100}]}];
plot2[a_, b_, t_] := 
  Plot[f[x], {x, 0.5, \[Pi]/2}, PlotStyle -> Black, 
   AxesLabel -> {"z", 
     "tan(z)-\!\(\*SqrtBox[\(\*SuperscriptBox[\((\*SubscriptBox[\(z\),\
 \(0\)]/z)\), \(2\)] - 1\)]\)"}, LabelStyle -> {Bold, Black},
   Epilog -> {PointSize -> 0.02 (1 - t), Red, Point[{(a + b)/2, 0}], 
     Line[{{(a + b)/2, -30*speedstep[t]}, {(a + b)/2, 30*speedstep[t]}}],
      Gray, PointSize -> 0.02, Point[{{a, 0}, {b, 0}}], Opacity[0.3], 
     Rectangle[{-10, -100}, {a, 100}], Rectangle[{b, -100}, {10, 100}]}];
plot3[a_, b_, a1_, b1_, t_] := 
  Plot[f[x], {x, 0.5, \[Pi]/2}, PlotStyle -> Black, 
   AxesLabel -> {"z", 
     "tan(z)-\!\(\*SqrtBox[\(\*SuperscriptBox[\((\*SubscriptBox[\(z\),\
 \(0\)]/z)\), \(2\)] - 1\)]\)"}, LabelStyle -> {Bold, Black},
   Epilog -> {Opacity[1 - t], Red, 
     Line[{{(a + b)/2, -30}, {(a + b)/2, 30}}], Opacity[1], Gray, 
     PointSize -> 0.02, 
     Point[{{a + speedstep[t] (a1 - a), 0}, {b + speedstep[t] (b1 - b),
         0}}], Opacity[0.3], 
     Rectangle[{-10, -100}, {a + speedstep[t] (a1 - a), 100}], 
     Rectangle[{b + speedstep[t] (b1 - b), -100}, {10, 100}]}];
frames = 
  Flatten@Table[
    Join[Table[
      plot1[bracketlist[[j, 1]], 
       bracketlist[[j, 2]], \[Tau]], {\[Tau], 0, 1, 1/(
       15 (bracketlist[[j, 2]] - bracketlist[[j, 1]]))}], 
     Table[plot2[bracketlist[[j, 1]], 
       bracketlist[[j, 2]], \[Tau]], {\[Tau], 0, 1, 1/5}], 
     Table[plot3[bracketlist[[j, 1]], bracketlist[[j, 2]], 
       bracketlist[[j + 1, 1]], 
       bracketlist[[j + 1, 2]], \[Tau]], {\[Tau], 0, 1, 1/(
       15 (bracketlist[[j, 2]] - bracketlist[[j, 1]]))}] ], {j, 1, 8}];
ListAnimate[frames]

Lizenz

Ich, der Urheber dieses Werkes, veröffentliche es unter der folgenden Lizenz:
Creative Commons CC-Zero Diese Datei wird unter der Creative-Commons-Lizenz CC0 1.0 Verzicht auf das Copyright zur Verfügung gestellt.
Die Person, die das Werk mit diesem Dokument verbunden hat, übergibt dieses weltweit der Gemeinfreiheit, indem sie alle Urheberrechte und damit verbundenen weiteren Rechte – im Rahmen der jeweils geltenden gesetzlichen Bestimmungen – aufgibt. Das Werk kann – selbst für kommerzielle Zwecke – kopiert, modifiziert und weiterverteilt werden, ohne hierfür um Erlaubnis bitten zu müssen.

Kurzbeschreibungen

Ergänze eine einzeilige Erklärung, was diese Datei darstellt.
Starting with a bracket that contains a root of the function, one divide that region in two and update the bracket, converging to the root position.

In dieser Datei abgebildete Objekte

Motiv

861.594 Byte

289 Pixel

480 Pixel

image/gif

b811a105ce7dc9d5848dc9631c46d05e5b3ca9f7

Dateiversionen

Klicke auf einen Zeitpunkt, um diese Version zu laden.

Version vomVorschaubildMaßeBenutzerKommentar
aktuell10:53, 18. Jul. 2025Vorschaubild der Version vom 10:53, 18. Jul. 2025480 × 289 (841 KB)wikimediacommons>ClodovendroUploaded own work with UploadWizard

Die folgende Seite verwendet diese Datei: