Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Numerical Differentiation in Python

A tutorial on numerical differentiation in Python

Andrew Joseph Davies
Python in Plain English
4 min readOct 19, 2021

--

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.

Photo by Marek Piwnicki on Unsplash

Theory

Equation 1 is the slope of a line:

Equation 1 — Slope of a Line (Image By Author)

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.

Figure 1 — Rise Over Run (Slope Definition) (Image By Author)

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

Equation 2 — Limit Derivative (Image By Author)

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.

Figure 2 — Differential Calculus Derivative Definition (Image By Author)

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.

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by Andrew Joseph Davies

I’m Andy! I have interests in maths and engineering. I’ll be writing about some small projects as I learn new things. 1x Top Writer in Science 🚀

Responses (1)

Write a response