Skip to main content

Numerical Differentiation in Excel: Calculating First Derivatives

Numerical methods are powerful tools for mechanical engineering design calculations. In this post, I will demonstrate how to calculate the first derivative (velocity) of a motion profile using numerical methods directly in Microsoft Excel, without the need for specialized math software.

While textbooks provide extensive derivations, for practical engineering, we can jump straight to the high-accuracy finite difference formulas.

The 5-Point Stencil Formula

To calculate the first derivative of a function f(x) with high precision, we use the "Five-Point Stencil" method. This formula utilizes interior points to achieve an error order of h4, which is significantly more accurate than standard forward or backward difference methods.

f'(xi) = [ -f(xi+2) + 8f(xi+1) - 8f(xi-1) + f(xi-2) ] / 12h

Where:
i = The current point of interest
h = The step size (the distance between points)
The smaller the step size (h), the higher the accuracy of the result.

Advertisement

Example Application: Cycloid Cam Motion

To demonstrate this, let's use a favorite curve in machine design: the Cycloid. This curve provides smooth motion by starting with zero acceleration, accelerating to peak, and decelerating back to zero.

The displacement equation for a Cycloid is:

s = Hm × [ (θ / β) - (1 / 2Ï€) × sin( 2Ï€ × Î¸ / β ) ]

Where Hm is total stroke, θ is current angle, and β is total angle of motion.

Graph of Cycloid Motion Displacement Curve
Figure 1: The smooth displacement curve of Cycloid motion.

Analytically, the velocity (first derivative) is calculated as:

v = (Hm / β) × [ 1 - cos( 2Ï€ × Î¸ / β ) ] × Ï‰

However, instead of using this analytical formula, we will use the Numerical Method (Formula 1) to derive the velocity from the displacement data alone.

Step 1: Create the Data Table

First, create an Excel table with the displacement data. In this example, we use a step size of 1.25 degrees.

Angle (deg) Angle (rad) Displacement s (mm)
0.000.00000.00000
1.250.02180.00346
2.500.04360.02758
3.750.06540.09270
5.000.08730.21894
.........

Note on Step Size (h): Although the table shows degrees, the numerical calculation requires radians.
h = 1.25 × Ï€ / 180 = 0.021816616 rad

Advertisement

Step 2: Calculate the Derivative

Let's calculate the velocity at 15 degrees.
Assume Camshaft Speed = 50 RPM.
Angular velocity (ω) = 2 × Ï€ × 50 / 60 = 5.2359 rad/s

Using the 5-point stencil formula, we reference the two cells above and the two cells below our target point (15 deg).

Excel Screenshot showing the 5-point derivative calculation selection
Figure 2: Visualizing the 5-point selection in Excel. Points xi-2 to xi+2 are used.

Calculation Example:

f'(15°) = [ -4.20 + (8 × 3.48) - (8 × 2.23) + 1.72 ] / (12 × 0.0218) × 5.236

Result = 149.23 mm/s (0.149 m/s)

By dragging this formula down in Excel, you instantly generate the complete velocity profile without complex calculus.

Velocity Profile Graph generated by Numerical Methods
Figure 3: The resulting velocity profile matches the analytical solution perfectly.

This technique proves that you don't always need MATLAB or Mathematica. Excel, combined with a basic understanding of numerical methods, is often sufficient for high-precision engineering design.

Comments

leoo said…
So how do you calculate for the derivative for points i = 1 and i = 2? Since the formula requires values for f(x at i-1) and f(x at i-2).

Hoping for your reply asap. Hehe. I'm finishing my lab report for tomorrow.
Ake said…
Hi leoo,

I would extend the table and calculate f(x at i-1) and f(x at i-2) like this...

f'(0 deg) = [-f(2.5 deg) + 8xf(1.25 deg) - 8xf(-1.25 deg) + f(-2.5 deg)]/(12x0.021816616) x 5.235987756 = 0.00230668 mm/s

also for f'(1 deg) can be calculated from
f'(1.25 deg) = [-f(3.75 deg) + 8xf(2.5 deg) - 8xf(0 deg) + f(-1.25 deg)]/(12x0.021816616) x 5.235987756 = 1.405807453 mm/s

We can compare this approximated values with the exact solution.

f'(theta) = hm/bm[1 - cos(2*pi*theta/bm)] x omega

from this formula we get
f'(0 deg) = 0 mm/s
f'(1.25 deg) = 1.403529172 mm/s

Ake
Disclosure: As an Amazon Associate, I earn from qualifying purchases.

Popular posts from this blog

Dowel Pins & Locating Pins: The Basics of Fixture Design

Figure 1: A typical fixture setup. Notice how dowel pins (silver) provide precise location, while bolts (not shown here) provide the clamping force. In the world of Precision Engineering , the difference between a high-quality product and a scrap part often comes down to microns. While bolts hold parts together, they are terrible at positioning them. This is where Dowel Pins and Locating Pins become essential components in industrial tooling . Advertisement What is a Dowel Pin? Dowel pins are precision-ground fasteners used to secure the relative position of two parts. They are typically machined to extremely tight tolerances (often within 0.0001 inches) and are available in materials like: Hardened Steel: For high-wear applications in CNC fixtures . Stainless Steel: For corrosion resistance in medical or food processing machinery. Plastic (Thermoplastic): For lightweight, non-conductive, low-load alignment. The ...

Hoeken's Linkage: Kinematics and Walking Robot Design

Figure 1: Animated simulation of the Hoeken’s Linkage showing the characteristic "tear-drop" coupler curve. 🚀 New Design Guide Available Don't just read about it—build it. Check out our new tutorial: How to Design a Hoeken’s Linkage in Excel (with Free VBA Simulator) » Introduction to the Hoekens Linkage The Hoekens linkage is a specialized four-bar mechanism designed to convert rotational motion into an approximate straight-line motion. While it serves a similar purpose to other straight-line generators, its unique coupler curve—a "tear-drop" shape—makes it exceptionally useful for intermittent motion and walking machines. One of the most fascinating aspects of kinematic theory is the concept of "Cognates." The Hoekens linkage is actually a cognate linkage of the Chebyshev Straight-line Mechanism . This means that while the physical structure and link lengths differ, they can generate...

Watt Straight-Line Linkage: Analysis and Automotive Uses

Figure 1: Watt's linkage example geometry and path generation. Introduction to Watt's Linkage The Watt's linkage (also known as the parallel motion linkage) is a cornerstone in the history of mechanical engineering. It is a type of four-bar linkage originally invented by James Watt in the late 18th century to solve a critical problem in steam engine design: constraining the piston rod to move in a straight line without using high-friction guideways. Before this invention, engines used chains to connect the piston to the beam, which meant they could only pull, not push. Watt's rigid linkage allowed for double-acting engines (pushing and pulling), doubling the power output. He was immensely proud of this kinematic solution, describing it in a 1784 letter to his partner Matthew Boulton: "I have got a glimpse of a method of causing a piston rod to move up and down perpendicularly by only fixing it to a piece of iron u...