Finite Differences
1# Forward difference
2df_dx = (f(x + h) - f(x)) / h
3
4# Central difference (more accurate)
5df_dx = (f(x + h) - f(x - h)) / (2 * h)
6
7# NumPy gradient
8df_dx = np.gradient(y, x)
Further Reading
Related Snippets
- Interpolation Methods
Linear, polynomial, and spline interpolation - Numerical Integration
Trapezoidal rule, Simpson's rule, Gaussian quadrature - Optimization Methods
Gradient descent, Newton's method, BFGS - Regularization Techniques
L1, L2, Tikhonov, and elastic net regularization - Root Finding Methods
Newton's method, bisection, and secant method - Solving Linear Systems
LU decomposition and iterative methods