Recall that a function $f$ on $[a,b$] is a step function when there exists a partition $P$ of $[a,b]$ such that $f$ is constant on the interior of each $I \in P$.
Show that for any step function f on $[a,b]$, and any $\epsilon > 0$, there is a continuous function $g$ such that $$ \int_{a}^{b}|f(x)-g(x)|dx < \epsilon $$
I know that for every $\epsilon > 0$, $\exists \delta > 0$ s.t. $|x-a| < \delta \implies |g(x)-g(a)| < \epsilon$. But I cannot connect the concept of continuous and step functions together.
The idea of Ted Shifrin is Good. We indicate with
$f_-(x_0):=\lim_{x\to x_0^-}f(x)$;
$f_+(x_0):=\lim_{x\to x_0^+}f(x)$;
The function $f$ is a step function and $[a,b]$ is compact, so there exists $x_1,\dots x_n$ points such that $f$ is not continuos in the point $x_i\in [a,b]$ for each $i=1,\dots n$. WLOG we suppose that
$x_1< x_2< \dots < x_n$
We fix some positive Number $\alpha_1, \dots , \alpha_n$.
We define the following function on (a, x_1]:
$g_1(x):=f_-(x_1)$ for each $x\in (a, x_1-\alpha_1)$
and
$g_1(x):=\frac{f_+(x_1)-f_-(x_1)}{2\alpha_1}(x-(x_1-\alpha_1))+f_-(x_1)$ if $x\in (x_1-\alpha_1, x_1]$
while for each $i=1,\dots n-1$ we define the folliwing function on $[x_i, x_{i+1}]$:
$g_{i+1}(x):=\frac{f_+(x_i)-f_-(x_i)}{2\alpha_i}(x-(x_i-\alpha_i))+f_-(x_i)$ if $x\in [x_i, x_i+\alpha_i)$ ;
$g_{i+1}(x):= f_+(x_i)=f_-(x_{i+1})$ on $[x_i+\alpha_i, x_{i+1}-\alpha_{i+1}]$
and
$g_{i+1}(x):=\frac{f_+(x_{i+1})-f_-(x_{i+1})}{2\alpha_{i+1}}(x-(x_{i+1}-\alpha_{i+1}))+f_-(x_{i+1})$ if $x\in (x_{i+1}-\alpha_{i+1}, x_{i+1}]$
Moreover we define the following last function $g_n$ on $[x_n, b]$:
$g_n(x):=\frac{f_+(x_n)-f_-(x_n)}{2\alpha_n}(x-(x_n-\alpha_n))+f_-(x_n)$ if $x\in [x_n, x_n+\alpha_n)$
$g_n(x):=f_+(x_n)=f(b)$ on $[x_n+\alpha_n, b]$.
It is clear that $g_i$ are continuos functions on their definition domain. Morever these functions coincides on their intersections, so it is possibile to define the natural function
$g:=\cup_{i=1}^ng_n$
defined on $[a, b]$.
This function is continuos by construction.
We fix $\epsilon>0$. The next step is to find the values $\alpha_1,\dots , \alpha_n$ for which it holds
$\int_a^b|f-g|dx < \epsilon$
$\int_a^b|f-g|dx $
$=\sum_{i=1}^{n}(\int_{x_i-\alpha_i}^{x_i}|f_-(x_i)-g|dx +\int_{x_i}^{x_i+\alpha_i}|f_+(x_i)-g|dx)$
$=\sum_{i=1}^{n}(\int_{x_i-\alpha_i}^{x_i}|f_-(x_i)- (\frac{f_+(x_i)-f_-(x_i)}{2\alpha_i}(x-(x_i-\alpha_i))+f_-(x_i ))|dx )$
$+\int_{x_i}^{x_i+\alpha_i}|f_+(x_i)-(\frac{f_+(x_i)-f_-(x_i)}{2\alpha_i}(x-(x_i-\alpha_i))+f_-(x_i ))|dx)$
$=\sum_{i=1}^n(\frac{|f_+(x_i)-f_-(x_i)|}{2\alpha_i}\int_{x_i-\alpha_i}^{x_i} |x-(x_i-\alpha_i))|dx $
$+\frac{|f_+(x_i)-f_-(x_i)|}{2\alpha_i}\int_{x_i}^{x_i+\alpha_i} |(x_i+\alpha_i)-x)|dx)$
$=\sum_{i=1}^n \frac{|f_+(x_i)-f_-(x_i)|}{2\alpha_i}(\frac{\alpha_i^2}{2}+\frac{\alpha_i^2}{2})=$
$=\sum_{i=1}^n \alpha_i\frac{|f_+(x_i)-f_-(x_i)|}{2}$
that is what we expected to find.
Thus we must choose, if they exist, $\alpha_1,\dots , \alpha_n$ such that
$\sum_{i=1}^n \alpha_i\frac{|f_+(x_i)-f_-(x_i)|}{2}<\epsilon$
This inequality is satisfied if
$\alpha_i< 2 \frac{\epsilon}{n|f_+(x_i)-f_-(x_i)|}$
In fact we get that
$\sum_{i=1}^n \alpha_i\frac{|f_+(x_i)-f_-(x_i)|}{2}$
$<\sum_{i=1}^n 2 \frac{\epsilon}{n|f_+(x_i)-f_-(x_i)|} \frac{|f_+(x_i)-f_-(x_i)|}{2}$
$=\sum_{i=1}^n\frac{\epsilon}{n}$
$=n\frac{\epsilon}{n}$
$=\epsilon$
Your exercise is fundamental to prove that the Space of continuos functions $C([a,b])$ is dense in the space of summable functions $L^1[(a,b])$. The idea of the proof is the following:
$cl(S([a,b]) )=L^1([a,b])$;
$g^{\alpha_1^m, \dots ,\alpha_n^m}$ such that
$\alpha_i^m< \frac{2}{mn|f_+(x_i)-f_-(x_i)|}$ and we get
$||f-g^{\alpha_1^m, \dots \alpha_n^m}||_{L_1}= \sum_{i=1}^n \alpha_i\frac{|f_+(x_i)-f_-(x_i)|}{2}$
$<\sum_{i=1}^n \frac{1}{mn}=$
$=n\frac{1}{mn}=$
$=\frac{1}{m}\to_{m\to \infty }0$.
So
$g^{\alpha_1^m, \dots \alpha_n^m}\to_{m\to \infty} f$
Finally we obtain that
$L_1([a,b])=cl(S([a,b])\subseteq cl(cl(C([a,b]))=cl(C([a,b])$