Skip to main content

Featured Post

Why I Wrote The Sheet Mechanic (And Why Calculations Aren’t Enough)

For engineers who already know the math—but still lose projects. For the last few years, I’ve been sharing technical guides here on Mechanical Design Handbook —how to size a motor, how to calculate fits, and (as you recently read) how to choose between timing belts and ball screws. But after 25 years in industrial automation, I realized something uncomfortable: Projects rarely fail because the math was wrong. They fail because: The client changed the scope three times in one week. A critical vendor lied about a shipping date (and no one verified it). The installation technician couldn’t fit a wrench into the gap we designed. University taught us the physics. It didn’t teach us the reality. That gap is why I wrote my new book, The Sheet Mechanic . This is not a textbook. It is a field manual for the messy, political, and chaotic space between the CAD model and the factory floor. It captures the systems I’ve used to survive industrial projec...
NEW RELEASE: Stop trying to be a Hero. Start being a Mechanic. Get "The Sheet Mechanic" on Amazon »
Disclosure: As an Amazon Associate, I earn from qualifying purchases.

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

Popular posts from this blog

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...

Dowel Pins & Locating Pins: The Basics of Fixture Design

Dowel pins are precision cylindrical pins used for accurate part alignment in assemblies. They control position, not clamping force. This guide explains tolerances, fits, sizing rules, and design best practices. 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-wea...

Conveyor Belt Tension Calculation: T1, T2 & Take-Up Design

In any friction-driven conveyor system, the most fundamental concept is the relationship between the Tight Side Tension (T 1 ) and the Slack Side Tension (T 2 ) . If you get this ratio wrong, your drive pulley will slip, your belt will wear out prematurely, or your take-up counterweight will be too light to maintain traction. In this guide, we will use CEMA standard calculations to determine the correct tensions and take-up weight. Table of Contents 1. The Basics: T1 vs T2 2. Euler’s Equation (The Grip Formula) 3. Worked Example: Calculating Tensions 4. Take-Up Units: Gravity vs Screw 5. Common Failure Modes Advertisement 1. The Basics: T1 vs T2 Imagine a conveyor belt running over a drive pulley. The motor pulls the belt, creating a tension differential: T 1 (Tight Side): The tension pulling the loaded belt toward the drive pulley. This is the highest tension point in the system. ...