-
Notifications
You must be signed in to change notification settings - Fork 0
GLI
GLI computes the improved Grünwald-Letnikov (GL) fractional derivative of a function over a specified domain, using quadratic (3-point Lagrange) interpolation for higher accuracy. It implements the method described in:
Oldham, K. & Spanier, J. (1974). The Fractional Calculus: Theory and Applications of Differentiation and Integration to Arbitrary Order. Academic Press.
This approach provides a higher-order, more accurate approximation of the fractional derivative than the standard GL method, particularly when working with smooth functions or limited discretization points.
The improved GL algorithm utilizes a 3-point Lagrange interpolation to better estimate the function's values between grid points, reducing discretization error. For each interior point, the interpolated value is given by:
where the coefficients depend on the fractional order
$a = \frac{\alpha(\alpha - 2)}{8}$ $b = \frac{4 - \alpha^2}{4}$ $c = \frac{\alpha(\alpha + 2)}{8}$
These interpolated values are then convolved with the Grünwald-Letnikov binomial coefficients and scaled by the step size raised to
-
Hybrid Convolution:
For small arrays (
num_points< 800), a direct NumPy convolution (np.convolve) is used. For larger arrays, a fast FFT-based convolution (scipy.signal.fftconvolve) is automatically selected for optimal performance. -
Input Flexibility:
GLIaccepts a callable function, NumPy array, or Python list. If a callable is provided, it is evaluated atnum_pointsequally spaced points betweendomain_startanddomain_end.
GLI(
alpha: float,
f_name: Callable | np.ndarray | list,
domain_start: float = 0.0,
domain_end: float = 1.0,
num_points: int = 100,
) -> np.ndarray-
alpha (
float): The order of the fractional derivative. -
f_name (
Callable,list, ornp.ndarray): Function, lambda, or sequence of function values to be differintegrated. -
domain_start (
float, optional): Left endpoint of the domain. Default is0.0. -
domain_end (
float, optional): Right endpoint of the domain. Default is1.0. -
num_points (
int, optional): Number of points in the domain. Default is100.
-
result (
np.ndarray): Array containing the improved GL fractional derivative at each grid point.
import numpy as np
from differintP import GLI
# Example 1: Fractional derivative of a quadratic polynomial
result_poly = GLI(-0.5, lambda x: x**2 - 1)
# Example 2: Fractional derivative of sqrt(x) on [0, 1]
result_sqrt = GLI(0.5, np.sqrt, 0., 1., 100)- The interpolation and convolution steps are fully vectorized for speed.
- Hybrid convolution ensures performance is optimal for both small and large arrays.
- This method is especially useful when higher accuracy is desired with moderate grid resolution.
- Oldham, K. & Spanier, J. (1974). The Fractional Calculus: Theory and Applications of Differentiation and Integration to Arbitrary Order. Academic Press.