Created during UMC 202 at the Indian Institute of Science, Bengaluru
Functions
- Support for polynomials
- Support for function arithmetic, composition and other methods
- Support for derivatives and differentiation
- Forward difference
- Backward difference
- Central difference
- n-th order derivative
- Allows probing algorithms
- Support for integration
- Rectangular
- Midpoint
- Trapezoidal
- Simpson's
- Gaussian Quadrature (n = 1, 2)
- Support for multivariable functions
- Support for vectors and vector-valued functions
- Support for matrices (vector of vectors)
Other Utilities
- Plotting (requires
matplotlib
)
Methods
- Root finding
- Bisection
- Newton-Raphson and Modified Newton
- Fixed-point iteration
- Secant
- Regula-Falsi
- Interpolating Polynomial
- Lagrange
- Newton's divided difference
- Forward difference
- Backward difference
- Solving initial value problems on one-dimensional first order linear ODEs (and systems of such ODEs)
- Euler's method
- Taylor's method (for n = 1, 2)
- Runga Kutta (for n = 1, 2, 3, 4)
- Trapezoidal
- Adam-Bashforth (for n = 2, 3, 4)
- Adam-Moulton (for n = 2, 3, 4)
- Predictor-Corrector (with initial approximation from Runga-Kutta order-4, predictor as Adam-Bashforth order-4 and corrector as Adam-Moulton order-3)
- Solving boundary value problems on one-dimensional second order linear ODEs
- Shooting method
- Finite difference method
- Solving initial value problems on one-dimensional second order ODEs
- All methods from solving first order linear ODEs
- Solving boundary value problems on one-dimensional second order ODEs
- Shooting method
- Newton method
- Shooting method
- Solving systems of linear equations
- Gaussian elimination with backward substitution
- Gauss-Jacobi method
- Gauss-Seidel method
The file function.py
contains all the important classes and methods, and is the main file to be imported. The file util.py
has a few helper methods required by the main file. Some practice problem sets have been included in the examples
directory to demonstrate the usage of the library.
Note
Documentation below was generated automatically using pdoc.
class BivariateFunction( function )
class Cos( f: function.Function )
class Exponent( f: function.Function, base: float = 2.718281828459045 )
class FirstOrderLinearODE( f: function.BivariateFunction, a: float, b: float, y0: float )
y'(x) = f(x, y(x)) These are initial value problems.
f is a function of x and y(x)
def solve( self, h: float = 0.1, method: Literal['euler', 'runge-kutta', 'taylor', 'trapezoidal', 'adam-bashforth', 'adam-moulton', 'predictor-corrector'] = 'euler', n: int = 1, step: int = 2, points: list[float] = [] )
def solve_adam_bashforth( self, h: float, step: int, points: list[float] ) ‑> function.Polynomial
def solve_adam_moulton( self, h: float, step: int, points: list[float] ) ‑> function.Polynomial
def solve_predictor_corrector( self, h: float ) ‑> function.Polynomial
def solve_runge_kutta( self, h: float, n: int ) ‑> function.Polynomial
def solve_taylor( self, h: float, n: int ) ‑> function.Polynomial
def solve_trapezoidal( self, h: float ) ‑> function.Polynomial
class Function( function )
def bisection( self, a: float, b: float, TOLERANCE=1e-10, N=100, early_stop: int = None )
def differentiate( self, func=None, h=1e-05, method: Literal['forward', 'backward', 'central'] = 'forward' )
Sets or returns the derivative of the function. If func is None, returns the derivative. If func is a Function, sets the derivative to func. If func is a lambda, sets the derivative to a Function with the lambda.
def differentiate_central( self, h )
def differentiate_forward( self, h )
def fixed_point( self, p0: float, TOLERANCE=1e-10, N=100 )
def integral( self, func=None, h=1e-05 )
Sets or returns the integral of the function. If func is None, returns the integral. If func is a Function, sets the integral to func. If func is a lambda, sets the integral to a Function with the lambda.
def integrate( self, a: float, b: float, method: Literal['rectangular', 'midpoint', 'trapezoidal', 'simpson', 'gauss'] = None, n: int = None )
Definite integral of the function from a to b.
def integrate_gauss( self, a: float, b: float, n: int = None )
def integrate_midpoint( self, a: float, b: float, n: int = None )
def integrate_rectangular( self, a: float, b: float, n: int = None )
def integrate_simpson( self, a: float, b: float, n: int = None )
def integrate_trapezoidal( self, a: float, b: float, n: int = None )
def modified_newton( self, p0: float, TOLERANCE=1e-10, N=100, early_stop: int = None )
def multi_differentiate( self, n: int, h=1e-05, method: Literal['forward', 'backward', 'central'] = 'forward' )
Returns the nth derivative of the function.
def newton( self, p0: float, TOLERANCE=1e-10, N=100, early_stop: int = None )
def plot( self, min: float, max: float, N=1000, file: str = '', clear: bool = False )
def regula_falsi( self, p0: float, p1: float, TOLERANCE=1e-10, N=100, early_stop: int = None )
def root( self, method: Literal['bisection', 'newton', 'secant', 'regula_falsi', 'modified_newton'], a: float = None, b: float = None, p0: float = None, p1: float = None, TOLERANCE=1e-10, N=100, return_iterations=False, early_stop: int = None )
def secant( self, p0: float, p1: float, TOLERANCE=1e-10, N=100, early_stop: int = None )
class LinearODE
class LinearSystem( A: function.Matrix, b: function.Vector )
A system of linear equations.
def solve( self, method: Literal['gauss_elimination', 'gauss_jacobi', 'gauss_seidel'] = 'gauss_elimination', TOL: float = 1e-05, initial_approximation: function.Vector = None, MAX_ITERATIONS: int = 100 )
def solve_gauss_elimination( self ) ‑> function.Vector
def solve_gauss_jacobi( self, TOL: float, initial_approximation: function.Vector, MAX_ITERATIONS ) ‑> function.Vector
def solve_gauss_seidel( self, TOL: float, initial_approximation: function.Vector, MAX_ITERATIONS ) ‑> function.Vector
class Log( f: function.Function, base: float = 2.718281828459045 )
class Matrix( *rows: list[function.Vector] )
class MultiVariableFunction( function )
class OrdinaryDifferentialEquation
class Polynomial( *coefficients )
coefficients are in the form a_0, a_1, ... a_n
def interpolate( data: tuple, method: Literal['lagrange', 'newton'] = 'newton', f: function.Function = None, form: Literal['standard', 'backward_diff', 'forward_diff'] = 'standard' )
data is a list of (x, y) tuples. alternative: f is a Function that returns the y values and data is a list of x values.
def interpolate_lagrange( data: tuple )
data is a tuple of (x, y) tuples
def interpolate_newton( data: tuple )
data is a tuple of (x, y) tuples
def interpolate_newton_backward_diff( data: tuple )
data is a tuple of (x, y) tuples
def interpolate_newton_forward_diff( data: tuple )
data is a tuple of (x, y) tuples
class SecondOrderLinearODE_BVP( p: function.Function, q: function.Function, r: function.Function, a: float, b: float, y0: float, y1: float )
y''(x) = p(x)y'(x) + q(x)y(x) + r(x) These are boundary value problems.
def solve( self, h: float = 0.1, method: Literal['shooting', 'finite_difference'] = 'shooting' )
def solve_finite_difference( self, h: float ) ‑> function.Polynomial
def solve_shooting( self, h: float ) ‑> function.Polynomial
class SecondOrderODE_BVP( f: function.MultiVariableFunction, a: float, b: float, y0: float, y1: float )
y''(x) = f(x, y(x), y'(x)) These are boundary value problems.
f is a function of x, y(x), and y'(x)
def solve( self, h: float = 0.1, method: Literal['shooting_newton'] = 'shooting_newton', M: int = 100, TOL: float = 1e-05, initial_approximation=None )
def solve_shooting_newton( self, h: float, M, TOL, initial_approximation ) ‑> function.Polynomial
class SecondOrderODE_IVP( f: function.MultiVariableFunction, a: float, b: float, y0: float, y1: float )
y''(x) = f(x, y(x), y'(x)) These are initial value problems.
f is a function of x, y(x), and y'(x)
def solve( self, h: float = 0.1, method: Literal['euler', 'runge-kutta', 'taylor', 'trapezoidal', 'adam-bashforth', 'adam-moulton', 'predictor-corrector'] = 'euler', n: int = 1, step: int = 2, points: list[float] = [] )
class Sin( f: function.Function )
class Tan( f: function.Function )
class Vector( *components )