Bisection method example [closed]

I'm writing a small program to resolve functions using bisection method. I want to test the case when the method finds 2 roots, but I can't find examples.

Can anyone give me an example of a function that when resoved using bisection method gives 2 roots?

My only request is that when evaluated, the function does not evaluate 0 (because f(a)*f(b) using 0 will give 0).

Thanks.

• Usually the bisection method is written so that it only finds one root at a time between $a$ and $b$. Maybe you can modify your method so that after finding one root, it changes the endpoints $a$ and $b$ to look for another root? Commented Apr 1, 2013 at 0:10
• I am confused about what you mean. Are you looking for a $f(x) = ax^2 + bx + c$ with two unique roots or two identical roots or something else? Commented Apr 1, 2013 at 0:11
• @deezy: I need to find 2 roots. It's mandatory for my program. Commented Apr 1, 2013 at 0:15
• @Amzoti: Any function wich gives 2 roots it's ok. f(x)=(x-1)(x-2) gives me 2 roots (1 and 2), but as I say I don't want to evaluate 0 (f(x)=(x-1)(x-2) evaluates on 0 and 3). Commented Apr 1, 2013 at 0:18

If you evaluate $f(x)$ and get zero, you have found a root. Bisection should report it and move on to the next stage. Consider a function like $f(x)=(x-1)(x-2)$. Somehow you have to find the interval $(a,2)$ where the function is negative. Now you take one point outside $(1,2)$ and one point inside it as your starting points. Bisection will converge on $1$ or $2$ (whichever is in the interval you start with). Say you find $1$. In theory, you can now consider $\frac {f(x)}{x-1}$ and if you can find points with opposite signs you can use bisection again to find the root of that. The problem is that maybe you don't find $1$ exactly, so your new function will not be exactly $g(x)=x-2$, but it will be close.
• You have to bracket the roots first for bisect ion. That is, you need to find $a,b$ with $f(a)f(b) \lt 0$ otherwise you don't know there is a root to find at all. Think about$x^2-x+3$. If you start with $-2,3$ there are no roots inside. Commented Apr 1, 2013 at 1:33