File:False position method.gif

Uploaded by Clodovendro
Upload date 2025-07-18T09:00:43Z
MIME type image/gif
Dimensions 480 × 289 px
File size 612.2 KB

Summary

Description
English: An improvement over the bisection method is the so-called "false position" method, where instead of dividing the bracket region in two, you cut at the point where the line through the two bracket extremes crosses zero.
Date
Source https://mathstodon.xyz/@j_bertolotti/114852558938672805
Author Clodovendro
Permission
(Reusing this file)
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 = 
  negativebraket - 
   f[negativebraket] (positivebraket - negativebraket)/(
    f[positivebraket] - f[negativebraket]);
 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}];
 , 25];
points = Join[{{#, f[#]} & /@ bracketlist[[1]]},
  Partition[Riffle[
    {#, f[#]} & /@ Flatten@Table[Select[
        Elementwise[If[#1 != #2, #2] &][bracketlist[[j]], 
         bracketlist[[j + 1]]]
        , RealValuedNumericQ]
       , {j, 1, 25}] 
    ,
    {#, f[#]} & /@ Flatten@Table[Select[
        Elementwise[If[#1 == #2, #2] &][bracketlist[[j]], 
         bracketlist[[j + 1]]]
        , RealValuedNumericQ]
       , {j, 1, 25}] 
    ], 2]
  ];
speedstep[t_] := t^2;
bouncestep[t_] := 1 - Sin[\[Pi]/(2 (1 - t))] (1 - t)^2; (**beware of t=1 **);
line[{{x1_, y1_}, {x2_, y2_}}] := Solve[{y1 == m x1 + q, y2 == m x2 + q}, {m, q}][[1]];
plot1[j_, \[Tau]_] := 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}, LabelStyle -> {Bold, Black},
  Epilog -> {PointSize -> 0.02, Red, Point[points[[j]] ], 
    Line[{points[[j, 1]], points[[j, 1]] + speedstep[\[Tau]]*(points[[j, 2]] - points[[j, 1]])}], 
    PointSize -> 0.02*speedstep[\[Tau]], Point[{-q/m /. line[points[[j]]], 0}]}
  ];
plot2[j_, \[Tau]_] := 
 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}, 
  LabelStyle -> {Bold, Black},
  Epilog -> {PointSize -> 0.02, Red, 
    Point[{-q/m /. line[points[[j]]], 
      bouncestep[\[Tau]]*f[-q/m /. line[points[[j]]] ]}], 
    Point[points[[j + 1, 2]]], Opacity[1 - \[Tau]], 
    Point[points[[j]] ], Line[points[[j]] ],}
  ];
frames = Flatten@Table[ Join[Table[plot1[j, t], {t, 0, 1, 0.1}], Table[plot2[j, t], {t, 0, 1 - 10^-5, 0.1}] ], {j, 1, 5}];
ListAnimate[frames]

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Captions

Starting with a bracket that contains a root of the function, one divide the region using the point where the line between the two extremes cross the horizontal axis as the cutting point.

Items portrayed in this file

depicts

14 July 2025

626,906 byte

289 pixel

480 pixel

image/gif

b7340235bf5153b7939ab17e4f7c8b62d97ae33b

Category:Animations of search algorithms Category:CC-Zero Category:Images with Mathematica source code Category:Self-published work