{ "hash": "7de6019c5ee744a1d63f36de9098cd63", "result": { "markdown": "# Area under a curve\n\n\n\nThis section uses these add-on packages:\n\n``` {.julia .cell-code}\nusing CalculusWithJulia\nusing Plots\nusing QuadGK\nusing Roots\n```\n\n\n\n\n---\n\n\nThe question of area has long fascinated human culture. As children, we learn early on the formulas for the areas of some geometric figures: a square is $b^2$, a rectangle $b\\cdot h$ a triangle $1/2 \\cdot b \\cdot h$ and for a circle, $\\pi r^2$. The area of a rectangle is often the intuitive basis for illustrating multiplication. The area of a triangle has been known for ages. Even complicated expressions, such as [Heron's](http://tinyurl.com/mqm9z) formula which relates the area of a triangle with measurements from its perimeter have been around for 2000 years. The formula for the area of a circle is also quite old. Wikipedia dates it as far back as the [Rhind](http://en.wikipedia.org/wiki/Rhind_Mathematical_Papyrus) papyrus for 1700 BC, with the approximation of $256/81$ for $\\pi$.\n\n\nThe modern approach to area begins with a non-negative function $f(x)$ over an interval $[a,b]$. The goal is to compute the area under the graph. That is, the area between $f(x)$ and the $x$-axis between $a \\leq x \\leq b$.\n\n\nFor some functions, this area can be computed by geometry, for example, here we see the area under $f(x)$ is just $1$, as it is a triangle with base $2$ and height $1$:\n\n::: {.cell hold='true' execution_count=4}\n``` {.julia .cell-code}\nf(x) = 1 - abs(x)\nplot(f, -1, 1)\nplot!(zero)\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n{}\n:::\n:::\n\n\nSimilarly, we know this area is also $1$, it being a square:\n\n::: {.cell hold='true' execution_count=5}\n``` {.julia .cell-code}\nf(x) = 1\nplot(f, 0, 1)\nplot!(zero)\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n{}\n:::\n:::\n\n\nThis one, is simply $\\pi/2$, it being half a circle of radius $1$:\n\n::: {.cell hold='true' execution_count=6}\n``` {.julia .cell-code}\nf(x) = sqrt(1 - x^2)\nplot(f, -1, 1)\nplot!(zero)\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n{}\n:::\n:::\n\n\nAnd this area can be broken into a sum of the area of square and the area of a rectangle, or $1 + 1/2$:\n\n::: {.cell hold='true' execution_count=7}\n``` {.julia .cell-code}\nf(x) = x > 1 ? 2 - x : 1.0\nplot(f, 0, 2)\nplot!(zero)\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n{}\n:::\n:::\n\n\nBut what of more complicated areas? Can these have their area computed?\n\n\n## Approximating areas\n\n\nIn a previous section, we saw this animation:\n\n::: {.cell cache='true' hold='true' execution_count=8}\n\n::: {.cell-output .cell-output-display execution_count=9}\n```{=html}\n
The first triangle has area \\(1/2\\), the second has area \\(1/8\\), then \\(2\\) have area \\((1/8)^2\\), \\(4\\) have area \\((1/8)^3\\), ... With some algebra, the total area then should be \\(1/2 \\cdot (1 + (1/4) + (1/4)^2 + \\cdots) = 2/3\\).
\nIllustration of left Riemann sum for increasing \\(n\\) values
\n