It is a quite simple method of solving an equation numerically in cases where the exact solution is difficuilt to find. In this method we repetedly bisect an interval into halves until we reach the desired accuracy. It is a consequence of well known mean value theorem of calculus.
I have used the equation x - cos(x) = 0
as a demonstration. This problem is also on the book "Quantum Mechanics" of Schaum Outlines page 256. They have done that in FORTRAN though while my code is on Python (2.7.13). My C version of the same problem can be found here.
The code was written under Debian GNU/Linux in Python IDLE
under Python
.
$ python --version
Python 2.7.13
Here's the code running. The value obtained after 16 iterations can be verified with the book or other sources as well. Also note that we obtained exactly the same value using C as well.
If your maximum iterations is say 20 then you can use,
python bisection.py 20
Alternatively you can also chmod +x bisection.py
and then
./bisection.py 20
Totally RMS approved! While you're at it, please check out GNU and Free Software Foundation as well!