Skip to content

arindam-codes/general-root-finder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

General Root Finder (Bisection Method)

Overview

This project implements a general root-finding algorithm using the bisection method.
The goal was to translate mathematical intuition from calculus into a working computational algorithm.


Motivation

While studying Chapter 4 of Guttag’s book, I initially struggled to fully internalize the bisection approach.
Instead of memorizing the method, I decided to rebuild it from first principles.

The key realization was that efficient root-finding depends on correctly identifying boundaries that contain a root.
Reducing the search space early makes the algorithm both correct and fast.


Mathematical Insight

From James Stewart’s Calculus, I used the idea that:

If a real root exists, the function must cross the x-axis at least once.

This implies that a root exists in an interval where: f(x) * f(x + Δx) < 0

Using this idea, I scanned for sign changes to automatically determine valid boundaries for the bisection process.


Approach

The implementation is structured into three main components:

1. boundary_finder()

  • Iteratively searches for an interval where the function changes sign
  • Uses a while loop with incremental steps
  • Returns the lower and upper bounds that contain a root

2. bisection_search()

  • Applies the bisection method within the identified boundaries
  • Repeatedly halves the interval until convergence

3. find_root()

  • Combines boundary detection and bisection search
  • Returns:
    • the root estimate
    • the number of iterations required

Testing

A separate test function, test_find_root(), was implemented to validate correctness.

  • Tests 27 different combinations of parameters
  • Ensures robustness across multiple scenarios
  • Verifies convergence behavior and iteration counts

What I Learned

  • How calculus concepts translate into computational algorithms
  • Why boundary selection is critical for numerical methods
  • How abstraction helps structure problem-solving
  • How to build algorithms incrementally instead of copying formulas

References

Concepts and inspiration were drawn from:

  • MIT 6.100L
  • Guttag, Introduction to Computation and Programming
  • Think Python
  • James Stewart, Calculus

Notes

This project reflects my learning process and focuses on understanding over optimization.
Future improvements could include:

  • adaptive step sizing for boundary detection
  • support for other root-finding methods

About

general root finder using bisection algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages