Skip to content

samwaseee/Numerical-Methods-Visualizer

Repository files navigation

📈 Numerical Methods Visualizer

A robust, interactive web application built with Streamlit and Plotly to visualize and solve non-linear equations using standard numerical analysis techniques.

Designed for students and researchers to understand the behavior of algorithms like Newton-Raphson, Bisection, and Secant methods through step-by-step graphical playback.

🌐 Live Demo

Try it online now (no installation required):
🔗 https://numerical-methods-visualizer.streamlit.app/

Or follow the installation steps below to run it locally on your machine.

Numerical methods are mathematical algorithms used to find approximate solutions to complex problems that cannot be solved analytically. This tool focuses on root-finding methods—techniques to find where a function equals zero. Understanding how these algorithms converge, visualizing their iterations, and analyzing their performance is crucial for numerical analysis studies.

alt text

🚀 Features

🧮 Supported Methods

  • Bracketing Methods: Bisection Method, False Position (Regula Falsi).
  • Open Methods: Newton-Raphson, Secant Method, Fixed Point Iteration.
  • Root Scanner: A "Find All Roots" tool that scans a range to detect multiple sign changes and approximate roots automatically.

📊 Interactive Visualization

  • Step-by-Step Playback: Use a slider to replay the algorithm's progress iteration by iteration.
  • Smart Plotting: * Auto-Zoom: Automatically focuses on the root area while preventing infinite zooming on huge errors.
    • Method-Specific Geometry: Shows Tangent lines (Newton), Secant lines, Cobweb plots (Fixed Point), and Bracketing windows (Bisection).
  • Dynamic Tables: Real-time data tables with Green Highlighting for converged steps and Yellow Highlighting for the active step.

alt text

🛡️ Robust Algorithms

  • Singularity Handling: "Soft landings" for division-by-zero errors (e.g., flat derivatives).
  • Exact Root Detection: Immediately detects and stops if the function hits exactly $0.0$.
  • Dual-Check Convergence: Verifies roots using both Relative Error (%) and Residual Check ($|f(x)| \approx 0$).

alt text

🛠️ Installation & Setup

System Requirements

  • Python: 3.8 or higher
  • OS: Windows, macOS, Linux
  • Memory: Minimum 2GB RAM
  • Browser: Modern browser (Chrome, Firefox, Safari, Edge)

Installation Steps

  1. Clone the repository:

    git clone https://github.com/samwaseee/Numerical-Methods-Visualizer.git
    cd Numerical-Methods-Visualizer
  2. Create a virtual environment (Recommended):

    python -m venv venv
    # Windows:
    venv\Scripts\activate
    # Mac/Linux:
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt

📦 Requirements

The project uses the following Python packages:

streamlit>=1.28.0
plotly>=5.17.0
pandas>=2.0.0
numpy>=1.24.0
sympy>=1.12

Create a requirements.txt file or run:

pip install streamlit plotly pandas numpy sympy

💡 Usage Guide

Quick Start

  1. Launch the application:

    streamlit run app.py

    The app will open in your default browser at http://localhost:8501

  2. Enter a Function:

    • Type any mathematical expression (e.g., x**3 - 2*x - 5, cos(x) - x, exp(x) - 3*x)
    • Supported functions: sin, cos, tan, exp, log, sqrt, abs, etc.
  3. Select a Method:

    • Choose from Bracketing Methods (Bisection, False Position)
    • Or Open Methods (Newton-Raphson, Secant, Fixed Point Iteration)
  4. Configure Parameters:

    • For Bracketing Methods: Set lower bound $a$ and upper bound $b$ (must have $f(a) \cdot f(b) < 0$)
    • For Open Methods: Set initial guess(es) $x_0$ (and $x_1$ for Secant)
    • Tolerance: Set convergence criteria (relative error percentage)
    • Max Iterations: Limit the algorithm runtime
  5. Analyze Results:

    • Use the Iteration Slider to step through each iteration
    • Check the Results Table for detailed metrics (iteration, $x_n$, $f(x_n)$, error)
    • Observe the Interactive Graph showing function behavior and method geometry

Example Use Cases

  1. Finding roots of polynomials: $x^3 - 4x^2 + x + 6 = 0$
  2. Transcendental equations: $e^{-x} = x$, $\sin(x) = 0.1x$
  3. Engineering problems: $f(x) = x - \cos(x)$ (heat transfer)
  4. Comparing algorithm convergence rates between methods
  5. Understanding singularities: Methods that fail on flat derivatives

📂 Project Structure

