Hi all,

For have implemented a program that performs the bisection method, currently with the user entering the initial interval to find one root. However I was wondering if I could get the program to find the intervals automatically without the users input.

The only way I can think to do this is by using the intermediate value theorem, and calculating the function values over a certain range.

E.g for x^2 - 9 = 0

f(-4) = 7
f(-3) = 0
f(-2) = -5
f(-1) = -8
f(0) = -9

so we know there is a root when the sign changes etc. so obviously I can tell this from looking, but I'm struggling for a way of how to get c++ to recognise this? Could anyone please give me a push in the right direction?

Thanks in advance!

Compare each value to zero, if f(0) < 0 && f(1) > 0 then search in between them (so theoretically you could space your function values at say 5 apart or something and then zero in on it. 5->2.5->1.25 within one interval.