Skip to main content
5 of 5
added 2 characters in body

Area will be red or blue depending whether $b > a$ or not.

Manipulate[
  Plot[{f[x], UnitStep[Sign[b - a] (x - a)] UnitStep[Sign[b - a] (b - x)] f[x]}, 
    {x, -7, 7}, PlotStyle -> {Thick, Thickness[0]}, Filling -> {2 -> 0}, 
  FillingStyle -> Directive[Opacity[.5], If[b - a > 0, Red, Blue]], 
  PlotLabel -> "AREA = " <> ToString[NIntegrate[f[x], {x, a, b}]]], {{b, 4}, -7, 7},   
   {{a, -1}, -7, 7}, {f, {Sin, Cos, Tanh, Sech}}]

enter image description here

enter image description here

Also take a look at source code at the Wolfram Demonstration Project.

Vitaliy Kaurov
  • 73.4k
  • 9
  • 206
  • 365