Skip to content

Repository files navigation

Python Advanced Calculus & Analysis Toolkit

A comprehensive collection of 30 Python programs implementing numerical methods for advanced calculus and mathematical analysis. Each program is self-contained, educational, and demonstrates step-by-step computation with clear output.

No external dependencies beyond NumPy — every algorithm is implemented from scratch.


Table of Contents


Categories

01 — Root Finding Methods

#ProgramMethodExample ProblemConvergence
1bisection.pyBisection Methodx³ − x − 2 = 0 on [1, 2]Linear (½)
2newton_raphson.pyNewton-Raphson Methodcos(x) − x = 0, x₀ = 0.5Quadratic
3secant.pySecant Methodx³ − 2x − 5 = 0 on [2, 3]Superlinear (≈1.618)
4fixed_point.pyFixed-Point Iterationx³ + x − 1 = 0Linear

02 — Linear Algebra

#ProgramMethodExample ProblemFeatures
5gaussian_elimination.pyGaussian Elimination3×3 system, partial pivotingStep-by-step elimination
6lu_decomposition.pyLU Decomposition4×4 system (Doolittle)L, U, P matrices
7jacobi.pyJacobi Iterative MethodDiagonally dominant 3×3Convergence tracking
8gauss_seidel.pyGauss-Seidel MethodSame 3×3 systemSpeed comparison vs Jacobi

03 — Interpolation & Approximation

#ProgramMethodExample ProblemKey Output
9lagrange.pyLagrange Interpolationf(x) = x³ at 5 pointsBasis polynomial values
10newton_divided_diff.pyNewton Divided Differenceeˣ at 4 pointsFull DD table
11cubic_spline.pyNatural Cubic Spline5 data pointsCoefficients per interval

04 — Numerical Integration

#ProgramMethodExample ProblemAccuracy
12trapezoidal.pyComposite Trapezoidal∫sin(x)dx, [0, π]O(h²) convergence
13simpson.pySimpson's 1/3 Rule∫eˣdx, [0, 1]O(h⁴) convergence
14romberg.pyRomberg Integration∫4/(1+x²)dx, [0, 1] → πRichardson extrapolation
15gaussian_quadrature.pyGauss-Legendre (1–5 pt)∫e^(−x²)dx, [−1, 1]Nodes & weights

05 — Numerical Differentiation

#ProgramMethodExample ProblemDemonstrates
16finite_differences.pyForward/Backward/Centralf(x) = x³ at x = 2O(h) vs O(h²) error
17richardson_extrapolation.pyRichardson Extrapolationf(x) = eˣ at x = 11st & 2nd derivatives
18higher_order_derivatives.py1st–4th derivativesf(x) = sin(x) at π/4Round-off tradeoffs

06 — ODE Solvers

#ProgramMethodExample ProblemOrder
19euler.pyForward Eulery' = x + y, y(0) = 11st
20runge_kutta4.pyClassical RK4y' = −2xy, y(0) = 14th
21adams_bashforth.pyAdams-Bashforth (2 & 4 step)y' = x² + y2nd & 4th
22shooting_method.pyShooting Method (BVP)y'' = −y, BCs at 0 and π/2BVP solver

07 — Eigenvalue Problems

#ProgramMethodExample ProblemFinds
23power_method.pyPower Method3×3 symmetric matrixDominant eigenvalue
24qr_algorithm.pyQR Algorithm (Gram-Schmidt)3×3 tridiagonalAll eigenvalues
25jacobi_eigenvalue.pyJacobi Rotation3×3 symmetricEigenvalues + eigenvectors

08 — Advanced Analysis

#ProgramMethodExample ProblemTopics
26fourier_series.pyFourier SeriesSquare waveGibbs phenomenon
27gradient_descent.pyGradient DescentRosenbrock functionLearning rate effects
28newton_optimization.pyNewton's OptimizationQuadratic minimizationHessian-based search
29polynomial_curve_fitting.pyLeast Squares FittingNoisy sin(x) dataUnder/overfitting
30heat_equation_1d.py1D Heat Equation (FTCS)u_t = α·u_xxPDE solver

Quick Start

# Clone the repository
git clone https://github.com/yourusername/python-calculus-analysis.git
cd python-calculus-analysis
# Install dependencies
pip install -r requirements.txt
# Run any single program
python src/01_root_finding/bisection.py
python src/06_ode_solvers/runge_kutta4.py
python src/08_advanced_analysis/heat_equation_1d.py

Output Example

Every program prints a formatted, step-by-step output. For example, bisection.py:

Bisection Method for f(x) = x^3 - x - 2
Searching on interval [1.000, 2.000]
Iter | a | b | f(a) | f(b) | c | f(c) | Error
-----|---------|---------|---------|---------|---------|----------|----------
1 | 1.00000 | 2.00000 | -2.0000 | 4.0000 | 1.50000 | -0.12500 | 0.50000
2 | 1.50000 | 2.00000 | -0.1250 | 4.0000 | 1.75000 | 1.35938 | 0.25000
...
Result: Root = 1.521379706799053 in 33 iterations

Running All Programs

# Run all 30 programs
python run_all.py
# Run only a specific category
python run_all.py 01 # Root Finding
python run_all.py 04 # Integration
python run_all.py 08 # Advanced Analysis

Requirements

PackageVersionPurpose
NumPy>= 1.21.0Array operations, linear algebra (verification only)
Python>= 3.8f-strings, type hints

Note: All numerical algorithms are implemented from scratch using only NumPy for array operations. No SciPy dependency is required.


Project Structure

python-calculus-analysis/
├── README.md # This file
├── LICENSE # MIT License
├── requirements.txt # Python dependencies
├── run_all.py # Run all programs at once
├── src/
│ ├── 01_root_finding/
│ │ ├── bisection.py
│ │ ├── newton_raphson.py
│ │ ├── secant.py
│ │ └── fixed_point.py
│ ├── 02_linear_algebra/
│ │ ├── gaussian_elimination.py
│ │ ├── lu_decomposition.py
│ │ ├── jacobi.py
│ │ └── gauss_seidel.py
│ ├── 03_interpolation/
│ │ ├── lagrange.py
│ │ ├── newton_divided_diff.py
│ │ └── cubic_spline.py
│ ├── 04_integration/
│ │ ├── trapezoidal.py
│ │ ├── simpson.py
│ │ ├── romberg.py
│ │ └── gaussian_quadrature.py
│ ├── 05_differentiation/
│ │ ├── finite_differences.py
│ │ ├── richardson_extrapolation.py
│ │ └── higher_order_derivatives.py
│ ├── 06_ode_solvers/
│ │ ├── euler.py
│ │ ├── runge_kutta4.py
│ │ ├── adams_bashforth.py
│ │ └── shooting_method.py
│ ├── 07_eigenvalues/
│ │ ├── power_method.py
│ │ ├── qr_algorithm.py
│ │ └── jacobi_eigenvalue.py
│ └── 08_advanced_analysis/
│ ├── fourier_series.py
│ ├── gradient_descent.py
│ ├── newton_optimization.py
│ ├── polynomial_curve_fitting.py
│ └── heat_equation_1d.py
├── examples/
│ └── ... # Example usage and tutorials
└── tests/
└── ... # Unit tests (optional)

Design Principles

  1. Self-Contained: Each program is a standalone script — run it directly with python script.py
  2. Educational: Step-by-step output shows every iteration and intermediate computation
  3. No Black Boxes: All algorithms implemented from scratch; NumPy only used for array ops and verification
  4. Verified: Every program compares its numerical result against known analytical solutions
  5. Documented: Comprehensive docstrings with mathematical formulas, complexity analysis, and references

License

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages