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

Ball Detent Torque Limiter – Working Principle & Selection

Figure 1: The ball detent mechanism provides precise overload protection by disengaging instantly when the torque limit is exceeded. The First Line of Defense: Overload Clutches In high-speed automation and heavy industrial machinery, a "jam" is not a matter of if , but when . Whether it is a cardboard box getting stuck in a packaging machine or a tool crashing in a CNC lathe, the resulting torque spike can destroy gearboxes, twist shafts, and burn out expensive servo motors in milliseconds. A torque limiter (or overload clutch) is the mechanical fuse of the drive system. While electronic monitoring (current limiting) is common, it is often too slow to prevent physical damage from the massive kinetic energy stored in the system inertia. A mechanical torque limiter provides a physical disconnect that operates in a fraction of a second. Search for Torque Limiters & Safety Couplings Advertisement Why Choose ...

Taper-Lock Bushing Failures: The Physics of Wedge Angles

The Failure Scenario: A technician is installing a heavy 20-inch cast-iron V-belt sheave onto a motor shaft using a standard Taper-Lock® bushing. To make future removal easier, they apply a generous coat of anti-seize lubricant to the tapered surface. They tighten the set screws with an impact wrench. Instantly, a loud "CRACK" echoes through the shop. The massive cast-iron hub has split perfectly in half. The Cause: The technician misunderstood the physics of mechanical wedges and friction. By lubricating the taper and using unregulated torque, they generated a radial expansion force that exceeded the Ultimate Tensile Strength of the cast iron, causing a catastrophic hoop stress failure. Tapered bushings (including Taper-Lock and QD styles) are the industrial standard for mounting sprockets, gears, and pulleys to shafts. They rely on the mechanical advantage of a wedge to create massive clamping friction. This guide explains the physics of wedge mechanics, the de...

Polynomial Cams: Analysis & Design Pitfalls (Part 3)

Figure 1: Mathematical coefficients determine the physical shape. Poor math leads to physical defects like the "dip" shown on the right. In [ Polynomial Cam Function (Derivation of Fifth-degree function) - Part 2 ], we derived the equations for the Fifth-Degree (3-4-5) Polynomial . Advertisement Now, we apply this math to the real world of Mechanical Cam Design . The shape of the physical cam is determined by plotting these functions. Unlike a standard Cycloid curve, the polynomial allows us to manipulate the Start Velocity (v 0 ) and End Velocity (v 1 ) of the follower. However, this flexibility requires careful design. If the coefficients are not balanced, the physical cam profile can develop "dips" or negative slopes, causing the mechanical linkage to behave unpredictably. Case 1: Standard Dwell-to-Dwell (Zero Velocity) Figure 2: The standard profile (v 0 =0, v 1 =0). Safe, smooth, and ide...