A high-performance Python library for advanced linear algebra, numerical interpolation, numerical integration, matrix operations, and linear system solving. Optimized for numerical computing with NumPy BLAS/LAPACK backends.
pip install avlgmath- Interpolation Methods: Newton Forward/Backward Difference, Lagrangian
- Numerical Integration: Trapezoidal Rule, Simpson's 1/3 Rule with error estimation
- Linear Algebra: Matrix operations, eigenvalues, eigenvectors, rank computation
- Linear System Solving: Jacobi iteration method
- Vector Analysis: Dependence checking
- Differential Equations: First-order linear ODE solver
- Taylor Series: Taylor theorem expansions for 1 and 2 variables
import numpy as np
from avlgmath import *
# Newton Forward Difference Interpolation
X = np.array([0, 1, 2, 3])
Y = np.array([1, 3, 7, 13])
table = nfd(X, Y)
y_interp = nfd_interpolate(X, Y, 1.5)
# Matrix Operations
A = np.array([[1, 2], [3, 4]])
eigenvalues = eigenval(A)
# Jacobi Iteration
A = np.array([[4, -1], [-1, 3]])
b = np.array([7, 5])
result = jacobi_iter(A, b, n=20)Newton Forward Difference Table - Creates difference table for equally spaced points
| Parameter | Type | Description |
|---|---|---|
| X | numpy array | x-coordinates (equally spaced) |
| Y | numpy array | y-coordinates |
| Returns | numpy array | 2D array of differences |
X = np.array([0, 1, 2, 3, 4])
Y = np.array([1, 2, 5, 10, 17])
table = nfd(X, Y)Newton Forward Difference Interpolation - Interpolates value at point x
| Parameter | Type | Description |
|---|---|---|
| X | numpy array | x-coordinates (equally spaced) |
| Y | numpy array | y-coordinates |
| x | float | Point at which to interpolate |
| Returns | float | Interpolated value |
X = np.array([0, 1, 2, 3])
Y = np.array([1, 2, 5, 10])
y_at_1_5 = nfd_interpolate(X, Y, 1.5) # ≈ 3.375Load Newton forward difference from CSV file
| Parameter | Type | Description |
|---|---|---|
| path | str | Path to CSV file with columns 'x' and 'y' |
| Returns | numpy array | Difference table |
Newton Backward Difference Table - Creates difference table from end points
| Parameter | Type | Description |
|---|---|---|
| X | numpy array | x-coordinates (equally spaced) |
| Y | numpy array | y-coordinates |
| Returns | numpy array | 2D array of differences |
Newton Backward Difference Interpolation - Interpolates using backward differences
| Parameter | Type | Description |
|---|---|---|
| X | numpy array | x-coordinates (equally spaced) |
| Y | numpy array | y-coordinates |
| x | float | Point at which to interpolate |
| Returns | float | Interpolated value |
Load Newton backward difference from CSV file
| Parameter | Type | Description |
|---|---|---|
| path | str | Path to CSV file with columns 'x' and 'y' |
| Returns | numpy array | Difference table |
Lagrangian Interpolation - Creates interpolating polynomial through all points
| Parameter | Type | Description |
|---|---|---|
| X | numpy array | x-coordinates (must be distinct) |
| Y | numpy array | y-coordinates |
| Returns | dict | Contains polynomial object and evaluation function |
X = np.array([1, 2, 3])
Y = np.array([2, 3, 5])
result = lagrangian(X, Y)
y_at_1_5 = result['evaluate'](1.5)Polynomial Trapezoidal Rule - Integrates polynomial using trapezoidal method
| Parameter | Type | Description |
|---|---|---|
| coefficients | list/array | Polynomial coefficients [c₀, c₁, c₂, ...] |
| a | float | Lower limit of integration |
| b | float | Upper limit of integration |
| n | int | Number of subintervals (default 100) |
| Returns | float | Estimated integral value |
coeffs = [1, 2, 1] # 1 + 2x + x²
result = ploytrap(coeffs, a=0, b=3, n=100)Trapezoidal Rule Error Estimation
| Parameter | Type | Description |
|---|---|---|
| coefficients | list/array | Polynomial coefficients |
| a | float | Lower limit |
| b | float | Upper limit |
| n | int | Number of subintervals |
| Returns | dict | Error bound and max second derivative |
Polynomial Simpson's 1/3 Rule - More accurate than trapezoidal
| Parameter | Type | Description |
|---|---|---|
| coefficients | list/array | Polynomial coefficients |
| a | float | Lower limit of integration |
| b | float | Upper limit of integration |
| n | int | Number of subintervals (must be even) |
| Returns | float | Estimated integral value |
Simpson's 1/3 Rule Error Estimation
| Parameter | Type | Description |
|---|---|---|
| coefficients | list/array | Polynomial coefficients |
| a | float | Lower limit |
| b | float | Upper limit |
| n | int | Number of subintervals (must be even) |
| Returns | dict | Error bound and max fourth derivative |
Efficient Matrix Multiplication - BLAS-optimized
| Parameter | Type | Description |
|---|---|---|
| A | numpy array | First matrix (m × n) |
| B | numpy array | Second matrix (n × p) |
| Returns | numpy array | Result matrix (m × p) |
Diagonal Matrix Multiplication - O(mn) instead of O(mn²)
| Parameter | Type | Description |
|---|---|---|
| A | numpy array | 2D matrix |
| diagonal | array/scalar | Diagonal elements (None = extract from A) |
| Returns | dict | Result matrix and operation details |
Matrix Rank - Using efficient SVD method
| Parameter | Type | Description |
|---|---|---|
| A | numpy array | Any 2D matrix |
| Returns | int | Rank of the matrix |
Eigenvalues - For square or singular values for rectangular matrices
| Parameter | Type | Description |
|---|---|---|
| A | numpy array | Any 2D matrix |
| Returns | dict | Type and values |
A = np.array([[1, 2], [3, 4]])
result = eigenval(A)
# {'type': 'eigenvalues', 'values': array([5.372, -0.372])}Eigenvectors - Unique, normalized eigenvectors or singular vectors
| Parameter | Type | Description |
|---|---|---|
| A | numpy array | Any 2D matrix |
| Returns | dict | Eigenvectors with eigenvalues |
Jacobi Iteration - Solves Ax = b using iterative method
| Parameter | Type | Description |
|---|---|---|
| A | numpy array | Coefficient matrix (n × n, square) |
| b | numpy array | Constants vector |
| n | int | Maximum iterations |
| x0 | array | Initial guess (default zero vector) |
| tolerance | float | Convergence tolerance |
| Returns | dict | Solution, convergence history, residual |
A = np.array([[4, -1], [-1, 3]], dtype=float)
b = np.array([7, 5], dtype=float)
result = jacobi_iter(A, b, n=20, tolerance=1e-6)
print(result['solution']) # [2., 1.]
print(result['converged']) # TrueDependent Vectors - Check linear dependence/independence
| Parameter | Type | Description |
|---|---|---|
| vectors | numpy array | 2D array where each row is a vector |
| Returns | dict | Dependent flag (1=dependent, 0=independent) |
v = np.array([[1, 0], [0, 1]])
result = depvec(v)
# {'dependent': 0, 'rank': 2, 'explanation': 'Linearly independent'}Linear Differential Equation Solver - Solves dy/dx + p(x)y = q(x)
| Parameter | Type | Description |
|---|---|---|
| p_coeffs | list/array | Coefficients of p(x) polynomial |
| q_coeffs | list/array | Coefficients of q(x) polynomial |
| y0 | float | Initial condition y(0) |
| Returns | dict | Particular and general solutions |
p_coeffs = [0, 2] # 0 + 2x
q_coeffs = [0, 1] # 0 + x
result = Lde(p_coeffs, q_coeffs, y0=1)Taylor Series Expansion - Single Variable
Computes the Taylor polynomial of degree n for a function around point x₀.
| Parameter | Type | Description |
|---|---|---|
| f_expr | str or sympy expr | Function expression (e.g., "sin(x)", "exp(x)") |
| x0 | float | Center point for Taylor expansion |
| n | int | Degree of Taylor polynomial |
| x_eval | float | Optional point to evaluate Taylor approximation |
| Returns | dict | Symbolic series, value, error, terms |
# Taylor expansion of sin(x) around x=0
result = taylor_1var("sin(x)", 0, 5)
print(result['series']) # x**5/120 - x**3/6 + x
# Evaluate at x=0.1
result = taylor_1var("sin(x)", 0, 5, x_eval=0.1)
print(f"Approximation: {result['value']}")
print(f"Actual value: {result['actual_value']}")
print(f"Error: {result['error']}")
# Exponential function
result = taylor_1var("exp(x)", 0, 4, x_eval=0.5)Taylor Series Expansion - Two Variables
Computes the Taylor polynomial of degree n for a two-variable function around point (x₀, y₀).
| Parameter | Type | Description |
|---|---|---|
| f_expr | str or sympy expr | Function of x,y (e.g., "x2 + y2", "sin(x)*cos(y)") |
| x0 | float | Center point x-coordinate |
| y0 | float | Center point y-coordinate |
| n | int | Degree of Taylor polynomial |
| x_eval | float | Optional x-coordinate for evaluation |
| y_eval | float | Optional y-coordinate for evaluation |
| Returns | dict | Symbolic series, partial derivatives, value, error |
# Taylor expansion of x² + y² + xy around (0,0)
result = taylor_2var("x**2 + y**2 + x*y", 0, 0, 2)
print(result['series']) # x**2 + x*y + y**2
# With evaluation
result = taylor_2var("x**2 + y**2 + x*y", 0, 0, 2, x_eval=0.1, y_eval=0.1)
print(f"Taylor value: {result['value']}") # 0.03
print(f"Partial derivatives: {result['partial_derivatives']}")
# Two-variable trigonometric function
result = taylor_2var("sin(x)*cos(y)", 0, 0, 3, x_eval=0.2, y_eval=0.2)
print(f"Error: {result['error']}")numpy>=1.20
pandas>=1.3
scipy>=1.7
sympy>=1.9
- All functions use NumPy with BLAS/LAPACK backends
- Matrix operations: O(n³) for multiplication
- Interpolation: O(n) per evaluation
- Jacobi iteration: O(n²) per iteration
- Simpson's rule: ~100x more accurate than trapezoidal
Comprehensive validation included:
- Dimension checks
- Singular matrix detection
- Invalid parameter ranges
- Convergence monitoring
MIT License - Free to use and modify
For issues, contributions, and feedback, please submit to the repository.
@software{avlgmath2026,
title = {AVLGMath: Advanced Linear Algebra and Numerical Methods Library},
year = {2026}
}