Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Newton Basins Visualization

This project visualizes the basins of attraction for the roots of a polynomial using the Newton-Raphson method. The visualization is rendered in real-time using a Tkinter GUI.

Features

  • Polynomial Evaluation: Supports complex coefficients and roots.
  • Newton-Raphson Method: Iterative root-finding algorithm.
  • Dynamic Visualization: Displays convergence basins with color-coded roots.
  • Customizable Parameters: Easily modify polynomial coefficients, canvas size, and convergence criteria.

How It Works

  1. Polynomial Definition: The polynomial is defined by its coefficients in ascending order (constant term first).
  2. Newton-Raphson Iteration: For each randomly sampled initial guess, the Newton-Raphson method is applied to find a root.
  3. Root Classification: Roots are classified and assigned unique colors. Points that converge to the same root share the same color.
  4. Real-Time Rendering: The canvas is updated in real-time to show the basins of attraction.

Getting Started

Prerequisites

  • Python 3.7+
  • Required libraries: numpy, tkinter

Installation

  1. Clone the repository:
    git clone <repository-url>
  2. Navigate to the project directory:
    cd Newton-Basins
  3. Install dependencies:
    pip install numpy

Running the Project

To start the visualization, run the following command:

python newton.py

Customization

  • Polynomial Coefficients: Modify the Poli instance in newton.py to change the polynomial.
  • Canvas Size and Limits: Adjust the Basin class initialization to change the visualization area and resolution.

Code Overview

Poli Class

Represents a polynomial and provides methods for evaluation, differentiation, and root classification.

newton_raphson Function

Performs the Newton-Raphson iteration to find a root of the polynomial.

Basin Class

Handles the Tkinter GUI and visualization of the basins of attraction.

Example

The default polynomial is:

P(x) = 48 + 8x + 4x^2 - 10x^3 + 2x^4 - 3x^5 + x^6

The visualization shows the basins of attraction for the roots of this polynomial.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Inspired by the mathematical beauty of fractals and root-finding algorithms.
  • Special thanks to the Python community for providing excellent libraries like numpy and tkinter.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages