TExcelTAD
Home › Differential Equations › Step Functions and Shifting

Step Functions and Shifting

Many inputs switch on or off: a voltage applied at t=2t = 2, a pump that runs for ten minutes, a force that stops. The unit step function (Heaviside function)

u(t−a)={0t<a1t≥au(t - a) = \begin{cases} 0 & t < a \\ 1 & t \ge a \end{cases}

describes them, and the Laplace transform handles it with one rule.

Building piecewise functions

  • Switch on at aa: f(t) u(t−a)f(t)\,u(t - a).
  • On between aa and bb: f(t)(u(t−a)−u(t−b))f(t)\big(u(t - a) - u(t - b)\big).

Example. A force of 3 between t=1t = 1 and t=4t = 4, then 0: F(t)=3u(t−1)−3u(t−4)F(t) = 3u(t - 1) - 3u(t - 4).

The time-shift rule

L{f(t−a) u(t−a)}=e−asF(s),a≥0.\mathcal{L}\{f(t - a)\,u(t - a)\} = e^{-as}F(s), \qquad a \ge 0.

A delay by aa in time is multiplication by e−ase^{-as} in the ss-domain. In particular L{u(t−a)}=e−ass\mathcal{L}\{u(t - a)\} = \frac{e^{-as}}{s}.

Careful: the function must be shifted too. To transform t2u(t−1)t^2u(t - 1), write t2=(t−1)2+2(t−1)+1t^2 = (t - 1)^2 + 2(t - 1) + 1, so L{t2u(t−1)}=e−s(2s3+2s2+1s)\mathcal{L}\{t^2u(t - 1)\} = e^{-s}\left(\frac{2}{s^3} + \frac{2}{s^2} + \frac{1}{s}\right).

python · try it yourself
import sympy as sp

t, s = sp.symbols("t s", positive=True)
H = sp.Heaviside
for f in (H(t - 2), (t - 1)**2 * H(t - 1), t**2 * H(t - 1), 3 * H(t - 1) - 3 * H(t - 4)):
    print(f"L{{{f}}} =", sp.simplify(sp.laplace_transform(f, t, s, noconds=True)))
L{Heaviside(t - 2)} = exp(-2*s)/s
L{(t - 1)**2*Heaviside(t - 1)} = 2*exp(-s)/s**3
L{t**2*Heaviside(t - 1)} = (s**2 + 2*s + 2)*exp(-s)/s**3
L{-3*Heaviside(t - 4) + 3*Heaviside(t - 1)} = (3*exp(3*s) - 3)*exp(-4*s)/s

Example: a mass pushed for a while

x′′+x=u(t−1)−u(t−4)x'' + x = u(t - 1) - u(t - 4), x(0)=x′(0)=0x(0) = x'(0) = 0. Transforming: (s2+1)X=e−s−e−4ss(s^2 + 1)X = \frac{e^{-s} - e^{-4s}}{s}, so

X=(e−s−e−4s)1s(s2+1),1s(s2+1)=1s−ss2+1  ↔  1−cos⁡t.X = \left(e^{-s} - e^{-4s}\right)\frac{1}{s(s^2 + 1)}, \qquad \frac{1}{s(s^2 + 1)} = \frac{1}{s} - \frac{s}{s^2 + 1} \;\leftrightarrow\; 1 - \cos t.

The shift rule gives

x(t)=(1−cos⁡(t−1))u(t−1)−(1−cos⁡(t−4))u(t−4).x(t) = \big(1 - \cos(t - 1)\big)u(t - 1) - \big(1 - \cos(t - 4)\big)u(t - 4).

After t=4t = 4 the force is gone and the mass oscillates freely.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp

force = lambda t: 1.0 if 1 <= t < 4 else 0.0
sol = solve_ivp(lambda t, Y: [Y[1], force(t) - Y[0]], (0, 8), [0.0, 0.0],
                t_eval=[0.5, 2, 4, 6, 8], max_step=0.01, rtol=1e-10, atol=1e-12)
u = lambda t, a: np.where(t >= a, 1.0, 0.0)
exact = lambda t: (1 - np.cos(t - 1)) * u(t, 1) - (1 - np.cos(t - 4)) * u(t, 4)
for t, x in zip(sol.t, sol.y[0]):
    print(f"t = {t}: solver {x: .6f}, formula {exact(t): .6f}")
t = 0.5: solver  0.000000, formula  0.000000
t = 2.0: solver  0.459698, formula  0.459698
t = 4.0: solver  1.989992, formula  1.989992
t = 6.0: solver -0.699809, formula -0.699809
t = 8.0: solver -1.407546, formula -1.407546

max_step=0.01 keeps the solver from stepping over the switching times; for exact switching, solve each interval separately or use events.

Inverse transforms with exponentials

When e−ase^{-as} appears in Y(s)Y(s), invert the rest and shift: L−1{e−asG(s)}=g(t−a) u(t−a)\mathcal{L}^{-1}\{e^{-as}G(s)\} = g(t - a)\,u(t - a).

python · try it yourself
import sympy as sp

t, s = sp.symbols("t s", positive=True)
Y = (sp.exp(-s) - sp.exp(-4 * s)) / (s * (s**2 + 1))
print(sp.inverse_laplace_transform(Y, s, t))
cos(t - 4)*Heaviside(t - 4) - cos(t - 1)*Heaviside(t - 1) - Heaviside(t - 4) + Heaviside(t - 1)

In software

  • Simulink and similar tools have "step" blocks for exactly this; controller tuning is judged by the "step response".
  • In numerical simulation, discontinuous inputs require care: adaptive solvers must stop at the switching times (events or splitting the integration interval), or they waste steps and lose accuracy.

Exercises

Exercise 1: Write with steps

Write f(t)=0f(t) = 0 for t<2t < 2, tt for 2≤t<52 \le t < 5, 00 for t≥5t \ge 5 using step functions.

Answer

f(t)=t u(t−2)−t u(t−5)f(t) = t\,u(t - 2) - t\,u(t - 5).

Solution

u(t−2)−u(t−5)u(t - 2) - u(t - 5) is 1 exactly on [2,5)[2, 5); multiply by tt.

Exercise 2: Transform

Find L{(t−3)u(t−3)}\mathcal{L}\{(t - 3)u(t - 3)\} and L{t u(t−3)}\mathcal{L}\{t\,u(t - 3)\}.

Answer

e−3ss2\frac{e^{-3s}}{s^2} and e−3s(1s2+3s)e^{-3s}\left(\frac{1}{s^2} + \frac{3}{s}\right).

Solution

The first is the shift rule with f(t)=tf(t) = t. For the second, write t=(t−3)+3t = (t - 3) + 3.

Exercise 3: Switched RC circuit (code)

q′+q=u(t−2)q' + q = u(t - 2), q(0)=0q(0) = 0 (an RC circuit with RC=1RC = 1, battery connected at t=2t = 2). Find q(t)q(t) and q(3)q(3).

Answer

q=(1−e−(t−2))u(t−2)q = (1 - e^{-(t-2)})u(t - 2); q(3)=1−e−1≈0.632q(3) = 1 - e^{-1} \approx 0.632.

Solution

(s+1)Q=e−2ss(s + 1)Q = \frac{e^{-2s}}{s}, and 1s(s+1)=1s−1s+1↔1−e−t\frac{1}{s(s + 1)} = \frac{1}{s} - \frac{1}{s + 1} \leftrightarrow 1 - e^{-t}.

python · try it yourself
import sympy as sp
t, s = sp.symbols("t s", positive=True)
q = sp.inverse_laplace_transform(sp.exp(-2 * s) / (s * (s + 1)), s, t)
print(q, "|", round(float(q.subs(t, 3)), 4))
-exp(2 - t)*Heaviside(t - 2) + Heaviside(t - 2) | 0.6321

Test yourself

L{u(t−5)}\mathcal{L}\{u(t - 5)\} is…

  1. 1s−5\frac{1}{s - 5}
  2. e−5ss\frac{e^{-5s}}{s}
  3. e5se^{5s}
  4. 5s\frac{5}{s}

A factor e−2se^{-2s} in Y(s)Y(s) means the corresponding part of y(t)y(t)…

  1. is multiplied by e−2te^{-2t}
  2. is delayed by 2 and switched on at t=2t = 2
  3. is divided by 2
  4. is zero

The function u(t−1)−u(t−3)u(t - 1) - u(t - 3) equals 1…

  1. for t≥1t \ge 1
  2. for 1≤t<31 \le t < 3
  3. for t<3t < 3
  4. never