A comprehensive Python application with tkinter GUI that implements three numerical methods for solving nonlinear equations: Bisection, Newton-Raphson, and Secant methods.
- Features
- Installation
- Quick Start
- Usage Guide
- Examples
- Method Details
- Contributing
- License
- Acknowledgments
- Bisection Method: Guaranteed convergence with linear rate
- Newton-Raphson Method: Fast quadratic convergence
- Secant Method: Super-linear convergence without derivative
- Solve nonlinear equations using any of the three methods
- Compare all methods simultaneously
- Visualize functions and convergence
- Detailed iteration-by-iteration analysis
- Error tracking and convergence comparison
- Pre-defined test functions
- Custom function input support
- Function plotting with root markers
- Convergence rate graphs (log scale)
- Side-by-side method comparison charts
- Interactive matplotlib plots
- Python 3.7 or higher
- pip package manager
-
Clone the repository
git clone https://github.com/HasithFernando/Numerical-Methods-GUI.git cd Numerical-Methods-GUI -
Install Required Packages
pip install -r requirements.txt
Or install individually:
pip install numpy matplotlib sympy
-
Run the Application
python numerical_methods_gui.py
# Simply run the application
python numerical_methods_gui.py
# Or on Windows
py numerical_methods_gui.pyThen:
- Enter a function (e.g.,
x**3 - 6*x**2 + 11*x - 6) - Select a method (Bisection, Newton-Raphson, or Secant)
- Set parameters
- Click "Solve" or "Compare All Methods"
-
Enter a Function
- Type in the function input box using Python syntax
- Example:
x**3 - 6*x**2 + 11*x - 6 - Or select from predefined functions
-
Select a Method
- Choose between Bisection, Newton-Raphson, or Secant method
- Enter method-specific parameters:
- Bisection: Interval [a, b]
- Newton-Raphson: Initial guess x₀
- Secant: Two initial guesses x₀ and x₁
-
Set Parameters
- Tolerance (default: 1e-6)
- Maximum iterations (default: 100)
-
Solve or Compare
- Click "Solve" to run the selected method
- Click "Compare All Methods" to run all three methods simultaneously
Supported operators and functions:
- Operators:
+,-,*,/,**(power) - Functions:
sin(x),cos(x),tan(x),exp(x),log(x),sqrt(x),abs(x) - Constants:
pi,e - Variable: Always use
xas the variable
-
Polynomial:
x**3 - 6*x**2 + 11*x - 6- Roots at x = 1, 2, 3
-
Transcendental:
cos(x) - x- Root near x ≈ 0.739
-
Exponential:
exp(x) - 3*x**2- Root near x ≈ 0.620
-
Simple:
x**2 - 4- Roots at x = ±2
-
Mixed:
sin(x) - x/2- Root at x = 0 and others
- Function input with predefined options
- Method selection (radio buttons)
- Parameter configuration
- Solve and comparison buttons
- Detailed solution information
- Iteration-by-iteration table
- Function plot with root marker
- Convergence rate graph
- Summary table of all methods
- Detailed analysis (fastest, most accurate)
- Bar charts comparing:
- Number of iterations
- Final error
- Computation time
- Method descriptions
- Convergence properties
- Usage instructions
- Feature list
- Input: Function f(x), interval [a, b], tolerance, max iterations
- Requirement: f(a) and f(b) must have opposite signs
- Convergence: Linear, guaranteed
- Output: Root, iterations, error, iteration history
- Input: Function f(x), initial guess x₀, tolerance, max iterations
- Derivative: Automatically computed using SymPy
- Convergence: Quadratic (when close to root)
- Warning: May diverge with poor initial guess
- Output: Root, iterations, error, iteration history
- Input: Function f(x), two initial guesses x₀ and x₁, tolerance, max iterations
- Advantage: No derivative needed
- Convergence: Super-linear
- Output: Root, iterations, error, iteration history
- Estimated root value (15 decimal places)
- Function value at root f(root)
- Number of iterations
- Final error
- Computation time
- Bisection: a, b, midpoint c, f(c), error
- Newton-Raphson: x, f(x), f'(x), x_new, error
- Secant: x₀, x₁, f(x₁), x₂, error
- Method rankings by speed
- Accuracy comparison
- Performance metrics
- Visual comparisons
-
Bisection Method
- Ensure f(a) and f(b) have opposite signs
- Choose a small interval containing the root
- Works well for all continuous functions
-
Newton-Raphson Method
- Start with a guess close to the expected root
- Avoid points where f'(x) = 0
- Very fast when it converges
-
Secant Method
- Choose initial guesses on opposite sides of root
- Good alternative when derivative is complex
- More robust than Newton-Raphson
-
General
- Use smaller tolerance for higher accuracy
- Increase max iterations for difficult functions
- Compare methods to understand behavior
-
"f(a) and f(b) must have opposite signs"
- Solution: Choose different interval for bisection method
-
"Derivative too close to zero"
- Solution: Change initial guess for Newton-Raphson method
-
"Invalid function"
- Solution: Check function syntax, use
**for power, not^
- Solution: Check function syntax, use
-
"Could not compute derivative"
- Solution: Simplify function or use Secant method instead
-
Method doesn't converge
- Solution: Try different initial values or increase max iterations
numerical-methods-gui/
│
├── numerical_methods_gui.py # Main application file
├── requirements.txt # Python dependencies
├── README.md # This file
├── LICENSE # MIT License
├── CONTRIBUTING.md # Contribution guidelines
└── .gitignore # Git ignore file
- tkinter: GUI framework (included with Python)
- numpy: Numerical computations
- matplotlib: Plotting and visualization
- sympy: Symbolic mathematics (derivative computation)
- Object-oriented design with main
NumericalMethodsGUIclass - Separate methods for each numerical algorithm
- Modular visualization functions
- Error handling and validation
- Real-time computation
- Efficient plotting with matplotlib
- Memory-optimized iteration storage
- Fast symbolic differentiation
This application is designed for the coursework: "Numerical Methods for Solving Nonlinear Equations: Theory and Python Implementation"
- ✅ Theoretical Background (implemented in code comments and About tab)
- ✅ Python Implementation (all three methods fully implemented)
- ✅ Comparative Analysis (comprehensive comparison feature)
- ✅ Report and Documentation (results export and detailed output)
- f(x) = x³ - 6x² + 11x - 6 (roots at x = 1, 2, 3)
- f(x) = cos(x) - x (root near x ≈ 0.739)
- f(x) = eˣ - 3x² (root near x ≈ 0.620)
Function: x**2 - 4
Method: Bisection
Interval: [1, 3]
Result: x = 2.000000Function: cos(x) - x
Method: Newton-Raphson
Initial guess: 0.5
Result: x ≈ 0.739085Function: exp(x) - 3*x**2
All methods tested simultaneously
Best convergence: Newton-Raphson (4 iterations)Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
- 🐛 Report bugs
- 💡 Suggest new features
- 📖 Improve documentation
- 🔧 Submit bug fixes
- ✨ Add new numerical methods
This project is licensed under the MIT License - see the LICENSE file for details.
Developed by Group E:
- Hasith Fernando
- Rumesha Harshan
- Harshana Bandara
- Dinesh Pethiyagoda
- Ayeshi Wasana
- Pathumi Chamuditha
- Ruwani Chandrarathne
Academic Context:
- Course: CS303.3 - Computational Theory
- Institution: NSBM Green University
- Date: November 2025
- Built for educational purposes as part of numerical methods coursework
- Inspired by classical numerical analysis textbooks
- Thanks to the Python scientific computing community
If you have questions or need help:
Give a ⭐️ if this project helped you!
Note: This application provides numerical approximations. For exact analytical solutions, use computer algebra systems like Mathematica or SymPy directly.
Made with ❤️ for learning and education