A [[Numerical Analysis]] aproach to solving for the [[Roots|root]] of a [[Continuous]] [[Function]] in some domain, $f\in \mathcal C[a,b]$ (where $[a,b]$ contains the root). We start with an upper and lower domain bound $x_{L}=a$ $x_{R}=b$. For every iteration, we find the midpoint $x_{M}=(x_{L}+x_{R}) \frac{1}{2}$. If $\op{sgn}(f(x_{M})) = \op{sgn}(f(x_{L}))$, then for the next iteration $x_{L}=x_{M}$, else $x_{R}=x_{M}$ for the next iteration. This method works by progressively 'trapping' the root between two known bounds of it (due to the sign difference and it being [[Continuous]]). >[!example] >```rust >let mut x_left = 0; >let mut x_right = 2; >let mut y_left = f(x_left); >let mut y_right = f(x_right); > >while x_right - x_left > err { > let x_mid = (x_left + x_right) / 2.; > let y_mid = f(x_mid); > > if y_mid.sign() == y_left.sign() { > x_left = x_mid; > } else { > x_right = x_mid; > } > >```