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:
| 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.
|