RootFinder/
├── app.py                          # Main Streamlit entry point
├── algorithms.py                   # Numerical methods implementations (Newton, Secant, Bisection, etc.)
├── requirements.txt                # Python dependencies
├── README.md                       # Project documentation
├── components/                     # Reusable UI components
│   ├── __init__.py
│   ├── graph_plotter.py            # Plotly visualization & smart zoom logic
│   ├── header.py                   # Application header UI
│   ├── math_display.py             # Mathematical expression rendering
│   ├── navbar.py                   # Navigation bar UI
│   ├── results_table.py            # Results table with conditional formatting
│   └── __pycache__/
├── views/                          # Page layouts
│   ├── __init__.py
│   ├── input_page.py               # User input form page
│   ├── dashboard_page.py           # Main analysis dashboard
│   ├── result_page.py              # Detailed results display
│   └── __pycache__/
└── __pycache__/

File Descriptions

File Purpose
app.py Application entry point; orchestrates page routing and state management
algorithms.py Core numerical methods: Newton-Raphson, Secant, Bisection, False Position, Fixed Point Iteration
components/graph_plotter.py Generates interactive Plotly graphs with method-specific geometry (tangent lines, secant lines, cobweb plots)
components/results_table.py Formats and displays iteration tables with color-coded convergence status
views/input_page.py User interface for entering functions and method parameters
views/dashboard_page.py Main dashboard showing real-time visualization and analysis
views/result_page.py Detailed results and convergence metrics

📊 Performance & Limitations

Performance Characteristics

Method Convergence Speed Reliability Requires Derivative
Bisection Linear Slow Very High No
False Position Super-linear Moderate High No
Newton-Raphson Quadratic Very Fast Moderate Yes
Secant Super-linear Fast Moderate No
Fixed Point Linear Depends Variable No

Limitations

  1. Function Input: Currently uses text parsing; complex functions may fail silently
  2. Derivative Calculation: Symbolic derivatives may be slow for complex functions
  3. Numerical Precision: Limited to ~15 decimal places (IEEE 754 double precision)
  4. Large Iterations: Performance degrades with >1000 iterations
  5. Singularities: Vertical asymptotes or undefined regions may cause errors
  6. Multi-valued Functions: Only finds one root per method execution

🐛 Troubleshooting

Common Issues

Q: "Function parsing error" message

  • A: Ensure proper syntax: use ** for powers (not ^), * for multiplication (not implicit)
  • Example: ✓ x**2 + 3*x - 5 vs ✗ x^2 + 3x - 5

Q: Method diverges or doesn't converge

  • A: Check that your initial guess is close to the actual root (for Newton-Raphson)
  • For bracketing methods, ensure $f(a)$ and $f(b)$ have opposite signs

Q: "Derivative is zero" error in Newton-Raphson

  • A: The derivative at that point is zero; try a different initial guess closer to the root

Q: Graph not showing properly

  • A: Try a different function range; very large or very small function values can cause auto-zoom issues

Q: Slow performance

  • A: Reduce the number of maximum iterations or use a simpler function

Getting Help

  • Review the displayed error messages carefully
  • Check that your function uses valid NumPy/SymPy syntax
  • Try a known function like x**2 - 4 (root at $x = 2$) to verify functionality

📝 License

You are free to use, modify, and distribute this software for educational and commercial purposes.

🤝 Contributing

Contributions are welcome! Help improve the visualizer for the community.

How to Contribute

  1. Fork the repository on GitHub
  2. Create a feature branch:
    git checkout -b feature/YourFeatureName
  3. Make your changes and test thoroughly
  4. Commit with clear messages:
    git commit -m 'Add: Description of your feature'
  5. Push to your branch:
    git push origin feature/YourFeatureName
  6. Open a Pull Request with a detailed description

Contribution Ideas

  • Add new numerical methods (Steffensen, Brent's method)
  • Improve error handling and input validation
  • Enhance UI/UX design
  • Add multilingual support
  • Create unit tests and documentation

📚 References & Resources

Numerical Methods References

Tools & Libraries Used

👤 Author & Contact

Developed by: [Samiur Rahman Wasi]

Questions or feedback? Feel free to:

📄 Changelog

Version 1.0 (Initial Release)

  • ✓ Newton-Raphson, Secant, Bisection methods
  • ✓ Interactive visualization with step-by-step playback
  • ✓ Smart auto-zoom for better graph rendering
  • ✓ Comprehensive results tables
  • ✓ Root scanner for finding multiple roots

Last Updated: January 2026
Status: Active Development

About

Numerical methods are the backbone of engineering and scientific computing, yet they can be difficult to grasp through static formulas. This visualizer bridges the gap between theory and practice by allowing users to see how different algorithms 'hunt' for roots in real-time, providing deep insights into convergence rates and potential failure

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages