Skip to content

Mrazbb/Numerical-Methods-with-Python

Repository files navigation

Numerical Methods with Python

This repository demonstrates a set of numerical methods implemented in Python, using high-precision arithmetic provided by GMPY2. It covers several mathematical problems including root-finding for equations, numerical integration, solving systems of linear equations, and polynomial interpolation/approximation.

Below is an overview of each file and its purpose, followed by instructions on how to install dependencies and run the examples.


Table of Contents

  1. Project Structure
    1.1 Core Modules
    1.2 Notebooks
  2. Usage Instructions
  3. Dependencies

1. Project Structure

1.1 Core Modules

  1. algorithm.py
    • Defines the base abstract class Algorithm.
    • Provides a precision setup (using GMPY2) and basic iteration tracking (accuracy, iteration counts).
    • Acts as a backbone for all other numerical methods.

  2. rootequation.py
    • Implements root-finding classes, inheriting from Algorithm.

    • RootEquation: Abstract extension specialized for root-finding tasks.
    • Bisection: Standard Bisection method implementation.
    • RegulaFalsi: False Position (Regula Falsi) method.
    • Newton: Newton–Raphson method.
      • Each class tracks precision, iterations, and provides a print_result() method for convenient output.
  3. integral.py
    • Implements numerical integration classes (extending Algorithm):

    • Integral: Base class for integration tasks.
    • RectangularMethod: Uses the midpoint (rectangular) rule with adaptive refinement.
    • TrapezoidalMethod: Uses the trapezoidal rule with adaptive refinement.
  4. interpolation_approximation.py
    • Defines classes to solve interpolation and approximation problems (extending Algorithm):

    • InterpolationApproximation: Base class providing coordinate sorting, result storage, etc.
    • LagrangePolynomial: Implements Lagrange polynomials for interpolation.
    • Approximation: Performs a least squares linear fit.
    • LinearInterpolationSpline: Framework for piecewise-linear interpolation (placeholder example).
  5. linearequations.py
    • Extends Algorithm with classes that solve systems of linear equations:

    • LinearSolver: Base class that reads matrix A and vector b, checks convergence, etc.
    • JacobiMethod & GaussSeidelMethod: Iterative methods for solving systems of linear equations.
  6. requirements.txt
    • Lists all Python dependencies needed to run the project (numpy, gmpy2, sympy, matplotlib, scipy).


1.2 Notebooks

Several Jupyter notebooks showcase how to use these core modules. Each notebook demonstrates an example numerical problem and how to apply the corresponding method:

  1. rootequation.ipynb
    • Uses Bisection, RegulaFalsi, and Newton to find roots of a sample function (e.g., x^(1/2) - 2.5).

  2. integer.ipynb
    • Demonstrates numerical integration methods, calling RectangularMethod and TrapezoidalMethod, and showing how Integral classes refine the computation until desired precision is reached.

  3. interpolation_aproximacion.ipynb
    • Shows how LagrangePolynomial, Approximation, and LinearInterpolationSpline can be used for interpolating or approximating a set of points.

  4. linearequations.ipynb
    • Demonstrates solving linear systems with JacobiMethod and GaussSeidelMethod.


2. Usage Instructions

  1. Clone the Repository
    • Run:
    git clone https://github.com/your_username/your_repository.git
    

cd your_repository

  1. Install Dependencies
    • From the project’s root directory:
    pip install -r requirements.txt
    

  1. Run a Notebook
    • Launch JupyterLab or Jupyter Notebook:
    jupyter notebook
    

• Open one of the supplied .ipynb files (e.g., rootequation.ipynb) to experiment with the numerical methods.

  1. Using the Python Modules Directly
    • You can also import the modules in your own Python scripts or notebooks.
    • For example:
    from rootequation import Bisection, RegulaFalsi, Newton
    
    

my_function = lambda x: x**2 - 4 solver = Bisection(my_function, 10, [[1, 3]]) solver.compute() solver.print_result()


3. Dependencies

All external libraries are listed in requirements.txt:

  • numpy
  • matplotlib
  • sympy
  • gmpy2
  • scipy

These handle numerical arrays (numpy), big-number arithmetic (gmpy2), symbolic operations (sympy), plotting (matplotlib), and advanced computations (scipy).


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •