Why this matters for simulation: A pilot's step input on the elevator is a Heaviside function.
By the end of this lesson you can…
Write a switched-on, switched-off or piecewise forcing (rectangular pulse, ramp-and-hold, staircase, sawtooth segment) as a sum of Heaviside steps $u(t-a)$.
Derive $\mathcal L\{u(t-a)\} = e^{-as}/s$ and the second shifting theorem $\mathcal L\{u(t-a)f(t-a)\} = e^{-as}F(s)$, and say why $f$ must be shifted too.
Transform a function like $u(t-a)\,g(t)$ by rewriting $g(t)$ as a function of $t-a$, and invert any $F(s)$ that carries a factor $e^{-as}$.
Transform a periodic function with the factor $1/(1-e^{-sT})$, and explain it as a geometric series of delayed copies.
Solve a spring-mass-damper driven by a rectangular pulse, and read the response after switch-off as free ringing from the state at that instant.
Explain why an ODE solver stepping across a jump loses accuracy or misses a short pulse, and fix it by splitting the interval at the switch times.
In 6.2 Solving Initial Value Problems every forcing was a single smooth formula. Real inputs are not like that. A pilot slams the elevator over and holds it, a valve opens at t=0.55 s and shuts at 1.45 s, a gust arrives and leaves. These are piecewise: one formula until a switch time, another after. The tool that makes them one formula again is the Heaviside step functionu(t−a), and the Laplace transform handles it with a single new rule, the second shifting theorem. We reuse the spring-mass-damper of 5.3 Mechanical Vibrations: Spring–Mass–Damper and the forced-response ideas of 5.6 Forced Oscillations & Resonance, and finish with a warning that matters to anyone who writes a time stepper: a jump in the forcing is exactly where RK45 can go wrong.
▶ VideoSteps as switches, building pulses and ramps, the delay rule, a periodic wave as a geometric series, a pulse on a spring, and an ODE solver stepping across a jumpcaptions only
Transcript
Real forcing is piecewise: a valve opens at 0.55 seconds and shuts at 1.45. The Heaviside step u of t minus a is zero before a, one after. Subtract two steps and you get a rectangular pulse of height F naught.
Stack steps and any piecewise-constant force follows: a sum of jumps A i times u of t minus t i. A ramp-and-hold uses two ramps, a staircase is four jumps of plus 10, and a sawtooth tooth is t times a window.
A step's transform is one integral, zero before a: e to the minus a s over s. At a equals 0.5 and s equals 2, that is e to the minus 1 over 2, 0.18394. A pulse is a difference, and each switch time becomes a factor e to the minus time times s.
Now delay a whole function. The second shifting theorem: the transform of u of t minus a times f of t minus a is e to the minus a s times F of s. Substitute tau equals t minus a, and the integral turns into e to the minus a s times the original. A delay costs one factor.
But the function must be shifted too. With a equal to 1 and s equal to 2, u of t minus 1 times sine of t minus 1 gives 0.027067. For plain sine t, rewrite it as sine of t minus 1 plus 1: that gives 0.060177, more than twice as large.
A periodic function is one tooth, repeated and delayed by T. Each copy brings a factor q, equal to e to the minus s T, so the tooth's transform gets 1 plus q plus q squared and on: a geometric series, which sums to one over 1 minus e to the minus s T.
Square wave, period 2, at s equals 1. The tooth integral is 0.39958, and the geometric factor is 1.15652, which is 1 plus e to the minus 2 plus e to the minus 4 and on. The product is 0.46212, which is tanh of one half.
Now a spring: m is 2, c is 8, k is 200. Push with 20 newtons from 0.55 to 1.45 seconds, from rest. The transform is F naught over m times the two exponentials, over s times s squared plus 2 alpha s plus omega naught squared, and partial fractions give the unit step response sigma.
The shifting theorem delays each exponential: x of t is F naught over k, 0.1 meters, times sigma of t minus a minus sigma of t minus b. During the pulse only the first term is on: the mass rings about the static deflection 0.1, peaking at t equals 0.87064 with value 0.15266.
After b both terms are on and the constant 1 cancels: free vibration from the state at switch-off, x equal 0.11166 and x prime 0.09618. At t equals 1 the mass is at 0.12006. At 2.5, formula and free ringing agree: minus 0.011923.
Now the numerics. Naive RK4 steps on a fixed grid, so a switch lands inside a step. Restart cuts the axis at each switch. At h equals 0.1 the gaps are 2.64 times 10 to the minus 2 and 2.40 times 10 to the minus 3. Halving h, restart shrinks 16 times, naive only 3.8.
Adaptive RK45 notices a wide pulse and shrinks the step. But a narrow pulse, on at 0.91 and off at 0.94, is never sampled: the estimate stays zero, steps grow, and the pulse is skipped, a gap of 2.26 times 10 to the minus 2. Split at the switches: 1.03 times 10 to the minus 8.
So: steps are switches, each delay is a factor e to the minus a s, and the function must be shifted too. Periodic means a geometric series. A pulse on a spring is a step response, then free ringing. Put the discontinuity on a step boundary. Next: impulses and the delta.
Steps as switches
The Heaviside function is u(t−a)=0 for t<a and 1 for t≥a. Multiply any f(t) by it and f is switched on at t=a. Subtract two steps and you get a window: u(t−a)−u(t−b) is 1 on [a,b) and 0 elsewhere, so
f(t)=F0[u(t−a)−u(t−b)]
is a rectangular pulse of height F0. A force that jumps by Ai at each switch time ti is f(t)=∑iAiu(t−ti), which is what the lab below builds. More shapes follow:
Ramp-and-hold: r(t)=tu(t)−(t−1)u(t−1) rises as t until t=1, then the second ramp cancels the slope and the value stays at 1.
Staircase: four jumps of +10 at 0.4,0.8,1.2,1.6, a crude ramp.
One tooth of a sawtooth: t on [0,1) and 0 afterwards is t[u(t)−u(t−1)].
The transform of a step is one integral, since the integrand is zero before a:
L{u(t−a)}=∫a∞e−stdt=se−as,s>0.
At a=0.5, s=2 this is e−1/2=0.18394, and block A of the lab cell below finds the same number by summing the definition. The pulse is the difference, L{F0[u(t−a)−u(t−b)]}=F0(e−as−e−bs)/s. Each switch time becomes a factor e−time⋅s. The value of u exactly at t=a does not matter for the transform: a single point has zero area under the integrand, so u(0)=0, 21 or 1 all give the same F(s). It does matter to a program, which must choose one of them when it evaluates the forcing on a switch time (the lab uses u(0)=1).
A delay in a simulation is the same thing seen from outside. If a controller’s command reaches the aircraft τd seconds late, the aircraft sees u(t−τd)f(t−τd), and in the s-domain that is the extra factor e−τds multiplying everything else (this will return in the control module).
The second shifting theorem
The tooth t[u(t)−u(t−1)] contains tu(t−1), and that is not yet in the table. The rule that handles it is: if F(s)=L{f}, then
L{u(t−a)f(t−a)}=e−asF(s).
Why. The integral only sees t≥a. Substitute τ=t−a, so t=τ+a, dt=dτ, and e−st=e−sae−sτ:
Picture it as a delay: the shifted function is the same graph started late, so it starts from the beginning of its own shape at t=a. The delay costs the transform the single factor e−as (in 6.1 The Laplace Transform the first shifting theorem, eatf, moved s; this one multiplies by an exponential in s).
The trap. The theorem needs the function evaluated at t−a, not at t. Take a=1, f=sin, and s=2:
L{u(t−1)sin(t−1)}=e−s/(s2+1)=0.027067. Shifted properly, so the rule applies directly.
L{u(t−1)sint} is not that. Write sint=sin((t−1)+1)=sin(t−1)cos1+cos(t−1)sin1, apply the rule to each piece, and get e−s(cos1+ssin1)/(s2+1)=0.060177.
The two numbers differ by a factor of more than two, and block B computes both by direct quadrature to confirm. The recipe is: to transform u(t−a)g(t), replace g(t) by g(τ+a) with τ=t−a, transform that in τ, then multiply by e−as. For the sawtooth tooth, tu(t−1)=(t−1)u(t−1)+u(t−1), so L{tu(t−1)}=e−s(1/s2+1/s).
Inverting transforms with e−as
Run the rule backwards. Strip off e−as, invert what is left as a function of τ, then replace τ by t−a and multiply by u(t−a). For example,
The answer is 0 before t=2, then climbs toward 1 as if the system had just been switched on. At t=3 it is 1−e−1=0.63212, and the transform of this f at s=1 is e−2/2=0.067668 both by the formula and by summing the definition (block D).
Periodic functions
Suppose f(t+T)=f(t). The part on [0,T) is one tooth f0(t), and f is the tooth repeated, each copy delayed by one more period: f=f0(t)+f0(t−T)u(t−T)+f0(t−2T)u(t−2T)+⋯. By the second shifting theorem each delayed copy adds a factor e−sT, so with q=e−sT and F0(s)=∫0Tf(t)e−stdt,
F(s)=F0(s)(1+q+q2+⋯)=1−e−sT∫0Tf(t)e−stdt.
The series converges because 0<q<1 for s>0. Square wave of period T=2 (+1 on [0,1), −1 on [1,2)): the tooth integral is [(1−e−s)−(e−s−e−2s)]/s=(1−e−s)2/s, and 1−e−2s=(1−e−s)(1+e−s), so
F(s)=s11+e−s1−e−s=stanh(s/2).
At s=1 the tooth integral is (1−e−1)2=0.39958, the geometric factor is 1/(1−e−2)=1.15652, and the product is 0.46212=tanh(0.5). Block C sums the square wave’s definition out to t=30 and gets the same 0.46212. The factor 1.15652 is not a mystery: it is 1+e−2+e−4+⋯, each later period weighted by how far the probe e−st has decayed.
Worked example: a pulse on a spring
Take m=2 kg, c=8 N s/m, k=200 N/m, the damper-spring-mass of 5.3 Mechanical Vibrations: Spring–Mass–Damper, so α=c/2m=2, β=k/m−α2=9.79796 and the damped period is 0.64127 s. Push with F0=20 N from a=0.55 s to b=1.45 s, starting at rest. Then mx′′+cx′+kx=F0[u(t−a)−u(t−b)] transforms to
X(s)=mF0s(s2+2αs+ω02)e−as−e−bs,ω02=100.
Partial fractions give ms(s2+2αs+ω02)1=k1[s1−(s+α)2+β2(s+α)+α] (using k=mω02), which inverts to k1σ(τ) with the unit step response
σ(τ)=1−e−ατ(cosβτ+βαsinβτ).
The second shifting theorem delays each exponential, so
x(t)=kF0[σ(t−a)u(t−a)−σ(t−b)u(t−b)],kF0=0.1 m.
Read it in three pieces. Before a nothing has happened, x=0. During the pulse only the first term is on: the mass rings around the static deflection F0/k=0.1, first peaking half a damped period after switch-on, at τ=π/β=0.32064, i.e. t=0.87064, with value 0.1(1+e−απ/β)=0.15266. After b both terms are on, and the constant 1 in each σ cancels, which leaves only decaying oscillation: the response is free vibration launched from the state (x,x′) at t=b, here x(1.45)=0.11166 and x′(1.45)=0.09618. Using the free-vibration formula x=e−ατ[xbcosβτ+βxb′+αxbsinβτ] with τ=t−b gives x(2.5)=−0.011923, the same as the shifting-theorem formula. Block E prints all of these. The mass overshoots in both directions because ζ=0.2.
◆ InteractiveBuild a forcing out of up to four steps and compare the exact response with RK4, with and without restarting at the switches
Loading simulation…
On the first preset the readout at t∗=1 gives x=0.12006 and at t∗=2.5 it gives −0.011923. Try the staircase: each step re-excites the ringing, and the peak ∣x∣ grows to 0.21924. Then try the narrow pulse, which is the next section’s subject.
What a time stepper does at a jump
Every solver in 4.3 Runge–Kutta Methods & Butcher Tableaux assumes f(t,y) is smooth over a step, because the error estimate comes from Taylor expansion. A jump in the forcing breaks that assumption. The lab uses fixed-step RK4 with step h in two ways. Naive: steps on the grid 0,h,2h,…, with the forcing sampled at the stage times, so a switch lands inside a step. Restart: cut the time axis at each switch time and take whole steps in between, holding the forcing at its value for that piece.
With the rectangular pulse and h=0.1 (the lab’s default), the largest gap to the exact curve at the step points is 2.64×10−2 for naive stepping and 2.40×10−3 restarted, about 11 times smaller, against a peak of 0.15266. Halving to h=0.05 gives 6.93×10−3 and 1.51×10−4. So the restarted gap shrinks by about 16 per halving, the fourth-order behaviour RK4 promises, while the naive gap shrinks by only about 3.8. The jump poisons the one step it sits in, and that spoils the order. The narrow pulse (on at 0.91, off at 0.94, peak response 0.022599) is worse. At h=0.1 the RK4 stage times are multiples of 0.05, none of which lies in [0.91,0.94), so the forcing is never sampled while it is on: the numeric solution stays at zero and the gap is 2.13×10−2, nearly the whole response. At h=0.05 a stage time 0.925 does fall inside, and the gaps are 2.58×10−3 naive and 2.83×10−5 restarted.
An adaptive solver reacts differently. The cell in Computing it runs SciPy’s RK45 with rtol=1e-6 on the same pulse. For the wide pulse, one call gives a gap of 1.38×10−7 using 1520 function evaluations, because the error estimator flags the step containing the jump, rejects it and shrinks h. Splitting at the switches gives 6.56×10−8 with 1014 evaluations: the same accuracy for about two thirds of the work. For the narrow pulse the solver never notices: stages at t<0.91 see zero forcing, the error estimate is zero, steps grow, and the whole pulse is skipped. One call gives a gap of 2.26×10−2, the full peak, using 110 evaluations. Splitting at 0.91 and 0.94 gives 1.03×10−8.
Computing it
🐍 PythonLab: transforms of steps, the shifting trap, a square wave, and the pulse on the spring (blocks A to E)
⌘/Ctrl + Enter
Block A confirms 0.18394; block B prints 0.027067 for the shifted sine and 0.060177 for the unshifted one, each matching its formula; block C prints 0.46212 both ways; block D prints 0.63212 and 0.067668; block E prints the pulse numbers above.
🐍 PythonLab: RK45 across the jump, one call versus split at the switch times
⌘/Ctrl + Enter
The cell prints the gaps and evaluation counts quoted in the previous section. Now build the two halves yourself: the exact pulse response from the shifting theorem, and the RK45 comparison.
🧪 Coding exerciseExercise: response to a rectangular pulse, formula against RK45✓ passed
⌘/Ctrl + Enter
💡 Reuse unit_step_response for both shifts. For the split version, a loop over three (lo, hi, level) triples works, with u0 = r.y[:, -1] after each solve.
Concept checks
✅ Concept check
What is $F(2)$ for $f(t) = u(t-1)\,(t-1)$? (Give a number.)
Why: This is the shifted ramp: f(t - a) with f = t and a = 1, so F(s) = e^(-s)/s^2. At s = 2 that is e^(-2)/4 = 0.03383.
✅ Concept check
Which is $\mathcal L\{u(t-2)\,t^2\}$?
Why: Write t as (t - 2) + 2 before applying the second shifting theorem.
✅ Concept check
A forcing switches on at $t = 0.91$ and off at $t = 0.94$. A single call to an adaptive RK45 with default step growth returns a response that is identically zero. What is the most likely reason?
Why: Put the discontinuity on a step boundary by integrating the pieces separately.
Problems
✏️ Pen & paperTransform of a tent●○○
Write f(t)=t on [0,1), 2−t on [1,2), and 0 after, using steps, and find F(s). Evaluate F(1).
Show worked solution
The slope is +1 from 0, becomes −1 at t=1 (change of −2), and returns to 0 at t=2 (change of +1): f=tu(t)−2(t−1)u(t−1)+(t−2)u(t−2). Each term is already a function of its own shifted variable, so F(s)=s21−2e−s+e−2s=s2(1−e−s)2. At s=1: (1−e−1)2=0.6321212=0.399576.
✏️ Pen & paperA pulse into a first-order system●●○
Solve y′+2y=u(t−1)−u(t−2) with y(0)=0. Find y(3).
Show worked solution
(s+2)Y=(e−s−e−2s)/s, so Y=(e−s−e−2s)s(s+2)1 and s(s+2)1=21(s1−s+21), which inverts to 21(1−e−2t). Shifting: y=21(1−e−2(t−1))u(t−1)−21(1−e−2(t−2))u(t−2). For t=3 both are on, and the constants cancel: y(3)=21(e−2−e−4)=21(0.135335−0.018316)=0.058510. Check on the shape: y rises toward 21 for 1<t<2, reaching 21(1−e−2)=0.432332 at t=2, then decays as e−2(t−2), and 0.432332e−2=0.058510.
✏️ Pen & paperA sawtooth●●●
Let f(t)=t on [0,1), repeated with period 1. Find F(s), and check F(1). What does F(s) look like for small s, and why?
Show worked solution
The tooth integral is ∫01te−stdt=s21−(1+s)e−s (by parts). With T=1, F(s)=s2(1−e−s)1−(1+s)e−s. At s=1: 1−e−11−2e−1=0.6321210.264241=0.418023. For small s, the wave never decays and has average value 21, so F(s)≈21⋅s1 (the transform of a constant 21). Check at s=0.01: the formula gives 49.917 against 21/0.01=50.
Key Takeaways
u(t−a) switches a function on at t=a; a window u(t−a)−u(t−b) is a rectangular pulse, and a sum ∑Aiu(t−ti) builds any piecewise-constant forcing (ramps and sawtooth teeth come from steps times t).
L{u(t−a)}=e−as/s, and each delay multiplies the transform by e−as.
Second shifting theorem: L{u(t−a)f(t−a)}=e−asF(s) (substitute τ=t−a). The function must be shifted too: for u(t−a)g(t) rewrite g(t) in terms of t−a first.
To invert with e−as, invert the rest, replace t by t−a and multiply by u(t−a).
Periodic f of period T: F(s)=1−e−sT1∫0Tfe−stdt, a geometric series of delayed copies.
A pulse on a spring: the response during the pulse is a step response, and after switch-off it is free vibration from the state at t=b.
Numerically, a jump inside a step ruins the order of RK4 and can make RK45 miss a short pulse entirely. Split at the switch times and carry the state across.