Week 04 — Limits, Secants (\(h \to 0\)) & Differentials (\(dx, dy\))
Engineering Focus: Radar Speed-Gun Telemetry,
Instantaneous Braking Rates, Algebraic \(0/0\) Cancellation & Finite-Difference
Error Scaling Companion Dataset:
Week04_HighSpeed_Rail_Radar_Kinematics_Data.csv
1. “Calculus Made Easy” Intuition: Slaying the \(0/0\) Paradox
Welcome to the heart of Differential Calculus! Before starting, repeat Silvanus Thompson’s famous motto: “What one fool can do, another can.”
Suppose an electric train glides down a track and its odometer records position \(s(t) = 5t^2\) meters after \(t\) seconds.
- Average speed between \(t = 2\text{ s}\) (\(20\text{ m}\)) and \(t = 4\text{ s}\) (\(80\text{ m}\)) is easy: \(\frac{80 - 20}{4 - 2} = 30\text{ m/s}\).
- Now ask: How fast is the speedometer pointing at the exact instant \(t = 2.0000\dots\text{ s}\)? If you try plugging one single point into “distance divided by time,” you get zero distance over zero time: \(\frac{0}{0}\) — complete nonsense!
How Calculus Beats \(0/0\): Nudge by a Little Bit (\(dt\) or \(h\))!
Instead of freezing time completely, let time advance by a tiny little bit \(dt\) (often written \(h\)). Then position advances by a corresponding tiny bit \(ds\): \[s(t + dt) = 5(t + dt)^2 = 5t^2 + 10t\,(dt) + 5(dt)^2\] Subtract the starting position \(5t^2\) to see only the tiny gain \(ds\): \[ds = 10t\,(dt) + 5(dt)^2\] Now divide both sides by the tiny nudge \(dt\) (we are allowed to divide because \(dt\) is tiny, not zero!): \[\frac{ds}{dt} = 10t + 5(dt)\] Now, let your magnifying glass shrink the tiny interval \(dt \to 0\). The leftover sliver \(5\,dt\) shrinks into nothing, leaving the exact instantaneous speedometer reading: \[\frac{ds}{dt} = \lim_{h \to 0}\frac{s(t+h) - s(t)}{h} = \mathbf{10t}\] At \(t = 2\text{ s}\), the instantaneous velocity is exactly \(20\text{ m/s}\)! Look at the secret: you expand and cancel \(h\) FIRST, and only set \(h \to 0\) AFTER the division paradox is gone!
2. Complete Mathematical Derivations & Reference Guide
2.1 Geometric Meaning: Secant Line Rotating Into the Tangent Line
Draw a curve \(y = f(x)\) through anchor point \(P(x, f(x))\) and nearby neighbor \(Q(x+h, f(x+h))\):
The straight line cutting through two points \(P\) and \(Q\) is called the secant line, with average slope: \[m_{\text{sec}}(h) = \frac{f(x+h) - f(x)}{h}\]
As \(h\) shrinks (\(h = 1 \to 0.5 \to 0.1 \to 0.001 \to 0\)), point \(Q\) slides along the curve toward \(P\), rotating the two-point secant cleanly until it kisses the curve at a single point \(P\). That limiting line is the tangent line, whose slope IS the derivative \(f'(x) = \frac{dy}{dx}\)!
2.2 Step-by-Step Algebraic Indeterminate Resolution (\(0/0\)) Methods
When evaluating \(f'(x) = \lim_{h\to 0}\frac{f(x+h)-f(x)}{h}\), three algebraic tools cancel the \(h\) in the denominator:
- Polynomial Expansion: Expand \((x+h)^n\), cancel all terms without \(h\), factor out \(h\) from numerator, cancel \(h/h\), then set \(h=0\).
- Fraction Clearing (for \(1/x\)): Combine \(\frac{1/(x+h) - 1/x}{h} = \frac{x - (x+h)}{h x(x+h)} = \frac{-h}{h x(x+h)} = \frac{-1}{x(x+h)} \xrightarrow{h\to 0} \mathbf{-\frac{1}{x^2}}\).
- Conjugate Multiplication (for \(\sqrt{x}\)): \[\frac{\sqrt{x+h} - \sqrt{x}}{h} \cdot \frac{\sqrt{x+h}+\sqrt{x}}{\sqrt{x+h}+\sqrt{x}} = \frac{(x+h) - x}{h\left(\sqrt{x+h}+\sqrt{x}\right)} = \frac{1}{\sqrt{x+h}+\sqrt{x}} \xrightarrow{h\to 0} \mathbf{\frac{1}{2\sqrt{x}}}\]
2.3 Real-World Sensor Pitfall: Forward vs. Central Finite Difference
In digital control (PLCs, drones, ABS brakes), computers cannot take \(h \to 0\) infinitely; they sample sensors at finite intervals \(h = \Delta t\).
- Forward secant \(\frac{f(t+h)-f(t)}{h}\) has error proportional to \(h\) (\(\mathcal{O}(h)\)).
- Central secant \(\frac{f(t+h)-f(t-h)}{2h}\) cancels the linear error term cleanly, dropping error to \(\mathcal{O}(h^2)\) (\(100\times\) more accurate at \(h = 0.01\)!).
| Formula | Name | Physical Interpretation |
|---|---|---|
| \(f'(x) = \frac{dy}{dx} = \lim_{h\to 0}\frac{f(x+h)-f(x)}{h}\) | Difference Quotient Limit | Instantaneous rate of change / tangent slope |
| \(y_{\text{tan}}(x) = f(x_0) + f'(x_0)(x - x_0)\) | Tangent Line Equation | Best straight-line local model at \(x_0\) |
| \(m_{\text{cen}} = \frac{f(x+h)-f(x-h)}{2h}\) | Symmetric Central Secant | Zero-lag high-accuracy digital sensor differentiation |
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sympy as sp
from pathlib import Path
plt.rcParams.update({
"figure.dpi": 150,
"font.size": 10,
"axes.grid": True,
"grid.alpha": 0.30,
"axes.spines.top": False,
"axes.spines.right": False,
})
def load_week_csv(filename):
for p in [Path("datasets") / filename, Path("../datasets") / filename]:
if p.exists():
return pd.read_csv(p)
raise FileNotFoundError(f"Dataset not found: {filename}")3. High-Speed Rail Braking Telemetry & Convergence Analysis
We load Week04_HighSpeed_Rail_Radar_Kinematics_Data.csv,
logging radar distance \(s(t)\) and
Doppler speed \(v(t)\) of an electric
commuter train during regenerative braking, and plot secant convergence
alongside forward vs. central finite-difference error curves.
df = load_week_csv("Week04_HighSpeed_Rail_Radar_Kinematics_Data.csv")
print("Week 04 High-Speed Rail Braking Log (first 6 rows):")
print(df.head(6).to_string(index=False))
t_d = df["Time_s"].values
s_d = df["Distance_s_m"].values
v_d = df["Doppler_Velocity_m_s"].values
dt = t_d[1] - t_d[0]
# Compare forward vs central finite-difference velocity from distance radar
v_fwd = (s_d[2:] - s_d[1:-1]) / dt
v_cen = (s_d[2:] - s_d[:-2]) / (2.0 * dt)
err_fwd = np.mean(np.abs(v_fwd - v_d[1:-1]))
err_cen = np.mean(np.abs(v_cen - v_d[1:-1]))
print(f"\n[Telemetry Sampling Comparison at dt={dt:.1f} s]")
print(f" Mean Forward-Secant Velocity Error = {err_fwd:.4f} m/s")
print(f" Mean Central-Secant Velocity Error = {err_cen:.4f} m/s")
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11.8, 4.3))
x_g = np.linspace(0.2, 2.6, 300)
f_fn = lambda x: 2.0 * x**3 - 3.0 * x
x0, y0 = 1.5, f_fn(1.5)
ax1.plot(x_g, f_fn(x_g), "k-", lw=2.2, label=r"$y(x) = 2x^3 - 3x$")
for h_v, col in [(0.8, "#059669"), (0.35, "#d97706")]:
m_s = (f_fn(x0 + h_v) - y0) / h_v
ax1.plot(x_g, y0 + m_s*(x_g - x0), "--", color=col, lw=1.7, label=rf"Secant ($h={h_v}$, $m={m_s:.2f}$)")
ax1.plot(x_g, y0 + 10.5*(x_g - x0), color="#dc2626", lw=2.2, label=r"Tangent ($h\to 0$, $m=10.5$)")
ax1.scatter([x0], [y0], color="#dc2626", s=55, zorder=5)
ax1.set_ylim(-3, 20)
ax1.set_title("Secant Lines Converging to Tangent Line")
ax1.set_xlabel("$x$")
ax1.set_ylabel("$y(x)$")
ax1.legend(fontsize=8.2)
h_arr = np.logspace(-4, 0, 80)
ax2.loglog(h_arr, np.abs(((f_fn(x0+h_arr)-y0)/h_arr) - 10.5), "b-", lw=2.0, label="Forward Secant Error O(h)")
ax2.loglog(h_arr, np.abs(((f_fn(x0+h_arr)-f_fn(x0-h_arr))/(2*h_arr)) - 10.5), "r--", lw=2.0, label="Central Secant Error O(h^2)")
ax2.set_title("Step-Size Convergence Rate $h \\to 0$")
ax2.set_xlabel("Sampling Interval $h$")
ax2.set_ylabel("Slope Error $|m_h - f'(1.5)|$")
ax2.legend(fontsize=8.4)
plt.tight_layout()
plt.show()# Verified Output:
Week 04 High-Speed Rail Braking Log (first 6 rows):
Time_s Distance_s_m Doppler_Velocity_m_s
0.0 0.00 68.00
1.0 66.16 64.28
2.0 128.48 60.32
3.0 186.72 56.12
4.0 240.64 51.68
5.0 290.00 47.00
[Telemetry Sampling Comparison at dt=1.0 s]
Mean Forward-Secant Velocity Error = 2.6800 m/s
Mean Central-Secant Velocity Error = 0.0400 m/s
4. Three Unabridged Worked Engineering Problems
Worked Example 1 — First-Principles Derivative of a Cam Follower Lift Curve
Problem: A valve cam lifts an intake follower according to \(s(t) = 3t^2 - 2t + 5\ [\text{mm}]\). Expand the difference quotient step-by-step without any shortcut rules to find velocity \(v(t) = ds/dt\), then evaluate speed at \(t = 2.0\text{ s}\).
Unabridged Hand Solution:
Evaluate \(s(t+h)\) carefully: \[s(t+h) = 3(t^2 + 2th + h^2) - 2(t+h) + 5 = 3t^2 + 6th + 3h^2 - 2t - 2h + 5\]
Subtract \(s(t) = 3t^2 - 2t + 5\): every \(h\)-free term cancels out! \[s(t+h) - s(t) = 6th + 3h^2 - 2h\]
Factor out \(h\) and divide by \(h \neq 0\): \[\frac{s(t+h)-s(t)}{h} = \frac{h(6t + 3h - 2)}{h} = 6t - 2 + 3h\]
Take \(\lim_{h\to 0}\): the \(3h\) vanishes, giving \(v(t) = \mathbf{6t - 2\ [\text{mm/s}]}\). At \(t = 2.0\text{ s}\), \(v(2.0) = 6(2) - 2 = \mathbf{10.0\text{ mm/s}}\).
Worked Example 2 — Clearing Fractions for Boyle’s Law Compressibility (\(P(V) = c/V\))
Problem: During slow isothermal gas compression, pressure varies as \(P(V) = \frac{240}{V}\ [\text{kPa}]\). Derive \(\frac{dP}{dV}\) directly from the limit definition and find the pressure drop rate per liter at \(V = 4.0\text{ L}\).
Unabridged Hand Solution:
Form the difference quotient: \[\frac{P(V+h) - P(V)}{h} = \frac{1}{h}\left(\frac{240}{V+h} - \frac{240}{V}\right)\]
Put over the common denominator \(V(V+h)\): \[= \frac{1}{h} \cdot \frac{240V - 240(V+h)}{V(V+h)} = \frac{1}{h} \cdot \frac{-240h}{V(V+h)} = \frac{-240}{V(V+h)}\]
Let \(h \to 0\): \[\frac{dP}{dV} = \mathbf{-\frac{240}{V^2}}\]
At \(V = 4.0\text{ L}\): \(\frac{dP}{dV}\Big|_{V=4} = -\frac{240}{16} = \mathbf{-15.0\text{ kPa/L}}\).
Worked Example 3 — Conjugate Trick for Time-of-Fall Square Root (\(t(z) = \sqrt{2z/g}\))
Problem: Ignoring air drag, a sensor drops height \(z\) in time \(t(z) = 0.45\sqrt{z}\ [\text{s}]\). Find \(\frac{dt}{dz}\) directly from first principles using conjugate multiplication, and evaluate the timing sensitivity at drop height \(z = 9.0\text{ m}\).
Unabridged Hand Solution:
Difference quotient: \(\frac{\Delta t}{h} = 0.45\,\frac{\sqrt{z+h} - \sqrt{z}}{h}\).
Multiply top and bottom by the conjugate \(\left(\sqrt{z+h} + \sqrt{z}\right)\): \[= 0.45\,\frac{(z+h) - z}{h\left(\sqrt{z+h}+\sqrt{z}\right)} = \frac{0.45}{\sqrt{z+h}+\sqrt{z}}\]
Take \(h \to 0\): \[\frac{dt}{dz} = \frac{0.45}{2\sqrt{z}} = \frac{0.225}{\sqrt{z}}\ [\text{s/m}]\]
At \(z = 9.0\text{ m}\): \(\frac{dt}{dz}\Big|_{9} = \frac{0.225}{3} = \mathbf{0.075\text{ s/m}}\) (\(75\text{ ms}\) per extra meter of drop!).
x_s, h_s, t_s, V_s, z_s = sp.symbols("x h t V z", positive=True)
s_cam = 3*t_s**2 - 2*t_s + 5
v_cam = sp.limit((s_cam.subs(t_s, t_s + h_s) - s_cam) / h_s, h_s, 0)
P_gas = 240 / V_s
dP_dV = sp.limit((P_gas.subs(V_s, V_s + h_s) - P_gas) / h_s, h_s, 0)
t_drop = sp.Rational(9, 20) * sp.sqrt(z_s)
dt_dz = sp.limit((t_drop.subs(z_s, z_s + h_s) - t_drop) / h_s, h_s, 0)
print(f"[Example 1] Limit v(t) = {v_cam} | v(2.0) = {float(v_cam.subs(t_s, 2.0)):.2f} mm/s")
print(f"[Example 2] Limit dP/dV = {dP_dV} | dP/dV(4.0) = {float(dP_dV.subs(V_s, 4.0)):.2f} kPa/L")
print(f"[Example 3] Limit dt/dz = {dt_dz} | dt/dz(9.0) = {float(dt_dz.subs(z_s, 9.0)):.4f} s/m")# Verified Output:
[Example 1] Limit v(t) = 6*t - 2 | v(2.0) = 10.00 mm/s
[Example 2] Limit dP/dV = -240/V**2 | dP/dV(4.0) = -15.00 kPa/L
[Example 3] Limit dt/dz = 9/(40*sqrt(z)) | dt/dz(9.0) = 0.0750 s/m
5. Engineering Practice Problems (Self-Study Exercises)
Practice Problem 1 — Expanding a Cubic Thermal Jerk Curve
Use the limit definition \(y'(x) = \lim_{h\to 0}\frac{y(x+h)-y(x)}{h}\) step-by-step to differentiate \(y(x) = 2x^3 - 3x\), and write the equation of the tangent line at \(x_0 = 1.5\).
🔍 Click to View Complete Step-by-Step Solution
Expand \((x+h)^3 = x^3 + 3x^2h + 3xh^2 + h^3\). Thus: \[y(x+h) - y(x) = 2(3x^2h + 3xh^2 + h^3) - 3h = h(6x^2 + 6xh + 2h^2 - 3)\]
Divide by \(h\) and let \(h \to 0\): \(y'(x) = \mathbf{6x^2 - 3}\).
At \(x_0 = 1.5\): height \(y(1.5) = 2(3.375) - 4.5 = 2.25\), slope \(m = 6(2.25) - 3 = 10.5\).
Tangent line: \(y_{\text{tan}}(x) = 2.25 + 10.5(x - 1.5) = \mathbf{10.5x - 13.5}\).
Practice Problem 2 — When Does a Derivative Fail to Exist? (Sharp Corner in Rectifier)
A full-wave bridge rectifier converts AC voltage into \(y(t) = |t - 2|\) near \(t = 2\text{ s}\). Compute the right-hand limit (\(h \to 0^+\)) and left-hand limit (\(h \to 0^-\)) of \(\frac{y(2+h)-y(2)}{h}\) to prove why \(y'(2)\) does not exist.
🔍 Click to View Complete Step-by-Step Solution
- At \(t = 2\), \(y(2) = |0| = 0\).
- Right-hand limit (\(h > 0\)): \(\frac{|2+h-2| - 0}{h} = \frac{h}{h} = \mathbf{+1}\).
- Left-hand limit (\(h < 0\)): \(\frac{|2+h-2| - 0}{h} = \frac{|h|}{h} = \frac{-h}{h} = \mathbf{-1}\).
- Since \(+1 \neq -1\), the left and right slopes clash at a sharp corner (\(V\)-kink), so \(y'(2)\) does not exist.
Practice Problem 3 — Rational Function Velocity Limit
For a hydraulic valve flow curve \(Q(x) = \frac{x}{x + 2}\), use the difference quotient limit definition to prove that \(Q'(x) = \frac{2}{(x+2)^2}\).
🔍 Click to View Complete Step-by-Step Solution
Numerator difference: \[\frac{x+h}{x+h+2} - \frac{x}{x+2} = \frac{(x+h)(x+2) - x(x+h+2)}{(x+h+2)(x+2)}\]
Expand top: \((x^2 + 2x + xh + 2h) - (x^2 + xh + 2x) = 2h\).
Divide by \(h\) and let \(h \to 0\): \[Q'(x) = \lim_{h\to 0}\frac{2}{(x+h+2)(x+2)} = \mathbf{\frac{2}{(x+2)^2}}\]
Practice Problem 4 — Choosing Sensor Sampling Rate for \(1\%\) Accuracy
A robot joint moves along \(y(t) = t^2 + 4t\ [\text{mm}]\). At \(t = 3\text{ s}\), compare the forward secant slope \(\frac{y(3+h)-y(3)}{h}\) against the exact velocity \(y'(3) = 10\text{ mm/s}\) when sampling step size is \(h = 0.2\text{ s}\), then verify what the central secant gives at the same \(h = 0.2\text{ s}\)!
🔍 Click to View Complete Step-by-Step Solution
Forward secant (\(h = 0.2\)): \(y(3) = 21\), \(y(3.2) = 23.04\): \[m_{\text{fwd}} = \frac{23.04 - 21}{0.2} = \mathbf{10.20\text{ mm/s}} \quad (\text{Error} = +2.0\%)\]
Central secant (\(h = 0.2\)): \(y(2.8) = 19.04\), \(y(3.2) = 23.04\): \[m_{\text{cen}} = \frac{23.04 - 19.04}{0.4} = \frac{4.00}{0.4} = \mathbf{10.00\text{ mm/s}} \quad (\text{Exact } 0.0\% \text{ error for all quadratics!})\]
References
- Thompson, S. P. (1914). Calculus Made Easy (Ch. 1–3: To Deliver You from the Preliminary Terrors; On Different Degrees of Smallness). Macmillan.