\frametitle{Average Value of a Function}

  How to compute the \textcolor{cblue}{average value} of a function?
    \def\mfun{(-.9 + (\x-3+\mfunshift)^2 - .1*(\x-3+\mfunshift)^4)}

    \begin{scope}[ultra thick]
      \draw[cred] plot[smooth,domain=.5:5.5,samples=100] (\x,{\mfun});
      \node[anchor=north] at (.5,0) {$a$};
      \node[anchor=north] at (5.5,0) {$b$};
      \draw[cblue] (.5,2.01042/5) -- (5.5,2.01042/5);
      \foreach \nrsteps/\mcolor in {6/cred} {
        \foreach \xx in {0,...,\nrsteps} {
          \def\x{.5+ \xx*\mstep}
          \ifthenelse{\lengthtest{\pgfmathresult cm > 0cm}}{
          \draw[thick,draw=\mcolor!60!black,fill=\mcolor,opacity=.5] ({\x},0) rectangle ({\x+\mstep},{\mfun}); 
          \node[include=\mcolor] at ({\x+\mfunshift},{\mfun}) {};
  Idea: split in $n$ rectangles, take their average height.
    \frac{f(x_1) + f(x_2) + \ldots + f(x_n)}{n} 
    \mpause[1]{ &= \frac{1}{n}\sum_{i = 1}^n f(x_i) }
    \mpause{= \frac{1}{n\;\Delta x}\sum_{i = 1}^n f(x_i)\Delta x} \\[-.5ex]
    \mpause{&= \frac{1}{b-a}\sum_{i = 1}^n f(x_i)\Delta x}
    The sum \quad \alert{$\sum_{i = 1}^n f(x_i) \Delta x$} \quad 
    is called \emph{Riemann sum}.