# Piecewise function to heaviside

This was an example from online notes for one of my classes. This is the way the professor wants it to be done but I'm not sure how he arrives at each step. Can someone explain this to me? My attempt to understand it will be posted below each step. The goal is to describe the function g(t) in terms of a heaviside function.

$$g(t) = \begin{cases}2t-1 ,& 0 \leq t < 3 \\5 ,& t \geq 3\end{cases}$$

$Solution:$

$g(t) = (2t-1)H_{03}(t) + 5H_3(t)$

• (2t-1) is from the first function. $H_{03}(t)$ comes from the interval.

• (5) is from the second function. $H_3(t)$ comes from the interval.

$= (2t-1)(H(t) - H_3(t) + 5H_3(t)$

** This was typed up like this on the notes not sure if I'm supposed to ignore that single bracket or add one somewhere.

• I'm assuming the interval $H_{03}$ is split up here. So equation should probably read $(2t-1)(H(t) - H_3(t)) + 5H_3(t)$

$= (2t-1)H(t) + (-2t + 1 + 5)H_3(t)$

• No idea where this came from.

$=(2t-1)H(t) -2(t-3)H(t-3)$

• No idea where this came from.

Could someone confirm my attempts at understanding this and explain the parts that seem to come out of nowhere? This is really confusing me.

## 2 Answers

First, you want to turn "on" the function $2t-1$ at $t=0$. That function is

$$(2t-1)H(t)$$

But this expression keeps the $(2t-1)$ turned "on" for all $t>0$. Instead you want to turn it "off" at $t=3$, so we subtract from this expression the formula $(2t-1)H(t-3)$ (which turns $2t-1$ on at $t=3$).

But also at $t=3$ we want to turn on the constant $5$, so we add $5H(t-3)$.

Hence your piecewise function is

$$(2t-1)H(t)-(2t-1)H(t-3)+5H(t-3)$$

In general case, if $$g(t)=\left\lbrace\begin{array}{c l} g_1(t) &{~~~~~0\leq t<c_1 },\\ g_2(t) &{~~~~c_1\leq t<c_2},\\ g_3(t) &{~~~~c_2\leq t<c_3},\\ \vdots\\ g_{n-1}(t) &{~c_{n-2}\leq t<c_{n-1}},\\ g_n(t) &{~~~~~~t\geq c_{n-1}}. \end{array}\right.$$ then $$g=H_0(g_1)+H_{c_1}(g_2-g_1)+H_{c_2}(g_3-g_2)+\cdots+H_{c_{n-1}}(g_n-g_{n-1})$$