Member-only story
Numerical Differentiation in Python
A tutorial on numerical differentiation in Python
Introduction
Numerical differentiation is finding the numerical value of a function’s derivative at a given point.
A practical example of numerical differentiation is solving a kinematical problem. Kinematics describes the motion of a body without considering the forces that cause them to move.
Theory
Equation 1 is the slope of a line:

Rise is the change in the vertical distance on the curve. Run is the corresponding change in horizontal space. Therefore, the slope is the rise over run, as depicted in Figure 1.

This definition is comparable to the first-principles definition of the derivative in differential calculus, given by Equation 2 and depicted in Figure 2.

The limit indicates that x₁ and x₂ get infinitesimally close to one another, meaning the line joining these points becomes tangent to the curve.
The slope of the tangent line to the curve gives the derivative.

Analytical Derivative
Given Equation 3 describing the position (r) of a particle as a function of time expressed in meters (m), numerical differentiation can yield a time history of velocity (m/s) and acceleration (m/s²).
Velocity is the first derivative of position, and acceleration is the second derivative of displacement. The analytical representations are given in Equations 4 and 5, respectively.