lots of cleanup

This commit is contained in:
jverzani committed 2026-08-11 17:17:08 -04:00
1 parent ae461659e0
commit 253295ff6e
91 files changed
+18268 -7856

No files matched your search

+174 -117
View File
@@ -8,8 +8,7 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using SymPy
using QuadGK
using Roots
@@ -17,7 +16,7 @@ using Roots
---
::: {#fig-kids-jumprope}
```{julia}
#| hold: true
#| echo: false
@@ -31,10 +30,12 @@ A kids' jump rope by Lifeline is comprised of little plastic segments of uniform
nothing
```
![A kids' jump rope by Lifeline is comprised of little plastic segments of uniform length around a cord. The length of the rope can be computed by adding up the lengths of each segment, regardless of how the rope is arranged.
](./figures/jump-rope.png)
![](./figures/jump-rope.png)
The length of the jump rope in the picture can be computed by either looking at the packaging it came in, or measuring the length of each plastic segment and multiplying by the number of segments. The former is easier, the latter provides the intuition as to how we can find the length of curves in the $x-y$ plane. The idea is old, [Archimedes](http://www.maa.org/external_archive/joma/Volume7/Aktumen/Polygon.html) used fixed length segments of polygons to approximate $\pi$ using the circumference of circle producing the bounds $3~\frac{1}{7} > \pi > 3~\frac{10}{71}$.
A kids' jump rope by Lifeline is comprised of little plastic segments of uniform length around a cord. The length of the rope can be computed by adding up the lengths of each segment, regardless of how the rope is arranged.
:::
The length of the jump rope in @fig-kids-jumprope can be computed by either looking at the packaging it came in, or measuring the length of each plastic segment and multiplying by the number of segments. The former is easier, the latter provides the intuition as to how we can find the length of curves in the $x-y$ plane. The idea is old, [Archimedes](http://www.maa.org/external_archive/joma/Volume7/Aktumen/Polygon.html) used fixed length segments of polygons to approximate $\pi$ using the circumference of circle producing the bounds $3~\frac{1}{7} > \pi > 3~\frac{10}{71}$.
A more modern application is the algorithm used by GPS devices to record a path taken. However, rather than record times for a fixed distance traveled, the GPS device records position ($(x,y)$) or longitude and latitude at fixed units of time - similar to how parametric functions are used. The device can then compute distance traveled and speed using some familiar formulas.
@@ -43,13 +44,10 @@ A more modern application is the algorithm used by GPS devices to record a path
## Arc length formula
Recall the distance formula gives the distance between two points: $\sqrt{(x_1 - x_0)^2 + (y_1 - y_0)^2}$.
Consider now two functions $g(t)$ and $f(t)$ and the parameterized graph between $a$ and $b$ given by the points $(g(t), f(t))$ for $a \leq t \leq b$. Assume that both $g$ and $f$ are differentiable on $(a,b)$ and continuous on $[a,b]$ and furthermore that $\sqrt{g'(t)^2 + f'(t)^2}$ is Riemann integrable.
::: {.callout-note icon=false}
## The arc length of a curve
::: {.definition title="The arc length of a parameterized curve"}
For $f$ and $g$ as described, the arc length of the parameterized curve is given by
@@ -63,13 +61,12 @@ For the special case of the graph of a function $f(x)$ between $a$ and $b$ the f
:::{.callout-note}
## Note
The form of the integral may seem daunting with the square root and the derivatives. A more general writing would create a vector out of the two functions: $\phi(t) = \langle g(t), f(t) \rangle$. It is natural to then let $\phi'(t) = \langle g'(t), f'(t) \rangle$. With this, the integrand is just the norm - or length - of the derivative, or $L=\int \| \phi'(t) \| dt$. This is similar to the distance traveled being the integral of the speed, or the absolute value of the derivative of position.
The form of the integral may seem daunting with the square root and the derivatives. A more general writing would create a vector out of the two functions: $\phi(t) = \langle g(t), f(t) \rangle$. It is natural to then let $\phi'(t) = \langle g'(t), f'(t) \rangle$. With this, the integrand is just the norm---or length---of the derivative, or $L=\int \| \phi'(t) \| dt$. This is similar to the distance traveled being the integral of the speed, or the absolute value of the derivative of position.
:::
To see why, any partition of the interval $[a,b]$ by $a = t_0 < t_1 < \cdots < t_n =b$ gives rise to $n+1$ points in the plane given by $(g(t_i), f(t_i))$.
::: {#fig-arc-length-as-riemann-sum-animation}
```{julia}
#| hold: false
#| echo: false
@@ -113,21 +110,27 @@ end
imgfile = tempname() * ".gif"
gif(anim, imgfile, fps = 1)
caption = L"""
The arc length of the parametric curve can be approximated using straight line segments connecting points. This gives rise to an integral expression defining the length in terms of the functions $f$ and $g$.
"""
caption = ""
plotly()
ImageFile(imgfile, caption)
```
The distance between points $(g(t_i), f(t_i))$ and $(g(t_{i-1}), f(t_{i-1}))$ is just
The arc length of the parametric curve can be approximated using straight line segments connecting points. This gives rise to an integral expression defining the length in terms of the functions $f$ and $g$.
:::
Recall the distance formula:
$$
\text{distance between points} = \sqrt{(x_1 - x_0)^2 + (y_1 - y_0)^2}.
$$
We use this to see why the arc-length formula has its form. Let $a = t_0 < t_1 < \cdots < t_n =b$ be any partition of the interval $[a,b]$. This partition gives rise to $n+1$ points in the plane given by $(g(t_i), f(t_i))$. The distance between points $(g(t_i), f(t_i))$ and $(g(t_{i-1}), f(t_{i-1}))$ is given by the distance formula:
$$
d_i = \sqrt{(g(t_i)-g(t_{i-1}))^2 + (f(t_i)-f(t_{i-1}))^2}
d_i = \sqrt{(g(t_i)-g(t_{i-1}))^2 + (f(t_i)-f(t_{i-1}))^2}.
$$
The total approximate distance of the curve would be $L_n = d_1 + d_2 + \cdots + d_n$. This is exactly how we would compute the length of the jump rope or the distance traveled from GPS recordings.
@@ -157,7 +160,7 @@ $$
The values $\xi_i$ and $\psi_i$ are guaranteed by the mean value theorem and must be in $[t_{i-1}, t_i]$.
With this, if $\sqrt{f'(t)^2 + g'(t)^2}$ is integrable, as assumed, then as the size of the partition goes to zero, the sum of the $d_i$, $L_n$, must converge to the integral:
With this, if $\sqrt{f'(t)^2 + g'(t)^2}$ is integrable, as assumed, then as the size of the partition goes to zero (as suggested in @fig-arc-length-as-riemann-sum-animation) the sum of the $d_i$, $L_n$, must converge to the integral:
$$
@@ -190,14 +193,20 @@ F = integrate(sqrt(1 + (2x)^2), x)
F(1) - F(0)
```
That number has some context, as can be seen from the graph, which gives simple lower and upper bounds of $\sqrt{1^2 + 1^2} = 1.414...$ and $1 + 1 = 2$.
That number has some context, as can be seen from the graph in @fig-plot-x-squared-bounds-are-easy-for-arclength, which gives simple lower and upper bounds of $\sqrt{1^2 + 1^2} = 1.414...$ and $1 + 1 = 2$.
::: {#fig-plot-x-squared-bounds-are-easy-for-arclength}
```{julia}
#| echo: false
f(x) = x^2
plot(f, 0, 1)
plot(f, 0, 1; legend=false, line=(2, :black))
plot!([(0,0), (1,1)]; line=(1, :black, :dot))
plot!([(0,0), (1,0), (1,1)]; line=(1, :black, :dash))
```
The graph of $f(x) = x^2$ over $[0,1]$ has length *between* $\sqrt{2}$ (dotted line) and $2 = 1 + 1$ (dashed line segments)
:::
:::{.callout-note}
## Note
The integrand $\sqrt{1 + f'(x)^2}$ may seem odd at first, but it can be interpreted as the length of the hypotenuse of a right triangle with "run" of $1$ and "rise" of $f'(x)$. This triangle is easily formed using the tangent line to the graph of $f(x)$. By multiplying by $dx$, the integral is "summing" up the lengths of infinitesimal pieces of the tangent line approximation.
@@ -211,8 +220,12 @@ Let $f(t) = R\cos(t)$ and $g(t) = R\sin(t)$. Then the parametric curve over $[0,
$$
L = \int_0^{2\pi} \sqrt{(R\cos(t))^2 + (-R\sin(t))^2} dt = R\int_0^{2\pi} \sqrt{\cos(t)^2 + \sin(t)^2} dt =
R\int_0^{2\pi} dt = 2\pi R.
\begin{align*}
L &= \int_0^{2\pi} \sqrt{(R\cos(t))^2 + (-R\sin(t))^2} dt\\
&= R\int_0^{2\pi} \sqrt{\cos(t)^2 + \sin(t)^2} dt \\
&= R\int_0^{2\pi} dt \\
&= 2\pi R.
\end{align*}
$$
##### Example
@@ -239,32 +252,35 @@ Which isn't so satisfying. From a quick graph, we see the answer should be no mo
```{julia}
N(ex)
float(ex)
```
##### Example
A [catenary shape](http://en.wikipedia.org/wiki/Catenary) is the shape a hanging chain will take as it is suspended between two posts. It appears elsewhere, for example, power wires will also have this shape as they are suspended between towers. A formula for a catenary can be written in terms of the hyperbolic cosine, `cosh` in `julia` or exponentials.
A [catenary shape](http://en.wikipedia.org/wiki/Catenary) is the shape a hanging chain will take as it is suspended between two posts. It appears elsewhere, for example, power wires will also have this shape as they are suspended between towers. A formula for a catenary can be written in terms of the hyperbolic cosine, `cosh` in `Julia` or exponentials.
$$
y = a \cosh(x/a) = a \cdot \frac{e^{x/a} + e^{-x/a}}{2}.
$$
Suppose we have the following chain hung between $x=-1$ and $x=1$ with $a = 2$:
Suppose we have a chain hung between $x=-1$ and $x=1$ with $a = 2$, as in @fig-catenary-with-a-equal-2-over-minus-1-1.
::: {#fig-catenary-with-a-equal-2-over-minus-1-1}
```{julia}
chain(x; a=2) = a * cosh(x/a)
plot(chain, -1, 1)
```
Plot of catenary $a\cosh(x/a)$ with $a=2$ over $[-1,1]$
:::
How long is the chain? Looking at the graph we can guess an answer is between $2$ and $2.5$, say, but it isn't much work to get an approximate numeric answer. Recall, the accompanying `CalculusWithJulia` package defines `f'` to find the derivative using the `ForwardDiff` package.
```{julia}
quadgk(x -> sqrt(1 + chain'(x)^2), -1, 1)[1]
first(quadgk(x -> sqrt(1 + chain'(x)^2), -1, 1))
```
We used a numeric approach, but this can be solved by hand and the answer is surprising.
@@ -273,24 +289,27 @@ We used a numeric approach, but this can be solved by hand and the answer is sur
##### Example
This picture of Jasper John's [Near the Lagoon](http://www.artic.edu/aic/collections/artwork/184095) was taken at The Art Institute Chicago.
@fig-jasper-johns-catenary-chicago shows Jasper Johns' [Near the Lagoon](http://www.artic.edu/aic/collections/artwork/184095) from The Art Institute of Chicago.
::: {#fig-jasper-johns-catenary-chicago}
```{julia}
#| hold: true
#| echo: false
imgfile = "figures/johns-catenary.jpg"
caption = "One of Jasper Johns' Catenary series. Art Institute of Chicago."
caption = "One of Jasper Johns' Catenary series. The Art Institute of Chicago."
# ImageFile(:integrals, imgfile, caption)
nothing
```
![One of Jasper Johns' Catenary series. Art Institute of Chicago.](./figures/johns-catenary.jpg)
![](./figures/johns-catenary.jpg)
One of Jasper Johns' Catenary series (The Art Institute of Chicago)
:::
The museum notes have
> For his Catenary series (1997–2003), of which Near the Lagoon is the largest and last work, Johns formed catenaries—a term used to describe the curve assumed by a cord suspended freely from two points—by tacking ordinary household string to the canvas or its supports.
> For his Catenary series (1997–2003), of which Near the Lagoon is the largest and last work, Johns formed catenaries—a term used to describe the curve assumed by a cord suspended freely from two points—by tacking ordinary household string to the canvas or its supports.
@@ -324,7 +343,7 @@ Rounding, we take $a=13$. With these parameters ($a=13$, $b = 131$), we compute
a = 13
b = 118 + a
f(x) = cat(x; a=13, b=118+13)
quadgk(x -> sqrt(1 + f'(x)^2), -78/2, 78/2)[1]
first(quadgk(x -> sqrt(1 + f'(x)^2), -78/2, 78/2))
```
##### Example
@@ -339,8 +358,9 @@ The Verrazzano-Narrows [Bridge](https://www.brownstoner.com/brooklyn-life/verraz
Suppose the drop of the main cables is $147$ meters over this span. Then the cable itself can be modeled as a parabola with
* The $x$-intercepts $a = 1298/2$ and $-a$ and
* vertex $(0,b)$ with $b=-147$.
* The $x$-intercepts $a = 1298/2$ and $-a$ and
* vertex $(0,b)$ with $b=-147$.
The parabola that fits these three points is
@@ -362,6 +382,7 @@ val, _ = quadgk(x -> sqrt(1 + f'(x)^2), -a, a)
val
```
::: {#fig-verrazzano-bridge-unloaded-during-construction}
```{julia}
#| hold: true
#| echo: false
@@ -373,8 +394,12 @@ The Verrazzano-Narrows Bridge during construction. The unloaded suspension cable
nothing
```
![The Verrazzano-Narrows Bridge during construction. The unloaded suspension cables form a catenary.](./figures/verrazzano-unloaded.jpg)
![](./figures/verrazzano-unloaded.jpg)
The Verrazzano-Narrows Bridge during construction. The unloaded suspension cables form a catenary.
:::
::: {#fig-verrazzano-bridge-loaded-after-construction}
```{julia}
#| hold: true
#| echo: false
@@ -386,13 +411,15 @@ A rendering of the Verrazzano-Narrows Bridge after construction (cf. [nycgovpark
nothing
```
![A rendering of the Verrazzano-Narrows Bridge after construction (cf. [nycgovparks.org](https://www.nycgovparks.org/highlights/verrazano-bridge)). The uniformly loaded suspension cables would form a parabola, presumably a fact the artist of this rendering knew. (The spelling in the link is not the official spelling, which carries two zs.)
](./figures/verrazzano-loaded.jpg)
![](./figures/verrazzano-loaded.jpg)
A rendering of the Verrazzano-Narrows Bridge after construction (cf. [nycgovparks.org](https://www.nycgovparks.org/highlights/verrazano-bridge)). The uniformly loaded suspension cables would form a parabola, presumably a fact the artist of this rendering knew. (The spelling in the link is not the official spelling, which carries two zs.)
:::
##### Example
The [nephroid](http://www-history.mcs.st-and.ac.uk/Curves/Nephroid.html) is a curve that can be described parametrically by
The [nephroid](https://mathshistory.st-andrews.ac.uk/Curves/Nephroid/) is a curve that can be described parametrically by
$$
@@ -405,14 +432,17 @@ $$
Taking $a=1$ we have this graph:
::: {#fig-nephroid-with-a-equal-1}
```{julia}
a = 1
𝒈(t) = a*(3cos(t) - cos(3t))
𝒇(t) = a*(3sin(t) - sin(3t))
plot(𝒈, 𝒇, 0, 2pi)
g(t) = a * (3cos(t) - cos(3t))
f(t) = a * (3sin(t) - sin(3t))
plot(g, f, 0, 2pi)
```
Parametric plot of nephroid
:::
Find the length of the perimeter of the closed figure formed by the graph.
@@ -420,7 +450,7 @@ We have $\sqrt{g'(t)^2 + f'(t)^2} = \sqrt{18 - 18\cos(2t)}$. An antiderivative i
```{julia}
quadgk(t -> sqrt(𝒈'(t)^2 + 𝒇'(t)^2), 0, 2pi)[1]
quadgk(t -> sqrt(g'(t)^2 + f'(t)^2), 0, 2pi)[1]
```
The answer seems like a floating point approximation of $24$, which suggests that this integral is tractable. Pursuing this, the integrand simplifies:
@@ -446,14 +476,18 @@ By graphing, we see that integrating over $[0,2\pi]$ gives twice the answer to i
$$
L = \int_0^{2\pi} \sqrt{g'(t)^2 + f'(t)^2}dt = \int_0^{2\pi} 3\sqrt{2}\sqrt{2\sin(t)^2} =
3 \cdot 2 \cdot 2 \int_0^\pi \sin(t) dt = 3 \cdot 2 \cdot 2 \cdot 2 = 24.
\begin{align*}
L &= \int_0^{2\pi} \sqrt{g'(t)^2 + f'(t)^2}dt = \int_0^{2\pi} 3\sqrt{2}\sqrt{2\sin(t)^2}\\
&= 3 \cdot 2 \cdot 2 \int_0^\pi \sin(t) dt = 3 \cdot 2 \cdot 2 \cdot 2 \\
&= 24.
\end{align*}
$$
##### Example
The following link shows how the perimeter of a complex figure relates to the perimeter of a circle:
::: {#fig-tweet-of-pineapple-shape-being-formed}
```{julia}
#| echo: false
tweet = """
@@ -463,10 +497,13 @@ tweet = """
HTMLoutput(tweet)
```
Relationship of perimeter of circle to a complex shape
:::
##### Example
A teacher of small children assigns his students the task of computing the length of a jump rope by counting the number of $1$-inch segments it is made of. He knows that if a student is accurate, no matter how fast or slow they count the answer will be the same. (That is, unless the student starts counting in the wrong direction by mistake). The teacher knows this, as he is certain that the length of curve is independent of its parameterization, as it is a property intrinsic to the curve.
A teacher of small children assigns his students the task of computing the length of a jump rope by counting the number of $1$-inch segments it is made of. He knows that if a student is accurate, no matter how fast or slow they count the answer will be the same. (That is, unless the student starts counting in the wrong direction by mistake). The teacher knows this, as they are certain that the length of curve is independent of its parameterization, as it is a property intrinsic to the curve.
Mathematically, suppose a curve is described parametrically by $(g(t), f(t))$ for $a \leq t \leq b$. A new parameterization is provided by $\gamma(t)$. Suppose $\gamma$ is strictly increasing, so that an inverse function exists. (This assumption is implicitly made by the teacher, as it implies the student won't start counting in the wrong direction.) Then the same curve is described by composition through $(g(\gamma(u)), f(\gamma(u)))$, $\gamma^{-1}(a) \leq u \leq \gamma^{-1}(b)$. That the arc length is the same follows from substitution:
@@ -495,7 +532,7 @@ $$
\gamma(u) = \int_0^u \sqrt{g'(t)^2 + f'(t)^2} dt.
$$
Supposing $\sqrt{g'(t)^2 + f'(t)^2}$ is continuous and positive, This transformation is increasing, as its derivative by the Fundamental Theorem of Calculus is $\gamma'(u) = \sqrt{g'(u)^2 + f'(u)^2}$, which by assumption is positive. (It is certainly non-negative.) So there exists an inverse function. That it exists is one thing, computing all of this is a different matter, of course.
Supposing $\sqrt{g'(t)^2 + f'(t)^2}$ is continuous and positive, This transformation is increasing, as its derivative---by the Fundamental Theorem of Calculus---is $\gamma'(u) = \sqrt{g'(u)^2 + f'(u)^2}$, which by assumption is positive. (It is certainly non-negative.) So there exists an inverse function. That it exists is one thing, computing all of this is a different matter, of course.
For a simple example, we have $g(t) = R\cos(t)$ and $f(t)=R\sin(t)$ parameterizing the circle of radius $R$. The arc length between $0$ and $t$ is simply $\gamma(t) = Rt$, which we can easily see from the formula. The inverse of this function is $\gamma^{-1}(u) = u/R$, so we get the parameterization $(g(Rt), f(Rt))$ for $0/R \leq t \leq 2\pi/R$.
@@ -517,38 +554,40 @@ Where $C = 2c + c^2$ is a constant. But, despite it not looking too daunting, th
```{julia}
𝒂, 𝒃 = 1, 2
𝒔(u) = quadgk(t -> sqrt(𝒂^2 * sin(t)^2 + 𝒃^2 * cos(t)^2), 0, u)[1]
a, b = 1, 2
s(u) = first(quadgk(t -> sqrt(a^2 * sin(t)^2 + b^2 * cos(t)^2), 0, u))
```
This has a graph, which does not look familiar, but we can see is monotonically increasing, so will have an inverse function:
This has a graph shown in @fig-plot-arc-length-parameterization which does not look familiar, but we can see is monotonically increasing, so will have an inverse function whose domain will be $[0, s(2\pi)]$.
::: {#fig-plot-arc-length-parameterization}
```{julia}
plot(s, 0, 2pi)
```
Plot of $s$ over $[0, 2\pi]$. This monotonic function has some inverse function.
:::
The inverse function can be found by solving numerically. We use the bracketing version of `find_zero` for this:
```{julia}
plot(𝒔, 0, 2pi)
sinv(u) = find_zero(x -> s(x) - u, (0, s(2pi)))
```
The range is $[0, s(2\pi)]$.
The inverse function can be found by solving, we use the bracketing version of `find_zero` for this:
```{julia}
sinv(u) = find_zero(x -> 𝒔(x) - u, (0, 𝒔(2pi)))
```
Here we see visually that the new parameterization yields the same curve:
@fig-plot-g-f-parameterized-by-arc-length shows that the new parameterization yields the same elliptical curve.
::: {#fig-plot-g-f-parameterized-by-arc-length}
```{julia}
#| hold: true
g(t) = 𝒂 * cos(t)
f(t) = 𝒃 * sin(t)
plot(t -> g(𝒔(t)), t -> f(𝒔(t)), 0, sinv(2*pi))
g(t) = a * cos(t)
f(t) = b * sin(t)
plot(g∘s, f∘s, 0, sinv(2*pi))
```
Plot of $(g(s(t)), f(s(t)))$ shows the parameterization doesn't effect the shape of the resulting curve
:::
#### Example: An implication of concavity
@@ -563,69 +602,79 @@ Following (faithfully) [Kantorwitz and Neumann](https://www.researchgate.net/pub
```{julia}
#| hold: true
#| echo: false
function trajectory(x; g = 9.8, v0 = 50, theta = 45*pi/180, k = 1/8)
let
gr()
function trajectory(x; g = 9.8, v0 = 50, theta = 45*pi/180, k = 1/8)
a = v0 * cos(theta)
(g/(k*a) + tan(theta))* x + (g/k^2) * log(1 - k/a*x)
end
v0 = 50; theta = 45*pi/180; k = 1/5
a = v0 * cos(theta)
(g/(k*a) + tan(theta))* x + (g/k^2) * log(1 - k/a*x)
Δ = a/k
a = find_zero(trajectory, (50, Δ-1/10))
plt = plot(;legend=false, ylims=(0,90))
plot!(trajectory,0, a; line=(5, :blue))
u=25
fu = trajectory(u)
v = find_zero(x -> trajectory(x) - fu, (50, Δ))
plot!([u,v], [fu,fu]; line=(1, :black))#, linestyle = :dash)
c = find_zero(trajectory', (50, 100))
plot!([c,c],[0, trajectory(c)]; line=(1, :black))
h(y)= tangent(trajectory, u)(y) - tangent(trajectory, v)(y)
d = find_zero(h, (u,v))
plot!(tangent(trajectory, u), 5, 110; line=(1, :black))
plot!(tangent(trajectory, v), 80, 150; line=(1, :black))
plot!(zero)
𝒚 = 4
annotate!([(0, 𝒚, text(L"a")), (152, 𝒚, text(L"b")), (u, 𝒚, text(L"u")),
(v, 𝒚, text(L"v")), (c, 𝒚, text(L"c",:right))])
plotly()
plt
end
v0 = 50; theta = 45*pi/180; k = 1/5
𝒂 = v0 * cos(theta)
Δ = 𝒂/k
a = find_zero(trajectory, (50, Δ-1/10))
plot(trajectory,0, a, legend=false, linewidth=5)
u=25
fu = trajectory(u)
v = find_zero(x -> trajectory(x) - fu, (50, Δ))
plot!([u,v], [fu,fu])#, linestyle = :dash)
c = find_zero(trajectory', (50, 100))
plot!([c,c],[0, trajectory(c)])
h(y)= tangent(trajectory, u)(y) - tangent(trajectory, v)(y)
d = find_zero(h, (u,v))
plot!(tangent(trajectory, u), 0, 110)
plot!(tangent(trajectory, v), 75, 150)
plot!(zero)
𝒚 = 4
annotate!([(0, 𝒚, "a"), (152, 𝒚, "b"), (u, 𝒚, "u"), (v, 𝒚, "v"), (c, 𝒚, "c")])
```
Graph of function $f(x)$ with both $f$ and $f'$ strictly concave down.
:::
By Rolle's theorem there exists $c$ in $(a,b)$, a critical point, as in the picture. There must be a critical point by Rolle's theorem, and it must be unique, as the derivative, which exists by the assumptions, must be strictly decreasing due to concavity of $f$ and hence there can be at most $1$ critical point.
By Rolle's theorem there exists a critical point $c$ in $(a,b)$, as in the picture. There must be a unique critical point as the derivative, which exists by the assumptions, must be strictly decreasing due to concavity of $f$.
Take $a < u < c < v < b$ with $f(u) = f(v)$.
Some facts about this picture can be proven from the definition of concavity:
> The slope of the tangent line at $u$ goes up slower than the slope of the tangent line at $v$ declines: $f'(u) < -f'(v)$.
Since $f'$ is *strictly* concave, we have for any $a<u<v<b$ from the definition of concavity that for all $0 \leq t \leq 1$
Some facts about this picture can be proven from this definition of *strict* concavity of $f'$ for all $0 \le t \le 1$:
$$
tf'(u) + (1-t)f'(v) < f'(tu + (1-t)v).
$$
So
First:
> The slope of the tangent line at $u$ goes up slower than the slope of the tangent line at $v$ declines: $f'(u) < -f'(v)$.
Since $f'$ is *strictly* concave, we have by integrating both sides of the concavity inequality:
$$
\begin{align*}
\int_0^1 (tf'(u) + (1-t)f'(v)) dt &< \int_0^1 f'(tu + (1-t)v) dt, \text{or}\\
\frac{f'(u) + f'(v)}{2} &< \frac{1}{v-u}\int_u^v f'(w) dw,
\end{align*}
\int_0^1 (tf'(u) + (1-t)f'(v)) dt < \int_0^1 f'(tu + (1-t)v) dt.
$$
Integrating the left-hand side and using the substitution $w = tu + (1-t)v$ on the right yields:
$$
\frac{f'(u) + f'(v)}{2} < \frac{1}{v-u}\int_u^v f'(w) dw.
$$
by the substitution $w = tu + (1-t)v$. Using the fundamental theorem of calculus to compute the mean value of the integral of $f'$ over $[u,v]$ gives the following as a consequence of strict concavity of $f'$:
Using the fundamental theorem of calculus to compute the integral of $f'$ over $[u,v]$ gives the following as a consequence of strict concavity of $f'$:
$$
@@ -768,7 +817,7 @@ $$
$$
Letting $h=f(u \rightarrow c)$ we get the *inequality*
Letting $u \rightarrow c$ we get the *inequality*:
$$
@@ -798,14 +847,22 @@ This comes from solving the projectile motion equations with a drag force *propo
```{julia}
#| hold: true
@syms gₑ::positive, k::positive, v₀::positive, θ::positive, x::positive
ex = (gₑ/(k*v₀*cos(θ)) + tan(θ))*x + gₑ/k^2 * log(1 - k/(v₀*cos(θ))*x)
diff(ex, x, x), diff(ex, x, x, x,)
ex = (gₑ/(k*v₀*cos(θ)) + tan(θ))*x + gₑ/k^2 * log(1 - k*x/(v₀*cos(θ)))
diff(ex, x, x)
```
Both the second and third derivatives are negative (as $0 \leq x < (v_0\cos(\theta))/k$ due to the logarithm term), so, both $f$ and $f'$ are strictly concave down. Hence the results above apply. That is the arrow will fly further as it goes up, than as it comes down and will carve out more area on its way up, than its way down. The trajectory could also show time versus height, and the same would hold, e.g, the arrow would take longer to go up than come down.
So the second derivative is negative. Furthermore:
```{julia}
diff(ex, x, x, x)
```
But the logarithm term in `ex` ensures $1 - k\cdot x / (v_0\cos(\theta)) > 0$, so $f'''$ is also negative and $f'$ is strictly concave down. Hence the results above apply.
That is the arrow will fly further as it goes up, than as it comes down and will carve out more area on its way up, than its way down. The trajectory could also show time versus height, and the same would hold, e.g, the arrow would take longer to go up than come down.
In general, the drag force need not be proportional to the velocity, but merely in opposite direction to the velocity vector $\langle x'(t), y'(t) \rangle$:
In general, Kantorwitz and Neumann note that the drag force need not be proportional to the velocity---merely in opposite direction to the velocity vector $\langle x'(t), y'(t) \rangle$:
$$
+307 -917
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+220 -130
View File
@@ -8,18 +8,17 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using Roots
using QuadGK
using SymPy
```
---
::: {#fig-seesaw-image-for-center-of-mass}
```{julia}
#| hold: true
#| echo: false
@@ -37,15 +36,18 @@ distance, the balance will tip in favor of the heavier.
nothing
```
![A silhouette of two children on a seesaw. The seesaw can be balanced
![
](./figures/seesaw.png)
A silhouette of two children on a seesaw. The seesaw can be balanced
only if the distance from the central point for each child reflects
their relative weights, or masses, through the formula $d_1m_1 = d_2
m_2$. This means if the two children weigh the same the balance will
tip in favor of the child farther away, and if both are the same
distance, the balance will tip in favor of the heavier.
](./figures/seesaw.png)
:::
The game of seesaw is one where children earn an early appreciation for the effects of distance and relative weight. For children with equal weights, the seesaw will balance if they sit an equal distance from the center (on opposite sides, of course). However, with unequal weights that isn't the case. If one child weighs twice as much, the other must sit twice as far.
@fig-seesaw-image-for-center-of-mass shows the game of seesaw. One where children earn an early appreciation for the effects of distance and relative weight. For children with equal weights, the seesaw will balance if they sit an equal distance from the center (on opposite sides, of course). However, with unequal weights that isn't the case. If one child weighs twice as much, the other must sit twice as far.
The key relationship is that $d_1 m_1 = d_2 m_2$. This come from physics, where the moment about a point is defined by the mass times the distance. This balance relationship says the overall moment balances out. When this is the case, then the *center of mass* is at the fulcrum point, so there is no impetus to move.
@@ -58,7 +60,7 @@ In general, we use position of the mass, rather than use distance from some fixe
$$
\bar{\text{cm}} = \frac{m_1 x_1 + m_2 x_2 + \cdots + m_n x_n}{m_1 + m_2 + \cdots + m_n}.
\overline{\text{cm}} = \frac{m_1 x_1 + m_2 x_2 + \cdots + m_n x_n}{m_1 + m_2 + \cdots + m_n}.
$$
Writing $w_i = m_i / (m_1 + m_2 + \cdots + m_n)$, we get the center of mass is just a weighted sum: $w_1 x_1 + \cdots + w_n x_n$, where the $w_i$ are the relative weights.
@@ -68,10 +70,10 @@ With some rearrangement, we can see that the center of mass satisfies the equati
$$
w_1 \cdot (x_1 - \bar{\text{cm}}) + w_2 \cdot (x_2 - \bar{\text{cm}}) + \cdots + w_n \cdot (x_n - \bar{\text{cm}}) = 0.
w_1 \cdot (x_1 - \overline{\text{cm}}) + w_2 \cdot (x_2 - \overline{\text{cm}}) + \cdots + w_n \cdot (x_n - \overline{\text{cm}}) = 0.
$$
The center of mass is a balance of the weighted signed distances. This property of the center of mass being a balancing point makes it of intrinsic interest and can be - in the case of sufficient symmetry - easy to find.
The center of mass is a balance of the weighted signed distances. This property of the center of mass being a balancing point makes it of intrinsic interest and can be---in the case of sufficient symmetry---easy to find.
##### Example
@@ -80,7 +82,7 @@ The center of mass is a balance of the weighted signed distances. This property
A set of weights sits on a dumbbell rack. They are spaced 1 foot apart starting with the 5, then the 10-, 15-, 25-, and 35-pound weights. Where is the center of mass?
We begin by letting $m_1=5$, $m_2=10$, $m_3=15$, $m_4=25$ and $m_5=35$. Our positions will be labeled $x_i = i-1$, so the five-pound weight is at position $0$ and the $35$-pound one at $4$. The center of mass is then given by:
We begin by letting $m_1=5$, $m_2=10$, $m_3=15$, $m_4=25$ and $m_5=35.$ Our positions will be labeled $x_i = i-1$, so the five-pound weight is at position $0$ and the $35$-pound one at $4$. The center of mass is then given by:
$$
@@ -106,17 +108,21 @@ The center of mass shifts slightly, but since the removed weight was already clo
Consider now a more general problem, the center of mass of a solid figure. We will restrict our attention to figures that can be represented by functions in the $x-y$ plane which are two dimensional. For example, consider the region in the plane bounded by the $x$ axis and the function $1 - \lvert x \rvert$. This is triangle with vertices $(-1,0)$, $(0,1)$, and $(1,0)$.
This graph shows that the figure is symmetric:
@fig-graph-1-absx-over-minus-3-over-2-to-3-over-2 shows that the graph is symmetric:
::: {#fig-graph-1-absx-over-minus-3-over-2-to-3-over-2}
```{julia}
#| hold: true
#| echo: false
f(x) = 1 - abs(x)
a, b = -1.5, 1.5
plot(f, a, b)
plot(f, a, b; legend=false)
plot!(zero, a, b)
```
Plot of symmetric function $1 - \lvert x \rvert$ over $[-3/2, 3/2]$
:::
As the center of mass should be a balancing value, we would guess intuitively that the center of mass in the $x$ direction will be $x=0$.
@@ -125,7 +131,7 @@ But what should the center of mass formula be?
As with many formulas that will end up involving a derived integral, we start with a sum approximation. If the region is described as the area under the graph of $f(x)$ between $a$ and $b$, then we can form a Riemann sum approximation, that is a choice of $a = x_0 < x_1 < x_2 \cdots < x_n = b$ and points $c_1$, $\dots$, $c_n$. If all the rectangles are made up of a material of uniform density, say $\rho$, then the mass of each rectangle will be the area times $\rho$, or $\rho f(c_i) \cdot (x_i - x_{i-1})$, for $i = 1, \dots , n$.
::: {#fig-center-of-mass-of-1-minus-absx}
```{julia}
#| hold: true
#| echo: false
@@ -152,34 +158,38 @@ plot!(p, [-1,1], [0,0])
p
```
The figure shows the approximating rectangles and circles representing their masses for $n=20$.
Approximating rectangles with circles representing their masses for a equal sized partition of $[-3/2, 3/2$ with $n=20$
:::
Generalizing from this figure shows the center of mass for such an approximation will be:
Generalizing from @fig-center-of-mass-of-1-minus-absx shows the center of mass for such an approximation will be:
$$
\begin{align*}
&\frac{\rho f(c_1) (x_1 - x_0) \cdot x_1 + \rho f(c_2) (x_2 - x_1) \cdot x_1 + \cdots + \rho f(c_n) (x_n- x_{n-1}) \cdot x_{n-1}}{\rho f(c_1) (x_1 - x_0) + \rho f(c_2) (x_2 - x_1) + \cdots + \rho f(c_n) (x_n- x_{n-1})} \\
&=\\
&\quad\frac{f(c_1) (x_1 - x_0) \cdot x_1 + f(c_2) (x_2 - x_1) \cdot x_1 + \cdots + f(c_n) (x_n- x_{n-1}) \cdot x_{n-1}}{f(c_1) (x_1 - x_0) + f(c_2) (x_2 - x_1) + \cdots + f(c_n) (x_n- x_{n-1})}.
&=
\frac{f(c_1) (x_1 - x_0) \cdot x_1 + f(c_2) (x_2 - x_1) \cdot x_1 + \cdots + f(c_n) (x_n- x_{n-1}) \cdot x_{n-1}}{f(c_1) (x_1 - x_0) + f(c_2) (x_2 - x_1) + \cdots + f(c_n) (x_n- x_{n-1})}.
\end{align*}
$$
But the top part is an approximation to the integral $\int_a^b x f(x) dx$ and the bottom part the integral $\int_a^b f(x) dx$. The ratio of these defines the center of mass.
::: {.callout-note icon=false}
## Center of Mass
::: {.definition title="Center of mass"}
The center of mass (in the $x$ direction) of a region in the $x-y$ plane described by the area under a (positive) function $f(x)$ between $a$ and $b$ is given by
$$
\text{Center of mass} =
\text{cm}_x = \frac{\int_a^b xf(x) dx}{\int_a^b f(x) dx}.
\overline{\text{cm}}_x = \frac{\int_a^b xf(x) dx}{\int_a^b f(x) dx}.
$$
For regions described by a more complicated set of equations, the center of mass is found from the same formula where $f(x)$ is the total height in the $x$ direction for a given $x$.
For a region bounded between $g(x) \le f(x)$ over $[a,b]$ the center of mass is given by:
$$
\overline{\text{cm}}_x = \frac{\int_a^b x(f(x)-g(x)) dx}{\int_a^b (f(x)-g(x)) dx}.
$$
:::
@@ -189,51 +199,63 @@ For the triangular shape, we have by the fact that $f(x) = 1 - \lvert x \rvert$
##### Example
What about the center of mass of the triangle formed by the line $x=-1$, the $x$ axis and $(1-x)/2$? This too is defined between $a=-1$ and $b=1$, but the center of mass will be negative, as a graph shows more mass to the left of $0$ than the right:
What about the center of mass of the triangle formed by the line $x=-1$, the $x$ axis and $(1-x)/2$? This too is defined between $a=-1$ and $b=1,$ but the center of mass will be negative, as a graph shows more mass to the left of $0$ than the right:
::: {#fig-plot-1-x-over-2-and-center-of-mass}
```{julia}
#| hold: true
#| echo: false
f(x) = (1-x)/2
plot(f, -1, 1)
plot!(zero, -1, 1)
plot(f, -1, 1; legend=false, line=(1, :black))
plot!(zero; line=(1, :black))
plot!([(-1,0), (-1, f(-1))]; line=(1, :black))
```
Plot of $(1-x)/2$ over $[-1, 1]$
:::
The formulas give:
$$
\int_{-1}^1 xf(x) dx = \int_{-1}^1 x\cdot (1-x)/2 = (\frac{x^2}{4} - \frac{x^3}{6})\big|_{-1}^1 = -\frac{1}{3}.
\int_{-1}^1 xf(x) dx = \int_{-1}^1 x\cdot (1-x)/2 = \left(\frac{x^2}{4} - \frac{x^3}{6}\right)\Big|_{-1}^1 = -\frac{1}{3}.
$$
The bottom integral is just the area (or total mass if the $\rho$ were not canceled) and by geometry is $1/2 (1)(2) = 1$. So $\text{cm}_x = -1/3$.
The bottom integral is just the area (or total mass if the $\rho$ were not canceled) and by geometry is $1/2 (1)(2) = 1$. So $\overline{\text{cm}}_x = -1/3$.
##### Example
Find the center of mass formed by the intersection of the parabolas $y=1 - x^2$ and $y=(x-1)^2 - 2$.
The center of mass (in the $x$ direction) can be seen to be close to $x=1/2$:
Find the center of mass formed by the intersection of the parabolas $y=1 - x^2$ and $y=(x-1)^2 - 2$. @fig-center-of-mass-of-two-parabola-1-minus-xsquared-and-x-minus-1-sqared-minus-2 shows that for the $x$ direction, it is close to $1/2$.
::: {#fig-center-of-mass-of-two-parabola-1-minus-xsquared-and-x-minus-1-sqared-minus-2}
```{julia}
#| echo: false
f1(x) = 1 - x^2
f2(x) = (x-1)^2 -2
plot(f1, -3, 3)
plot!(f2, -3, 3)
plot(f1, -3, 3; legend=false)
plot!(f2)
```
To find it, we need to find the intersection points, then integrate. We do so numerically.
Plot of $1-x^2$ and $(x-1)^2-2$ used to find intersection points for a center of mass calculation
:::
We first find the intersection points numerically, though where two quadratics can readily be solved algebraically:
```{julia}
#| hold: true
h(x) = f1(x) - f2(x)
a,b = find_zeros(h, -3, 3)
top, err = quadgk(x -> x * h(x), a, b)
bottom, err = quadgk(h, a, b)
```
With these, the computation of the center of mass involves two integrations:
```{julia}
top = first(quadgk(x -> x * h(x), a, b))
bottom = first(quadgk(h, a, b))
cm = top / bottom
```
@@ -259,17 +281,17 @@ We need to compute $\int_{-\infty}^\infty xf(x) dx$, but in this case since $f$
$$
\mu = \int_0^\infty x e^{-x} dx = -(1+x) \cdot e^{-x} \big|_0^\infty = 1
\mu = \int_0^\infty x e^{-x} dx = -(1+x) \cdot e^{-x} \Big|_0^\infty = 1
$$
For fun, we compare this to the median, which is the value $M$ so that the total area is split in half. That is, the following formula is satisfied: $\int_0^M f(x) dx = 1/2$. To compute, we have:
$$
\int_0^M e^{-x} dx = -e^{-x} \big|_0^M = 1 - e^{-M}.
\int_0^M e^{-x} dx = -e^{-x} \Big|_0^M = 1 - e^{-M}.
$$
Solving $1/2 = 1 - e^{-M}$ gives $M=\log(2) = 0.69...$, The median is to the left of the mean in this example.
Solving $1/2 = 1 - e^{-M}$ gives $M=\log(2) = 0.69\cdots$, The median is to the left of the mean in this example.
:::{.callout-note}
@@ -281,21 +303,29 @@ In this example, we used an infinite region, so the idea of "balancing" may be a
##### Example
A figure is formed by transformations of the function $\phi(u) = e^{2(k-1)} - e^{2(k-u)}$, for some fixed $k$, as follows:
@fig-center-of-mass-between-two-shifted-exponentials shows a region formed by transformations of the function $\phi(u) = e^{2(k-1)} - e^{2(k-u)}$, for some fixed $k$ ($k=3$ in the figure) between $0$ and $3$. The region is basically the graph of $\phi(u)$ and the graph of its shifted value $\phi(u+1)$, only truncated on the top and bottom.
We have
```{julia}
k = 3
phi(u) = exp(2(k-1)) - exp(2(k-u))
f(u) = max(0, phi(u))
g(u) = min(f(u+1), f(k))
plot(f, 0, k, legend=false)
plot!(g, 0, k)
plot!(zero, 0, k)
```
(This is basically the graph of $\phi(u)$ and the graph of its shifted value $\phi(u+1)$, only truncated on the top and bottom.)
::: {#fig-center-of-mass-between-two-shifted-exponentials}
```{julia}
#| echo: false
k = 3
plot(f, 0, k; legend=false, line=(1, :black))
plot!(g; line=(1, :black))
plot!(zero; line=(1, :black))
```
Plot of shifts of $\phi(u) = e^{2(k-1)} - e^{2(k-u)}$ over $[0,k]$
:::
The center of mass of this figure is found with:
@@ -308,9 +338,9 @@ bottom, _ = quadgk(h, 0, k)
top/bottom
```
This figure has constant slices of length $1$ for fixed values of $y$. If we were to approximate the values with blocks of height $1$, then the center of mass would be to the left of $1$ - for any $k$, but the top most block would have an overhang to the right of $1$ - out to a value of $k$. That is, this figure should balance:
This figure has constant slices of length $1$ for fixed values of $y$. If we were to approximate the values with blocks of height $1$, then the center of mass would be to the left of $1$---for any $k$, but the top most block would have an overhang to the right of $1$---out to a value of $k$. That is, the blocks in @fig-max-hangover-figure should balance.
::: {#fig-max-hangover-figure}
```{julia}
#| echo: false
u(i) = 1/2*(2k - log(exp(2(k-1)) - i))
@@ -324,6 +354,8 @@ plot!(p, f, 0, e, linewidth=5);
plot!(p, g, 0, 3, linewidth=5)
p
```
Figure of block arrangement that should be stable
:::
See this [paper](https://math.dartmouth.edu/~pw/papers/maxover.pdf) and its references for some background on this example and its extensions.
@@ -331,56 +363,69 @@ See this [paper](https://math.dartmouth.edu/~pw/papers/maxover.pdf) and its refe
### The $y$ direction.
We can talk about the center of mass in the $y$ direction too. The approximating picture uses horizontal rectangles - not vertical ones - and if we describe them by $f(y)$, then the corresponding formulas would be
We can talk about the center of mass in the $y$ direction too. Suppose our region is bounded by $g(x) \le f(x)$ over $[a,b]$. The center of mass can be computed different ways. If the region can be described by two functions in the $y$ direction, the same formulas as in the $x$ direction can be used.
However, with the region as described, we can use this form
> $\text{center of mass} = \text{cm}_y = \frac{\int_a^b y f(y) dy}{\int_a^b f(y) dy}.$
For example, consider, again, the triangle bounded by the line $x=-1$, the $x$ axis, and the line $y=(1-x)/2$. In terms of describing this in $y$, the function $f(y)=2 -2y$ gives the total length of the horizontal slice (which comes from solving $y=(1-x)/2$for $x$, the general method to find an inverse function, and subtracting $-1$) and the interval is $y=0$ to $y=1$. Thus our center of mass in the $y$ direction will be
::: {.definition title="Center of mass in y direction"}
For a region bounded between $g(x) \le f(x)$ over $[a,b]$, the center of mass in the $y$ direction can be computed by:
$$
\text{cm}_y = \frac{\int_0^1 y (2 - 2y) dy}{\int_0^1 (2 - 2y) dy} = \frac{(2y^2/2 - 2y^3/3)\big|_0^1}{1} = \frac{1}{3}.
$$
Here the center of mass is below $1/2$ as the bulk of the area is. (The bottom area is just $1$, as known from the area of a triangle.)
As seen, the computation of the center of mass in the $y$ direction has an identical formula, though may be more involved if an inverse function must be computed.
::: {.callout-note}
#### An alternative formula
An alternative formula, which is easily derived once double integrals are introduced, to find the center of mass in the $y$ direction is
$$
\text{cm}_y = \frac{\int_a^b \frac{1}{2}(f(x)^2 - g(x)^2) dx}{\int_a^b (f(x) -g(x)) dx}.
\overline{\text{cm}}_y = \frac{\int_a^b \frac{1}{2}(f(x)^2 - g(x)^2) dx}{\int_a^b (f(x) -g(x)) dx}.
$$
:::
This formula follows readily once two dimensional integrals are discussed.^[If $\rho(x,y)$ describes the density of a region $A$, then the center of mass in the $y$ direction is found by $\iint_A y \rho(x,y) dy dx / \iint_A \rho(x,y) dy dx$. With constant density, as assumed herein, and the region described by $g(x) \le f(x)$, the top integral becomes $\int_a^b \int_{g(x)}^{f(x)} y dy dx = \int_a^b (1/2)\left(f(x)^2 - g(x)^2\right) dx$. Similarly. for the $x$ direction, the top integral is $\iint x \rho(x,y) dy dx$ which becomes under these assumptions $\int_a^b \int_{g(x)}^{f(x)} x dy dx = \int_a^b x\left(f(x) - g(x)\right) dx$.]
For example, consider, again, the triangle bounded by the line $x=-1$, the $x$ axis, and the line $y=(1-x)/2$. In terms of describing this in $y$, the function $u(y)=2 -2y$ gives the total length of the horizontal slice (which comes from solving $y=(1-x)/2$for $x$, the general method to find an inverse function, and subtracting $-1$) and the interval is $y=0$ to $y=1$. Thus our center of mass in the $y$ direction will be
$$
\overline{\text{cm}}_y = \frac{\int_0^1 y (2 - 2y) dy}{\int_0^1 (2 - 2y) dy} = \frac{(2y^2/2 - 2y^3/3)\Big|_0^1}{1} = \frac{1}{3}.
$$
Here the center of mass is below $1/2$ as the bulk of the area is. (The bottom area is just $1$, as known from the area of a triangle.)
Using the other formula, where $f(x) = (1-x)/2$ and $g(x)=0$, we have
$$
\begin{align*}
\frac{1}{2} \int_{-1}^1 (f(x)^2 - g(x)^2) dx
&= \frac{1}{2} \int_{-1}^1 \frac{(1-x)^2}{4} dx\\
&= \frac{1}{2}\frac{1}{4} \left(-\frac{(1-x)^3}{3}\right) \big|_{-1}^1\\
&= \frac{1}{24} \left((1-x)^3\right) \big|_1^{-1}\\
&= \frac{8}{24} - 0 = \frac{1}{3}
\end{align*}
$$
The total area is
$$
\int_{-1}^1 \frac{1-x}{2} dx = -\frac{(1-x)^2}{4}\big|_{-1}^1 = 0 - (-1) = 1
$$
Leaving, $\overline{\text{cm}}_y = 1/3$, as before.
##### Example
More generally, consider a right triangle with vertices $(0,0)$, $(0,a)$, and $(b,0)$. The center of mass of this can be computed with the help of the equation for the line that forms the hypotenuse: $x/b + y/a = 1$. We find the center of mass symbolically in the $y$ variable by solving for $x$ in terms of $y$, then integrating from $0$ to $a$:
More generally, consider a right triangle with vertices $(0,0)$, $(0,a)$, and $(b,0)$. The center of mass of this can be computed with the help of the equation for the line that forms the hypotenuse: $x/b + y/a = 1$. We find the center of mass symbolically in the $y$ variable by writing $f(x) = a \cdot (1 - x)/b$ and $g(x) = 0$
```{julia}
@syms a b x y
eqn = x/b + y/a - 1
fy = solve(eqn, x)[1]
integrate(y*fy, (y, 0, a)) / integrate(fy, (y, 0, a))
fx = only(solve(x/b + y/a ~ 1, y))
(1//2) * integrate(fx^2, (x, 0, b)) / integrate(fx, (x, 0, b))
```
The answer involves $a$ linearly, but not $b$. If we find the center of mass in $x$, we *could* do something similar:
The answer involves $a$ linearly, but not $b$. If we find the center of mass in $x,$ we *could* do something similar:
```{julia}
fx = solve(eqn, y)[1]
integrate(x*fx, (x, 0, b)) / integrate(fx, (x, 0, b))
```
@@ -389,7 +434,7 @@ But really, we should have just noted that simply by switching the labels $a$ an
:::{.callout-note}
## Note
The [centroid](http://en.wikipedia.org/wiki/Centroid) of a region in the plane is just $(\text{cm}_x, \text{cm}_y)$. This last fact says the centroid of the right triangle is just $(b/3, a/3)$. The centroid can be found by other geometric means. The link shows the plumb line method. For triangles, the centroid is also the intersection point of the medians, the lines that connect a vertex with its opposite midpoint.
The [centroid](http://en.wikipedia.org/wiki/Centroid) of a region in the plane is just $(\overline{\text{cm}}_x, \overline{\text{cm}}_y)$. This last fact says the centroid of the right triangle is just $(b/3, a/3)$. The centroid can be found by other geometric means. The link shows the plumb line method. For triangles, the centroid is also the intersection point of the medians, the lines that connect a vertex with its opposite midpoint.
:::
@@ -398,29 +443,21 @@ The [centroid](http://en.wikipedia.org/wiki/Centroid) of a region in the plane i
Compute the $x$ and $y$ values of the center of mass of the half circle described by the area below the function $f(x) = \sqrt{1 - x^2}$ and above the $x$-axis.
A plot shows the value of cm$_x$ will be $0$ by symmetry:
As $f(x)$ is even, $x \cdot f(x)$ would be odd, so the center of mass in the $x$ direction is $0$.
```{julia}
#| hold: true
f(x) = sqrt(1 - x^2)
plot(f, -1, 1)
```
($f(x)$ is even, so $xf(x)$ will be odd.)
However, the value for cm$_y$ will - like the last problem - be around $1/3$. The exact value is compute using slices in the $y$ direction. Solving for $x$ in $y=\sqrt{1-x^2}$, or $x = \pm \sqrt{1-y^2}$, if $f(y) = 2\sqrt{1 - y^2}$. The value is then:
The value for $\overline{\text{cm}}_y$ will certainly be less than $1/2$ as the circle narrows as $y$ increases to $1$. The exact value is given by:
$$
\text{cm}_y = \frac{\int_{0}^1 y 2 \sqrt{1 - y^2}dy}{\int_{0}^1 2\sqrt{1-y^2}} =
\frac{-2(1-y^2)^{3/2}/3\big|_0^1}{\pi/2} = \frac{4}{3\pi}.
\begin{align*}
\frac{1}{2}\frac{2}{\pi} \cdot \int_{-1}^1 (\sqrt{1 - x^2})^2 dx
&= \frac{1}{\pi} \int_{-1}^1 ( 1 - x^2) dx\\
&= \frac{1}{\pi} (x - \frac{x^3}{3})\big|_{-1}^1 = \frac{1}{\pi}\frac{4}{3}\\
&= 0.424413\cdots.
\end{align*}
$$
The top calculation is done by $u$-substitution, the bottom by using the area formula for a half circle, $\pi r^2/2$.
The value $2/\pi$ comes from the area of the figure being the area of half the unit circle, which has area $\pi$.
##### Example
@@ -428,24 +465,34 @@ The top calculation is done by $u$-substitution, the bottom by using the area fo
A disc of radius $2$ is centered at the origin, as a disc of radius $1$ is bored out between $y=0$ and $y=1$. Find the resulting center of mass.
A picture shows that this could be complicated, especially for $y > 0$, as we need to describe the length of the red lines below for $-2 < y < 2$:
@fig-disc-radius-2-hole-bored-out shows that this could be complicated, especially for $y > 0$, as we need to describe the length of the red lines below for $-2 < y < 2$:
::: {#fig-disc-radius-2-hole-bored-out}
```{julia}
#| hold: true
#| echo: false
a,b = 0, 2pi
ts = range(a, stop=b, length=50)
p = plot(t -> 2cos(t), t->2sin(t), a, b, legend=false, aspect_ratio=:equal);
plot!(p, cos.(ts), 1 .+ sin.(ts), linetype=:polygon, color=:red);
plot!(p, [-sqrt(3), sqrt(3)], [-1,-1], color=:orange);
plot!(p, [-sqrt(3), -1], [1,1], color=:orange);
plot!(p, [sqrt(3), 1], [1,1], color=:orange);
p
let
gr()
a,b = 0, 2pi
ts = range(a, stop=b, length=50)
p = plot(t -> 2cos(t), t->2sin(t), a, b; legend=false, line=(1, :black), aspect_ratio=:equal);
plot!(p, cos.(ts), 1 .+ sin.(ts), linetype=:polygon, color=:red);
plot!(p, [(-sqrt(3), -1), (sqrt(3), -1)], line=(1, :orange))
plot!(p, [(-sqrt(3), 1), (-1, 1)]; line=(1, :orange))
plot!(p, [( 1, 1), (sqrt(3), 1)]; line=(1, :orange))
plotly()
p
end
```
We can see that cm$_x = 0$, by symmetry, but to compute cm$_y$ we need to find $f(y)$, which will depend on the value of $y$ between $-2$ and $2$. The outer circle is $x^2 + y^2 = 4$, the inner circle $x^2 + (y-1)^2 = 1$. When $y < 0$, $f(y)$ is the distance across the outer circle or, $2\sqrt{4 - y^2}$. When $y \geq 0$, $f(y)$ is *twice* the distance from the bigger circle to the smaller, of $2(\sqrt{4 - y^2} - \sqrt{1 - (y-1)^2})$.
Disk of radius $2$ with a hole of radius $1$ bored out
:::
We can see that $\overline{\text{cm}}_x = 0$, by symmetry.
To compute $\overline{\text{cm}}_y$ we choose to find $f(y)$, which will depend on the value of $y$ between $-2$ and $2$. The outer circle is $x^2 + y^2 = 4$, the inner circle $x^2 + (y-1)^2 = 1$. When $y < 0$, $f(y)$ is the distance across the outer circle or, $2\sqrt{4 - y^2}$. When $y \geq 0$, $f(y)$ is *twice* the distance from the bigger circle to the smaller, of $2(\sqrt{4 - y^2} - \sqrt{1 - (y-1)^2})$.
We use this to compute:
@@ -453,13 +500,48 @@ We use this to compute:
```{julia}
#| hold: true
f(y) = y < 0 ? 2*sqrt(4 - y^2) : 2* (sqrt(4 - y^2)- sqrt(1 - (y-1)^2))
top, _ = quadgk( y -> y * f(y), -2, 2)
bottom, _ = quadgk( f, -2, 2)
f(y) = y < 0 ? 2 * sqrt(4 - y^2) : 2 * (sqrt(4 - y^2)- sqrt(1 - (y-1)^2))
top, _ = quadgk(y -> y * f(y), -2, 2)
bottom, _ = quadgk(f, -2, 2)
top/bottom
```
The nice answer of $-1/3$ makes us think there may be a different way to visualize this. Were we to rearrange the top integral, we could write it as $\int_{-2}^2 y 2 \sqrt{4 -y^2}dy - \int_0^2 2y\sqrt{1 - (y-1)^2}dy$. Call this $A - B$. The left term, $A$, is part of the center of mass formula for the big circle (which is this value divided by $M=4\pi$), and the right term, $B$, is part of the center of mass formula for the (drilled out) smaller circle (which is this value divided by $m=\pi$. These values are weighted according to $(AM - Bm)/(M-m)$. In this case $A=0$, $B=1$ and $M=4m$, so the answer is $-1/3$.
The nice answer of $-1/3$ makes us think there may be a different way to compute this quantity.
Indeed, let $A$ be the big circle with the bite taken out, $B$ be the smaller circle, $C$ the big circle. Clearly, the center of mass of $C$ in the $y$ direction is $0$ and the center of mass of $B$ in the $y$ direction is $1$. The center of mass of $C$ is the *weighted average* of the center of mass of $A$ plus that of $B$:
$$
\overline{\text{cm}_C} = \frac{4\pi - \pi}{4\pi} \overline{\text{cm}_A} + \frac{\pi}{4\pi}\overline{\text{cm}_B}
$$
Or
$$
0 = \frac{3}{4}\overline{\text{cm}_A} + \frac{1}{4}
$$
which is solved by $\overline{\text{cm}_A}=-1/3$.
This above works as:
::: {.relationship title="Center of mass of complex shapes"}
If a complicated shape can be partitioned into simpler shapes for which the center of mass can be computed, then the resulting center of mass is the weighted sum of the centers of mass of the simpler shapes. The weights are given by the relative masses.^[Again, this follows readily from the center of mass formula in two dimensions. For example, if $A$ can be partitioned into $B$ and $C$ then we have in the $y$ direction:
$$
\begin{align*}
\overline{\text{cm}}_A &=
\frac{\iint_A y \rho da}{\iint_A \rho da}\\
&= \frac{\iint_B y \rho da}{\iint_A \rho da} + \frac{\iint_C y \rho da}{\iint_A \rho da}\\
&= \frac{\iint_B y \rho da}{\iint_B \rho da} \cdot \frac{\iint_B \rho da}{\iint_A \rho da} +
\frac{\iint_C y \rho da}{\iint_C \rho da} \cdot \frac{\iint_C \rho da}{\iint_A \rho da}\\
&= \overline{\text{cm}}_B \frac{\iint_B\rho da}{\iint_A \rho da} +
\overline{\text{cm}}_C \frac{\iint_C \rho da}{\iint_A \rho da}
\end{align*}
$$
]
:::
## Questions
@@ -613,37 +695,45 @@ numericq(val)
###### Question
A penny, nickel, dime and quarter are stacked so that their right most edges align and are centered so that the center of mass in the $y$ direction is $0$. Find the center of mass in the $x$ direction.
@fig-penny-nickel-dime-quarter visualizes a penny, nickel, dime and quarter that are stacked so that their right most edges align and are centered so that the center of mass in the $y$ direction is $0$. Find the center of mass in the $x$ direction.
::: {#fig-penny-nickel-dime-quarter}
```{julia}
#| hold: true
#| echo: false
ds = [0.75, 0.835, 0.705, 0.955]
rs = ds/2
xs = rs[4] .- rs
ts = range(0,stop=2pi, length=50)
p = plot(legend=false, aspect_ratio=:equal);
for i in 1:4
plot!(p, xs[i] .+ rs[i]*cos.(ts), rs[i]*sin.(ts));
let
ds = [0.75, 0.835, 0.705, 0.955]
rs = ds/2
xs = rs[4] .- rs
ts = range(0,stop=2pi, length=50)
p = plot(legend=false, aspect_ratio=:equal);
for i in 1:4
plot!(p, xs[i] .+ rs[i]*cos.(ts), rs[i]*sin.(ts); line=(1, :black));
end
p
end
p
```
You will need some specifications, such as these from the [US Mint](http://www.usmint.gov/about_the_mint/?action=coin_specifications)
Sketch of a dime, penny, nickel, and quarter stacked with an edge aligned
:::
You will need some specifications, such as the one from the [US Mint](http://www.usmint.gov/about_the_mint/?action=coin_specifications) in @tbl-diameter-mass-coins.
```{eval=false}
diameter(in) weight(gms)
penny 0.750 2.500
nickel 0.835 5.000
dime 0.705 2.268
quarter 0.955 5.670
::: {#tbl-diameter-mass-coins .striped .hover}
```
| | diameter(in) | weight(gms) |
|:---------:|:--------------:|:--------------:|
| penny | 0.750 | 2.500 |
| nickel | 0.835 | 5.000 |
| dime | 0.705 | 2.268 |
| quarter | 0.955 | 5.670 |
(Hint: Though this could be done with integration, it is easier to treat each coin as a single point (its centroid) with the given mass and then apply the formula for sums.)
Size and weight of US coins
:::
(Hint: Though this could be done with integration, it is easier to treat each coin as a single point (its centroid) with the given mass and then apply the center of mass formula for sums.)
```{julia}
Binary file not shown.

After

Width:  |  Height:  |  Size: 337 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 30 KiB

+210 -159
View File
@@ -8,90 +8,82 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using SymPy
using Roots
using QuadGK
```
---
We refer to the example from the section on [transformations](../precalc/transformations.html#two_operators_D_S) where two operators on functions were defined:
$$
D(f)(k) = f(k) - f(k-1), \quad S(f)(k) = f(1) + f(2) + \cdots + f(k).
$$
It was remarked that these relationships hold: $D(S(f))(k) = f(k)$ and $S(D(f))(k) = f(k) - f(0)$. These being a consequence of the inverse relationship between addition and subtraction. These two relationships are examples of a more general pair of relationships known as the [Fundamental theorem of calculus](http://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) or FTC.
We will see that with suitable rewriting, the derivative of a function is related to a certain limit of `D(f)` and the definite integral of a function is related to a certain limit of `S(f)`. The addition and subtraction rules encapsulated in the relations of $D(S(f))(k) = f(k)$ and $S(D(f))(k) = f(k) - f(0)$ then generalize to these calculus counterparts.
The FTC details the interconnectivity between the operations of integration and differentiation.
For example:
> What is the definite integral of the derivative?
That is, what is $A = \int_a^b f'(x) dx$? (Assume $f'$ is continuous.)
To investigate, we begin with the right Riemann sum using $h = (b-a)/n$:
$$
A \approx S_n = \sum_{i=1}^n f'(a + ih) \cdot h.
$$
But the mean value theorem says that for small $h$ we have $f'(x) \approx (f(x) - f(x-h))/h$. Using this approximation with $x=a+ih$ gives:
$$
A \approx
\sum_{i=1}^n \left(f(a + ih) - f(a + (i-1)h)\right).
$$
If we let $g(i) = f(a + ih)$, then the summand above is just $g(i) - g(i-1) = D(g)(i)$ and the above then is just the sum of the $D(g)(i)$s, or:
$$
A \approx S(D(g))(n) = g(n) - g(0).
$$
But $g(n) - g(0) = f(a + nh) - f(a + 0h) = f(b) - f(a)$. That is, we expect that the $\approx$ in the limit becomes $=$, or:
$$
\int_a^b f'(x) dx = f(b) - f(a).
$$
This is indeed the case.
The other question would be
The Fundamental Theorem of Calculus (FTC) details the interconnectivity between the operations of integration and differentiation. Two questions come up. First:
> What is the derivative of the integral?
That is, can we find the derivative of $\int_a^x f(u) du$ for some fixed $a$? (The derivative in $x$, the variable $u$ is a dummy variable of integration.)
That is, can we find the derivative of $\int_0^x f(u) du$? (The derivative in $x$, the variable $u$ is a dummy variable of integration.)
The other question is:
> What is the definite integral of the derivative?
That is, what is $A = \int_a^b f'(x) dx$? (Assuming $f'$ is continuous.)
These questions are answered in the following theorem:
::: {.theorem title="The fundamental theorem of calculus"}
Part 1: Let $f$ be a continuous function on a closed interval $[a,b]$ and define $F(x) = \int_a^x f(u) du$ for $a \leq x \leq b$. Then $F$ is continuous on $[a,b]$, differentiable on $(a,b)$ and moreover, $F'(x) =f(x)$.
Part 2: Now suppose $f$ is any integrable function on a closed interval $[a,b]$ and $F(x)$ is *any* differentiable function on $[a,b]$ with $F'(x) = f(x)$. Then $\int_a^b f(x)dx=F(b)-F(a)$.
:::
Let's look first at the integral using the right-Riemann sum, again using $h=(b-a)/n$:
:::{.callout-note}
## Note
In Part 1, the integral $F(x) = \int_a^x f(u) du$ is defined for any Riemann integrable function, $f$. If the function is not continuous, then it is true the $F$ will be continuous, but it need not be true that it is differentiable at all points in $(a,b)$. Forming $F$ from $f$ is a form of *smoothing*. It makes a continuous function out of an integrable one, a differentiable function from a continuous one, and a $k+1$-times differentiable function from a $k$-times differentiable one.
:::
To motivate these statements, we refer to the example from the section on transformations^[XXX(../precalc/transformations.html#two_operators_D_S)] where two operators on functions were defined by what they do to some $k$:
$$
\int_a^b f(u) du \approx f(a + 1h)h + f(a + 2h)h + \cdots + f(a +nh)h = S(g)(n),
\begin{align*}
D(f)(k) &= f(k) - f(k-1),\\
S(f)(k) &= f(1) + f(2) + \cdots + f(k).
\end{align*}
$$
It was remarked that the following relationships hold, a consequence of the inverse relationship between addition and subtraction:
$$
\begin{align*}
D(S(f))(k) &= f(k),\\
S(D(f))(k) &= f(k) - f(0).
\end{align*}
$$
These two relationships analogs of the [Fundamental theorem of calculus](http://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus).
We will see that with suitable rewriting, the derivative of a function is related to a certain limit of `D(f)` and the definite integral of a function is related to a certain limit of `S(f)`. The addition and subtraction rules encapsulated in the relations above then generalize to these calculus counterparts.
---
To explore the first part of the FTC, let's look first at the integral using the right-Riemann sum, again using $h=(b-a)/n$:
$$
\begin{align*}
\int_a^b f(u) du &\approx f(a + 1h)h + f(a + 2h)h + \cdots + f(a +nh)h \\
&= S(g)(n),
\end{align*}
$$
where we define $g(i) = f(a + ih)h$. In the above, $n$ relates to $b$, but we could have stopped accumulating at any value. The analog for $S(g)(k)$ would be $\int_a^x f(u) du$ where $x = a + kh$. That is we can make a function out of integration by considering the mapping $(x, \int_a^x f(u) du)$. This might be written as $F(x) = \int_a^x f(u)du$. With this definition, can we take a derivative in $x$?
@@ -131,33 +123,43 @@ $$
That is $F'(x) \approx f(x)$.
In the limit, then, we would expect that
In the limit as $n\rightarrow \infty$, we would expect that:
$$
\frac{d}{dx} \int_a^x f(u) du = f(x).
$$
With these heuristics, we now have:
::: {.callout-note icon=false}
## The fundamental theorem of calculus
To investigate the integral of a derivative, we begin with the right Riemann sum for $\int_a^b f'(x)dx$ using $h = (b-a)/n$:
Part 1: Let $f$ be a continuous function on a closed interval $[a,b]$ and define $F(x) = \int_a^x f(u) du$ for $a \leq x \leq b$. Then $F$ is continuous on $[a,b]$, differentiable on $(a,b)$ and moreover, $F'(x) =f(x)$.
$$
A \approx S_n = \sum_{i=1}^n f'(a + ih) \cdot h.
$$
Part 2: Now suppose $f$ is any integrable function on a closed interval $[a,b]$ and $F(x)$ is *any* differentiable function on $[a,b]$ with $F'(x) = f(x)$. Then $\int_a^b f(x)dx=F(b)-F(a)$.
But the mean value theorem says that for small $h$ we have $f'(x) \approx (f(x) - f(x-h))/h$. Using this approximation with $x=a+ih$ gives, after canceling an $h$:
:::
$$
A \approx
\sum_{i=1}^n \left(f(a + ih) - f(a + (i-1)h)\right).
$$
If we let $g(i) = f(a + ih)$, then the summand above is just $g(i) - g(i-1) = D(g)(i)$ and the above then is just the sum of the $D(g)(i)$s, or:
:::{.callout-note}
## Note
In Part 1, the integral $F(x) = \int_a^x f(u) du$ is defined for any Riemann integrable function, $f$. If the function is not continuous, then it is true the $F$ will be continuous, but it need not be true that it is differentiable at all points in $(a,b)$. Forming $F$ from $f$ is a form of *smoothing*. It makes a continuous function out of an integrable one, a differentiable function from a continuous one, and a $k+1$-times differentiable function from a $k$-times differentiable one.
$$
A \approx S(D(g))(n) = g(n) - g(0).
$$
:::
But $g(n) - g(0) = f(a + nh) - f(a + 0h) = f(b) - f(a)$. That is, we expect that the $\approx$ in the limit as $n\rightarrow \infty$ becomes $=$, or:
This figure relating the area under some continuous $f(x)$ from $a$ to both $x$ and $x+h$ for some small $h$ helps to visualize the two fundamental theorems.
$$
\int_a^b f'(x) dx = f(b) - f(a).
$$
@fig-FTC-derivative relates the area under some continuous $f(x)$ from $a$ to both $x$ and $x+h$ for some small $h$ to help visualize the two fundamental theorems.
::: {#fig-FTC-derivative}
```{julia}
@@ -189,7 +191,7 @@ let
(b, 0, text(L"x", :top)),
(b+h,0,text(L"x+h", :top)),
(2b/3, 1/2, text(L"A(x)")),
(b + h/2, 1/2, text(L"f(x)\cdot h \approx A(x+h)-A(x)", rotation=90))
(b + h/2, 1/2, text(L"A(x+h)-A(x) \approx f(x)\cdot h", rotation=90))
])
@@ -224,20 +226,20 @@ That is $A(x)$ satisfies the two parts of the fundamental theorem.
## Using the fundamental theorem of calculus to evaluate definite integrals
The most visible use of the FTC is the computation of definite integrals, $\int_a^b f(x) dx$. Rather than resort to Riemann sums or geometric arguments, there is an alternative - *when possible*, find a function $F$ with $F'(x) = f(x)$ and compute $F(b) - F(a)$.
The most visible use of the FTC is the computation of definite integrals, $\int_a^b f(x) dx$. Rather than resort to Riemann sums or geometric arguments, there is an alternative---*when possible*: find a function $F$ with $F'(x) = f(x)$ and compute $F(b) - F(a)$.
Some examples:
* Consider the problem of Archimedes, $\int_0^1 x^2 dx$. Clearly, we have with $f(x) = x^2$ that $F(x)=x^3/3$ will satisfy the assumptions of the FTC, so that:
* Consider the problem of Archimedes, $\int_0^1 x^2 dx$. Clearly, we have with $f(x) = x^2$ that $F(x)=x^3/3$ will satisfy the assumptions of the FTC, so that:
$$
\int_0^1 x^2 dx = F(1) - F(0) = \frac{1^3}{3} - \frac{0^3}{3} = \frac{1}{3}.
$$
* More generally, we know if $n\neq-1$ that if $f(x) = x^{n}$, that
* More generally, we know if $n\neq-1$ that if $f(x) = x^{n}$, that
$$
@@ -264,7 +266,7 @@ $$
\int_a^b \frac{1}{x} dx = \log(b) - \log(a).
$$
* Let $f(x) = \cos(x)$. How much area is between $-\pi/2$ and $\pi/2$? We have that $F(x) = \sin(x)$ will have $F'(x) = f(x)$, so:
* Let $f(x) = \cos(x)$. How much area is between $-\pi/2$ and $\pi/2$? We have that $F(x) = \sin(x)$ will have $F'(x) = f(x)$, so:
$$
@@ -281,7 +283,7 @@ $$
\int_a^b f(x) dx = F(b) - F(a) = F(x)\Big|_{x=a}^b, \text{ or just expr}\Big|_{x=a}^b.
$$
The vertical bar is used for the *evaluation* step, in this case the $a$ and $b$ mirror that of the definite integral. This notation lends itself to working inline, as we illustrate with this next problem where we "know" a function "$F$", so just express it "inline":
The vertical bar is used for the *evaluation* step, in this case the $a$ and $b$ mirror that of the definite integral. This notation lends itself to working "inline", as we illustrate with this next problem where we "know" a function "$F$", so just express it inline:
$$
@@ -301,7 +303,7 @@ This says nothing more than $F(b)-F(a) = -F(a) - (-F(b))$, though more compactly
## The indefinite integral
A function $F(x)$ with $F'(x) = f(x)$ is known as an *antiderivative* of $f$. For a given $f$, there are infinitely many antiderivatives: if $F(x)$ is one, then so is $G(x) = F(x) + C$. But - due to the mean value theorem - all antiderivatives for $f$ differ at most by a constant.
A function $F(x)$ with $F'(x) = f(x)$ is known as an *antiderivative* of $f$. For a given $f$, there are infinitely many antiderivatives: if $F(x)$ is one, then so is $G(x) = F(x) + C$. But---due to the mean value theorem---all antiderivatives for $f$ differ at most by a constant.
The **indefinite integral** of $f(x)$ is denoted by:
@@ -331,7 +333,7 @@ where $C$ is the *constant of integration* and isn't really a fixed constant, bu
* `integrate(ex, (var, a, b))` to find the definite integral. This integrates the expression in the variable `var` from `a` to `b`.
To illustrate, we have, this call finds an antiderivative:
To illustrate, this call finds an antiderivative for $\sin(x)$:
```{julia}
@@ -339,7 +341,7 @@ To illustrate, we have, this call finds an antiderivative:
integrate(sin(x),x)
```
Whereas this call computes the "area" under $f(x)$ between `a` and `b`:
Whereas, this call computes the "area" under $f(x)$ between `a` and `b`:
```{julia}
@@ -398,40 +400,42 @@ Different cases explored by `integrate` are mentioned after the questions.
There are some "rules" of integration that allow indefinite integrals to be re-expressed.
* The integral of a constant times a function:
::: {.relationship title = "The integral of a constant times a function"}
$$
\int c \cdot f(x) dx = c \cdot \int f(x) dx.
$$
:::
This follows as if $F(x)$ is an antiderivative of $f(x)$, then $[cF(x)]' = c f(x)$ by rules of derivatives.
* The integral of a sum of functions:
::: {.relationship title="The integral of a sum of functions"}
$$
\int (f(x) + g(x)) dx = \int f(x) dx + \int g(x) dx.
$$
:::
This follows immediately as if $F(x)$ and $G(x)$ are antiderivatives of $f(x)$ and $g(x)$, then $[F(x) + G(x)]' = f(x) + g(x)$, so the right hand side will have a derivative of $f(x) + g(x)$.
In fact, this more general form where $c$ and $d$ are constants covers both cases and referred to by the linearity of the integral:
::: {.relationship title="The integral of a linear combination of functions"}
$$
\int (cf(x) + dg(x)) dx = c \int f(x) dx + d \int g(x) dx.
$$
:::
This statement is nothing more than the derivative formula $[cf(x) + dg(x)]' = cf'(x) + dg'(x)$. The product rule gives rise to a technique called *integration by parts* and the chain rule gives rise to a technique of *integration by substitution*, but we defer those discussions to other sections.
This statement is nothing more than the derivative formula for a linear combination of functions, $[cf(x) + dg(x)]' = cf'(x) + dg'(x)$. The product rule gives rise to a technique called *integration by parts* and the chain rule gives rise to a technique of *integration by substitution*, but we defer those discussions to other sections.
##### Examples
* The antiderivative of the polynomial $p(x) = a_n x^n + \cdots + a_1 x + a_0$ follows from the linearity of the integral and the general power rule:
* The antiderivative of the polynomial $p(x) = a_n x^n + \cdots + a_1 x + a_0$ follows from the linearity of the integral and the general power rule:
$$
@@ -444,7 +448,7 @@ $$
$$
* More generally, a [Laurent](https://en.wikipedia.org/wiki/Laurent_polynomial) polynomial allows for terms with negative powers. These too can be handled by the above. For example
* More generally, a [Laurent](https://en.wikipedia.org/wiki/Laurent_polynomial) polynomial allows for terms with negative powers. These too can be handled by the above. For example
$$
@@ -475,14 +479,21 @@ So the answer to the question is
$$
\int_0^\pi 100 \sin(x) dx = (100 (-\cos(\pi))) - (100(-\cos(0))) = (100(-(-1))) - (100(-1)) = 200.
\begin{align*}
\int_0^\pi 100 \sin(x) dx &= (100 (-\cos(\pi))) - (100(-\cos(0)))\\
&= (100(-(-1))) - (100(-1)) \\
&= 200.
\end{align*}
$$
This seems like a lot of work, and indeed it is more than is needed. The following would be more typical once the rules are learned:
$$
\int_0^\pi 100 \sin(x) dx = 100(-\cos(x)) \Big|_0^{\pi} = 100 \cos(x) \Big|_{\pi}^0 = 100(1) - 100(-1) = 200.
\begin{align*}
\int_0^\pi 100 \sin(x) dx &= 100(-\cos(x)) \Big|_0^{\pi} = 100 \cos(x) \Big|_{\pi}^0 \\
&= 100(1) - 100(-1) = 200.
\end{align*}
$$
## The derivative of the integral
@@ -769,7 +780,7 @@ xstar, x0
The asymptotic answer agrees with the answer in the first four decimal places.
As an aside, we ask how many function evaluations were taken? We can track this with a trick - using a closure to record when $f$ is called:
As an aside, we ask how many function evaluations were taken? We can track this with a trick---using a closure to record when $f$ is called:
```{julia}
@@ -870,10 +881,10 @@ This has the advantage that each "dot" still represents a calorie burned, so tha
Sadly though, users didn't like it. Instead of a set of dots being, say, 5 high, they were now 3 high and 2 high. It "looked" like they were doing less work! What to do?
The users actually were not responding to the number of dots, which hadn't changed, but rather the *area* that they represented - and this shrank in half. (It is much easier to visualize area than count dots when tired.) How to adjust for that?
The users actually were not responding to the number of dots, which hadn't changed, but rather the *area* that they represented---and this shrank in half. (It is much easier to visualize area than count dots when tired.) How to adjust for that?
Well our engineer knew - double the dots and count each as half a calorie. This makes the "area" constant. She also generalized letting `n` be the number of updates per minute, in anticipation of even further improvements in the display technology:
Well our engineer knew---double the dots and count each as half a calorie. This makes the "area" constant. She also generalized letting `n` be the number of updates per minute, in anticipation of even further improvements in the display technology:
```{julia}
@@ -885,7 +896,7 @@ end
Then the "area" represented by the dots stays fixed over this time frame.
The engineer then thought a bit more, as the form of her answer seemed familiar. She decides to parameterize it in terms of $t$ and found with $h=1/n$: `c(t) = (C(t) - C(t-h))/h`. Ahh - the derivative approximation. But then what is the "area"? It is no longer just the sum of the dots, but in terms of the functions she finds that each column represents $c(t)\cdot h$, and the sum is just $c(t_1)h + c(t_2)h + \cdots + c(t_n)h$ which looks like an approximate integral.
The engineer then thought a bit more, as the form of her answer seemed familiar. She decides to parameterize it in terms of $t$ and found with $h=1/n$: `c(t) = (C(t) - C(t-h))/h`. Ahh---the derivative approximation. But then what is the "area"? It is no longer just the sum of the dots, but in terms of the functions she finds that each column represents $c(t)\cdot h$, and the sum is just $c(t_1)h + c(t_2)h + \cdots + c(t_n)h$ which looks like an approximate integral.
If the display were to reach the modern age and replace LED "dots" with a higher-pixel display, then the function to display would be $c(t) = C'(t)$ and the area displayed would be $\int_{t-10}^t c(u) du$.
@@ -987,8 +998,8 @@ choices = [
"``-x^2\\cos(x) + 2x\\sin(x)``",
"``-x^2\\cos(x) + 2x\\sin(x) + 2\\cos(x)``"
]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -1006,8 +1017,8 @@ choices = [
"``-(1+x) e^{-x}``",
"``-(1 + x + x^2) e^{-x}``"
]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -1024,6 +1035,7 @@ val = N(integrate(exp(x) * sin(x), (x, 0, 2pi)))
numericq(val)
```
###### Question
@@ -1054,9 +1066,9 @@ numericq(f(pi/2))
###### Question
The position of a particle is given by $x(t) = \int_0^t g(u) du$, where $x(0)=0$ and $g(u)$ is given by this piecewise linear graph:
The position of a particle is given by $x(t) = \int_0^t g(u) du$, where $x(0)=0$ and $g(u)$ is given by the piecewise linear graph of @fig-piecewise-linear-graph-for-particle-over-0-to-5.
::: {#fig-piecewise-linear-graph-for-particle-over-0-to-5}
```{julia}
#| hold: true
#| echo: false
@@ -1069,10 +1081,13 @@ function g1(x)
1 + (1/2)*(x-3)
end
end
plot(g1, 0, 5)
plot(g1, 0, 5; legend=false)
```
* The velocity of the particle is positive over:
Plot of piecewise linear function over $[0,5]$
:::
* The velocity of the particle is positive over:
```{julia}
@@ -1084,11 +1099,11 @@ choices = [
L"Between $0$ and $1$",
L"Between $1$ and $5$"
]
answ = 4
radioq(choices, answ, keep_order=true)
answer = 4
radioq(choices, answer, keep_order=true)
```
* The position of the particle is $0$ at $t=0$ and:
* The position of the particle is $0$ at $t=0$ and:
```{julia}
@@ -1099,11 +1114,11 @@ choices = [
"``t=2``",
"``t=3``",
"``t=4``"]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
* The position of the particle at time $t=5$ is?
* The position of the particle at time $t=5$ is?
```{julia}
@@ -1113,7 +1128,7 @@ val = 4
numericq(val)
```
* On the interval $[2,3]$:
* On the interval $[2,3]$:
```{julia}
@@ -1125,8 +1140,8 @@ L"The position, $x(t)$, increases with a slope of $1$",
L"The position, $x(t)$, increases quadratically from $-1/2$ to $1$",
L"The position, $x(t)$, increases quadratically from $0$ to $1$"
]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -1143,8 +1158,8 @@ choices = [
"``-f(t-10)``",
"``f(t) - f(t-10)``"
]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -1160,16 +1175,16 @@ choices = [
"At a critical point",
L"At the endpoint $0$",
L"At the endpoint $1$"]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
###### Question
Let $F(x) = \int_0^x f(u) du$, where $f(x)$ is given by the graph below. Identify the $x$ values of all *relative maxima* of $F(x)$. Explain why you know these are the values.
Let $F(x) = \int_0^x f(u) du$, where $f(x)$ is given by in @fig-identify-relative-maxima-from-graph-of-xs-ys. Identify the $x$ values of all *relative maxima* of $F(x)$. Explain why you know these are the values.
::: {#fig-identify-relative-maxima-from-graph-of-xs-ys}
```{julia}
#| hold: true
#| echo: false
@@ -1178,6 +1193,9 @@ ys = [-1,0,1,0,-1,0,1/2, 0, 1/2, 0, -1]
plot(xs, ys , linewidth=3, legend=false, xticks=0:10)
```
Plot of $f(x)$ over $[-1,1]$
:::
```{julia}
#| hold: true
#| echo: false
@@ -1187,8 +1205,8 @@ choices = [
"The derivative of ``F`` is ``f``, so by the second derivative test, ``x=7``",
"The graph of ``f`` has relative maxima at ``x=2,6,8``"
]
answ = 2
radioq(choices, answ)
answer = 2
radioq(choices, answer)
```
###### Question
@@ -1391,8 +1409,8 @@ L"At a critical point, either $0$ or $1$",
L"At a critical point, $1/2$",
L"At the endpoint $0$",
L"At the endpoint $1$"]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -1401,40 +1419,37 @@ radioq(choices, answ, keep_order=true)
Barrow presented a version of the fundamental theorem of calculus in a 1670 volume edited by Newton, Barrow's student (cf. [Wagner](http://www.maa.org/sites/default/files/0746834234133.di020795.02p0640b.pdf)). His version can be stated as follows (cf. [Jardine](http://www.maa.org/publications/ebooks/mathematical-time-capsules)):
Consider the following figure where $f$ is a strictly increasing function with $f(0) = 0$. and $x > 0$. The function $A(x) = \int_0^x f(u) du$ is also plotted with a dashed red line. The point $Q$ is $f(x)$, and the point $P$ is $A(x)$. The point $T$ is chosen to so that the length between $T$ and $x$ times the length between $Q$ and $x$ equals the length from $P$ to $x$. ($\lvert Tx \rvert \cdot \lvert Qx \rvert = \lvert Px \rvert$.) Barrow showed that the line segment $PT$ is tangent to the graph of $A(x)$. This figure illustrates the labeling for some function:
Consider the @fig-borrowed-from-barrow where $f$ is a strictly increasing function with $f(0) = 0$. and $x > 0$. The function $A(x) = \int_0^x f(u) du$ is also plotted with a dashed red line. The point $Q$ is $f(x)$, and the point $P$ is $A(x)$. The point $T$ is chosen to so that the length between $T$ and $x$ times the length between $Q$ and $x$ equals the length from $P$ to $x$. ($\lvert Tx \rvert \cdot \lvert Qx \rvert = \lvert Px \rvert$.) Barrow showed that the line segment $PT$ is tangent to the graph of $A(x)$. This figure illustrates the labeling for some function:
::: {#fig-borrowed-from-barrow}
```{julia}
#| hold: true
#| echo: false
let
gr()
f(x) = x^(2/3)
x = 2
A(x) = quadgk(f, 0, x)[1]
m=f(x)
T = x - A(x)/f(x)
Q = f(x)
P = A(x)
secpt = u -> 0 + P/(x-T) * (u-T)
xs = range(0, stop=x+1/4, length=50
)
p = plot(f, 0, x + 1/4, legend=false, line=(:black,2))
plot!(p, A, 0, x + 1/4, line=(:red, 2,:dash))
scatter!(p, [T, x, x, x], [0, 0, Q, P], color=:orange)
annotate!(p, collect(zip([T, x, x+.1, x+.1], [0-.15, 0-.15, Q-.1, P], [L"T", L"x", L"Q", L"P"])))
plot!(p, [T-1/4, x+1/4], map(secpt, [T-1/4, x + 1/4]), color=:orange)
plot!(p, [T, x, x], [0, 0, P], color=:green)
f(x) = x^(2/3)
x = 2
A(x) = quadgk(f, 0, x)[1]
m=f(x)
T = x - A(x)/f(x)
Q = f(x)
P = A(x)
secpt = u -> 0 + P/(x-T) * (u-T)
xs = range(0, stop=x+1/4, length=50
)
p = plot(f, 0, x + 1/4, legend=false, line=(:black,2))
plot!(p, A, 0, x + 1/4, line=(:red, 2,:dash))
scatter!(p, [T, x, x, x], [0, 0, Q, P], color=:orange)
annotate!(p, collect(zip([T, x, x+.1, x+.1], [0-.15, 0-.15, Q-.1, P], [L"T", L"x", L"Q", L"P"])))
plot!(p, [T-1/4, x+1/4], map(secpt, [T-1/4, x + 1/4]), color=:orange)
plot!(p, [T, x, x], [0, 0, P], color=:green)
plotly()
p
end
```
```{julia}
#| echo: false
plotly()
nothing
```
Plot illustrating labeling of Barrow
:::
The fact that $\lvert Tx \rvert \cdot \lvert Qx \rvert = \lvert Px \rvert$ says what in terms of $f(x)$, $A(x)$ and $A'(x)$?
@@ -1447,8 +1462,8 @@ choices = [
"``A(x) / \\lvert Tx \\rvert = A'(x)``",
"``A(x) \\cdot A'(x) = f(x)``"
]
answ = 1
radioq(choices, answ, keep_order=true)
answer = 1
radioq(choices, answer, keep_order=true)
```
The fact that $\lvert PT \rvert$ is tangent says what in terms of $f(x)$, $A(x)$ and $A'(x)$?
@@ -1462,8 +1477,8 @@ choices = [
"``A(x) / \\lvert Tx \\rvert = A'(x)``",
"``A(x) \\cdot A'(x) = f(x)``"
]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
Solving, we get:
@@ -1478,8 +1493,8 @@ choices = [
"``A'(x) = A(x)``",
"``A(x) = f(x)``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -1494,8 +1509,44 @@ According to [Bressoud](http://www.math.harvard.edu/~knill/teaching/math1a_2011/
choices = [
L"Part 1: $[\int_a^x f(u) du]' = f$",
L"Part 2: $\int_a^b f(u) du = F(b)- F(a)$."]
answ=1
radioq(choices, answ, keep_order=true)
answer=1
radioq(choices, answer, keep_order=true)
```
###### Question
How does the mean value theorem say that if $F(x)$ and $G(x)$ are two different antiderivatives of $f(x)$ that $F$ and $G$ differ by a constant?
Let $H(x) = F(x) - G(x)$. What is $H'(x)$?
```{julia}
#| echo: false
choices = ["It is hard to say, as it depends on ``x``.",
"It is ``0``."]
anwwer = 2
explanation = raw"$H(x)$ has derivative $f'(x) - f'(x) = 0$"
buttonq(choices, answer; explanation)
```
The mean value theorem says that for any $a < b$ there is a $c$ in between with $H'(c) = (H(b)-H(a))/(b-a)$. Why does this imply for any $a$ and $b$ that $H(a) = H(b)$?
```{julia}
#| echo: false
choices = [L"As $b-a < 0$ it must be that $H(b) - H(a) = 0$.",
L"It doesn't really. The value of $H(a)$ and the value of $H(b)$ can be anything."
]
answer = 1
buttonq(choices, answer)
```
If $H(a) = H(b)$ for any $a < b$ then $H(x)$ must be a constant. Why?
```{julia}
#| echo: false
choices = [L"If $H(x)$ is *not* a constant, then some $x$ satisfies $H(a) \neq H(x)$. But take $b=x$ and we see this can't be so.",
L"Because the polynomial $H(x)$ must have even degree."]
answer = 1
buttonq(choices, answer)
```
## More on SymPy's `integrate`
+131 -63
View File
@@ -8,8 +8,7 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using SymPy
using QuadGK
```
@@ -21,9 +20,9 @@ using QuadGK
A function $f(x)$ is Riemann integrable over an interval $[a,b]$ if some limit involving Riemann sums exists. This limit will fail to exist if $f(x) = \infty$ in $[a,b]$. As well, the Riemann sum idea is undefined if either $a$ or $b$ (or both) are infinite, so the limit won't exist in this case.
To define integrals with either functions having singularities or infinite domains, the idea of an improper integral is introduced with definitions to handle the two cases above.
To define integrals when a function has a singularity or there is an infinite domains, the idea of an improper integral is introduced.
::: {#fig-area-under-sqrt-x-animation}
```{julia}
#| hold: true
#| echo: false
@@ -39,7 +38,7 @@ function make_sqrt_x_graph(n)
f(x) = 1/sqrt(x)
val = N(integrate(f(x), (x, 1/2^n, b)))
title = L"area under $f$ over $[2^{-%$n}, %$b]$ is $%$(rpad(round(val, digits=2), 4))$"
title = L"area under $f$ over $[2^{-%$n}, %$b]$ is $%$(rpad(round(val, digits=2), 4, '0'))$"
plt = plot(f, range(a, stop=b, length=1000);
@@ -53,11 +52,7 @@ function make_sqrt_x_graph(n)
end
caption = L"""
Area under $1/\sqrt{x}$ over $[a,b]$ increases as $a$ gets closer to $0$. Will it grow unbounded or have a limit?
"""
caption = ""
n = 10
anim = @animate for i=1:n
make_sqrt_x_graph(i)
@@ -69,13 +64,17 @@ plotly()
ImageFile(imgfile, caption)
```
Area under $1/\sqrt{x}$ over $[a,1]$ increases as $a$ gets closer to $0$. Will the area grow unbounded or have a limit?
:::
## Infinite domains
Let $f(x)$ be a reasonable function, so reasonable that for any $a < b$ the function is Riemann integrable, meaning $\int_a^b f(x)dx$ exists.
What needs to be the case so that we can discuss the integral over the entire real number line?
What needs to be the case so that we can discuss the integral of $f(x)$ over the entire real number line?
Clearly something. The function $f(x) = 1$ is reasonable by the idea above. Clearly the integral over $[a,b]$ is just $b-a$, but the limit over an unbounded domain would be $\infty$. Even though limits of infinity can be of interest in some cases, not so here. What will ensure that the area is finite over an infinite region?
@@ -84,26 +83,32 @@ Clearly something. The function $f(x) = 1$ is reasonable by the idea above. Clea
Or is that even the right question. Now consider $f(x) = \sin(\pi x)$. Over every interval of the type $[-2n, 2n]$ the area is $0$, and over any interval, $[a,b]$ the area never gets bigger than $2$. But still this function does not have a well defined area on an infinite domain.
The right question involves a limit. Fix a finite $a$. We define the definite integral over $[a,\infty)$ to be
The right approach involves a limit.
::: {.definition title="Definite integral over an unbounded domain"}
Fix a finite $a$. We define the definite integral over $[a,\infty)$ to be
$$
\int_a^\infty f(x) dx = \lim_{M \rightarrow \infty} \int_a^M f(x) dx,
$$
when the limit exists. Similarly, we define the definite integral over $(-\infty, a]$ through
when the limit exists.
Similarly, we define the definite integral over $(-\infty, a]$ through
$$
\int_{-\infty}^a f(x) dx = \lim_{M \rightarrow -\infty} \int_M^a f(x) dx.
$$
For the interval $(-\infty, \infty)$ we have need *both* these limits to exist, and then:
For the interval $(-\infty, \infty)$ we need *both* these limits to exist, and then:
$$
\int_{-\infty}^\infty f(x) dx = \lim_{M \rightarrow -\infty} \int_M^a f(x) dx + \lim_{M \rightarrow \infty} \int_a^M f(x) dx.
$$
:::
:::{.callout-note}
## Note
@@ -118,7 +123,7 @@ When the integral exists, it is said to *converge*. If it doesn't exist, it is s
$$
\lim_{M \rightarrow \infty} \int_1^M \frac{1}{x^2}dx = \lim_{M \rightarrow \infty} -\frac{1}{x}\big|_1^M
\lim_{M \rightarrow \infty} \int_1^M \frac{1}{x^2}dx = \lim_{M \rightarrow \infty} -\frac{1}{x}\Big|_1^M
= \lim_{M \rightarrow \infty} 1 - \frac{1}{M} = 1.
$$
@@ -126,7 +131,7 @@ $$
$$
\lim_{M \rightarrow \infty} \int_1^M \frac{1}{x^{1/2}}dx = \lim_{M \rightarrow \infty} \frac{x^{1/2}}{1/2}\big|_1^M
\lim_{M \rightarrow \infty} \int_1^M \frac{1}{x^{1/2}}dx = \lim_{M \rightarrow \infty} \frac{x^{1/2}}{1/2}\Big|_1^M
= \lim_{M \rightarrow \infty} 2\sqrt{M} - 2 = \infty.
$$
@@ -152,28 +157,37 @@ $$
for any finite $a$. This is because, $F(M) = e^x$ and this has a limit as $x$ goes to $-\infty$, but not $\infty$.
* Let $f(x) = x e^{-x^2}$. This function has an integral over $[0, \infty)$ and more generally $(-\infty, \infty)$. To see, we note that as it is an odd function, the area from $0$ to $M$ is the opposite sign of that from $-M$ to $0$. So $\lim_{M \rightarrow \infty} (F(M) - F(0)) = \lim_{M \rightarrow -\infty} (F(0) - (-F(\lvert M\lvert)))$. We only then need to investigate the one limit. But we can see by substitution with $u=x^2$, that an antiderivative is $F(x) = (-1/2) \cdot e^{-x^2}$. Clearly, $\lim_{M \rightarrow \infty}F(M) = 0$, so the answer is well defined, and the area from $0$ to $\infty$ is just $1/2$. From $-\infty$ to $0$ it is $-1/2$ and the total area is $0$, as the two sides "cancel" out.
* Let $f(x) = \sin(x)$. Even though $\lim_{M \rightarrow \infty} (F(M) - F(-M) ) = 0$, this function is not integrable. The fact is we need *both* the limit $F(M)$ and $F(-M)$ to exist as $M$ goes to $\infty$. In this case, even though the area cancels if $\infty$ is approached at the same rate, this isn't sufficient to guarantee the two limits exists independently.
* Let $f(x) = x e^{-x^2}$. This function has an integral over $[0, \infty)$ and more generally $(-\infty, \infty)$. To see, we note that as it is an odd function, the area from $0$ to $M$ is the opposite sign of that from $-M$ to $0$. So:
$$
\lim_{M \rightarrow \infty} (F(M) - F(0)) = \lim_{M \rightarrow -\infty} (F(0) - (-F(\lvert M\lvert))).
$$
We only then need to investigate the one limit. But we can see by substitution with $u=x^2$, that an antiderivative is $F(x) = (-1/2) \cdot e^{-x^2}$. Clearly, $\lim_{M \rightarrow \infty}F(M) = 0$, so the answer is well defined, and the area from $0$ to $\infty$ is just $1/2$. From $-\infty$ to $0$ it is $-1/2$ and the total area is $0$, as the two sides "cancel" out.
* Let $f(x) = \sin(x)$. Even though $\lim_{M \rightarrow \infty} (F(M) - F(-M) ) = 0$, this function is not integrable. The fact is we need *both* the limit $F(M)$ and $F(-M)$ to exist as $M$ goes to $\infty$. In this case, even though the area cancels if $\infty$ is approached at the same rate, this isn't sufficient to guarantee the two limits exists independently.
* Will the function $f(x) = 1/(x\cdot(\log(x))^2)$ have an integral over $[e, \infty)$?
* Will the function $f(x) = 1/(x\cdot(\log(x))^2)$ have an integral over $[e, \infty)$?
We first find an antiderivative using the $u$-substitution $u(x) = \log(x)$:
$$
\begin{align*}
\int_e^M \frac{1}{x \log(x)^{2}} dx
= \int_{\log(e)}^{\log(M)} \frac{1}{u^{2}} du
= \frac{-1}{u} \big|_{1}^{\log(M)}
= \frac{-1}{\log(M)} - \frac{-1}{1}
= 1 - \frac{1}{\log(M)}.
&= \int_{\log(e)}^{\log(M)} \frac{1}{u^{2}} du\\
&= \frac{-1}{u} \Big|_{1}^{\log(M)}\\
&= \frac{-1}{\log(M)} - \frac{-1}{1}\\
&= 1 - \frac{1}{\log(M)}.
\end{align*}
$$
As $M$ goes to $\infty$, this will converge to $1$.
* The sinc function $f(x) = \sin(\pi x)/(\pi x)$ does not have a nice antiderivative. Seeing if the limit exists is a bit of a problem. However, this function is important enough that there is a built-in function, `Si`, that computes $\int_0^x \sin(u)/u\cdot du$. This function can be used through `sympy.Si(...)`:
* The sinc function $f(x) = \sin(\pi x)/(\pi x)$ does not have a nice antiderivative. Seeing if the limit exists is a bit of a problem^[Well, we could break the answer into an alternating series with clearly shrinking terms, so this is a bit of an exaggeration.]. However, this function is important enough that there is a built-in function, `Si`, that computes $\int_0^x \sin(u)/u\cdot du$. This function can be used through `sympy.Si(...)`:
```{julia}
@@ -192,13 +206,13 @@ $$
we introduce a trick and rely on some theorems that have not been discussed.
First, we notice that $\Si(x)$ is the value of $I(\alpha)$ when $\alpha=0$ where
First, we notice that $\text{Si}(x)$ is the value of $I(\alpha)$ when $\alpha=0$ where
$$
I(\alpha) = \int_0^\infty \exp(-\alpha t) \frac{\sin(t)}{t} dt
$$
We differentiate $I$ in $\alpha$ to get:
We differentiate $I$ in $\alpha$ to get:^[This is a bit of a fast one, as we move the derivative *inside* the integral.]
$$
\begin{align*}
@@ -217,8 +231,8 @@ $$
&=\sin(t) \frac{-\exp(-\alpha t)}{\alpha} \Big|_0^\infty -
\int_0^\infty \frac{-\exp(-\alpha t)}{\alpha} \cos(t) dt \\
&= 0 + \frac{1}{\alpha} \cdot \int_0^\infty \exp(-\alpha t) \cos(t) dt \\
&= \frac{1}{\alpha} \cdot \cos(t)\frac{-\exp(-\alpha t)}{\alpha} \Big|_0^\infty -
\frac{1}{\alpha} \cdot \int_0^\infty \frac{-\exp(-\alpha t)}{\alpha} (-\sin(t)) dt \\
&= \frac{1}{\alpha} \cdot \cos(t)\frac{-\exp(-\alpha t)}{\alpha} \Big|_0^\infty -\\
&\quad\frac{1}{\alpha} \cdot \int_0^\infty \frac{-\exp(-\alpha t)}{\alpha} (-\sin(t)) dt \\
&= \frac{1}{\alpha^2} - \frac{1}{\alpha^2} \cdot \int_0^\infty \exp(-\alpha t) \sin(t) dt
\end{align*}
$$
@@ -232,7 +246,7 @@ $$
Solving gives the desired integral as
$$
I'(\alpha) = -\frac{1}{\alpha^2} / (1 + \frac{1}{\alpha^2}) = -\frac{1}{1 + \alpha^2}.
I'(\alpha) = -\frac{1}{\alpha^2} / \left(1 + \frac{1}{\alpha^2}\right) = -\frac{1}{1 + \alpha^2}.
$$
@@ -242,14 +256,15 @@ As our question is answered by $I(0)$, we get $I(0) = \tan^{-1}(0) + C = C = \pi
The above argument requires two places where a *limit* is passed inside the integral. The first involved the derivative. The [Leibniz integral rule](https://en.wikipedia.org/wiki/Leibniz_integral_rule) can be used to verify the first use is valid:
:::{.callout-note icon=false}
## Leibniz integral rule
:::{.theorem title="Leibniz integral rule"}
If $f(x,t)$ and the derivative in $x$ for a fixed $t$ is continuous (to be discussed later) in a region containing $a(x) \leq t \leq b(x)$ and $x_0 < x < x_1$ and both $a(x)$ and $b(x)$ are continuously differentiable, then
$$
\frac{d}{dx}\int_{a(x)}^{b(x)} f(x, t) dt =
\int_{a(x)}^{b(x)} \frac{d}{dx}f(x,t) dt +
f(x, b(x)) \frac{d}{dx}b(x) - f(x, a(x)) \frac{d}{dx}a(x).
\begin{align*}
\frac{d}{dx}\int_{a(x)}^{b(x)} f(x, t) dt
&= \int_{a(x)}^{b(x)} \frac{d}{dx}f(x,t) dt \\
&\quad + f(x, b(x)) \frac{d}{dx}b(x) - f(x, a(x)) \frac{d}{dx}a(x).
\end{align*}
$$
:::
@@ -296,7 +311,7 @@ Suppose $a < c$, we define $\int_a^c f(x) dx = \lim_{M \rightarrow c-} \int_a^M
$$
\lim_{M \rightarrow 0+} \int_M^1 \frac{1}{\sqrt{x}} dx
= \lim_{M \rightarrow 0+} \frac{\sqrt{x}}{1/2} \big|_M^1
= \lim_{M \rightarrow 0+} \frac{\sqrt{x}}{1/2} \Big|_M^1
= \lim_{M \rightarrow 0+} 2(1) - 2\sqrt{M} = 2.
$$
@@ -311,7 +326,7 @@ The cases $f(x) = x^{-n}$ for $n > 0$ are tricky to keep straight. For $n > 1$,
$$
\lim_{M \rightarrow 0+} \int_M^1 \frac{1}{x} dx
= \lim_{M \rightarrow 0+} \log(x) \big|_M^1
= \lim_{M \rightarrow 0+} \log(x) \Big|_M^1
= \lim_{M \rightarrow 0+} \log(1) - \log(M) = \infty.
$$
@@ -363,7 +378,7 @@ A probability density is a function $f(x) \geq 0$ which is integrable on $(-\inf
Probability densities are good example of using improper integrals.
* Show that $f(x) = (1/\pi) (1/(1 + x^2))$ is a probability density function.
* Show that $f(x) = (1/\pi) (1/(1 + x^2))$ is a probability density function.
We need to show that the integral exists and is $1$. For this, we use the fact that $(1/\pi) \cdot \tan^{-1}(x)$ is an antiderivative. Then we have:
@@ -376,7 +391,7 @@ $$
and as $\tan^{-1}(x)$ is odd, we must have $F(-\infty) = \lim_{M \rightarrow -\infty} f(M) = -(1/\pi) \cdot \pi/2$. All told, $F(\infty) - F(-\infty) = 1/2 - (-1/2) = 1$.
* Show that $f(x) = 1/(b-a)$ for $a \leq x \leq b$ and $0$ otherwise is a probability density.
* Show that $f(x) = 1/(b-a)$ for $a \leq x \leq b$ and $0$ otherwise is a probability density.
The integral for $-\infty$ to $a$ of $f(x)$ is just an integral of the constant $0$, so will be $0$. (This is the only constant with finite area over an infinite domain.) Similarly, the integral from $b$ to $\infty$ will be $0$. This means:
@@ -389,10 +404,10 @@ $$
(One might also comment that $f$ is Riemann integrable on any $[0,M]$ despite being discontinuous at $a$ and $b$.)
* Show that if $f(x)$ is a probability density then so is $f(x-c)$ for any $c$.
* Show that if $f(x)$ is a probability density then so is $f(x-c)$ for any $c$.
We have by the $u$-substitution
We have by the $u$-substitution $u(x)=x-c$ that
$$
@@ -402,7 +417,7 @@ $$
The key is that we can use the regular $u$-substitution formula provided $\lim_{M \rightarrow \infty} u(M) = u(\infty)$ is defined. (The *informal* notation $u(\infty)$ is defined by that limit.)
* If $f(x)$ is a probability density, then so is $(1/h) f((x-c)/h)$ for any $c, h > 0$.
* If $f(x)$ is a probability density, then so is $(1/h) f((x-c)/h)$ for any $c, h > 0$.
Again, by a $u$ substitution with, now, $u(x) = (x-c)/h$, we have $du = (1/h) \cdot dx$ and the result follows just as before:
@@ -412,10 +427,10 @@ $$
\int_{-\infty}^\infty \frac{1}{h}f(\frac{x-c}{h})dx = \int_{u(-\infty)}^{u(\infty)} f(u) du = \int_{-\infty}^\infty f(u) du = 1.
$$
* If $F(x) = 1 - e^{-x}$, for $x \geq 0$, and $0$ otherwise, find $f(x)$.
* If $F(x) = 1 - e^{-x}$, for $x \geq 0$, and $0$ otherwise, find $f(x)$.
We want to just say $F'(x)= e^{-x}$ so $f(x) = e^{-x}$. But some care is needed. First, that isn't right. The derivative for $x<0$ of $F(x)$ is $0$, so $f(x) = 0$ if $x < 0$. What about for $x>0$? The derivative is $e^{-x}$, but is that the right answer? $F(x) = \int_{-\infty}^x f(u) du$, so we have to at least discuss if the $-\infty$ affects things. In this case, and in general the answer is *no*. For any $x$ we can find $M < x$ so that we have $F(x) = \int_{-\infty}^M f(u) du + \int_M^x f(u) du$. The first part is a constant, so will have derivative $0$, the second will have derivative $f(x)$, if the derivative exists (and it will exist at $x$ if the derivative is continuous in a neighborhood of $x$).
We want to just say $F'(x)= e^{-x}$ so $f(x) = e^{-x}$. But some care is needed. First, that isn't right. The derivative for $x<0$ of $F(x)$ is $0$, so $f(x) = 0$ if $x < 0$. What about for $x>0$? The derivative is $e^{-x}$, but is that the right answer? $F(x) = \int_{-\infty}^x f(u) du$, so we have to at least discuss if the $-\infty$ affects things. In this case, and in general, the answer is *no*. For any $x$ we can find $M < x$ so that we have $F(x) = \int_{-\infty}^M f(u) du + \int_M^x f(u) du$. The first part is a constant, so will have derivative $0$, the second will have derivative $f(x)$, if the derivative exists (and it will exist at $x$ if the derivative is continuous in a neighborhood of $x$).
Finally, at $x=0$ we have an issue, as $F'(0)$ does not exist. The left limit of the secant line approximation is $0$, the right limit of the secant line approximation is $1$. So, we can take $f(x) = e^{-x}$ for $x > 0$ and $0$ otherwise, noting that redefining $f(x)$ at a point will not effect the integral as long as the point is finite.
@@ -424,16 +439,45 @@ Finally, at $x=0$ we have an issue, as $F'(0)$ does not exist. The left limit of
## Application to series
In this application, we compare a series to a related integral to decide convergence or divergence of the series.
In this application, we compare a series to a related integral to decide convergence or divergence of the series. @fig-integral-test-figure motivates the following theorem.
:::{.theorem title="The integral test"}
:::{.callout-note appearance="minimal"}
#### The integral test
Consider a continuous, monotone decreasing function $f(x)$ defined on some interval of the form $[N,\infty)$. Let $a_n = f(n)$ and $s_n = \sum_{k=N}^n a_n$.
* If $\int_N^\infty f(x) dx < \infty$ then the partial sums converge.
* If $\int_N^\infty f(x) dx = \infty$ then the partial sums diverge.
:::
::: {#fig-integral-test-figure}
```{julia}
#| echo: false
let
# integral test
gr()
f(x) = 1/x
p1 = plot(; legend=false, framestyle=:origin, xticks=1:8, yaxis=([], false))
p2 = plot(; legend=false, framestyle=:origin, xticks=1:8, yaxis=([], false))
plot!(p1, f, 0.75, 8.25; line=(1, :black))
plot!(p2, f, 0.75, 8.25; line=(1, :black))
for k in 1:7
plot!(p1, [(k,0), (k+1,0), (k+1, f(k)), (k, f(k)), (k,0)]; line=(1, :black, :dot))
annotate!(p1, [(k+1/2, f(k+1)/2, latexstring("a_{$k}"))])
end
for k in 1:7
plot!(p2, [(k,0), (k+1,0), (k+1, f(k+1)), (k, f(k+1)),(k,0)]; line=(1, :black, :dot))
annotate!(p2, [(k+1/2, f(k+2)/2, latexstring("a_{$(k+1)}"))])
end
plotly()
plot(p1, p2)
end
```
Illustration of the integral test, where a series $a_1 + a_2 + \cdots$ is bounded *below* by $\int_1^\infty f(x)dx$ and the series $a_2 + a_3 + \cdots$ is bounded *above* by $\int_1^\infty f(x)dx$ where $a_i=f(i)$. In either case, converge/divergence of the integral forces convergence/divergence of the series.
:::
By the monotone nature of $f(x)$, we have on any interval of the type $[i, i+1)$ for $i$ an integer, that $f(i) \geq f(x) \geq f(i+1)$ when $x$ is in the interval. For integrals, this leads to
$$
@@ -491,8 +535,7 @@ That this is finite shows the series converges.
The integral of a power series can be computed easily for some $x$:
:::{.callout-note appearance="minimal"}
### The integral of a power series
:::{.theorem title="The integral of a power series"}
Suppose $f(x) = \sum_n a_n (x-c)^n$ is a power series about $x=c$ with radius of convergence $r > 0$. [Then](https://en.wikipedia.org/wiki/Power_series#Differentiation_and_integration) the limits of the integral and the sum can be switched around when $x$ is within the radius of convergence:
@@ -501,7 +544,7 @@ $$
\int f(x) dx
&= \int \sum_n a_n(x-c)^n dx\\
&= \sum_{n=0}^\infty \int a_n(x-c)^n dx\\
= \sum_{n=0}^\infty a_n \frac{(x-c)^{n+1}}{n+1}
&= \sum_{n=0}^\infty a_n \frac{(x-c)^{n+1}}{n+1}
\end{align*}
$$
@@ -647,14 +690,39 @@ val, _ = quadgk(f , 0, 1, 2)
numericq(val)
```
###### Question
Consider the integral $\int_{-\infty}^\infty f(x) dx$. We do a change of variable with $x = t/(1-t^2)$. This gives:
$$
\int_a^b f\left(\frac{t}{1-t^2}\right) \frac{t^2 + 1}{t^2 - 1} dt
$$
What are the values of $a$ and $b$?
```{julia}
#| echo: false
choices = [
L"$a=-1$ and $b=1$",
L"$a=1$ and $b=-1$",
L"$a=1$ and $b=0$",
L"$a=0$ and $b=1$",
]
answer = 1
explanation = "As ``t`` goes to ``1`` from the left, ``x`` goes to what?"
buttonq(choices, answer; explanation)
```
###### Question
From the relationship that if $0 \leq f(x) \leq g(x)$ then $\int_a^b f(x) dx \leq \int_a^b g(x) dx$ it can be deduced that
* if $\int_a^\infty f(x) dx$ diverges, then so does $\int_a^\infty g(x) dx$.
* if $\int_a^\infty g(x) dx$ converges, then so does $\int_a^\infty f(x) dx$.
* if $\int_a^\infty f(x) dx$ diverges, then so does $\int_a^\infty g(x) dx$.
* if $\int_a^\infty g(x) dx$ converges, then so does $\int_a^\infty f(x) dx$.
Let $f(x) = \lvert \sin(x)/x^2 \rvert$.
@@ -670,8 +738,8 @@ choices =[
"It is convergent",
"It is divergent",
"Can't say"]
answ = 1
radioq(choices, answ, keep_order=true)
answer = 1
radioq(choices, answer, keep_order=true)
```
---
@@ -690,8 +758,8 @@ choices =[
"It is convergent",
"It is divergent",
"Can't say"]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
---
@@ -707,8 +775,8 @@ choices =[
"It is convergent",
"It is divergent",
"Can't say"]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
---
@@ -724,8 +792,8 @@ choices =[
"It is convergent",
"It is divergent",
"Can't say"]
answ = 1
radioq(choices, answ, keep_order=true)
answer = 1
radioq(choices, answer, keep_order=true)
```
---
@@ -741,8 +809,8 @@ choices =[
"It is convergent",
"It is divergent",
"Can't say"]
answ = 1
radioq(choices, answ, keep_order=true)
answer = 1
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -759,8 +827,8 @@ choices = [
"``\\int_0^1 u^{2/3} \\cdot du``",
"``\\int_0^\\infty 1/u \\cdot du``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
+193 -85
View File
@@ -8,8 +8,7 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using SymPy
```
@@ -26,81 +25,82 @@ nothing
So far we have seen that the *derivative* rules lead to *integration rules*. In particular:
* The sum rule $[au(x) + bv(x)]' = au'(x) + bv'(x)$ gives rise to an integration rule: $\int (au(x) + bv(x))dx = a\int u(x)dx + b\int v(x))dx$. (That is, the linearity of the derivative means the integral has linearity.)
* The sum rule $[au(x) + bv(x)]' = au'(x) + bv'(x)$ gives rise to an integration rule: $\int (au(x) + bv(x))dx = a\int u(x)dx + b\int v(x))dx$. (That is, the linearity of the derivative means the integral has linearity.)
* The chain rule $[f(g(x))]' = f'(g(x)) g'(x)$ gives $\int_a^b f(g(x))g'(x)dx=\int_{g(a)}^{g(b)}f(x)dx$. That is, substitution reverses the chain rule.
* The chain rule $[g(u(x))]' = g'(u(x)) u'(x)$ gives $\int_a^b g(u(x))u'(x)dx=\int_{u(a)}^{u(b)}g(x)dx$. That is, $u$-substitution reverses the chain rule.
Now we turn our attention to the implications of the *product rule*: $[uv]' = u'v + uv'$. The resulting technique is called integration by parts.
::: {.callout-note}
## Integration by parts
::: {.definition title="Integration by parts"}
By the fundamental theorem of calculus:
$$
[u(x)\cdot v(x)]\Big|_a^b = \int_a^b [u(x) v(x)]' dx = \int_a^b u'(x) \cdot v(x) dx + \int_a^b u(x) \cdot v'(x) dx.
\begin{align*}
\left[u(x)\cdot v(x)\right]\Big|_a^b &= \int_a^b [u(x) v(x)]' dx\\
&= \int_a^b u'(x) \cdot v(x) dx + \int_a^b u(x) \cdot v'(x) dx.
\end{align*}
$$
Or,
$$
\int_a^b u(x) v'(x) dx = [u(x)v(x)]\Big|_a^b - \int_a^b v(x) u'(x)dx.
\int_a^b u(x) v'(x) dx = \left[u(x)v(x)\right]\Big|_a^b - \int_a^b v(x) u'(x)dx.
$$
:::
The following visually illustrates integration by parts:
@fig-visualize-integration-by-parts illustrates integration by parts showing a parametric plot of $(u(t),v(t))$ for $a \leq t \leq b$.
::: {#fig-visualize-integration-by-parts}
```{julia}
#| echo: false
#| label: fig-integration-by-parts
#| fig-cap: "Integration by parts figure ([original](http://en.wikipedia.org/wiki/Integration_by_parts#Visualization))"
let
## parts picture
gr()
u(x) = sin(x*pi/2)
v(x) = x
xs = range(0, stop=1, length=50)
a,b = 1/4, 3/4
u(x) = sin(x*pi/2)
v(x) = x
xs = range(0, stop=1, length=50)
a,b = 1/4, 3/4
p = plot(u, v, 0, 1; legend=false, axis=([], false), line=(:black,2))
plot!([0, u(1)], [0,0]; line=(:gray, 1), arrow=true, side=:head)
plot!([0, 0], [0, v(1) ]; line=(:gray, 1), arrow=true, side=:head)
p = plot(u, v, 0, 1; legend=false, axis=([], false), line=(:black,2))
plot!([0, u(1)], [0,0]; line=(:gray, 1), arrow=true, side=:head)
plot!([0, 0], [0, v(1) ]; line=(:gray, 1), arrow=true, side=:head)
xs′ = range(a, b, length=50)
plot!(Shape(vcat(u.(xs′), reverse(u.(xs′))),
vcat(zero.(xs′), v.(reverse(xs′)))),
fill=(:red, 0.15),
xlims=(-0.07, 1)
)
plot!(Shape([0,u(a),u(a),0],[0,0,v(a),v(a)]), fill=(:royalblue, 0.5))
scatter!(p, [u(a), u(b)], [v(a), v(b)], color=:mediumorchid3, markersize=5)
plot!(p, [u(a),u(a),0, 0, u(b),u(b),u(a)],
[0, v(a), v(a), v(b), v(b), 0, 0],
linetype=:polygon, fill=(:brown3, 0.25))
xs′ = range(a, b, length=50)
plot!(Shape(vcat(u.(xs′), reverse(u.(xs′))),
vcat(zero.(xs′), v.(reverse(xs′)))),
fill=(:red, 0.15),
xlims=(-0.07, 1)
)
plot!(Shape([0,u(a),u(a),0],[0,0,v(a),v(a)]), fill=(:royalblue, 0.5))
scatter!(p, [u(a), u(b)], [v(a), v(b)], color=:mediumorchid3, markersize=5)
plot!(p, [u(a),u(a),0, 0, u(b),u(b),u(a)],
[0, v(a), v(a), v(b), v(b), 0, 0],
linetype=:polygon, fill=(:brown3, 0.25))
annotate!(p, [(0.65, .25, text(L"A")),
(0.4, .55, text(L"B")),
(u(a),v(a), text(L"(u(a),v(a))", :bottom, :right)),
annotate!(p, [(0.65, .25, text(L"A")),
(0.4, .55, text(L"B")),
(u(a),v(a), text(L"(u(a),v(a))", :bottom, :right)),
(u(b),v(b), text(L"(u(b),v(b))", :bottom, :right)),
(u(a),0, text(L"u(a)", :top)),
(u(b),0, text(L"u(b)", :top)),
(u(a),0, text(L"u(a)", :top)),
(u(b),0, text(L"u(b)", :top)),
(0, v(a), text(L"v(a)", :right)),
(0, v(b), text(L"v(b)", :right)),
(0,0, text(L"(0,0)", :top))
])
(0,0, text(L"(0,0)", :top))
])
plotly()
p
end
```
```{julia}
#| echo: false
plotly()
nothing
```
Integration by parts figure ([original](http://en.wikipedia.org/wiki/Integration_by_parts#Visualization))
:::
@fig-integration-by-parts shows a parametric plot of $(u(t),v(t))$ for $a \leq t \leq b$..
The total shaded area, a rectangle, is $u(b)v(b)$, the area of $A$ and $B$ combined is just $u(b)v(b) - u(a)v(a)$ or $[u(x)v(x)]\Big|_a^b$. We will show that $A$ is $\int_a^b v(x)u'(x)dx$ and $B$ is $\int_a^b u(x)v'(x)dx$ giving the formula.
@@ -225,7 +225,7 @@ $$
\int_a^b x^2 e^x dx = (x^2 \cdot e^x)\Big|_a^b - \int_a^b 2x e^x dx.
$$
But we can do $\int_a^b x e^xdx$ the same way:
But we can compute $\int_a^b x e^xdx$ the same way:
$$
@@ -245,8 +245,8 @@ In fact, it isn't hard to see that an integral of $x^m e^x$, $m$ a positive inte
```{julia}
@syms 𝒙
integrate(𝒙^10 * exp(𝒙), 𝒙)
@syms x
integrate(x^10 * exp(x), x)
```
The general answer is $\int x^n e^xdx = p(x) e^x$, where $p(x)$ is a polynomial of degree $n$.
@@ -281,7 +281,10 @@ So:
$$
\int e^x \sin(x)dx = \sin(x) e^x - \int \cos(x) e^x dx = \sin(x)e^x - \cos(x)e^x + \int (-\sin(x))e^x dx.
\begin{align*}
\int e^x \sin(x)dx &= \sin(x) e^x - \int \cos(x) e^x dx \\
&= \sin(x)e^x - \cos(x)e^x + \int (-\sin(x))e^x dx.
\end{align*}
$$
But simplifying this gives:
@@ -324,11 +327,11 @@ $$
This is called a reduction formula as it reduces the problem from an integral with a power of $n$ to one with a power of $n - 2$, so could be repeated until the remaining indefinite integral required knowing either $\int \cos(x) dx$ (which is $-\sin(x)$) or $\int \cos(x)^2 dx$, which by a double angle formula application, is $x/2 + \sin(2x)/4$.
`SymPy` is able and willing to do this repeated bookkeeping. For example with $n=10$:
`SymPy` is willing and able to do this repeated bookkeeping. For example with $n=10$:
```{julia}
integrate(cos(𝒙)^10, 𝒙)
integrate(cos(x)^10, x)
```
##### Example
@@ -367,7 +370,7 @@ $$
Using right triangles to simplify, the last value $\cos(\sin^{-1}(x))$ can otherwise be written as $\sqrt{1 - x^2}$.
##### Example
##### Example: maximum error in the trapezoid rule
The [trapezoid](http://en.wikipedia.org/wiki/Trapezoidal_rule) rule is an approximation to the definite integral like a Riemann sum, only instead of approximating the area above $[x_i, x_i + h]$ by a rectangle with height $f(c_i)$ (for some $c_i$), it uses a trapezoid formed by the left and right endpoints. That is, this area is used in the estimation: $(1/2)\cdot (f(x_i) + f(x_i+h)) \cdot h$.
@@ -393,14 +396,17 @@ $$
$$
We choose $A$ to be $-h/2$, any constant is possible, for then the term $f(t+x_i)(t+A)\Big|_0^h$ becomes $(1/2)(f(x_i+h) + f(x_i)) \cdot h$, or the trapezoid approximation. This means, the error over this interval - actual minus estimate - satisfies:
We choose $A$ to be $-h/2$, any constant is possible, for then the term $f(t+x_i)(t+A)\Big|_0^h$ becomes $(1/2)(f(x_i+h) + f(x_i)) \cdot h$, or the trapezoid approximation. This means, the error over this interval---actual minus estimate---satisfies:
$$
\text{error}_i = \int_{x_i}^{x_i+h}f(x) dx - \frac{f(x_i+h) -f(x_i)}{2} \cdot h = - \int_0^h (t + A) f'(t + x_i) dt.
\begin{align*}
\text{error}_i &= \int_{x_i}^{x_i+h}f(x) dx - \frac{f(x_i+h) -f(x_i)}{2} \cdot h \\
&= - \int_0^h (t + A) f'(t + x_i) dt.
\end{align*}
$$
For this, we *again* integrate by parts with
To compute this, we *again* integrate by parts with
$$
@@ -415,7 +421,10 @@ Again we added a constant of integration, $B$, to $v$. The error becomes:
$$
\text{error}_i = -\left(\frac{(t+A)^2}{2} + B\right)f'(t+x_i)\Big|_0^h + \int_0^h \left(\frac{(t+A)^2}{2} + B\right) \cdot f''(t+x_i) dt.
\begin{align*}
\text{error}_i &= -\left(\frac{(t+A)^2}{2} + B\right)f'(t+x_i)\Big|_0^h \\
&\quad + \int_0^h \left(\frac{(t+A)^2}{2} + B\right) \cdot f''(t+x_i) dt.
\end{align*}
$$
With $A=-h/2$, $B$ is chosen so $(t+A)^2/2 + B = 0$ at endpoints, or $B=-h^2/8$. The error becomes
@@ -429,7 +438,7 @@ Now, we assume the $\lvert f''(t)\rvert$ is bounded by $K$ for any $a \leq t \le
$$
\lvert \text{error}_i \rvert \leq K \int_0^h \lVert \left(\frac{(t-h/2)^2}{2} - \frac{h^2}{8}\right) \rVert dt.
\lvert \text{error}_i \rvert \leq K \int_0^h \lvert \left(\frac{(t-h/2)^2}{2} - \frac{h^2}{8}\right) \rvert dt.
$$
But what is the function in the integrand? Clearly it is a quadratic in $t$. Expanding gives $1/2 \cdot (t^2 - ht)$. This is negative over $[0,h]$ (and $0$ at these endpoints, so the integral above is just:
@@ -446,7 +455,7 @@ $$
\lvert \text{error}\rvert \leq n \cdot \frac{Kh^3}{12} = \frac{K(b-a)^3}{12}\frac{1}{n^2}.
$$
So the error is like $1/n^2$, in contrast to the $1/n$ error of the Riemann sums. One way to see this, for the Riemann sum it takes twice as many terms to half an error estimate, but for the trapezoid rule only $\sqrt{2}$ as many, and for Simpson's rule, only $2^{1/4}$ as many.
So the maximum error^[This is a worst-case estimate. There are functions for which the trapezoid method converges exponentially and are discussed in [Trefethen and Weiderman](https://people.maths.ox.ac.uk/trefethen/sirev56-3_385.pdf).] is like $1/n^2$, in contrast to the $1/n$ error of the Riemann sums. One way to see this, for the Riemann sum it takes twice as many terms to half an error estimate, but for the trapezoid rule only $\sqrt{2}$ as many, and for Simpson's rule, only $2^{1/4}$ as many.
## Area related to parameterized curves
@@ -458,9 +467,9 @@ The figure introduced to motivate the integration by parts formula also suggests
When $u(t)$ is strictly *increasing*, and hence having an inverse function, then re-parameterizing by $\phi(t) = u^{-1}(t)$ gives a $x=u(u^{-1}(t))=t, y=v(u^{-1}(t))$ and integrating this gives the area by $A=\int_a^b v(t) u'(t) dt$
However, the correct answer requires understanding a minus sign. Consider the area enclosed by $x(t) = \cos(t), y(t) = \sin(t)$:
However, the correct answer requires understanding a minus sign. Consider the area enclosed by $x(t) = \cos(t), y(t) = \sin(t)$ in @fig-area-parameterized-curve-example.
::: {#fig-area-parameterized-curve-example}
```{julia}
#| echo: false
let
@@ -477,6 +486,9 @@ let
end
```
Area consideration for a parameterized curve
:::
We added a rectangle for a Riemann sum for $t_i = \pi/3$ and $t_{i+1} = \pi/3 + \pi/8$. The height of this rectangle is $y(t_i)$, the base is of length $x(t_i) - x(t_{i+1})$ *given* the orientation of how the circular curve is parameterized (counter clockwise here).
@@ -488,16 +500,18 @@ $$
A &\approx \sum_i y(t_i) \cdot (x(t_{i}) - x(t_{i+1}))\\
&= - \sum_i y(t_i) \cdot (x(t_{i+1}) - x(t_{i}))\\
&= - \sum_i y(t_i) \cdot \frac{x(t_{i+1}) - x(t_i)}{t_{i+1}-t_i} \cdot (t_{i+1}-t_i)\\
&\approx -\int_a^b y(t) x'(t) dt.
&\approx -\int_a^b y(t) x'(t) dt\\
&= \int_a^b x(t) y'(t) dt.
\end{align*}
$$
So with a counterclockwise rotation, the actual answer for the area includes a minus sign. If the area is traced out in a *clockwise* manner, there is no minus sign.
The last line using integration by parts to reverse the role of $x$ and $y$.
When traversing a curve in a counter clockwise manner $\int x(t) y'(t) dt$ has no minus sign and when traversing in a clockwise manner $\int y(t) x'(t) dt$ has no minus sign.
This is a case of [Green's Theorem](https://en.wikipedia.org/wiki/Green%27s_theorem#Area_calculation) to be taken up in [Green's Theorem, Stokes' Theorem, and the Divergence Theorem](file:///Users/verzani/julia/CalculusWithJulia/html/integral_vector_calculus/stokes_theorem.html).
We also revisit this in the section on the area between curves where this formula comes from decomposing the area contained within a simple polygon using trapezoids.
##### Example
@@ -510,7 +524,7 @@ Apply the formula to a parameterized circle to ensure, the signed area is proper
@syms r t
x = r * cos(t)
y = r * sin(t)
-integrate(y * diff(x, t), (t, 0, 2PI))
integrate(x * diff(y, t), (t, 0, 2PI))
```
We see the expected answer for the area of a circle.
@@ -539,9 +553,9 @@ integrate(y * diff(x, t), (t, 0, 2PI))
##### Example
Consider the example $x(t) = \cos(t) + t\sin(t), y(t) = \sin(t) - t\cos(t)$ for $0 \leq t \leq 2\pi$.
Consider the example $x(t) = \cos(t) + t\sin(t), y(t) = \sin(t) - t\cos(t)$ for $0 \leq t \leq 2\pi$ shown in @fig-area-spiraling-curve-over-0-2pi.
::: {#fig-area-spiraling-curve-over-0-2pi}
```{julia}
#| echo: false
let
@@ -551,17 +565,20 @@ let
plot(x.(ts), y.(ts))
end
```
Plot of parameterized spiraling curve over $[0, 2\pi]$
:::
How much area is enclosed by this curve and the $x$ axis? The area is described in a counterclockwise manner, so we have:
```{julia}
#| hold: true
let
let # a let block avoids the issue that `x` has already been used as a constant
x(t) = cos(t) + t*sin(t)
y(t) = sin(t) - t*cos(t)
yx′(t) = -y(t) * x'(t) # yx\prime[tab]
quadgk(yx′, 0, 2pi)
xy′(t) = x(t) * y'(t) # xy\prime[tab]
quadgk(xy′, 0, 2pi)
end
```
@@ -584,8 +601,8 @@ choices = [
"``du=1/x dx \\quad v = x``",
"``du=x\\log(x) dx\\quad v = 1``",
"``du=1/x dx\\quad v = x^2/2``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -602,8 +619,8 @@ choices = [
"``du=\\csc(x) dx \\quad v=\\sec(x)^3 / 3``",
"``du=\\tan(x) dx \\quad v=\\sec(x)\\tan(x)``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -620,8 +637,8 @@ choices = [
"``du=-e^{-x} dx \\quad v=-\\sin(x)``",
"``du=\\sin(x)dx \\quad v=-e^{-x}``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -683,10 +700,56 @@ choices = [
"``\\int (\\log(x))^{n+1}/(n+1) dx``",
"``x(\\log(x))^n - \\int (\\log(x))^{n-1} dx``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
Let $k$ be a positive integer. We can use integration by parts to understand the value of
$$
I_k = \int x^k \exp(-x) dx
$$
Let $u = x^k$ and $dv = \exp(-x)$. What becomes of $uv$?
```{julia}
#| echo: false
choices = [L"-kx^{k-1} \exp(-x)",
L"-x^{k+1}/(k+1) \exp(-x)",
L"-x^k \exp(-x)"]
answer = 3
buttonq(choices, answer)
```
What becomes of $\int v du$?
```{julia}
#| echo: false
choices = [L"\int k x^{k-1} (-\exp(-x)) dx",
L"\int x^{k+1}/(k+1) (-\exp(-x)) dx",
L"\int x^k (-\exp(-x)) dx"]
answer = 1
buttonq(choices, answer)
```
Does this show that $I_k = -x^k \exp(-x) + k I_{k-1}$?
```{julia}
#| echo: false
choices = ["Yes", "No"]
answer = 1
buttonq(choices, answer)
```
If so them be repeating the above until $k=0$, we can see that $I_k = p_k \exp(-x)$ for some polynomial $p_k$ of degree $k$.
###### Question
@@ -700,8 +763,8 @@ Consider the integral $\int x \cos(x) dx$. Which letter should be tried first?
#| hold: true
#| echo: false
choices = ["L", "I", "A", "T", "E"]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
---
@@ -714,8 +777,8 @@ Consider the integral $\int x^2\log(x) dx$. Which letter should be tried first?
#| hold: true
#| echo: false
choices = ["L", "I", "A", "T", "E"]
answ = 1
radioq(choices, answ, keep_order=true)
answer = 1
radioq(choices, answer, keep_order=true)
```
---
@@ -728,8 +791,8 @@ Consider the integral $\int x^2 \sin^{-1}(x) dx$. Which letter should be tried f
#| hold: true
#| echo: false
choices = ["L", "I", "A", "T", "E"]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
---
@@ -742,8 +805,8 @@ Consider the integral $\int e^x \sin(x) dx$. Which letter should be tried first?
#| hold: true
#| echo: false
choices = ["L", "I", "A", "T", "E"]
answ = 4
radioq(choices, answ, keep_order=true)
answer = 4
radioq(choices, answer, keep_order=true)
```
###### Question
@@ -759,6 +822,51 @@ choices = [
"``x\\cos^{-1}(x)-\\sqrt{1 - x^2}``",
"``x^2/2 \\cos^{-1}(x) - x\\sqrt{1-x^2}/4 - \\cos^{-1}(x)/4``",
"``-\\sin^{-1}(x)``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
In [notes by S.G. Johnson](https://math.mit.edu/~stevenj/trap-iap-2011.pdf) we find a simpler means to estimate the maximum error in the (composite) trapezoid rule.
Each trapezoid estimate uses a line between two points, $x_{i-1}$ and $x_i$ so deviates from a Taylor polynomial how?
```{julia}
#| echo: false
choices = ["In the constant term",
"In the linear term",
"In the quadratic term"]
answer = 3
explanation = "The constant and linear terms can match off, leaving a quadratic."
buttonq(choices, answer; explanation)
```
The worst case error in a single approximation is then around $\Delta_x^2$ times a constant depending on $f''$.
The error in the approximation---up to a constant---over the interval is:
```{julia}
#| echo: false
choices = [L"Basically $\Delta_x$",
L"Basically $\Delta_x^2$",
L"Basically $\Delta_x^2 \cdot \Delta_x$"]
answer = 3
explanation = "The worst case is the error *times* the length of the base"
buttonq(choices, answer; explanation)
```
In terms of $n$, the error in each sub-interval is like $1/n^3$. The total error in the approximation is then
```{julia}
#| echo: false
choices = [L"Basically $1/n^3$",
L"Basically $1/n^2 = 1/n^3 \cdot n$",
L"Basically $1/n = 1/n^3 \cdot n^2$"]
answer = 2
explanation = "There are ``n`` terms each with error like ``1/n^3``"
buttonq(choices, answer; explanation)
```
This is a worst case estimate, of course, as it doesn't account for individual errors canceling each other off.
+58 -18
View File
@@ -1,5 +1,14 @@
# Mean value theorem for integrals
::: {#fig-ice-cream-shop}
![](./figures/ice-cream.jpg)
How to compare which container has more ice cream at an ice cream shop?
:::
At an ice cream shop, a container of vanilla and one of chocolate have been busy, leaving the containers with an uneven top due to areas where scoops have been taken out, and where not. Which container has more left? We could compare readily if we were willing to spread the ice cream around so that the top of the ice cream is a uniform level. Then the one with a height height has more volume. The uniform level is just the mean value theorem for integrals applied to volumes. The volume of ice cream in the container is equivalent to the area of the base times *some* height which reflects the amount of total ice cream.
----
{{< include ../_common_code.qmd >}}
@@ -8,13 +17,11 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using QuadGK
```
---
## Average value of a function
@@ -30,7 +37,7 @@ $$
\frac{1}{b-a} \int_a^b f(x) dx.
$$
If $f$ is a constant, this is just the constant value, as would be expected. If $f$ is *piecewise* linear, then this is the weighted average of these constants.
If $f$ is a constant, this is just the constant value, as would be expected. If $f$ is *piecewise* constant, then this is the weighted average of these constants.
#### Examples
@@ -63,20 +70,22 @@ What is the average value of $f(x)=\sin(x)$ over $[0, \pi]$?
$$
\text{average} = \frac{1}{\pi-0} \int_0^\pi \sin(x) dx = \frac{1}{\pi} (-\cos(x)) \big|_0^\pi = \frac{2}{\pi}
\text{average} = \frac{1}{\pi-0} \int_0^\pi \sin(x) dx = \frac{1}{\pi} (-\cos(x)) \Big|_0^\pi = \frac{2}{\pi}
$$
Visually:
@fig-integral-mean-value illustrates.
::: {#fig-integral-mean-value}
```{julia}
#| label: fig-integral-mean-value
#| fig-cap: "Area under sine curve is equal to area of rectangle"
#| echo: false
plot(sin, 0, pi, legend=false, fill=(:forestgreen, 0.25, 0))
plot!(x -> 2/pi, fill=(:royalblue, 0.25, 0))
```
In @fig-integral-mean-value the area under the sine curve ($2 = (-\cos(\pi)) - (-\cos(0))$) is equal to the area under the average (also $2 = 2/\pi \cdot \pi$).
Area under the sine curve over $[0, \pi]$ is equal to the area of a rectangle or the area under the constant function $f(x) = 2/\pi$
:::
##### Example
@@ -84,7 +93,7 @@ In @fig-integral-mean-value the area under the sine curve ($2 = (-\cos(\pi)) - (
What is the average value of the function $f$ which is $3$ between $[0,3]$, $2$ between $(3,5]$ and $1$ between $(5,6]$?
Though not continuous, $f(x)$ is integrable as it contains only jumps. The integral from $[0,6]$ can be computed with geometry: $3\cdot 3 + 2 \cdot 2 + 1 \cdot 1 = 14$. The average then is $14/(6-0) = 7/3$.
Though not continuous, $f(x)$ is integrable as it contains only jumps. The integral from $[0,6]$ can be computed with geometry: $3\cdot 3 + 2 \cdot 2 + 1 \cdot 1 = 14$. The average then is $14/(6-0) = 7/3$. This can also be expressed as a weighted sum: $3 \cdot 3/6 + 2 \cdot 2/6 + 1 \cdot 1/6$, the weights reflecting the respective interval lengths.
##### Example
@@ -96,21 +105,25 @@ What is the average value of the function $e^{-x}$ between $0$ and $\log(2)$?
$$
\begin{align*}
\text{average} &= \frac{1}{\log(2) - 0} \int_0^{\log(2)} e^{-x} dx\\
&= \frac{1}{\log(2)} (-e^{-x}) \big|_0^{\log(2)}\\
&= \frac{1}{\log(2)} (-e^{-x}) \Big|_0^{\log(2)}\\
&= -\frac{1}{\log(2)} (\frac{1}{2} - 1)\\
&= \frac{1}{2\log(2)}.
\end{align*}
$$
Visualizing, we have
Visualizing, we have @fig-area-exp-x-0-log2-as-rectangle.
::: {#fig-area-exp-x-0-log2-as-rectangle}
#| echo: false
```{julia}
plot(x -> exp(-x), 0, log(2), legend=false, fill=(:forestgreen, 0.25, 0))
plot!(x -> 1/(2*log(2)), fill=(:royalblue, 0.25, 0))
```
Rectangle with same area as under $f(x) = e^{-x}$ over $[0,\log(2)]$
:::
## The mean value theorem for integrals
@@ -123,8 +136,7 @@ $$
When we assume that $f(x)$ is continuous, we can describe $K$ as a value in the range of $f$:
::: {.callout-note icon=false}
## The mean value theorem for integrals
::: {.theorem title="The mean value theorem for integrals"}
Let $f(x)$ be a continuous function on $[a,b]$ with $a < b$. Then there exists $c$ with $a \leq c \leq b$ with
@@ -144,6 +156,7 @@ $$
So in particular $K$ is in $[m, M]$. But $m$ and $M$ correspond to values of $f(x)$, so by the intermediate value theorem, $K=f(c)$ for some $c$ that must lie in between $c_m$ and $c_M$, which means as well that it must be in $[a,b]$.
##### Proof of the second part of the Fundamental Theorem of Calculus
@@ -157,7 +170,7 @@ $$
\frac{\int_a^{x+h} f(u) du - \int_a^x f(u) du}{h} =\frac{\int_x^{x+h} f(u) du}{h} = f(\xi(h)).
$$
The value $\xi(h)$ is just the $c$ corresponding to a given value in $[x, x+h]$ guaranteed by the mean value theorem. We only know that $x \leq \xi(h) \leq x+h$. But this is plenty - it says that $\lim_{h \rightarrow 0+} \xi(h) = x$. Using the fact that $f$ is continuous and the known properties of limits of compositions of functions this gives $\lim_{h \rightarrow 0+} f(\xi(h)) = f(x)$. But this means that the (right) limit of the secant line expression exists and is equal to $f(x)$, which is what we want to prove. Repeating a similar argument when $h < 0$, finishes the proof.
The value $\xi(h)$ is just the $c$ corresponding to a given value in $[x, x+h]$ guaranteed by the mean value theorem. We only know that $x \leq \xi(h) \leq x+h$. But this is plenty---it says that $\lim_{h \rightarrow 0+} \xi(h) = x$. Using the fact that $f$ is continuous and the known properties of limits of compositions of functions this gives $\lim_{h \rightarrow 0+} f(\xi(h)) = f(x)$. But this means that the (right) limit of the secant line expression exists and is equal to $f(x)$, which is what we want to prove. Repeating a similar argument when $h < 0$, finishes the proof.
The basic notion used is simply that for small $h$, this expression is well approximated by the left Riemann sum taken over $[x, x+h]$:
@@ -210,8 +223,8 @@ What integral will show the intuition of the Merton College scholars that the di
#| hold: true
#| echo: false
choices = [
"``\\int_0^t (v_0 + au) du = (v_0 t + a\\cdot u^2/2)\\big|_0^t``",
"``\\int_0^t (v(0) + v(u))/2 du = v(0)/2\\cdot t + x(u)/2\\ \\big|_0^t``",
"``\\int_0^t (v_0 + au) du = (v_0 t + a\\cdot u^2/2)\\Big|_0^t``",
"``\\int_0^t (v(0) + v(u))/2 du = v(0)/2\\cdot t + x(u)/2\\ \\Big|_0^t``",
"``(v(0) + v(t))/2 \\cdot \\int_0^t du = (v(0) + v(t))/2 \\cdot t``"
]
answ = 1
@@ -389,3 +402,30 @@ L"The exponential of the average of $\log(f)$"
answ = val1 > val2 ? 1 : 2
radioq(choices, answ)
```
###### Question
Above we showed the mean value theorem for integrals is used to prove part of the fundamental theorem of calculus. Suppose by some other means you knew that the FTC was correct and $f(x)$ is continuous. Then we have
$$
F(b) - F(a) = \int_a^b f(x) dx
$$
Now if $f(x)$ is continuous, $F(x)$ is differentiable and satisfies the mean value theorem for derivatives. What does this say:
```{julia}
#| echo: false
choices = [L"F'(\xi) = f(\xi) = (F(b) - F(a))/(b-a)",
L"f'(\xi) = (F(b) - F(a))/(b-a)",
L"F'(\xi) = (f(b) - f(a))/(b-a)"
]
answer = 1
buttonq(choices, answer)
```
Given the right answer, we can solve to get that $\xi$ exists in $[a,b]$ with:
$$
\int_a^b f(x) dx = f(\xi) \cdot (b-a)
$$
+861
View File
@@ -0,0 +1,861 @@
# Numeric approximations to definite integrals
{{< include ../_common_code.qmd >}}
This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots; plotly()
using QuadGK
using Roots
```
## Numeric integration
The fundamental theorem of calculus gives an easy to compute answer to the value of a definite integral *when* a computable (elementary) anti-derivative can be found. This is not always the case. See [Liousville's theorem](https://en.wikipedia.org/wiki/Liouville's_theorem_(differential_algebra)) to read more. If there is no computable anti-derivative the definite integral can be *approximated* numerically, as discussed in this section, where we begin with a Riemann sum approach, but end with a much more efficient Gauss-quadrature approach we will utilize in subsequent sections.
The Riemann sum approach gives a method to approximate the value of a definite integral. We just compute an approximating sum for a large value of $n$, so large that the limiting value and the approximating sum are close.
To see the mechanics, let's again return to Archimedes' problem and *approximate* $\int_0^1 x^2 dx$.
Let us fix some values, $a$, $b,$ and $f$ are part of the question, $n$ is related to the approximation.
```{julia}
a, b = 0, 1
f(x) = x^2
n = 5
```
Then for a given $n$ we have some steps to do: create the partition, find the $c_i$, multiply the pieces, and add them up. Here is one way to do all this:
```{julia}
xs = a:(b-a)/n:b # also range(a, b, length=n)
deltas = diff(xs) # forms x2-x1, x3-x2, ..., xn-xn-1
cs = xs[1:end-1] # finds left-hand end points. xs[2:end] would be right-hand ones.
```
We want to sum the products $f(c_i)\Delta_i$. Here is one way to do so using `zip` to iterate over the paired off values in `cs` and `deltas`.
```{julia}
sum(f(ci)*Δi for (ci, Δi) in zip(cs, deltas))
```
Our answer is not so close to the value of $1/3$, but what did we expect---we only used $n=5$ intervals. Trying again with $50,000$ gives us:
```{julia}
#| hold: true
n = 50_000
xs = a:(b-a)/n:b
deltas = diff(xs)
cs = xs[1:end-1]
sum(f(ci)*Δi for (ci, Δi) in zip(cs, deltas))
```
This value is about $10^{-5}$ off from the actual answer of $1/3$.
We should expect that larger values of $n$ will produce better approximate values, as long as numeric issues don't get involved.
Before continuing, we define a function to compute approximating sums for us with an extra argument to specifying one of four common methods for estimating $\int_{x_{i-1}}^{x_i}f(x)dx$. Leaving explanations for later, @fig-various-integration-methods shows the different approximations.
```{julia}
#| eval: false
function riemann(f, xs; method="right")
Ms = (left = (f,a,b) -> f(a),
right = (f,a,b) -> f(b),
trapezoid = (f,a,b) -> (f(a) + f(b))/2,
simpsons = (f,a,b) -> (c = a/2 + b/2; (1/6) * (f(a) + 4*f(c) + f(b)))
)
M = Ms[Symbol(method)}
xs′ = zip(xs[1:end-1], xs[2:end])
sum(M(f, a, b) * (b-a) for (a,b) ∈ xs′)
end
riemann(f, a, b, n; method="right") =
riemann(f, range(a,b,n+1); method)
```
(This function is defined in `CalculusWithJulia` and need not be copied over if that package is loaded.)
::: {#fig-various-integration-methods}
```{julia}
#| echo: false
let
gr()
f(x) = sin(x/3) + sin(x/1.5)
plt = plot(; legend=false, xaxis=([], false),
yaxis=([], false))#, empty_style...)
plot!(plt, [(-0.5, 0), (6.5,0)]; line=(1, :black), arrow=true)
plot!(f, 0, 6)
left = [(1,0), (2,0), (2, f(1)), (1, f(1))]
push!(left, first(left))
right = [(2,0), (3,0), (3, f(3)), (2, f(3))]
push!(right, first(right))
trapezoid = [(3,0), (4,0), (4, f(4)), (3, f(3))]
push!(trapezoid, first(trapezoid))
l1(x) = (x-4.5)*(x-5) / (4 - 4.5) / (4 - 5)
l2(x) = (x-4) * (x-5) / (4.5-4) / (4.5 - 5)
l3(x) = (x-4) * (x-4.5) / (5-4) / (5-4.5)
s(x) = f(4)*l1(x) + f(4.5)*l2(x) + f(5)*l3(x)
ts = range(4,5, 15)
simpsons = [(4,0), tuple.(ts, s.(ts))..., (5, 0)]
push!(simpsons, first(simpsons))
plot!(plt, left; line=(1, :blue))
plot!(plt, right; line=(1, :red))
plot!(plt, trapezoid, line=(1, :green))
plot!(plt, simpsons; line=(1, :brown))
annotate!(plt, [
(1.5, .5, text("left riemann", 90.0)),
(2.5, .5, text("right riemann", 90.0)),
(3.5, .5, text("trapezoid", 90.0)),
(4.5, .5, text("Simpson's", 90.0))])
plotly()
plt
end
```
Plot of a $f(x)$ showing (from left to right) a left Riemann sum approximation, a right Riemann sum approximation, a trapezoid approximation, and Simpson's approximation. The error in the Simpson's approximation (barely discernible) appears to be less than that of the trapezoid approximation which is less than either the left- or right-Riemann sum approximations.
:::
With this, we can easily find an approximate answer for a definite integral. We wrote the function to use the familiar template `action(function, arguments...)`, so we pass in a function and arguments to describe the problem (`a`, `b`, and `n` and, optionally, the `method`):
```{julia}
f(x) = exp(x)
riemann(f, 0, 5, 10)
```
Or with more intervals in the partition
```{julia}
riemann(f, 0, 5, 50_000)
```
(The answer is $e^5 - e^0 = 147.4131591025766\dots$, which shows that even $50,000$ partitions is not enough to guarantee many digits of accuracy.)
##### Example
Numerically estimate the definite integral $\int_0^2 x\log(x) dx$.
This particular integrand is continuous on $(0,2]$ *but* we can redefine it to be $0$ at $0$ to make it continuous on $[0,2]$, hence the integral above is well defined. Numerically though, we have to be a bit careful with the Riemann sum, as the left Riemann sum will have an issue at $0=x_0$---`0*log(0)` returns `NaN` which will poison any subsequent arithmetic operations, so the value returned will be `NaN` and not an approximate answer. We could define our function with a check, instead we avoid this value by using the right Riemann sum:
```{julia}
h(x) = x * log(x)
riemann(h, 0, 2, 50_000; method="right")
```
(The default is `"right"`, so no method specified would also work.)
## Error estimate
The Riemann sum above is actually extremely inefficient in that it can take a large number of rectangles to produce an "accurate" approximation for a definite integral, even for nice functions. To see how much so, we can derive an estimate for the error in approximating the value using an arithmetic progression as the partition. Let's assume that our function $f(x)$ is increasing, so that the right sum gives an upper estimate and the left sum a lower estimate, so the error in any Riemann sum estimate will be smaller than the distance between these two values:
$$
\begin{align*}
\text{error}
&\leq \text{upper sum} - \text{lower sum}\\
&=
\left(f(x_1) \cdot (x_{1} - x_0) + f(x_2) \cdot (x_{2} - x_1) + \cdots \right.\\
&\quad + \left. f(x_{n-1})(x_{n-1} - x_{n-2}) + f(x_n) \cdot (x_n - x_{n-1})\right)\\
&\quad -
\left(f(x_0) \cdot (x_{1} - x_0) + f(x_1) \cdot (x_{2} - x_1) + \cdots \right.\\
&\quad + \left. f(x_{n-1})(x_n - x_{n-1}) \right)\\
&=
\left(f(x_1) \cdot \Delta + f(x_2) \cdot \Delta + \cdots + f(x_{n-1})\Delta + f(x_n) \cdot \Delta y\right)\\
&\quad -
\left(f(x_0) \cdot \Delta + f(x_1) \cdot \Delta + \cdots + f(x_{n-1})\Delta\right) \\
&= \left(\left[f(x_1) + f(x_2) + \cdots + f(x_n)\right] - \left[f(x_0) + \cdots + f(x_{n-1})\right]\right) \cdot \Delta \\
&= \left(f(b) - f(a)\right) \cdot \frac{b-a}{n}.
\end{align*}
$$
We see the error goes to $0$ at a rate of $1/n$ with the constant depending on $b-a$ and the function $f$. In general, a similar bound holds when $f$ is not monotonic.
### The trapezoid rule
There are other ways to approximate the integral that use fewer points in the partition. Riemann sums approximate the definite integral over each "piece" of the partition---$\int_{x_{i-1}}^{x_i} f(x) dx$---using a rectangle. Other geometric shapes are possible.
The *trapezoid* rule uses a trapezoid formed to approximate this area, namely the one formed by $(x_{i-1}, 0)$, $(x_{i-1}, f(x_{i-1}))$, $(x_i, f(x_i))$, and $(x_i, 0)$ with area
$$
\frac{1}{2} \left(f(x_{i-1}) + f(x_i) \right) \cdot (x_i - x_{i-1}).
$$
If we use an equally spaced partition ($\Delta=(b-a)/n$) and add all the $n$ terms, we get single contributions from the endpoints and double from the others giving
$$
A \approx (\frac{f(x_0)}{2} + \frac{f(x_n)}{2})\Delta + \sum_{i=1}^{n-1} f(x_i) \Delta/
$$
In a later section, we will see that the error in using trapezoids to
estimate the area is bounded, for some constant $K$:
$$
\text{error} \leq \frac{K (b-a)^3}{12n^2}.
$$
The $n^2$ means *roughly* that the error in the estimate using a Riemann sum with $n$ terms is similar to the error in the estimate using the trapezoid rule with $\sqrt{n}$ terms.^[There are functions where the trapezoid method has much faster convergence, even exponential. (cf. [this article](https://people.maths.ox.ac.uk/trefethen/sirev56-3_385.pdf) and [these notes](https://math.mit.edu/~stevenj/trap-iap-2011.pdf) for some background.)]
##### Example
Consider the integral
$$
\int_0^2 x e^{-x} dx = 1 - 3 e^{-2} = 0.59399415\cdots
$$
For comparison sake, we define the exact answer as a constant:
```{julia}
A = 1 - 3 * exp(-2)
```
The error of a Riemann sum with $n=10^4$ is then:
```{julia}
a, b = 0, 2
f(x) = x * exp(-x)
riemann(f, a, b, 10^4; method="right") - A
```
and this is comparable to the error of the trapezoid method with $n=10^2$:
```{julia}
riemann(f, a, b, 10^2; method="trapezoid") - A
```
### Simpson's rule
[Simpson's](http://tinyurl.com/7b9pmu) rule is one, where instead of approximating the area with rectangles that go through some $c_i$ in $[x_{i-1}, x_i]$ instead the function is approximated by the quadratic polynomial going through $x_{i-1}$, $(x_i + x_{i-1})/2$, and $x_i$ and the exact area under that polynomial is used in the approximation. The explicit formula for a single partition is^[The `riemann` function sums this expression, but this approach is inefficient computationally. Alternative formulations would be suggested.]
$$
\int_{x_{i-1}}^{x_i} f(x) dx \approx \frac{x_i - x_{i-1}}{6}\left(f(x_{i-1}) + 4f(\frac{x_{i-1} + x_i}{2}) + f(x_i)\right)
$$
The error in this approximation can be shown to be
$$
\text{error} \leq \frac{(b-a)^5}{180n^4} \text{max}_{\xi \text{ in } [a,b]} \lvert f^{(4)}(\xi) \rvert.
$$
That is, the error is like $1/n^4$ with constants depending on the length of the interval, $(b-a)^5$, and the maximum value of the fourth derivative over $[a,b]$. This is significant, the error in $10$ steps of Simpson's rule is on the scale of the error of $10,000$ steps of the Riemann sum for well-behaved functions.
:::{.callout-note}
## Note
The Wikipedia article mentions that Kepler used a similar formula $100$ years prior to Simpson, or about $200$ years before Riemann published his work. Again, the value in Riemann's work is not the computation of the answer, but the framework it provides in determining if a function is Riemann integrable or not.
:::
##### Example
Continuing the previous example, the accuracy of Simpson's rule with $10$ steps is comparable to that of a Riemann sum with $10^4$ steps:
```{julia}
riemann(f, a, b, 10; method="simpsons") - A
```
## Gauss quadrature
There are function types where the above approximations are actually exact:
* Riemann sums are exact for *constant* functions (polynomials with order $0$)
* The trapezoid method is exact for *linear* functions (polynomials with order $1$)
* Simpson's rule is exact for *quadratic* functions (polynomials with degree $2$)
This pattern could be extended by taking more intermediate points. In fact an entire family of similar approximations using $n$ points can be made exact for any polynomial of degree $n-1$ or lower.
However, by choosing points judiciously---not necessarily evenly spaced out and not necessarily including the end points---$n$ points can be exact for polynomials of degree higher than $n$. (Simpson' rule actually being exact for *cubic* polynomials is something that hints at this.)
The formulas for an approximation to the integral $\int_{-1}^1 f(x) dx$ discussed so far can be written as:
$$
\begin{align*}
S &= f(x_1) \Delta_1 + f(x_2) \Delta_2 + \cdots + f(x_n) \Delta_n\\
&= w_1 f(x_1) + w_2 f(x_2) + \cdots + w_n f(x_n)\\
&= \sum_{i=1}^n w_i f(x_i).
\end{align*}
$$
The $w$s are "weights" and the $x$s are nodes. Restricting to the interval $[-1,1]$ presents no loss in generality.
A [Gaussian](http://en.wikipedia.org/wiki/Gaussian_quadrature) *quadrature rule* is a set of weights and nodes for $i=1, \dots n$ for which the sum is *exact* for any $f$ which is a polynomial of degree $2n-1$ or less. Such choices then also approximate well the integrals of functions which are not polynomials of degree $2n-1$ or less, provided $f$ can be well approximated by a polynomial over $[-1,1]$. (Which is the case for the "nice" functions we encounter, though not for highly oscillatory functions.) More details are discussed in the section on *orthogonal polynomials* and some examples are given in the questions.
### The quadgk function
In `Julia` a modification of the Gauss quadrature rule is implemented in the `quadgk` function (from the `QuadGK` package) to give numeric approximations to integrals. The `quadgk` function also has the familiar interface `action(function, arguments...)`. Unlike our `riemann` function, there is no `n` specified, as the number of steps is *adaptively* determined. (There is more partitioning occurring where the function is changing rapidly.) Instead, the algorithm outputs an estimate on the possible error along with the answer. Instead of $n$, some trickier problems require a specification of an error threshold.
To use the function to integrate `f` over an interval `[a,b]` we have:
```{julia}
#| hold: true
f(x) = x * log(x)
quadgk(f, 0, 2)
```
As mentioned, there are two values returned: an approximate answer, and an error estimate. In this example we see that the value of $0.3862943610307017$ is accurate to within $10^{-9}$. (The actual answer is $-1 + 2\cdot \log(2)$ and the error is only $10^{-11}$. The reported error is an estimated upper bound, and may be conservative, as with this problem.) Our previous answer using $50,000$ right-Riemann sums was $0.38632208884775737$ and is only accurate to $10^{-5}$. By contrast, this method uses just $256$ function evaluations in the above problem.
The method should be exact for polynomial functions:
```{julia}
#| hold: true
f(x) = x^5 - x + 1
quadgk(f, -2, 2)
```
The error term is $0$, the answer is $4$ up to the last unit of precision (1 ulp), so any error is only in floating point approximations.
For the numeric approximation of a definite integral, the `quadgk` function should be preferred over the other methods previously discussed.
Here are some sample integrals computed with `quadgk`:
----
$$
\int_0^\pi \sin(x) dx
$$
```{julia}
quadgk(sin, 0, pi)
```
(Again, the actual answer is off only in the last digit, the error estimate is an upper bound.)
----
$$
\int_0^5 e^x dx
$$
```{julia}
quadgk(exp, 0, 5)
```
----
$$
\int_0^2 x^x dx
$$
```{julia}
u(x) = x^x
quadgk(u, 0, 2)
```
The function $x^x$ is not continuous at $0$, but can be defined to be so. In this case, the numeric definition of `0^0` matches the limit, so no discussion of redefining the function is necessary, as was done earlier with the function $x\cdot \log(x)$.
In fact, the specified endpoints to `quadgk` are *never* evaluated, so such concerns are not needed. (Which can be exploited when integrals involving functions with vertical asymptotes are discussed.) This is why the first example---which integrated `x*log(x)`---did not return `NaN` but rather an estimate for the integral.
#### Dropping the error term
When composing the answer with other functions it may be desirable to drop the error in the answer, we discuss three styles that can be used for this. The first is to just name the two returned values:
```{julia}
#| hold: true
A, err = quadgk(cos, 0, pi/4)
A
```
The second is to ask for just the first component of the returned value:
```{julia}
#| hold: true
A = first(quadgk(tan, 0, pi/4))
```
Finally, direct indexing can be applied, as with
```{julia}
quadgk(tan, 0, pi/4)[1]
```
Though we try to avoid this style in favor of being more explicit when that is convenient.
##### Example
In probability theory, a *univariate density* is a function, $f(x)$ such that $f(x) \geq 0$ and $\int_a^b f(x) dx = 1$, where $a$ and $b$ are the range of the distribution.
The [Von Mises](http://en.wikipedia.org/wiki/Von_Mises_distribution) distribution, takes the form
$$
k(x) = C \cdot \exp(\cos(x)), \quad -\pi \leq x \leq \pi.
$$
Compute $C$ (numerically).
The fact that $1 = \int_{-\pi}^\pi C \cdot \exp(\cos(x)) dx = C \int_{-\pi}^\pi \exp(\cos(x)) dx$ implies that $C$ is the reciprocal of the definite integral:
```{julia}
k(x) = exp(cos(x))
A, err = quadgk(k, -pi, pi)
```
So
```{julia}
C = 1/A
k₁(x) = C * exp(cos(x))
```
The *cumulative distribution function* for $k(x)$ is $K(x) = \int_{-\pi}^x k(u) du$, $-\pi \leq x \leq \pi$. We just showed that $K(\pi) = 1$ and it is trivial that $K(-\pi) = 0$. The quantiles of the distribution are the values $q_1$, $q_2$, and $q_3$ for which $K(q_i) = i/4$. Can we find these?
First we define a function, that computes $K(x)$. We only need the first of the two answers given by `quadgk`.
```{julia}
K(x) = first(quadgk(k₁, -pi, x))
```
The question asks us to solve $K(x) = 0.25$, $K(x) = 0.5$ and $K(x) = 0.75$. The `Roots` package can be used for such work, in particular `find_zero`. We will use a bracketing method, as clearly $K(x)$ is increasing, as $k(u)$ is positive, so we can just bracket our answer with $-\pi$ and $\pi$. (We solve $K(x) - p = 0$, so $K(\pi) - p > 0$ and $K(-\pi)-p < 0$.). We could do this with a comprehension, but for variety use broadcasting with `solve` below.
```{julia}
#| hold: true
Z = ZeroProblem((x,p) -> K(x) - p, (-pi, pi))
solve.(Z, (1/4, 1/2, 3/4))
```
The middle one is clearly $0$. This distribution is symmetric about $0$, so half the area is to the right of $0$ and half to the left, so clearly when $p=0.5$, $x$ is $0$. The other two show that the area to the left of $-0.809767$ is equal to the area to the right of $0.809767$ and equal to $0.25$.
#### Visualizing the nodes chosen by `quadgk`
To visualize the choice of nodes by the algorithm, In @fig-visualize-node-choice-quadgk-algorithm-sin-x the nodes chosen are shown for $f(x)=\sin(x)$ over $[0,\pi]$. Relatively few nodes used to get a high-precision estimate.
::: {#fig-visualize-node-choice-quadgk-algorithm-sin-x}
```{julia}
#| echo: false
function FnWrapper(f)
xs=Any[]
ys=Any[]
x -> begin
fx = f(x)
push!(xs, x)
push!(ys, fx)
fx
end
end
nothing
```
```{julia}
#| hold: true
#| echo: false
let
a, b= 0, pi
f(x) = sin(x)
F = FnWrapper(f)
ans,err = quadgk(F, a, b)
plot(f, a, b, legend=false, title="Error ≈ $(round(err,sigdigits=2))")
scatter!(F.xs, F.ys)
end
```
The nodes chosen by `quadgk` for $f(x) = \sin(x)$ over $[0, \pi]$
:::
For a more oscillatory function, more nodes are chosen, as seen in @fig-visualize-quadgk-nodes-more-osciallations.
::: {#fig-visualize-quadgk-nodes-more-osciallations}
```{julia}
#| hold: true
#| echo: false
let
a, b= 0, pi
f(x) = exp(-x)*sinpi(x)
F = FnWrapper(f)
ans,err = quadgk(F, a, b)
plot(f, a, b, legend=false, title="Error ≈ $(round(err,sigdigits=2))")
scatter!(F.xs, F.ys)
end
```
Visualization nodes chosen by `quadgk` for $f(x) = e^{x} \sin(\pi x)$ over $[0, \pi]$. There are more nodes chosen then for the function $\sin(x)$, as seen in @fig-visualize-node-choice-quadgk-algorithm-sin-x
:::
In both @fig-visualize-node-choice-quadgk-algorithm-sin-x and @fig-visualize-quadgk-nodes-more-osciallations it can be verified that no node is one of the endpoints.
##### Example: Gauss nodes
The `QuadGK.gauss(n)` function returns a pair of $n$ quadrature points and weights to integrate a function over the interval $(-1,1)$, with an option to use a different interval $(a,b)$. For a given $n$, these values exactly integrate any polynomial of degree $2n-1$ or less. In this example, these $5$ points produce an answer accurate already to the $5$th decimal point.
```{julia}
xs, ws = QuadGK.gauss(5)
```
```{julia}
f(x) = exp(cos(x))
sum(w * f(x) for (x, w) in zip(xs, ws))
```
The pattern to integrate can be expressed in other ways, but using the `zip` function to iterate over the `xs` and `ws` as pairs of values is pretty direct.
## Questions
###### Question
For the function $f(x) = \sin(\pi x)$, estimate the integral for $-1$ to $1$ using a left-Riemann sum with the partition $-1 < -1/2 < 0 < 1/2 < 1$.
```{julia}
#| hold: true
#| echo: false
f(x) = sin(pi*x)
xs = -1:1/2:1
deltas = diff(xs)
val = sum(map(f, xs[1:end-1]) .* deltas)
numericq(val)
```
###### Question
For the right Riemann sum approximating $\int_0^{10} e^x dx$ with $n=100$ subintervals, what would be a good estimate for the error?
```{julia}
#| hold: true
#| echo: false
choices = [
"``(10 - 0)/100 \\cdot (e^{10} - e^{0})``",
"``10/100``",
"``(10 - 0) \\cdot e^{10} / 100^4``"
]
answ = 1
radioq(choices, answ)
```
###### Question
Use `quadgk` to find the following definite integral:
$$
\int_1^4 x^x dx .
$$
```{julia}
#| hold: true
#| echo: false
f(x) = x^x
a, b = 1, 4
val, _ = quadgk(f, a, b)
numericq(val)
```
###### Question
Use `quadgk` to find the following definite integral:
$$
\int_0^3 e^{-x^2} dx .
$$
```{julia}
#| hold: true
#| echo: false
f(x) = exp(-x^2)
a, b = 0, 3
val, _ = quadgk(f, a, b)
numericq(val)
```
###### Question
Use `quadgk` to find the following definite integral:
$$
\int_0^{9/10} \tan(u \frac{\pi}{2}) du.
$$
```{julia}
#| hold: true
#| echo: false
f(x) = tan(x*pi/2)
a, b = 0, 9/10
val, _ = quadgk(f, a, b)
numericq(val)
```
###### Question
Use `quadgk` to find the following definite integral:
$$
\int_{-1/2}^{1/2} \frac{1}{\sqrt{1 - x^2}} dx
$$
```{julia}
#| hold: true
#| echo: false
f(x) = 1/sqrt(1 - x^2)
a, b =-1/2, 1/2
val, _ = quadgk(f, a, b)
numericq(val)
```
###### Question
Let $A=1.98$ and $B=1.135$ and
$$
f(x) = \frac{1 - e^{-Ax}}{B\sqrt{\pi}x} e^{-x^2}.
$$
Find $\int_0^1 f(x) dx$
```{julia}
#| echo: false
let
A,B = 1.98, 1.135
f(x) = (1 - exp(-A*x))*exp(-x^2)/(B*sqrt(pi)*x)
val,_ = quadgk(f, 0, 1)
numericq(val)
end
```
###### Question
A bound for the complementary error function ( positive function) is
$$
\text{erfc}(x) \leq \frac{1}{2}e^{-2x^2} + \frac{1}{2}e^{-x^2} \leq e^{-x^2}
\quad x \geq 0.
$$
Let $f(x)$ be the first bound, $g(x)$ the second.
Assuming this is true, confirm numerically using `quadgk` that
$$
\int_0^3 f(x) dx \leq \int_0^3 g(x) dx
$$
The value of $\int_0^3 f(x) dx$ is
```{julia}
#| echo: false
let
f(x) = 1/2 * exp(-2x^2) + 1/2 * exp(-x^2)
val,_ = quadgk(f, 0, 3)
numericq(val)
end
```
The value of $\int_0^3 g(x) dx$ is
```{julia}
#| echo: false
let
g(x) = exp(-x^2)
val,_ = quadgk(g, 0, 3)
numericq(val)
end
```
###### Question
::: {#fig-jsxgraph-riemann-sum-illustration}
```{=html}
<div id="jsxgraph" style="width: 500px; height: 500px;"></div>
```
```{ojs}
//| echo: false
//| output: false
JXG = require("jsxgraph");
b = JXG.JSXGraph.initBoard('jsxgraph', {
boundingbox: [-0.5,0.3,1.5,-1/4], axis:true
});
g = function(x) { return x*x*x*x + 10*x*x - 60* x + 100}
f = function(x) {return 1/Math.sqrt(g(x))};
type = "right";
l = 0;
r = 1;
rsum = function() {
return JXG.Math.Numerics.riemannsum(f,n.Value(), type, l, r);
};
n = b.create('slider', [[0.1, -0.05],[0.75,-0.05], [2,1,50]],{name:'n',snapWidth:1});
graph = b.create('functiongraph', [f, l, r]);
os = b.create('riemannsum',
[f,
function(){ return n.Value();},
type, l, r
],
{fillColor:'#ffff00', fillOpacity:0.3});
b.create('text', [0.1,0.25, function(){
return 'Riemann sum='+(rsum().toFixed(4));
}]);
```
Interactive graphic showing the area of a right-Riemann sum for different partitions.
:::
The function in the interactive graph of @fig-jsxgraph-riemann-sum-illustration is
$$
f(x) = \frac{1}{\sqrt{ x^4 + 10x^2 - 60x + 100}}.
$$
When $n=5$ what is the area of the Riemann sum?
```{julia}
#| hold: true
#| echo: false
numericq(0.1224)
```
When $n=50$ what is the area of the Riemann sum?
```{julia}
#| hold: true
#| echo: false
numericq(0.1187)
```
Using `quadgk` what is the area under the curve?
```{julia}
#| hold: true
#| echo: false
g(x) = 1/sqrt(x^4 + 10x^2 - 60x + 100)
val, tmp = quadgk(g, 0, 1)
numericq(val)
```
###### Question
Gauss nodes for approximating the integral $\int_{-1}^1 f(x) dx$ for $n=4$ are:
```{julia}
ns = [-0.861136, -0.339981, 0.339981, 0.861136]
```
The corresponding weights are
```{julia}
wts = [0.347855, 0.652145, 0.652145, 0.347855]
```
Use these to estimate the integral $\int_{-1}^1 \cos(\pi/2 \cdot x)dx$ with $w_1f(x_1) + w_2 f(x_2) + w_3 f(x_3) + w_4 f(x_4)$.
```{julia}
#| hold: true
#| echo: false
f(x) = cos(pi/2*x)
val = sum([f(ni)*wi for (wi, ni) in zip(wts, ns)])
numericq(val)
```
The actual answer is $4/\pi$. How far off is the approximation based on 4 points?
```{julia}
#| hold: true
#| echo: false
choices = [
L"around $10^{-1}$",
L"around $10^{-2}$",
L"around $10^{-4}$",
L"around $10^{-6}$",
L"around $10^{-8}$"]
answ = 4
radioq(choices, answ, keep_order=true)
```
###### Question
Using the Gauss nodes and weights from the previous question, estimate the integral of $f(x) = e^x$ over $[-1, 1]$. The value is:
```{julia}
#| hold: true
#| echo: false
f(x) = exp(x)
val = sum([f(ni)*wi for (wi, ni) in zip(wts, ns)])
numericq(val)
```
+70 -21
View File
@@ -12,7 +12,7 @@ using Roots
using ForwardDiff: derivative
```
This section takes a detour to give some background on why the underlying method of `quadgk` is more efficient than those of Riemann sums. Orthogonal polynomials play a key role. There are many families of such polynomials. We highlight two.
This section takes an unnecessary detour to give some background on why the underlying method of `quadgk` is more efficient than those of Riemann sums. Orthogonal polynomials play a key role. There are many families of such polynomials. We highlight two.
## Inner product
@@ -50,17 +50,15 @@ $$
\angle(f,g) = \cos^{-1}\left(\frac{\langle f, g\rangle}{\lVert f \rVert \lVert g \rVert}\right).
$$
This says, the angle between two orthogonal elements is $90$ degrees (in some orientation)
The Cauchy-Schwarz inequality, $|\langle f, g \rangle| \leq \lVert f \rVert \lVert g\rVert$, for an inner product space, ensures the argument to $\cos^{-1}$ is between $-1$ and $1$.
These properties generalize two-dimensional vectors, with components $\langle x, y\rangle$. Recall, these can be visualized by placing a tail at the origin and a tip at the point $(x,y)$. Such vectors can be added by placing the tail of one at the tip of the other and using the vector from the other tail to the other tip.
These properties generalize two-dimensional vectors, with components $\langle x, y\rangle$. Recall, vectors can be visualized by placing a tail at the origin and a tip at the point $(x,y)$. Such vectors can be added by placing the tail of one at the tip of the other and using the vector from the other tail to the other tip.
With this, we have a vector anchored at the origin can be viewed as a line segment with slope $y/x$ (rise over run). A perpendicular line segment would have slope $-x/y$ (the negative reciprocal) which would be associated with the vector $\langle y, -x \rangle$. The dot product is just the sum of the multiplied components, or for these two vectors $x\cdot y + y\cdot (-x)$, which is $0$, as the line segments are perpendicular (orthogonal).
Consider now two vectors, say $f$, $g$. We can make a new vector that is orthogonal to $f$ by combining $g$ with a piece of $f$. But what piece?
Consider this
Consider this calculation (using the known answer):
$$
\begin{align*}
@@ -75,7 +73,7 @@ Define
$$
proj_f(g) = \frac{\langle f,g\rangle }{\langle f, f\rangle} f,
$$
then we have $u_1 = f$ and $u_2 = g-proj_f(g)$, $u_1$ and $u_2$ are orthogonal.
then we have with $u_1 = f$ and $u_2 = g-proj_f(g)$ that $u_1$ and $u_2$ are orthogonal.
A similar calculation shows if $h$ is added to the set of elements, then
$u_3 = h - proj_{u_1}(h) - proj_{u_2}(h)$ will be orthogonal to $u_1$ and $u_2$. etc.
@@ -94,7 +92,7 @@ $$
x^2 \mid_{-1}^1 = 1^2 - (-1)^2 = 0.
$$
Now consider a quadratic polynomial, $u_2(x) = ax^2 + bx + c$, we want a polynomial which is orthogonal to $u_0$ and $u_1$ with the extra condition that $u_2(1) = c =1$ (or $c=1$.). We can do this using Gram-Schmidt as above, or as here through a system of two equations:
Now consider a quadratic polynomial, $u_2(x) = ax^2 + bx + c$, we want a polynomial which is orthogonal to $u_0$ and $u_1$ with the extra condition that $u_2(1) = c =1$ (or $c=1$.). We can do this using Gram-Schmidt as above, or, as here, through a system of two equations:
```{julia}
@syms a b c d x
@@ -117,7 +115,7 @@ u3 = a*x^3 + b*x^2 + c*x + d
eqs = (integrate(u0 * u3, (x, -1, 1)) ~ 0,
integrate(u1 * u3, (x, -1, 1)) ~ 0,
integrate(u2 * u3, (x, -1, 1)) ~ 0)
sols = solve(eqs, (a, b, c, d)) # a => -5c/3, b=>0, d=>0
sols = solve(eqs, (a, b, c, d)) # a => -5c/3, b => 0, d => 0
u3 = u3(sols...)
u3 = simplify(u3/u3(x=>1)) # make u3(1) = 1
```
@@ -152,8 +150,6 @@ $$
Unique elements can be defined by specifying some additional property. For Legendre, it was $p_n(1)=1$, for other orthogonal families this may be specified by having leading coefficient of $1$ (monic), or a norm of $1$ (orthonormal), etc.
The above is the *absolutely continuous* case, generalizations of the integral allow this to be more general.
Orthogonality can be extended: If $q(x)$ is any polynomial of degree $m < n$, then
$\langle q, p_n \rangle = \int_I q(x) p_n(x) w(x) dx = 0$. (See the questions for more detail.)
@@ -186,9 +182,9 @@ As this has degree $n$ or less, it can be expressed in terms of $p_0, p_1, \dots
$$
\begin{align*}
\int_I p_m(x) u(x) w(x) dx &=
\int_I p_m(x) \sum_{j=0}^n p_j(x) w(x) dx \\
&= \int_I p_m(x) \left(p_m(x) + \textcolor{red}{\sum_{j=0, j\neq m}^{n} p_j(x)}\right) w(x) dx \\
&= \int_I p_m(x) p_m(x) w(x) dx = h_m
\int_I p_m(x) \left(\sum_{j=0}^n d_j p_j(x)\right) w(x) dx \\
&= \int_I p_m(x) \left(d_m p_m(x) + \textcolor{red}{\sum_{j=0, j\neq m}^{n} d_j p_j(x)}\right) w(x) dx \\
&= d_m \int_I p_m(x) p_m(x) w(x) dx = d_m \cdot h_m
\end{align*}
$$
@@ -205,8 +201,9 @@ $$
$$
The last integral being $0$ as $xp_m(x)$ has degree $n-1$ or less and hence is orthogonal to $p_n$.
If $m < n-1$, then $0 = d_m h_m$, with $h_m > 0$, so $d_m=0$
That is $p_{n+1} - A_n x p_n(x) = d_n p_n(x) + d_{n-1} p_{n-1}(x)$. Setting $B_n=d_n$ and $C_{n-1} = -d_{n-1}$ shows the three-term recurrence applies.
That is $p_{n+1} - A_n x p_n(x) = u(x) = d_n p_n(x) + d_{n-1} p_{n-1}(x)$. Setting $B_n=d_n$ and $C_{n-1} = -d_{n-1}$ shows the three-term recurrence applies.
#### Example: Legendre polynomials
@@ -221,7 +218,7 @@ I &= [-1,1]\\
A_n &= \frac{2n+1}{n+1}\\
B_n &= 0\\
C_n & = \frac{n}{n+1}\\
k_{n+1} &= \frac{2n+1}{n+1}k_n - \frac{n}{n-1}k_{n-1}, k_1=k_0=1\\
k_{n+1} &= \frac{2n+1}{n+1}k_n - \frac{n}{n-1}k_{n-1}, \quad k_1=k_0=1\\
h_n &= \frac{2}{2n+1}
\end{align*}
$$
@@ -385,7 +382,7 @@ As $u$ is continuous, this means there are at least $n$ sign changes, hence $n$
### Integration
## Integration
Recall, a Riemann sum can be thought of in terms of weights, $w_i$ and nodes $x_i$ for which $\int_I f(x) dx \approx \sum_{i=0}^{n-1} w_i f(x_i)$.
For a right-Riemann sum with partition given by $a_0 < a_1 < \cdots < a_n$ the nodes are $x_i = a_i$ and the weights are $w_i = (a_i - a_{i-1})$ (or in the evenly spaced case, $w_i = (a_n - a_0)/n$.
@@ -428,7 +425,7 @@ $$
h(x) = q(x) p_n(x) + r(x)
$$
and the degree of $r(x)$ is less than $n-1$, the degree of $p_n(x)$. Further, the degree of $q(x)$ is also less than $n-1$, as were it more, then the degree of $q(x)p_n(x)$ would be more than $n-1+n$ or $2n-1$. Let's note that if $x_i$ is a zero of $p_n(x)$ that $h(x_i)= r(x_i)$.
and the degree of $r(x)$ is no more than $n-1$, the degree of $p_n(x)$ being $n$. Further, the degree of $q(x)$ is also no more than $n-1$, as were it more, then the degree of $q(x)p_n(x)$ would be more than $n-1+n = 2n-1$. Let's note that if $x_i$ is a zero of $p_n(x)$ that $h(x_i)= r(x_i)$.
So
@@ -557,18 +554,22 @@ $$
The `QuadGK` package uses a modification to Gauss quadrature to estimate numeric integrals. Let's see how. Behind the scenes, `quadgk` calls `kronrod` to compute nodes and weights.
We have from earlier that
We have from earlier these Legendre polynomials:
```{julia}
u₃(x) = x*(5x^2 - 3)/2
u₄(x) = 35x^4 / 8 - 15x^2 / 4 + 3/8
```
The zeros can readily be found numerically:
```{julia}
xs = find_zeros(u₄, -1, 1)
```
From this we can compute the weights from the derived general formula:
From this we can compute the weights from the derived general formula when $n=4$:
```{julia}
k₃, k₄ = 5/2, 35/8
@@ -578,10 +579,10 @@ ws = [k₄/k₃ * 1/(derivative(u₄,xᵢ) * u₃(xᵢ)) * I for xᵢ ∈ xs]
(xs, ws)
```
We compare now to the values returned by `kronrod` in `QuadGK`
We compare now to the values returned by `kronrod` in `QuadGK` to see they agree after alignment:
```{julia}
kxs, kwts, wts = kronrod(4, -1, 1)
kxs, kwts, wts = QuadGK.kronrod(4, -1, 1)
[ws wts xs kxs[2:2:end]]
```
@@ -601,6 +602,54 @@ QL, esterror = quadgk(u, -1, 1)
The first two are expected to not be as accurate, as they utilize a fixed number of nodes.
----
The computation in `QuadGK` compares two values to estimate the error and to dexide if a subdivision is needed. The "common case" is based on Gauss nodes for degree $7$ and related nodes for *Kronrod*. The values below are copied from the source code, which caches them for re-use.
```{julia}
# precomputed n=7 rule in double precision (computed in 100-bit arithmetic),
# since this is the common case.
const xd7 = [-9.9145537112081263920685469752598e-01,
-9.4910791234275852452618968404809e-01,
-8.6486442335976907278971278864098e-01,
-7.415311855993944398638647732811e-01,
-5.8608723546769113029414483825842e-01,
-4.0584515137739716690660641207707e-01,
-2.0778495500789846760068940377309e-01,
0.0]
const wd7 = [2.2935322010529224963732008059913e-02,
6.3092092629978553290700663189093e-02,
1.0479001032225018383987632254189e-01,
1.4065325971552591874518959051021e-01,
1.6900472663926790282658342659795e-01,
1.9035057806478540991325640242055e-01,
2.0443294007529889241416199923466e-01,
2.0948214108472782801299917489173e-01]
const wgd7 = [1.2948496616886969327061143267787e-01,
2.797053914892766679014677714229e-01,
3.8183005050511894495036977548818e-01,
4.1795918367346938775510204081658e-01]
```
These weights can be used directly to integrate a function over $[-1,1]$ in the following manner. We know $\int_{-1}^1 \cos(\pi \cdot x/2) dx$ can be integrated and its value if $4/\pi$ or `1.2732395447351628...` With the weights above, we have this value is approximated by $\sum w_i (f(x_i) + f(-x_i))$.
The Kronrod weights are `wd7` and they yield:^[The awkward `!iszero` avoids double counting the node at `0.0`.]
```{julia}
f(x) = cos(pi/2 * x)
kr = sum(w * (f(x) + !iszero(x)*f(-x)) for (w,x) ∈ zip(wd7, xd7))
kr, kr - 4/pi
```
The Gauss weights are a bit different, as only 7 are used:
```{julia}
g = sum(w * (f(x) + !iszero(x)*f(-x)) for (w,x) ∈ zip(wgd7, xd7[2:2:8]))
g, g - 4/pi
```
The algorithm compares the value of `kr` to that of `g` and if it is "large" the interval is split making the algorithm adaptive. (Some detail is available at this [Wikipedia](https://en.wikipedia.org/wiki/Gauss%E2%80%93Kronrod_quadrature_formula) page.)
## Questions
###### Question
+18 -14
View File
@@ -11,12 +11,13 @@ using SymPy
---
Integration is facilitated when an antiderivative for $f$ can be found, as then definite integrals can be evaluated through the fundamental theorem of calculus.
However, despite differentiation being an algorithmic procedure, integration is not. There are "tricks" to try, such as substitution and integration by parts. These work in some cases---but not all!
However, there are classes of functions for which algorithms exist. For example, the `SymPy` `integrate` function mostly implements an algorithm that decides if an elementary function has an antiderivative. The [elementary](http://en.wikipedia.org/wiki/Elementary_function) functions include exponentials, their inverses (logarithms), trigonometric functions, their inverses, and powers, including $n$th roots. Not every elementary function will have an antiderivative comprised of (finite) combinations of elementary functions. The typical example is $e^{x^2}$, which has no simple antiderivative, despite its ubiquitousness.
Yet, there are classes of functions for which algorithms exist. For example, the `SymPy` `integrate` function mostly implements an algorithm that decides if an elementary function has an antiderivative. The [elementary](http://en.wikipedia.org/wiki/Elementary_function) functions include exponentials, their inverses (logarithms), trigonometric functions, their inverses, and powers, including $n$th roots. Not every elementary function will have an antiderivative comprised of (finite) combinations of elementary functions. The typical example is $e^{x^2}$, which has no simple antiderivative, despite its ubiquitousness.
There are classes of functions where an (elementary) antiderivative can always be found. Polynomials provide a case. More surprisingly, so do their ratios, *rational functions*.
@@ -30,8 +31,7 @@ Let $f(x) = p(x)/q(x)$, where $p$ and $q$ are polynomial functions with real co
The function $q(x)$ will factor over the real numbers. The fundamental theorem of algebra can be applied to say that $q(x)=q_1(x)^{n_1} \cdots q_k(x)^{n_k}$ where $q_i(x)$ is a linear or quadratic polynomial and $n_k$ a positive integer.
::: {.callout-note icon=false}
## Partial Fraction Decomposition
::: {.definition title="Partial Fraction Decomposition"}
There are unique polynomials $a_{ij}$ with degree $a_{ij} <$ degree $q_i$ such that
@@ -60,7 +60,7 @@ The value of this decomposition is that the terms $a_{ij}(x)/q_i(x)^j$ each have
:::{.callout-note}
## Note
Many calculus texts will give some examples for finding a partial fraction decomposition. We push that work off to `SymPy`, as for all but the easiest cases - a few are in the problems - it can be a bit tedious.
Many calculus texts will give some examples for finding a partial fraction decomposition. We push that work off to `SymPy`, as for all but the easiest cases---a few are in the problems---it can be a bit tedious.
:::
@@ -211,14 +211,15 @@ integrate(B/((a*x)^2 - 1)^4, x)
---
In [Bronstein](http://www-sop.inria.fr/cafe/Manuel.Bronstein/publications/issac98.pdf) this characterization can be found - "This method, which dates back to Newton, Leibniz and Bernoulli, should not be used in practice, yet it remains the method found in most calculus texts and is often taught. Its major drawback is the factorization of the denominator of the integrand over the real or complex numbers." We can also find the following formulas which formalize the above exploratory calculations ($j>1$ and $b^2 - 4c < 0$ below):
In [Bronstein](http://www-sop.inria.fr/cafe/Manuel.Bronstein/publications/issac98.pdf) this characterization can be found---"This method, which dates back to Newton, Leibniz and Bernoulli, should not be used in practice, yet it remains the method found in most calculus texts and is often taught. Its major drawback is the factorization of the denominator of the integrand over the real or complex numbers." We can also find the following formulas which formalize the above exploratory calculations ($j>1$ and $b^2 - 4c < 0$ below):
$$
\begin{align*}
\int \frac{A}{(x-a)^j} &= \frac{A}{1-j}\frac{1}{(x-a)^{j-1}}\\
\int \frac{A}{x-a} &= A\log(x-a)\\
\int \frac{Bx+C}{x^2 + bx + c} &= \frac{B}{2} \log(x^2 + bx + c) + \frac{2C-bB}{\sqrt{4c-b^2}}\cdot \arctan\left(\frac{2x+b}{\sqrt{4c-b^2}}\right)\\
\int \frac{Bx+C}{x^2 + bx + c} &= \frac{B}{2} \log(x^2 + bx + c)\\
&\quad + \frac{2C-bB}{\sqrt{4c-b^2}}\cdot \arctan\left(\frac{2x+b}{\sqrt{4c-b^2}}\right)\\
\int \frac{Bx+C}{(x^2 + bx + c)^j} &= \frac{B' x + C'}{(x^2 + bx + c)^{j-1}} + \int \frac{C''}{(x^2 + bx + c)^{j-1}}
\end{align*}
$$
@@ -231,10 +232,13 @@ That is integrating $f(x)/g(x)$, a rational function, will yield an output that
$$
\int f(x)/g(x) = P(x) + \frac{C(x)}{D{x}} + \sum v_i \log(V_i(x)) + \sum w_j \arctan(W_j(x))
\begin{align*}
\int f(x)/g(x) &= P(x) + \frac{C(x)}{D{x}} + \sum v_i \log(V_i(x))\\
&\quad + \sum w_j \arctan(W_j(x)).
\end{align*}
$$
(Bronstein also sketches the modern method which is to use a Hermite reduction to express $\int (f/g) dx = p/q + \int (g/h) dx$, where $h$ is square free (the "`j`" are all $1$). The latter can be written over the complex numbers as logarithmic terms of the form $\log(x-a)$, the "`a`s"found following a method due to Trager and Lazard, and Rioboo, which is mentioned in the SymPy documentation as the method used.)
(Bronstein also sketched the modern method which is to use a Hermite reduction to express $\int (f/g) dx = p/q + \int (g/h) dx$, where $h$ is square free (the "`j`" are all $1$). The latter can be written over the complex numbers as logarithmic terms of the form $\log(x-a)$, the "`a`s"found following a method due to Trager and Lazard, and Rioboo, which is mentioned in the SymPy documentation as the method used.)
#### Examples
@@ -447,8 +451,8 @@ choices = [
L"The value $c$ is a removable singularity, so the integral will be identical.",
L"The resulting function has an identical domain and is equivalent for all $x$."
]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
If $m = n$, then why can we cancel out the $(x-c)^n$ and not have a concern?
@@ -462,8 +466,8 @@ choices = [
L"The value $c$ is a removable singularity, so the integral will be identical.",
L"The resulting function has an identical domain and is equivalent for all $x$."
]
answ = 2
radioq(choices, answ, keep_order=true)
answer = 2
radioq(choices, answer, keep_order=true)
```
If $m < n$, then why can we cancel out the $(x-c)^m$ and not have a concern?
@@ -477,8 +481,8 @@ choices = [
L"The value $c$ is a removable singularity, so the integral will be identical.",
L"The resulting function has an identical domain and is equivalent for all $x$."
]
answ = 3
radioq(choices, answ, keep_order=true)
answer = 3
radioq(choices, answer, keep_order=true)
```
###### Question
+193 -95
View File
@@ -3,35 +3,37 @@
{{< include ../_common_code.qmd >}}
We discuss the integration techniques of $u$-substitution and trigonometric substitution.
This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using SymPy
```
---
## Integration by *u*-substitution
The technique of $u$-[substitution](https://en.wikipedia.org/wiki/Integration_by_substitution) is derived from reversing the chain rule: $[f(g(x))]' = f'(g(x)) g'(x)$.
::: {.definition title="Subsitution"}
Suppose that $g$ is continuous and $u(x)$ is differentiable with $u'(x)$ being Riemann integrable. Then both these integrals are defined:
Suppose that $g$ is continuous and $u(x)$ is differentiable with $u'(x)$ being Riemann integrable. Then both these integrals are defined and are equal:
$$
\int_a^b g(u(t)) \cdot u'(t) dt, \quad \text{and}\quad \int_{u(a)}^{u(b)} g(x) dx.
\int_a^b g(u(t)) \cdot u'(t) dt = \quad \int_{u(a)}^{u(b)} g(x) dx
$$
We wish to show they are equal.
:::
Let $G$ be an antiderivative of $g$, which exists as $g$ is assumed to be continuous. (By the Fundamental Theorem part I.) Consider the composition $G \circ u$. The chain rule gives:
Let $G$ be an antiderivative of $g$, which exists and is differentiable as $g$ is assumed to be continuous. (By the Fundamental Theorem part I.) Consider the composition $G \circ u$. The chain rule gives:
$$
@@ -50,28 +52,15 @@ $$
\end{align*}
$$
That is, this substitution formula applies:
> $\int_a^b g(u(x)) u'(x) dx = \int_{u(a)}^{u(b)} g(x) dx.$
Further, for indefinite integrals,
> $\int f(g(x)) g'(x) dx = \int f(u) du.$
---
We have seen a special case of substitution where $u(x) = x-c$ in the formula $\int_{a-c}^{b-c} g(x) dx= \int_a^b g(x-c)dx$.
The main use of this is to take complicated things inside of the function $g$ out of the function (the $u(x)$) by renaming them, then accounting for the change of name.
The main use of substitution is to take complicated things inside of the function $g$ out of the function (the $u(x)$) by renaming them, then accounting for the change of name.
Some examples are in order.
An example is in order.
Consider:
@@ -85,15 +74,13 @@ Clearly the $\sin(x)$ inside the exponential is an issue. If we let $u(x) = \sin
$$
\int_0^{\pi/2} u\prime(x) e^{u(x)} dx =
\int_{u(0)}^{u(\pi/2)} e^x dx = e^x \big|_{\sin(0)}^{\sin(\pi/2)} = e^1 - e^0.
\int_0^{\pi/2} u'(x) e^{u(x)} dx =
\int_{u(0)}^{u(\pi/2)} e^x dx = e^x \Big|_{\sin(0)}^{\sin(\pi/2)} = e^1 - e^0.
$$
This all worked, as the problem was such that it was more or less obvious what to choose for $u$ and $G$.
### Integration by substitution
The process of identifying the result of the chain rule in the function to integrate is not automatic, but rather a bit of an art. The basic step is to try some values and hope one works. Typically, this is taught by "substituting" in some value for part of the expression (basically the $u(x)$) and seeing what happens.
@@ -115,8 +102,13 @@ Again, we see that the $x^2$ inside the exponential is a complication. Letting $
$$
\int_0^2 4x e^{x^2} dx = 2\int_0^2 e^{x^2} \cdot 2x dx = 2\int_{u(0)}^{u(2)} e^u du = 2 \int_0^4 e^u du =
2 e^u\big|_{u=0}^4 = 2(e^4 - 1).
\begin{align*}
\int_0^2 4x e^{x^2} dx = 2\int_0^2 e^{x^2} \cdot 2x dx\\
& = 2\int_{u(0)}^{u(2)} e^u du\\
&= 2 \int_0^4 e^u du \\
&= 2 e^u\Big|_{u=0}^4 \\
&= 2(e^4 - 1).
\end{align*}
$$
---
@@ -126,8 +118,11 @@ Consider now $\int_0^1 2x^2 \sqrt{1 + x^3} dx$. Here we see that the $1 + x^3$ m
$$
\int_0^1 2x^2 \sqrt{1 + x^3} dx = \int_{u(0)}^{u(1)} 2 \sqrt{u} (1/3) du = 2/3 \cdot \frac{u^{3/2}}{3/2} \big|_1^2 =
\frac{4}{9} \cdot(2^{3/2} - 1).
\begin{align*}
\int_0^1 2x^2 \sqrt{1 + x^3} dx
&= \int_{u(0)}^{u(1)} 2 \sqrt{u} (1/3) du = 2/3 \cdot \frac{u^{3/2}}{3/2} \Big|_1^2\\
&= \frac{4}{9} \cdot(2^{3/2} - 1).
\end{align*}
$$
---
@@ -137,26 +132,29 @@ Consider $\int_0^{\pi} \cos(x)^3 \sin(x) dx$. The $\cos(x)$ function inside the
$$
\int_0^{\pi} \cos(x)^3 \sin(x) dx = \int_{u(0)}^{u(\pi)} -u^3 du= -\frac{u^4}{4}\big|_1^{-1} = 0.
\int_0^{\pi} \cos(x)^3 \sin(x) dx = \int_{u(0)}^{u(\pi)} -u^3 du= -\frac{u^4}{4}\Big|_1^{-1} = 0.
$$
Changing limits leaves the two antiderivative values of endpoints the same, which means the total area after substitution is $0$. A graph of this function shows that about $\pi/2$ the function has odd-like symmetry, so the answer of $0$ is supported by the plot:
Changing limits leaves the two antiderivative values of endpoints the same, which means the total area after substitution is $0$. A graph of this function in @fig-plot-cos-cubed-times-sin-over-0-pi shows that about $\pi/2$ the function has odd-like symmetry, so the answer of $0$ is supported by the plot.
::: {#fig-plot-cos-cubed-times-sin-over-0-pi}
```{julia}
#| hold: true
#| echo: false
f(x) = cos(x)^3 * sin(x)
plot(f, 0, 1pi)
plot(f, 0, pi; legend=false)
```
Plot of $f(x) = \cos(x)^3 \cdot \sin(x)$ over $[0, \pi]$ shows odd symmetry about $x=\pi/2$
:::
---
Consider $\int_1^e \log(x)/x dx$. There isn't really an "inside" function here, but instead just a tricky $\log(x)$. If we let $u=\log(x)$, what happens? We get $du = 1/x \cdot dx$, which we see present in the original. So with this, we have:
Consider $\int_1^e (\log(x)/x) dx$. There isn't really an "inside" function here, but instead just a tricky $\log(x)$. If we let $u=\log(x)$, what happens? We get $du = 1/x \cdot dx$, which we see present in the original. So with this, we have:
$$
\int_1^e \frac{\log(x)}{x} dx = \int_{u(1)}^{u(e)} u du = \frac{u^2}{2}\big|_0^1 = \frac{1}{2}.
\int_1^e \frac{\log(x)}{x} dx = \int_{u(1)}^{u(e)} u du = \frac{u^2}{2}\Big|_0^1 = \frac{1}{2}.
$$
##### Example: Transformations
@@ -165,7 +163,7 @@ $$
We say that the area intrinsically discussed in the definite integral $A=\int_a^b f(x-c) dx$ is unaffected by shifts, in that $A = \int_{a-c}^{b-c} f(x) dx$. What about more general transformations? For example: if $g(x) = (1/h) \cdot f((x-c)/h)$ for values $c$ and $h$ what is the integral over $a$ to $b$ in terms of the function $f(x)$?
If $A = \int_a^b (1/h) \cdot f((x-c)/h) dx$ then we let $u = (x-c)/h$. With this, $du = 1/h \cdot dx$. This allows a straight substitution:
If $A = \int_a^b (1/h) \cdot f((x-c)/h) dx$ then we let $u = (x-c)/h$. With this, $du = 1/h \cdot dx$ allowing a straight substitution:
$$
@@ -176,7 +174,7 @@ So the answer is: the area under the transformed function over $a$ to $b$ is the
For example, consider the "hat" function $f(x) = 1 - \lvert x \rvert$
when $-1 \leq x \leq 1$ and $0$ otherwise. The area under $f$ is just $1$ - the graph forms a triangle with base of length $2$ and height $1$. If we take any values of $c$ and $h$, what do we find for the area under the curve of the transformed function?
when $-1 \leq x \leq 1$ and $0$ otherwise. The area under $f$ is just $1$---the graph forms a triangle with base of length $2$ and height $1$. If we take any values of $c$ and $h$, what do we find for the area under the curve of the transformed function?
Let $u(x) = (x-c)/h$ and $g(x) = (1/h) \cdot f(u(x))$. Then, as $du = 1/h dx$
@@ -225,7 +223,7 @@ $$
Gives the *total distance* traveled.
To illustrate with a simple example, if a car drives East for one hour at 60 miles per hour, then heads back West for an hour at 60 miles per hour, the car's position after one hour is $x(2) = x(0)$, with a change in position $x(2) - x(0) = 0$. Whereas, the total distance traveled is $120$ miles. (Gas is paid on total distance, not change in position!). What are the formulas for speed and velocity? Clearly $s(t) = 60$, a constant, whereas here $v(t) = 60$ for $0 \leq t \leq 1$ and $-60$ for $1 < t \leq 2$.
To illustrate with a simple example, if a car drives East for one hour at 60 miles per hour, then heads back West for an hour at 60 miles per hour, the car's position after one hour is $x(2) = x(0)$, with a change in position $x(2) - x(0) = 0$. Whereas, the total distance traveled is $120$ miles. (Gas is paid on total distance, not change in position!) What are the formulas for speed and velocity? Clearly $s(t) = 60$, a constant, whereas here $v(t) = 60$ for $0 \leq t \leq 1$ and $-60$ for $1 < t \leq 2$.
Suppose $v(t)$ is given by $v(t) = (t-2)^3/3 - 4(t-2)/3$. If $x(0)=0$ Find the position after 3 time units and the total distance traveled.
@@ -235,16 +233,22 @@ We let $u(t) = t - 2$ so $du=dt$. The position is given by
$$
\int_0^3 ((t-2)^3/3 - 4(t-2)/3) dt = \int_{u(0)}^{u(3)} (u^3/3 - 4/3 u) du =
(\frac{u^4}{12} - \frac{4}{3}\frac{u^2}{2}) \big|_{-2}^1 = \frac{3}{4}.
\begin{align*}
\int_0^3 \left(\frac{(t-2)^3}{3} - \frac{4(t-2)}{3}\right) dt
&= \int_{u(0)}^{u(3)} \left(\frac{u^3}{3} - \frac{4u}{3} \right) du\\
&= \left(\frac{u^4}{12} - \frac{4}{3}\cdot\frac{u^2}{2}\right) \Big|_{-2}^1\\
&= \frac{3}{4}.
\end{align*}
$$
The speed is similar, but we have to work harder:
$$
\int_0^3 \lvert v(t) \rvert dt = \int_0^3 \lvert ((t-2)^3/3 - 4(t-2)/3) \rvert dt =
\int_{-2}^1 \lvert u^3/3 - 4u/3 \rvert du.
\begin{align*}
\int_0^3 \lvert v(t) \rvert dt &= \int_0^3 \lvert \left(\frac{(t-2)^3}{3} - \frac{4(t-2)}{3}\right) \rvert dt\\
&= \int_{-2}^1 \lvert \frac{u^3}{3} - \frac{4u}{3} \rvert du.
\end{align*}
$$
But $u^3/3 - 4u/3 = (1/3) \cdot u(u-2)(u+2)$, so between $-2$ and $0$ it is positive and between $0$ and $1$ negative, so this integral is:
@@ -252,9 +256,9 @@ But $u^3/3 - 4u/3 = (1/3) \cdot u(u-2)(u+2)$, so between $-2$ and $0$ it is posi
$$
\begin{align*}
\int_{-2}^0 (u^3/3 - 4u/3 ) du + \int_{0}^1 -(u^3/3 - 4u/3) du
&= (\frac{u^4}{12} - \frac{4}{3}\frac{u^2}{2}) \big|_{-2}^0 - (\frac{u^4}{12} - \frac{4}{3}\frac{u^2}{2}) \big|_{0}^1\\
&= \frac{4}{3} - -\frac{7}{12}\\
\int_{-2}^0 \left(\frac{u^3}{3} - \frac{4u}{3} \right) du &+ \int_{0}^1 -\left(\frac{u^3}{3} - \frac{4u}{3}\right) du\\
&= \left(\frac{u^4}{12} - \frac{4}{3}\frac{u^2}{2}\right) \Big|_{-2}^0 - \left(\frac{u^4}{12} - \frac{4}{3}\frac{u^2}{2}\right) \Big|_{0}^1\\
&= \frac{4}{3} - \left(-\frac{7}{12}\right)\\
&= \frac{23}{12}.
\end{align*}
$$
@@ -337,7 +341,7 @@ The above calculation is for illustration purposes. The add-on package `Distribu
:::
## SymPy and substitution
### SymPy and *u*-substitution
The `integrate` function in `SymPy` can handle most problems which involve substitution. Here are a few examples:
@@ -356,11 +360,11 @@ integrate(4x / sqrt(x^2 + 1), (x, 0, 2))
```{julia}
#| hold: true
f(x) = 1/(x*log(x))
integrate(f(x), (x, sympy.E, sympy.E^2))
E = sympy.E
integrate(1/(x*log(x)), (x, E, E^2))
```
(We used `sympy.E` - and not `e` - to avoid any conversion to floating point, which could yield an inexact answer.)
(We used `sympy.E`---and not `e` or even constant `ℯ`---to avoid any conversion to floating point with $e^2$, which could yield an inexact answer.)
The antiderivative is interesting here; it being an *iterated* logarithm.
@@ -370,7 +374,7 @@ The antiderivative is interesting here; it being an *iterated* logarithm.
integrate(1/(x*log(x)), x)
```
### Failures...
#### Failures...
Not every integral problem lends itself to solution by substitution. For example, we can use substitution to evaluate the integral of $xe^{-x^2}$, but for $e^{-x^2}$ or $x^2e^{-x^2}$. The first has no familiar antiderivative, the second is done by a different technique.
@@ -379,7 +383,7 @@ Not every integral problem lends itself to solution by substitution. For example
Even when substitution can be used, `SymPy` may not be able to algorithmically identify it. The main algorithm used can determine if expressions involving rational functions, radicals, logarithms, and exponential functions is integrable. Missing from this list are absolute values.
For some such problems, we can help `SymPy` out - by breaking the integral into pieces where we know the sign of the expression.
For some such problems, we can help `SymPy` out---by breaking the integral into pieces where we know the sign of the expression.
For substitution problems, we can also help out. For example, to find an antiderivative for
@@ -393,8 +397,8 @@ A quick attempt with `SymPy` turns up nothing:
```{julia}
𝒇(x) = (1 + log(x)) * sqrt(1 + (x*log(x))^2 )
integrate(𝒇(x), x)
f(x) = (1 + log(x)) * sqrt(1 + (x*log(x))^2 )
integrate(f(x), x)
```
But were we to try $u=x\log(x)$, we'd see that this simplifies to $\int \sqrt{1 + u^2} du$, which has some hope of having an antiderivative.
@@ -406,7 +410,7 @@ We can help `SymPy` out by substitution:
```{julia}
u(x) = x * log(x)
@syms w dw
ex = 𝒇(x)
ex = f(x)
ex₁ = ex(u(x) => w, diff(u(x),x) => dw)
```
@@ -441,7 +445,7 @@ This can be found using *trigonometric* substitution. In this example, we know t
$$
\int \sqrt{1 + x^2} dx = \int \sec(u)^2 \lvert \sec(u) \rvert du = \int \sec(u)^3 du,
\int \sqrt{1 + x^2} dx = \int \lvert \sec(u) \rvert \sec(u)^2 du = \int \sec(u)^3 du,
$$
if we know $\sec(u) \geq 0$.
@@ -491,7 +495,7 @@ integrate(1 / (a^2 + (b*x)^2), x)
##### Example
The expression $1-x^2$ can be attacked by the substitution $\sin(u) =x$ as then $1-x^2 = 1-\sin(u)^2 = \cos(u)^2$. Here we see this substitution being used successfully:
The expression $1-x^2$ can be attacked by the substitution $\sin(u) =x$ as then $1-x^2 = 1-\sin(u)^2 = \cos(u)^2$. Here we see the substitution $3\sin(u) = x$ with $3\cos(u)du = dx$ being used successfully:
$$
@@ -500,7 +504,7 @@ $$
&=\int \frac{1}{3\sqrt{1 - \sin(u)^2}}\cdot3\cos(u) du \\
&= \int du \\
&= u \\
&= \sin^{-1}(x/3).
&= \sin^{-1}(\frac{x}{3}).
\end{align*}
$$
@@ -514,6 +518,8 @@ Further substitution allows the following integral to be solved for an antideriv
integrate(1 / sqrt(a^2 - b^2*x^2), x)
```
In the above, we implicitly assumed the argument to square root function was non-negative which is the second of these two cases found in general.
##### Example
@@ -541,7 +547,7 @@ $$
$$
SymPy gives a different representation using the arccosine:
SymPy readily handles the more general case:
```{julia}
@@ -560,16 +566,18 @@ We need to compute:
$$
2\int_{-a}^a b \sqrt{1 - x^2/a^2} dx =
4 b \int_0^a\sqrt{1 - x^2/a^2} dx.
2\int_{-a}^a b \sqrt{1 - \frqc{x^2}{a^2}} dx =
4 b \int_0^a\sqrt{1 - \frac{x^2}{a^2}} dx.
$$
Letting $\sin(u) = x/a$ gives $a\cos(u)du = dx$ and an antiderivative is found with:
$$
4 b \int_0^a \sqrt{1 - x^2/a^2} dx = 4b \int_0^{\pi/2} \sqrt{1-\sin(u)^2} a \cos(u) du
= 4ab \int_0^{\pi/2} \cos(u)^2 du
\begin{align*}
4 b \int_0^a \sqrt{1 - \frac{x^2}{a^2}} dx &= 4b \int_0^{\pi/2} \sqrt{1-\sin(u)^2} a \cos(u) du\\
&= 4ab \int_0^{\pi/2} \cos(u)^2 du.
\end{align*}
$$
The identify $\cos(u)^2 = (1 + \cos(2u))/2$ makes this tractable:
@@ -579,7 +587,7 @@ $$
\begin{align*}
4ab \int \cos(u)^2 du
&= 4ab\int_0^{\pi/2}(\frac{1}{2} + \frac{\cos(2u)}{2}) du\\
&= 4ab(\frac{1}{2}u + \frac{\sin(2u)}{4})\big|_0^{\pi/2}\\
&= 4ab(\frac{1}{2}u + \frac{\sin(2u)}{4})\Big|_0^{\pi/2}\\
&= 4ab (\pi/4 + 0) = \pi ab.
\end{align*}
$$
@@ -605,8 +613,8 @@ choices = [
"``\\int u (1 - u^2) du``",
"``\\int u \\cos(x) du``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -624,8 +632,8 @@ choices = [
"``u=\\sec(x)``",
"``u=\\sec(x)^2``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -643,8 +651,8 @@ choices = [
"``u=\\sqrt{x^2 - 1}``",
"``u=x``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -671,7 +679,7 @@ yesnoq("yes")
###### Question
For $\int (\log(x))^3/x dx$ the substitution $u=\log(x)$ reduces this to what?
For $\int (\log(x))^3/x \cdot dx$ the substitution $u=\log(x)$ reduces this to what?
```{julia}
@@ -682,8 +690,8 @@ choices = [
"``\\int u du``",
"``\\int u^3/x du``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -700,8 +708,8 @@ choices = [
"``u=\\sin(x)``",
"``u=\\tan(x)``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -726,10 +734,100 @@ choices = [
"``a=0,~ b=0``",
"``a=1,~ b=1``"
]
answ = 2
radioq(choices, answ)
answer = 2
radioq(choices, answer)
```
###### Question
Some integration problems require trigonometric identities, not trigonometric substitution.
We consider first the integral
$$
\int_0^\pi \cos(\theta) \sin(\theta) d\theta
$$
Compute this using substitution or by noting the resemblance to the double angle formula $\sin(2\theta) = 2\sin(\theta)\cos(\theta)$.
```{julia}
#| echo: false
let
@syms x
val = integrate(cos(x)*sin(x), (x, 0, PI))
numericq(float(val))
end
```
Now let $k > 1$ be an integer. We wish to find the integral of
$$
I = \int_0^\pi \cos(k\theta) \cdot \sin(\theta) d\theta
$$
First, we combine the two formulas
$$
\begin{align*}
\sin(a + b) &= \sin(a) \cos(b) + \cos(a) \sin(b)\\
\sin(a - b) &= \sin(a) \cos(b) - \cos(a) \sin(b)
\end{align*}
$$
to get
$$
\sin(a + b) + \sin(a-b) = 2 \sin(a) \cos(b)
$$
Taking $a=\theta$ and $b = k\theta$, what is a re-expression for the integrand $\cos(k\theta) \sin(\theta)$?
```{julia}
#| echo: false
choices = [
L"1/2 \cdot (\sin((1 + k)\theta) + \sin((1-k)\theta))",
L"1/2 \cdot (\cos((1 + k) \theta) + \cos((1-k)\theta))",
L"\cos(\theta) \sin(k \theta)"
]
answer = 1
buttonq(choices, answer)
```
Using substitution (e.g. $u=a\theta$) or some other means find the value of
$$
\int_0^\pi \sin(a \theta) d\theta.
$$
```{julia}
#| echo: false
choices = [L"1/a - \cos(a\cdot \pi)/a",
L"1/a"]
answer = 1
buttonq(choices, answer)
```
When $a=k+1$ or $k-1$ we have to evaluate $\cos((k+1)\pi$ or $\cos((k-1)\pi)$. These have the same value, which can be seen by writing, say, $\cos((k +1)\pi) = \cos(k\pi + \pi)$. What is the value?
```{julia}
#| echo: false
choices = [L"-\cos(\pi)",
L"-\cos(k\pi)"]
answer = 2
explanation = L"the extra $\pi$ just rotates the angle half way around the unit circle so changes the sign but not the magnitude of the cosine of $k\pi$"
buttonq(choices, answer; explanation)
```
Combining, this gives a value of
$$
I = \frac{1 + \cos(k\pi)}{1 - k^2}.
$$
###### Question
@@ -745,14 +843,14 @@ choices = [
"``\\sec(u) = x``",
"``u = 1 - x^2``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
The integral $\int x/(1+x^2) dx$ lends itself to what substitution?
The integral $\int x/(1+x^2) \cdot dx$ lends itself to what substitution?
```{julia}
@@ -764,8 +862,8 @@ choices = [
"``\\tan(u) = x``",
"``\\sec(u) = x``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -783,8 +881,8 @@ choices = [
"``\\sec(u) = x``",
"``u = 1 - x^2``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -801,8 +899,8 @@ choices = [
"``\\sec(u) = x``",
"``4\\sin(u) = x``",
"``\\sin(u) = x``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -819,8 +917,8 @@ choices = [
"``\\tan(u) = x``",
"``a\\sec(u) = x``",
"``\\sec(u) = x``"]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
###### Question
@@ -845,8 +943,8 @@ choices =[
"``a=\\pi/3,~ b=\\pi/2``",
"``a=1/2,~ b= 1``"
]
answ =1
radioq(choices, answ)
answer =1
radioq(choices, answer)
```
###### Question
@@ -861,6 +959,6 @@ How would we verify that $\log\lvert (\sec(u) + \tan(u))\rvert$ is an antideriva
choices = [
L"We could differentiate $\sec(u)$.",
L"We could differentiate $\log\lvert (\sec(u) + \tan(u))\rvert$ "]
answ = 2
radioq(choices, answ)
answer = 2
radioq(choices, answer)
```
+83 -80
View File
@@ -9,8 +9,7 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using SymPy
using QuadGK
```
@@ -21,38 +20,22 @@ using QuadGK
## Surfaces of revolution
::: {#fig-gehry-hendrix-museum}
```{julia}
#| hold: true
#| echo: false
imgfile = "figures/gehry-hendrix.jpg"
caption = """
![](./figures/gehry-hendrix.jpg)
The exterior of the Jimi Hendrix Museum in Seattle has the signature
style of its architect Frank Gehry. The surface is comprised of
patches. A general method to find the amount of material to cover the
surface - the surface area - might be to add up the area of *each* of the
surface---the surface area---might be to add up the area of *each* of the
patches. However, in this section we will see for surfaces of
revolution, there is an easier way. (Photo credit to
[firepanjewellery](http://firepanjewellery.com/).)
"""
:::
# ImageFile(:integrals, imgfile, caption)
nothing
```
In this section we see how to find the surface area of volumes generated by revolution.
![The exterior of the Jimi Hendrix Museum in Seattle has the signature
style of its architect Frank Gehry. The surface is comprised of
patches. A general method to find the amount of material to cover the
surface - the surface area - might be to add up the area of *each* of the
patches. However, in this section we will see for surfaces of
revolution, there is an easier way. (Photo credit to
[firepanjewellery](http://firepanjewellery.com/).)
](./figures/gehry-hendrix.jpg)
::: {.callout-note icon=false}
## Surface area of a rotated curve
::: {.definition title="Surface area of a rotated curve"}
The surface area generated by rotating the graph of $f(x)$ between $a$ and $b$ about the $x$-axis is given by the integral
@@ -70,7 +53,7 @@ These formulas do not add in the surface area of either of the ends.
:::
::: {#fig-surface-revolution-cone}
```{julia}
#| hold: true
#| echo: false
@@ -82,6 +65,9 @@ surface(ws..., legend=false)
plot!([-0.5,1.5], [0,0],[0,0])
```
Surface of revolution forming a cone
:::
The above figure shows a cone (the line $y=x$) presented as a surface of revolution about the $x$-axis.
@@ -234,7 +220,7 @@ Illustration of function $(g(t), f(t))$ rotated about the $x$ axis with a secti
Consider a right-circular cone parameterized by an angle $\theta$ which at a given height has radius $r$ and slant height $l$ (so that the height satisfies $r/l=\sin(\theta)$). If this cone were made of paper, cut up a side, and laid out flat, it would form a sector of a circle, as illustrated below:
Consider a right-circular cone parameterized by an angle $\theta$ which at a given height has radius $r$ and slant height $l$ (so that the height satisfies $r/l=\sin(\theta)$). If this cone were made of paper, cut up a side, and laid out flat, it would form a sector of a circle, as illustrated in @fig-frustum-cone-area.
::: {#fig-frustum-cone-area}
@@ -433,8 +419,10 @@ Putting this altogether we get that the surface area generarated by rotating the
$$
\text{sa}_i = \pi (f(t_i)^2 - f(t_{i-1})^2) \cdot \sqrt{(\Delta g)^2 + (\Delta f)^2} / \Delta f =
2\pi \frac{f(t_i) + f(t_{i-1})}{2} \cdot \sqrt{(\Delta g)^2 + (\Delta f)^2}.
\begin{align*}
\text{sa}_i &= \pi \left(f(t_i)^2 - f(t_{i-1})^2\right) \cdot \sqrt{(\Delta g)^2 + (\Delta f)^2} / \Delta f\\
&= 2\pi \frac{f(t_i) + f(t_{i-1})}{2} \cdot \sqrt{(\Delta g)^2 + (\Delta f)^2}.
\end{align*}
$$
(This is $2 \pi$ times the average radius times the slant height.)
@@ -444,10 +432,10 @@ As was done in the derivation of the formula for arc length, these pieces are mu
$$
\text{sa}_i = \pi (f(t_i) + f(t_{i-1})) \cdot \sqrt{(g'(\xi))^2 + (f'(\psi))^2} \cdot (t_i - t_{i-1}).
\text{sa}_i = \pi \left(f(t_i) + f(t_{i-1})\right) \cdot \sqrt{(g'(\xi))^2 + (f'(\psi))^2} \cdot (t_i - t_{i-1}).
$$
Adding these up, $\text{sa}_1 + \text{sa}_2 + \cdots + \text{sa}_n$, we get a Riemann sum approximation to the integral
Adding these up, $\text{sa}_1 + \text{sa}_2 + \cdots + \text{sa}_n$, we get a Riemann sum approximation to the integral:
$$
@@ -472,7 +460,7 @@ $$
\begin{align*}
\int_0^h 2\pi f(x) \sqrt{1 + f'(x)^2}dx
&= \int_0^h 2\pi x \tan(\theta) \sqrt{1 + \tan(\theta)^2}dx \\
&= (2\pi\tan(\theta)\sqrt{1 + \tan(\theta)^2}) x^2/2 \big|_0^h \\
&= (2\pi\tan(\theta)\sqrt{1 + \tan(\theta)^2}) \frac{x^2}{2} \Big|_0^h \\
&= \pi \tan(\theta) \sec(\theta) h^2 \\
&= \pi r^2 / \sin(\theta).
\end{align*}
@@ -522,47 +510,65 @@ f(u) = 2cos(u)
a, b = 0, 2pi
```
The plot of this curve is:
The plot of this curve is shown in @fig-plot-of-some-circle-begin-rotated.
::: {#fig-plot-of-some-circle-begin-rotated}
```{julia}
#| hold: true
us = range(a, b, length=100)
plot(g.(us), f.(us), xlims=(-0.5, 9), aspect_ratio=:equal, legend=false)
plot!([(0, -3), (0, 3)], line=(:red, 5)) # z axis emphasis
plot!([(3, 0), (9, 0)], line=(:green, 5)) # x axis emphasis
plot!([(0, -3), (0, 3)], line=(5, :red)) # z axis emphasis
plot!([(3, 0), (9, 0)], line=(5, :green)) # x axis emphasis
```
Plot of curve to be rotated to form a torus
:::
Though parametric plots have a convenience constructor, `plot(g, f, a, b)`, we constructed the points with `Julia`'s broadcasting notation, as we will need to do for a surface of revolution. The `xlims` are adjusted to show the $y$ axis, which is emphasized with a layered line. The line is drawn by specifying two points, $(x_0, y_0)$ and $(x_1, y_1)$ using tuples and wrapping in a vector.
Though parametric plots have a convenience constructor, `plot(g, f, a, b)`, we constructed the points with `Julia`'s broadcasting notation, as we will need to do for a surface of revolution. The `xlims` are adjusted to show the $y$ axis, which is emphasized with a layered line. (The line is drawn by specifying two points, $(x_0, y_0)$ and $(x_1, y_1)$, using tuples and wrapping in a vector.)
Now, to rotate this about the $z$ axis, creating a surface plot, we have the following pattern:
Now, to rotate this about the $z$ axis, creating a surface plot, we have the following pattern. First we form a function $S$ of two variables in terms of $g$ and $f$:
```{julia}
S(u,v) = [g(u)*cos(v), g(u)*sin(v), f(u)]
```
The steps to plot the surface are then always similar, save for possibly adjustments to the viewing window, as is done with `zlims` in forming @fig-torus-plotted-as-rotated-parameterized-circle-of-radius-2
::: {#fig-torus-plotted-as-rotated-parameterized-circle-of-radius-2}
```{julia}
us = range(a, b, length=100)
vs = range(0, 2pi, length=100)
ws = unzip(S.(us, vs')) # reorganize data
surface(ws..., zlims=(-6,6), legend=false)
plot!([(0,0,-3), (0,0,3)], line=(:red, 5)) # z axis emphasis
ws = unzip(S.(us, vs')) # reorganize data into 3 vectors
surface(ws...; zlims=(-10,10), legend=false)
plot!([(0, 0, -10), (0, 0, 10)]; line=(5, :red, 0.25)) # add axis of rotation
```
A circle of radius $2$ rotated about the $z$ axis forms a torus
:::
The `unzip` function is not part of base `Julia`, rather part of `CalculusWithJulia` (it is really `SplitApplyCombine`'s `invert` function). This function rearranges data into a form consumable by the plotting methods like `surface`. In this case, the result of `S.(us,vs')` is a grid (matrix) of points, the result of `unzip` is three grids of values, one for the $x$ values, one for the $y$ values, and one for the $z$ values. A manual adjustment to the `zlims` is used, as `aspect_ratio` does not have an effect with the `plotly()` backend.
To rotate this about the $x$ axis, we have this pattern:
To rotate this region about the $x$ axis, we have the pattern forming @fig-surface-of-rotation-formed-by-rotating-about-x-axis.
::: {#fig-surface-of-rotation-formed-by-rotating-about-x-axis}
```{julia}
S(u,v) = [g(u), f(u)*cos(v), f(u)*sin(v)]
us = range(a, b, length=100)
vs = range(0, 2pi, length=100)
ws = unzip(S.(us,vs'))
plot([(3,0,0), (9,0,0)], line=(:green,5)) # x axis emphasis
surface!(ws..., legend=false)
surface(ws...; zlims=(-3,3), legend=false)
plot!([(3,0,0), (9,0,0)], line=(5, :green)) # emphasize axis of rotation
```
The above pattern covers the case of rotating the graph of a function $f(x)$ of $a,b$ by taking $g(t)=t$.
Figure showing rotation of circle parameterized by $(g, f)$ being rotated around the $x$ axis
:::
The above pattern covers the case of rotating the graph of a function $f(x)$ over $[a,b]$ by taking $g(t)=t$.
##### Example
@@ -584,17 +590,19 @@ val
(The function is not defined at $x=0$ mathematically, but is on the computer to be $1$, the limiting value. Even were this not the case, the `quadgk` function doesn't evaluate the function at the points `a` and `b` that are specified.)
::: {#fig-rotate-x-to-x-about-x-axis}
```{julia}
#| hold: true
g(u) = u
f(u) = u^u
S(u,v) = [g(u), f(u)*cos(v), f(u)*sin(v)]
us = range(0, 3/2, length=100)
vs = range(0, pi, length=100) # not 2pi (to see inside)
vs = range(0, pi, length=100) # not 2pi (to see inside)
ws = unzip(S.(us,vs'))
surface(ws..., alpha=0.75)
```
Partial rotation of $x^x$ about the $x$ axis
:::
We compare this answer to that of the frustum of a cone with radii $1$ and $(3/2)^2$, formed by rotating the line segment connecting $(0,f(0))$ with $(3/2,f(3/2))$. From looking at the graph of the surface, these values should be comparable. The surface area of the cone part is $\pi (r_1^2 - r_0^2) / \sin(\theta) = \pi (r_1 + r_0) \cdot \sqrt{(\Delta h)^2 + (r_1-r_0)^2}$.
@@ -613,8 +621,10 @@ What is the surface area generated by Gabriel's Horn, the solid formed by rotati
$$
\text{SA} = \int_a^b 2\pi f(x) \sqrt{1 + f'(x)^2}dx =
\lim_{M \rightarrow \infty} \int_1^M 2\pi \frac{1}{x} \sqrt{1 + (-1/x^2)^2} dx.
\begin{align*}
\text{SA} &= \int_1^\infty 2\pi f(x) \sqrt{1 + f'(x)^2}dx \\
&= \lim_{M \rightarrow \infty} \int_1^M 2\pi \frac{1}{x} \sqrt{1 + (-1/x^2)^2} dx.
\end{align*}
$$
We do this with `SymPy`:
@@ -632,7 +642,7 @@ The limit as $M$ gets large is of interest. The only term that might get out of
limit(asinh(M), M => oo)
```
So indeed it does. There is nothing to balance this out, so the integral will be infinite, as this shows:
So indeed that term gets out of hand. There is nothing to balance this out, so the integral will be infinite, as this shows:
```{julia}
@@ -648,9 +658,9 @@ This figure would have infinite surface, were it possible to actually construct
The curve described parametrically by $g(t) = 2(1 + \cos(t))\cos(t)$ and $f(t) = 2(1 + \cos(t))\sin(t)$ from $0$ to $\pi$ is rotated about the $x$ axis. Find the resulting surface area.
The graph shows half a heart, the resulting area will resemble an apple.
@fig-rotate-heart-to-get-apple shows half a heart, the resulting rotated surface area will resemble an apple.
::: {#fig-rotate-heart-to-get-apple}
```{julia}
#| hold: true
g(t) = 2(1 + cos(t)) * cos(t)
@@ -658,6 +668,9 @@ f(t) = 2(1 + cos(t)) * sin(t)
plot(g, f, 0, 1pi)
```
Paremeterized curve to rotate about $x$ axis
:::
The integrand simplifies to $8\sqrt{2}\pi \sin(t) (1 + \cos(t))^{3/2}$. This lends itself to $u$-substitution with $u=\cos(t)$.
@@ -665,7 +678,7 @@ $$
\begin{align*}
\int_0^\pi 8\sqrt{2}\pi \sin(t) (1 + \cos(t))^{3/2}
&= 8\sqrt{2}\pi \int_1^{-1} (1 + u)^{3/2} (-1) du\\
&= 8\sqrt{2}\pi (2/5) (1+u)^{5/2} \big|_{-1}^1\\
&= 8\sqrt{2}\pi (2/5) (1+u)^{5/2} \Big|_{-1}^1\\
&= 8\sqrt{2}\pi (2/5) 2^{5/2} = \frac{2^7 \pi}{5}.
\end{align*}
$$
@@ -681,13 +694,13 @@ $$
\text{SA} = 2 \pi \rho L
$$
That is, the surface area is simply the circumference of the circle traced out by the centroid of the curve times the length of the curve - the distances rotated are collapsed to that of just the centroid.
That is, the surface area is simply the circumference of the circle traced out by the centroid of the curve times the length of the curve---the distances rotated are collapsed to that of just the centroid.
##### Example
The surface area of an open cone can be computed, as the arc length is $\sqrt{h^2 + r^2}$ and the centroid of the line is a distance $r/2$ from the axis. This gives SA$=2\pi (r/2) \sqrt{h^2 + r^2} = \pi r \sqrt{h^2 + r^2}$.
The surface area of an open cone can be computed, as the arc length is $\sqrt{h^2 + r^2}$ and the centroid *of the line* is a distance $r/2$ from the axis. This gives $\text{SA} = 2\pi (r/2) \sqrt{h^2 + r^2} = \pi r \sqrt{h^2 + r^2}$.
##### Example
@@ -696,22 +709,9 @@ The surface area of an open cone can be computed, as the arc length is $\sqrt{h^
We can get the surface area of a torus from this formula.
The torus is found by rotating the curve $(x-b)^2 + y^2 = a^2$ about the $y$ axis. The centroid is $b$, the arc length $2\pi a$, so the surface area is $2\pi (b) (2\pi a) = 4\pi^2 a b$.
The torus is found by rotating the curve $(x-b)^2 + y^2 = a^2$ about the $y$ axis. The centroid is $b$, the arc length $2\pi a$, so the surface area is $2\pi (b) (2\pi a) = 4\pi^2 a b$. A torus with $a=2$ and $b=6$ was plotted for @fig-torus-plotted-as-rotated-parameterized-circle-of-radius-2.
A torus with $a=2$ and $b=6$
```{julia}
#| hold: true
#| echo: false
a,b = 2, 6
F₀(u,v) = [a*(cos(u) + b)*cos(v), a*(cos(u) + b)*sin(v), a*sin(u)]
us = vs = range(0, 2pi, length=35)
ws = unzip(F₀.(us, vs'))
surface(ws..., legend=false, zlims=(-12,12))
```
##### Example
@@ -720,8 +720,8 @@ The surface area of sphere will be SA$=2\pi \rho (\pi r) = 2 \pi^2 r \cdot \rho$
$$
\begin{align*}
\text{cm}_x &= \frac{1}{L} \int_a^b g(t) \sqrt{g'(t)^2 + f'(t)^2} dt\\
\text{cm}_y &= \frac{1}{L} \int_a^b f(t) \sqrt{g'(t)^2 + f'(t)^2} dt.
\overline{\text{cm}}_x &= \frac{1}{L} \int_a^b g(t) \sqrt{g'(t)^2 + f'(t)^2} dt\\
\overline{\text{cm}}_y &= \frac{1}{L} \int_a^b f(t) \sqrt{g'(t)^2 + f'(t)^2} dt.
\end{align*}
$$
@@ -733,11 +733,14 @@ For the sphere parameterized by $g(t) = r \cos(t)$, $f(t) = r\sin(t)$, we get th
$$
\text{cm}_x = \frac{1}{L}\int_0^\pi r\cos(t) \sqrt{r^2(\sin(t)^2 + \cos(t)^2)} dt = \frac{1}{L}r^2 \int_0^\pi \cos(t) = 0.
$$
$$
\text{cm}_y = \frac{1}{L}\int_0^\pi r\sin(t) \sqrt{r^2(\sin(t)^2 + \cos(t)^2)} dt = \frac{1}{L}r^2 \int_0^\pi \sin(t) = \frac{1}{\pi r} r^2 \cdot 2 = \frac{2r}{\pi}.
\begin{align*}
\overline{\text{cm}}_x &= \frac{1}{L}\int_0^\pi r\cos(t) \sqrt{r^2(\sin(t)^2 + \cos(t)^2)} dt\\
&= \frac{1}{L}r^2 \int_0^\pi \cos(t)\\
&= 0\\
\overline{\text{cm}}_y &= \frac{1}{L}\int_0^\pi r\sin(t) \sqrt{r^2(\sin(t)^2 + \cos(t)^2)} dt\\
&= \frac{1}{L}r^2 \int_0^\pi \sin(t) \\
&= \frac{1}{\pi r} r^2 \cdot 2 = \frac{2r}{\pi}.
\end{align*}
$$
Combining this, we see that the surface area of a sphere is $2 \pi^2 r (2r/\pi) = 4\pi r^2$, by Pappus' Theorem.
@@ -760,8 +763,8 @@ choices = [
"``-\\int_1^{_1} 2\\pi u \\sqrt{1 + u^2} du``",
"``-\\int_1^{_1} 2\\pi u^2 \\sqrt{1 + u} du``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
Though the integral can be computed by hand, give a numeric value.
@@ -830,8 +833,8 @@ choices = [
"``\\int_u^{u_h} 2\\pi y dx``",
"``\\int_u^{u_h} 2\\pi x dx``"
]
answ = 1
radioq(choices, answ)
answer = 1
radioq(choices, answer)
```
##### Questions
+60 -19
View File
@@ -16,8 +16,11 @@ gr();
---
In the March 2003 issue of the College Mathematics Journal, Leon M Hall posed 12 questions related to the following figure:
In the March 2003 issue of the College Mathematics Journal, Leon M Hall posed 12 questions related to @fig-parabola-tangent-normal-CMJ. The figure shows $f(x) = x^2$, the tangent line at $P = (a, f(a))$ (for $a > 0$), and the *normal* line at $(a, f(a))$. The questions all involve finding the value $a$ which minimizes a related quantity that has been previously discussed.
::: {#fig-parabola-tangent-normal-CMJ}
```{julia}
#| echo: false
a₀ = 7/8
@@ -63,10 +66,11 @@ end
make_plot()
```
The figure shows $f(x) = x^2$, the tangent line at $(a, f(a))$ (for $a > 0$), and the *normal* line at $(a, f(a))$. The questions all involve finding the value $a$ which minimizes a related quantity.
A parabola with tangent and normal line at point $P$
:::
We set up some variables to work symbolically:
The solutions are a bit of fun. To approach them, we set up some variables to work symbolically:
```{julia}
@syms a::positive x::real
@@ -86,6 +90,7 @@ The first question is simply:
> 1a. The $y$ coordinate of $Q$
::: {#fig-parabola-tangent-normal-CMJ-y-coordinate}
```{julia}
#| echo: false
let
@@ -94,6 +99,9 @@ let
end
```
Emphasis of $y$ coordinate of $Q$
:::
The value is $f(q)$
```{julia}
@@ -111,7 +119,7 @@ The lone critical point must be at a minimum. (Given the geometry of the problem
::: {.callout-note}
## We hide the code
In the remaining examples we don't show the code by default.
In the remaining examples we don't immediately show the code to describe the value to optimize; it is hidden in a collapsed block.
:::
@@ -119,12 +127,15 @@ In the remaining examples we don't show the code by default.
> 1b. The length of the line segment $PQ$
::: {#fig-parabola-tangent-normal-CMJ-PQ-line-segment}
```{julia}
#| echo: false
p = make_plot()
plot!([q₀, a₀], [f(q₀), f(a₀)], linewidth=5)
```
Emphasis of line segment connecting $P$ and $Q$
:::
```{julia}
#| code-fold: true
@@ -138,12 +149,15 @@ lseg = sqrt((f(a) - f(q))^2 + (a - q)^2);
> 2a. The horizontal distance between $P$ and $Q$
::: {#fig-parabola-tangent-normal-CMJ-PQ-horizontal-distance-PQ}
```{julia}
#| echo: false
p = make_plot()
plot!([q₀, a₀], [f(a₀), f(a₀)], linewidth=5)
```
Emphasis of horizontal distance between $P$ and $Q$
:::
```{julia}
#| code-fold: true
@@ -155,7 +169,7 @@ hd = a - q;
> 2b. The area of the parabolic segment
::: {#fig-parabola-tangent-normal-CMJ-area-parabolic-segment}
```{julia}
#| echo: false
p = make_plot()
@@ -165,6 +179,8 @@ ys = vcat(f.(xs′), normal.(reverse(xs′)), f(first(xs′)))
plot!(xs, ys, fill=(:green, 0.25, 0))
```
Emphasis of parabolic segment formed by the normal line
:::
```{julia}
#| code-fold: true
@@ -189,14 +205,15 @@ V = simplify(integrate(2PI*(nl-f(x))*(a - x + k),(x, q, a)));
> 3. The $y$ coordinate of the centroid of the parabolic segment
::: {#fig-parabola-tangent-normal-CMJ-centroid-parabolic-segment}
```{julia}
#| echo: false
p = make_plot()
scatter!(p, [-1/(4a₀)], [1], marker=(10, :diamond))
p
```
Emphasis of centrood of the parabolic segment formed by the normal line
:::
We warm up with the $x$ coordinate, given by:
@@ -218,7 +235,7 @@ yₘ = simplify(yₘ);
> 4. The length of the arc of the parabola between $P$ and $Q$
::: {#fig-parabola-tangent-normal-CMJ-arc-length-parabola}
```{julia}
#| echo: false
p = make_plot()
@@ -227,6 +244,9 @@ plot!(xs, f.(xs), linewidth=5)
p
```
Emphasis of arc-length along parabola
:::
```{julia}
#| code-fold: true
#| code-summary: "Show the code"
@@ -237,7 +257,7 @@ L = integrate(sqrt(1 + fp(x)^2), (x, q, a));
> 5. The $y$ coordinate of the midpoint of the line segment $PQ$
::: {#fig-parabola-tangent-normal-CMJ-y-coordinate-of-PQ}
```{julia}
#| echo: false
p = make_plot()
@@ -247,6 +267,8 @@ scatter!([mid], [normal(mid)], markersize=5)
p
```
Emphasis of $y$ intercept for line $PQ$
:::
```{julia}
#| code-fold: true
@@ -258,7 +280,7 @@ mp = nl(x => (a + q)/2);
> 6. The area of the trapezoid bound by the normal line, the $x$-axis, and the vertical lines through $P$ and $Q$.
::: {#fig-parabola-tangent-normal-CMJ-trapezoid-normal-segment}
```{julia}
#| echo: false
p = make_plot()
@@ -267,6 +289,10 @@ plot!([q₀, a₀, a₀, q₀, q₀],
p
```
Emphasis of traapezoid bounded by the normal line
:::
```{julia}
#| code-fold: true
#| code-summary: "Show the code"
@@ -277,6 +303,7 @@ trap = 1//2 * (f(q) + f(a)) * (a - q);
> 7. The area bounded by the parabola and the $x$ axis and the vertical lines through $P$ and $Q$
::: {#fig-parabola-tangent-normal-CMJ-area-under-parabola}
```{julia}
#| echo: false
p = make_plot()
@@ -287,6 +314,8 @@ plot!(xs, ys, fill=(:green, 0.25, 0))
p
```
Area under the parabola between $P$ and $Q$
:::
```{julia}
@@ -299,6 +328,7 @@ pa = integrate(x^2, (x, q, a));
> 8. The area of the surface formed by revolving the arc of the parabola between $P$ and $Q$ around the vertical line through $P$
::: {#fig-parabola-tangent-normal-CMJ-surface-area-rotation}
```{julia}
#| echo: false
let
@@ -310,6 +340,8 @@ let
end
```
Surface area formed by revolving arc through $P$
:::
```{julia}
@@ -325,6 +357,7 @@ SA = 2PI * integrate(uu(x) * sqrt(diff(uu(x),x)^2 + diff(vv(x),x)^2), (x, q, a))
> 9. The height of the parabolic segment (i.e. the distance between the normal line and the tangent line to the parabola that is parallel to the normal line)
::: {#fig-parabola-tangent-normal-CMJ-height-parabolic-segment}
```{julia}
#| echo: false
# distance point to a line
@@ -339,6 +372,9 @@ plot!(x -> f(b₀) + (-1/fp(a₀))*(x - b₀), -1, 1/2)
plot!([b₀,x₀], [f(b₀), normal(x₀)]; linewidth=5)
```
Emphasis of the height of the parabolic segment
:::
```{julia}
#| code-fold: true
#| code-summary: "Show the code"
@@ -354,6 +390,7 @@ segment_height = sqrt((b-b′)^2 + (f(b) - nl(x=>b′))^2);
> 10. The volume of the solid formed by revolving the parabolic segment around the $x$-axis
::: {#fig-parabola-tangent-normal-CMJ-volume-formed-on-revolving-parabolic-segment}
```{julia}
#| echo: false
let
@@ -365,6 +402,8 @@ let
end
```
Volume formed by revolving parabolic segment around $x$ axis
:::
```{julia}
#| code-fold: true
#| code-summary: "Show the code"
@@ -375,6 +414,7 @@ Vₓ = integrate(pi * (nl^2 - f(x)^2), (x, q, a));
> 11. The area of the triangle bound by the normal line, the vertical line through $Q$ and the $x$-axis
::: {#fig-parabola-tangent-normal-CMJ-area-triangle-normal-line-x-axis}
```{julia}
#| echo: false
make_plot()
@@ -384,7 +424,8 @@ xlims!((-2, p₀ + 0.2))
plot!([p₀,q₀,q₀,p₀], [0,f(q₀),0,0];
fill=(:green, 0.25,0))
```
Emphasis of triangle formed along normal line
:::
```{julia}
#| code-fold: true
#| code-summary: "Show the code"
@@ -396,27 +437,27 @@ triangle = 1/2 * f(q) * (a - f(a)/(-1/fp(a)) - q);
> 12. The area of the quadrilateral bound by the normal line, the tangent line, the vertical line through $Q$ and the $x$-axis
::: {#fig-parabola-tangent-normal-CMJ-quadrilateral-normal-line}
```{julia}
#| echo: false
make_plot()
plot!([a₀,q₀,q₀,a₀-f(a₀)/fp(a₀),a₀],
[f(a₀), f(q₀), 0, 0,f(a₀)], fill=(:green, 0.25, 0))
```
Emphasis of quadrilateral bounded by normal line and tangent line
:::
```{julia}
#| code-fold: true
#| code-summary: "Show the code"
# @syms x[1:4], y[1:4]
# v1, v2, v3 = [[x[i]-x[1],y[i]-y[1], 0] for i in 2:4]
# area = 1//2 * last(cross(v3,v2) + cross(v2, v1)) # 1/2 area of parallelogram
# print(simplify(area))
# (x₁ - x₂)*(y₁ - y₃)/2 - (x₁ - x₃)*(y₁ - y₂)/2 + (x₁ - x₃)*(y₁ - y₄)/2 - (x₁ - x₄)*(y₁ - y₃)/2
# use shoelace formula
# (1/2) * (x₁⋅y₂-y₁⋅x₂ + x₂⋅y₃-y₂⋅x₃ + x₃⋅y₄-y₃⋅x₄ + x₄⋅y₁-y₄⋅x₁)
tl₀ = a - f(a) / fp(a)
x₁,x₂,x₃,x₄ = (a,q,q,tl₀)
x₁, x₂, x₃, x₄ = (a, q, q, tl₀)
y₁, y₂, y₃, y₄ = (f(a), f(q), 0, 0)
quadrilateral = (x₁ - x₂)*(y₁ - y₃)/2 - (x₁ - x₃)*(y₁ - y₂)/2 + (x₁ - x₃)*(y₁ - y₄)/2 - (x₁ - x₄)*(y₁ - y₃)/2;
quadrilateral = (1/2) * (x₁*y₂ - y₁*x₂ + x₂*y₃ - y₂*x₃ + x₃*y₄ - y₃*x₄ + x₄*y₁ - y₄*x₁);
```
---
The answers appear here in sorted order, some given as approximate floating point values:
+127 -101
View File
@@ -8,8 +8,7 @@ This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
plotly()
using Plots; plotly()
using QuadGK
using Unitful, UnitfulUS
using Roots
@@ -75,8 +74,11 @@ Hey Michelin Man, how much does that costume weigh?
# ImageFile(:integrals, imgfile, caption)
nothing
```
::: {#fig-michelin-man-as-volume-slice}
![](./figures/michelin-man.jpg)
![Hey Michelin Man, how much does that costume weigh?](./figures/michelin-man.jpg)
Hey Michelin Man, how much does that costume weigh?
:::
An ad for a summer job says work as the Michelin Man! Sounds promising, but how much will that costume weigh? A very hot summer may make walking around in a heavy costume quite uncomfortable.
@@ -84,10 +86,13 @@ An ad for a summer job says work as the Michelin Man! Sounds promising, but how
A back-of-the envelope calculation would start by
* Mentally separating out each "tire" and lining them up one by one.
* Counting the number of "tires" (or rings), say $n$.
* Estimating the radius for each tire, say $r_i$ for $1 \leq i \leq n$.
* Estimating the height for each tire, say $h_i$ for $1 \leq i \leq n$
* Mentally separating out each "tire" and lining them up one by one.
* Counting the number of "tires" (or rings), say $n$.
* Estimating the radius for each tire, say $r_i$ for $1 \leq i \leq n$.
* Estimating the height for each tire, say $h_i$ for $1 \leq i \leq n$
Then the volume would be found by adding:
@@ -105,12 +110,15 @@ Looking at the sum though, we see the makings of an approximate integral. If the
In fact, we have in general:
::: {.definition title="Volume of a figure with a known cross section"}
> **Volume of a figure with a known cross section**: The volume of a solid with known cross-sectional area $A_{xc}(x)$ from $x=a$ to $x=b$ is given by
>
> $V = \int_a^b A_{xc}(x) dx.$
>
> This assumes $A_{xc}(x)$ is integrable.
The volume of a solid with known, integrable, cross-sectional area $A_{xc}(x)$ from $x=a$ to $x=b$ is given by
$$
V = \int_a^b A_{xc}(x) dx.
$$
:::
@@ -120,12 +128,12 @@ This formula is derived by approximating the volume by "slabs" with volume $A_{x
## Solids of revolution
We begin with some examples of a special class of solids - solids of revolution. These have an axis of symmetry from which the slabs are then just circular disks.
We begin with some examples of a special class of solids---solids of revolution. These have an axis of symmetry from which the slabs are then just circular disks.
Consider the volume contained in this glass, it will depend on the radius at different values of $x$:
Consider the volume contained in the glass of @fig-wine-glass-rotation, the volume will depend on the radius at different values of $x$:
::: {#fig-wine-glass-rotation}
```{julia}
#| hold: true
#| echo: false
@@ -141,12 +149,14 @@ between about $0$ and $6.2$cm.
nothing
```
![A wine glass oriented so that it is seen as generated by revolving a
![](./figures/integration-glass.jpg)
A wine glass oriented so that it is seen as generated by revolving a
curve about the $x$ axis. The radius of revolution varies as a function of $x$
between about $0$ and $6.2$cm.
](./figures/integration-glass.jpg)
:::
If $r(x)$ is the radius as a function of $x$, then the cross sectional area is $\pi r(x)^2$ so the volume is given by:
If $r(x)$ is the radius as a function of $x$, then the cross-sectional area is $\pi r(x)^2$ so the volume is given by:
$$
@@ -251,7 +261,7 @@ nothing
```
Illustration of a figure being rotated around the $x$-axis. The discs have approximate volume given by the area of the base times the height or $\pi r(x)^2 \Delta x$. (Figure ported from @Angenent.)
Illustration^[This illustration and others were directly inspired by @Angenent.] of a figure being rotated around the $x$-axis. The discs have approximate volume given by the area of the base times the height or $\pi r(x)^2 \Delta x$.
:::
@@ -302,9 +312,9 @@ If you are poor with units, `Julia` can provide some help through the `Unitful`
vol * u"inch"^3 |> us"floz"
```
Before Solo "squared" the cup, the Solo cup had markings that - [some thought](http://www.snopes.com/food/prepare/solocups.asp) - indicated certain volume amounts.
Before Solo "squared" the cup, the Solo cup had markings that--[some thought](http://www.snopes.com/food/prepare/solocups.asp)---indicated certain volume amounts.
::: {#fig-red-solo-cup-with-markings}
```{julia}
#| hold: true
#| echo: false
@@ -314,7 +324,10 @@ caption = "Markings on the red Solo cup indicated various volumes"
nothing
```
![Markings on the red Solo cup indicated various volumes.](./figures/red-solo-cup.jpg)
![](./figures/red-solo-cup.jpg)
Markings on the red Solo cup indicated various volumes
:::
What is the height for $5$ ounces (for a glass of wine)? $12$ ounces (for a beer unit)?
@@ -322,14 +335,14 @@ What is the height for $5$ ounces (for a glass of wine)? $12$ ounces (for a beer
Here the volume is fixed, but the height is not. For $v$ ounces, we need to convert to cubic inches. The conversion is $1$ ounce is $231/128 \text{in}^3$.
So we need to solve $v \cdot (231/128) = \int_0^h\pi r(x)^2 dx$ for $h$ when $v=5$ and $v=12$.
So we need to solve $v \cdot (231/128) =\int_0^h\pi r(x)^2 dx$ for $h$ when $v=5$ and $v=12$.
Let's express volume as a function of $h$:
```{julia}
Vol(h) = quadgk(x -> pi * rad(x)^2, 0, h)[1]
Vol(h) = first(quadgk(x -> pi * rad(x)^2, 0, h))
```
Then to solve we have:
@@ -395,12 +408,12 @@ frustum - cone * ( 3h0/h - 3(h0/h)^2 + (h0/h)^3) |> simplify
##### Example
[Gabriel's](http://tinyurl.com/8a6ygv) horn is a geometric figure of mathematics - but not the real world - which has infinite height, but not volume! The figure is found by rotating the curve $y=1/x$ around the $x$ axis from $1$ to $\infty$. If the volume formula holds, what is the volume of this "horn?"
[Gabriel's](https://en.wikipedia.org/wiki/Gabriel%27s_horn) horn is a geometric figure of mathematics---but not the real world---which has infinite height, but not volume! The figure is found by rotating the curve $y=1/x$ around the $x$ axis from $1$ to $\infty$. If the volume formula holds, what is the volume of this "horn?"
```{julia}
radius(x) = 1/x
quadgk(x -> pi*radius(x)^2, 1, Inf)[1]
first(quadgk(x -> pi*radius(x)^2, 1, Inf))
```
That is a value very reminiscent of $\pi$, which it is as $\int_1^\infty 1/x^2 dx = -1/x\big|_1^\infty=1$.
@@ -408,7 +421,7 @@ That is a value very reminiscent of $\pi$, which it is as $\int_1^\infty 1/x^2 d
:::{.callout-note}
## Note
The interest in this figure is that soon we will be able to show that it has **infinite** surface area, leading to the [paradox](http://tinyurl.com/osawwqm) that it seems possible to fill it with paint, but not paint the outside.
The interest in this figure is that soon we will be able to show that it has **infinite** surface area, leading to the paradox that it seems possible to fill it with paint, but not paint the outside.
:::
@@ -479,17 +492,20 @@ Rather than use $\pi r(x)^2$ for a cross section, we would use $\pi (R(x)^2 - r(
In general we call a shape like the tire a "washer" and use this formula for a washer's cross section $A_{xc}(x) = \pi(R(x)^2 - r(x)^2)$.
Then the volume for the solid of revolution whose cross sections are washers would be:
::: {.definition title="Volume by the washer method"}
The volume for the solid of revolution whose cross sections are washers with outer and inner radius given by $R(x)$ and $r(x)$ is:
$$
V = \int_a^b \pi \cdot (R(x)^2 - r(x)^2) dx.
$$
:::
::: {#fig-washer-illustration}
```{julia}
#| echo: false
plt = let
let
gr()
# Follow lead of # https://github.com/SigurdAngenent/WisconsinCalculus/blob/master/figures/221/09surf_of_rotation2.py
# plot surface of revolution around x axis between [0, 3]
@@ -519,7 +535,7 @@ plt = let
α = 1.0
line_style = (; line=(:black, 1))
plot(; empty_style..., aspect_ratio=:equal)
plt = plot(; empty_style..., aspect_ratio=:equal)
# by layering, we get x-axis as desired
plot!(pline(viewp, [-1,0,0], [0,0,0]); line_style...)
@@ -572,20 +588,12 @@ plt = let
plot!(curve; line=(:black, 1))
end
current()
plotly()
plt
end
plt
```
```{julia}
#| echo: false
plotly()
nothing
```
Modification of earlier figure to show washer method. The interior volume would be given by $\int_a^b \pi r(x)^2 dx$, the entire volume by $\int_a^b \pi R(x)^2 dx$. The difference then is the volume computed by the washer method.
Modification of @fig-solid-of-revolution to show the washer method. The interior volume would be given by $\int_a^b \pi r(x)^2 dx$, the entire volume by $\int_a^b \pi R(x)^2 dx$. The difference then is the volume computed by the washer method.
:::
@@ -629,10 +637,10 @@ vol, _ = quadgk(x -> d(x)^2, 0, h)
vol / 231 * 128
```
This shape would have more volume - the cross sections are bigger. Presumably the dimensions have changed. Without going out and buying a cup, let's assume the cross-sectional diameter remained the same, not the diameter. This means the largest dimension is the same. The cross section diameter is $\sqrt{2}$ larger. What would this do to the area?
This shape would have more volume---the cross sections are bigger. Presumably the dimensions have changed. Without going out and buying a cup, let's assume the cross-sectional diameter remained the same, not the diameter. This means the largest dimension is the same. The cross-sectional diameter is $\sqrt{2}$ larger. What would this do to the area?
We could do this two ways: divide $d_0$ and $d_1$ by $\sqrt{2}$ and recompute. However, each cross section of this narrower cup would simply be $\sqrt{2}^2$ smaller, so the total volume would change by $2$, or be 13 ounces. We have $26.04$ is too big, and $13.02$ is too small, so some other overall dimensions are used.
We could do this two ways: divide $d_0$ and $d_1$ by $\sqrt{2}$ and recompute. However, each cross section of this narrower cup would simply be $\sqrt{2}^2$ smaller, so the total volume would change by $2$, or be $13$ ounces. We have $26.04$ is too big, and $13.02$ is too small, so some other overall dimensions are used.
##### Example
@@ -645,7 +653,7 @@ For a general cone, we use this [definition](http://en.wikipedia.org/wiki/Cone):
Let $h$ be the distance from the apex to the base. Consider cones with the property that all planes parallel to the base intersect the cone with the same shape, though perhaps a different scale. This figure shows an example, with the rays coming from the apex defining the volume.
Let $h$ be the distance from the apex to the base. Consider cones with the property that all planes parallel to the base intersect the cone with the same shape, though perhaps a different scale. @fig-generic-cone shows an example, with the rays coming from the apex defining the volume.
::: {#fig-generic-cone}
```{julia}
@@ -736,18 +744,21 @@ $$
V = \int_0^h A_{xc}(u) du.
$$
The cross sectional area $A_{xc}(u)$ satisfies a formula in terms of $A_{xc}(0)$, the area of the base:
The cross-sectional area $A_{xc}(u)$ satisfies a formula in terms of $A_{xc}(0)$, the area of the base:
$$
A_{xc}(u) = A_{xc}(0) \cdot (1 - \frac{u}{h})^2
A_{xc}(u) = A_{xc}(0) \cdot \left(1 - \frac{u}{h}\right)^2
$$
So the integral becomes:
$$
V = \int_0^h A_{xc}(u) du = A_{xc}(0) \int_0^h (1 - \frac{u}{h})^2 du = A_{xc}(0) \int_0^1 v^2 h dv = A_{xc}(0) \frac{h}{3}.
\begin{align*}
V &= \int_0^h A_{xc}(u) du = A_{xc}(0) \int_0^h \left(1 - \frac{u}{h}\right)^2 du\\
&= A_{xc}(0) \int_0^1 v^2 h dv = A_{xc}(0) \frac{h}{3}.
\end{align*}
$$
This gives a general formula for the volume of such cones.
@@ -814,9 +825,8 @@ end
plt
```
This figure shows the volume of a figure being comprised of slices. A discrete approximation would be found by estimating the volume of each slice by the cross sectional area times a small $\Delta h$. This leads to a formula
$V = \int_a^b A(h)dh$, where $A$ computes the cross sectional area.
(This figure was ported from @Angenent.)
This figure shows the volume of a figure being comprised of slices. A discrete approximation would be found by estimating the volume of each slice by the cross-sectional area times a small $\Delta h$. This leads to a formula
$V = \int_a^b A(h)dh$, where $A$ computes the cross-sectional area.
:::
```{julia}
@@ -828,7 +838,9 @@ nothing
### Cavalieri's method
[Cavalieri's](http://tinyurl.com/oda9xd9) Principle is "Suppose two regions in three-space (solids) are included between two parallel planes. If every plane parallel to these two planes intersects both regions in cross-sections of equal area, then the two regions have equal volumes." (Wikipedia).
[Cavalieri's](https://en.wikipedia.org/wiki/Cavalieri%27s_principle) Principle is:
> Suppose two regions in three-space (solids) are included between two parallel planes. If every plane parallel to these two planes intersects both regions in cross-sections of equal area, then the two regions have equal volumes." (Wikipedia).
::: {#fig-Cavalieris-first}
@@ -868,19 +880,19 @@ plotly()
nothing
```
Illustration of Cavalieri's first principle. The discs from the left are moved around to form the left volume, but as the volumes of each cross-sectional disc remains the same, the two volumes are equally approximated. (This figure ported from @Angenent.)
Illustration of Cavalieri's first principle. The discs from the left are moved around to form the left volume, but as the volumes of each cross-sectional disc remains the same, the two volumes are equally approximated.
:::
With the formula for the volume of solids based on cross sections, this is a trivial observation, as the functions giving the cross-sectional area are identical. Still, it can be surprising.
Consider a sphere with an interior cylinder bored out of it. (The [Napkin](http://tinyurl.com/o237v83) ring problem.) The bore has height $h$ - for larger radius spheres this means very wide bores.
Consider a sphere with an interior cylinder bored out of it. (The [Napkin](https://en.wikipedia.org/wiki/Cavalieri%27s_principle#The_napkin_ring_problem) ring problem.) The bore has height $h$---for larger radius spheres this means very wide bores.
::: {#fig-napkin-ring-1}
```{julia}
#| echo: false
plt = let
let
gr()
# Follow lead of # https://github.com/SigurdAngenent/WisconsinCalculus/blob/master/figures/221/09surf_of_rotation2.py
# plot surface of revolution around x axis between [0, 3]
# best if r(t) decreases
@@ -937,7 +949,7 @@ plt = let
α = 1.0
line_style = (; line=(:black, 1))
plot(; empty_style..., aspect_ratio=:equal)
plt = plot(; empty_style..., aspect_ratio=:equal)
# washer
t0 = sqrt(3/4)
@@ -997,9 +1009,9 @@ plt = let
end
=#
current()
plotly()
plt
end
plt
```
Figure showing sphere with interior cylinder bored out.
@@ -1040,7 +1052,7 @@ plt = let
x₀ = sqrt(R^2 - (h/2)^2)
annotate!( [
(x₀/2, 0, text(L"\sqrt{R^2- (\frac{h}{2})^2}",10, :top)),
(x₀/2, 0, text(L"\sqrt{R^2- (\frac{h}{2})^2}", :top)),
(x₀, h/4, text(L"\frac{h}{2}",:right)),
(R/2*cos(θ),R/2*sin(θ), text(L"R", :bottom; rotation=rad2deg(θ)))
])
@@ -1067,13 +1079,15 @@ The small orange line is rotated, so using the washer method we get the cross se
The outer radii has points $(x,y)$ satisfying $x^2 + y^2 = R^2$, so is $\sqrt{R^2 - y^2}$. The inner radii has a constant value, and as indicated in the figure, is $\sqrt{R^2 - (h/2)^2}$, by the Pythagorean theorem.
Thus the cross sectional area is
Thus the cross-sectional area is
$$
\pi( (\sqrt{R^2 - y^2})^2 - (\sqrt{R^2 - (h/2)^2})^2 )
= \pi ((R^2 - y^2) - (R^2 - (h/2)^2))
= \pi ((\frac{h}{2})^2 - y^2)
\begin{align*}
\pi\left( (\sqrt{R^2 - y^2})^2 - (\sqrt{R^2 - (h/2)^2})^2 \right)
&= \pi \left((R^2 - y^2) - (R^2 - (h/2)^2)\right)\\
&= \pi \left((\frac{h}{2})^2 - y^2\right)
\end{align*}
$$
As this does not depend on $R$, and the limits of integration would always be $-h/2$ to $h/2$ by Cavalieri's principle, the volume of the solid will be independent of $R$ too.
@@ -1085,7 +1099,9 @@ To actually compute this volume, we take $R=h/2$, so that the bore hole is just
## The second theorem of Pappus
The second theorem of [Pappus](http://tinyurl.com/l43vw4) says that if a plane figure $F$ is rotated around an axis to form a solid of revolution, the total volume can be written as $2\pi r A(F)$, where $r$ is the distance the centroid is from the axis of revolution, and $A(F)$ is the area of the plane figure. In short, the distance traveled by the centroid times the area.
The second theorem of [Pappus](https://en.wikipedia.org/wiki/Pappus%27s_centroid_theorem) says
> If a plane figure $F$ is rotated around an axis to form a solid of revolution, the total volume can be written as $2\pi r A(F)$, where $r$ is the distance the centroid is from the axis of revolution, and $A(F)$ is the area of the plane figure. In short, the distance traveled by the centroid times the area. (Wikipedia)
This can make some computations trivial. For example, we can make a torus (or donut) by rotating the circle $(x-2)^2 + y^2 = 1$ about the $y$ axis. As the centroid is clearly $(2, 0)$, with $r=2$ in the above formula, and the area of the circle is $\pi 1^2$, the volume of the donut is $2\pi(2)(\pi) = 4\pi^2$.
@@ -1103,9 +1119,9 @@ Above, we found the volume of a cone, as it is a solid of revolution, through th
###### Question
Consider this big Solo cup:
@fig-big-solo-cup shows a big Solo cup.
::: {#fig-big-solo-cup}
```{julia}
#| hold: true
#| echo: false
@@ -1115,16 +1131,19 @@ caption = " Big solo cup. "
nothing
```
![Big solo cup.](./figures/big-solo-cup.jpg)
![](./figures/big-solo-cup.jpg)
Big solo cup
:::
It has approximate dimensions: smaller radius 5 feet, upper radius 8 feet and height 15 feet. How many gallons is it? At $8$ pounds a gallon this would be pretty heavy!
Two facts are useful:
* a cubic foot is 7.48052 gallons
* a cubic foot is 7.48052 gallons
* the radius as a function of height is $r(h) = 5 + (3/15)\cdot h$
* the radius as a function of height is $r(h) = 5 + (3/15)\cdot h$
```{julia}
@@ -1143,9 +1162,9 @@ numericq(val, 1e1)
In *Glass Shape Influences Consumption Rate* for Alcoholic [Beverages](http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0043007) the authors demonstrate that the shape of the glass can have an effect on the rate of consumption, presumably people drink faster when they aren't sure how much they have left. In particular, they comment that people have difficulty judging the half-finished-by-volume mark.
This figure shows some of the wide variety of beer-serving glasses:
@fig-beer-glasses shows some of a wide variety of beer-serving glasses:
::: {#fig-beer-glasses}
```{julia}
#| hold: true
#| echo: false
@@ -1155,7 +1174,10 @@ caption = "A variety of different serving glasses for beer."
nothing
```
![A variety of different serving glasses for beer.](./figures/beer_glasses.jpg)
![](./figures/beer_glasses.jpg)
A variety of different serving glasses for beer
:::
We work with metric units, as there is a natural relation between volume in cm$^3$ and liquid measure ($1$ liter = $1000$ cm$^3$, so a $16$-oz pint glass is roughly $450$ cm$^3$.)
@@ -1180,11 +1202,11 @@ The following functions find the volume as a function of height, $h$:
```{julia}
r1(h) = 3 + h/5
s1(h) = 2 + log(1 + h)
r_vol(h) = quadgk(x -> pi*r1(x)^2, 0, h)[1]
s_vol(h) = quadgk(x -> pi*s1(x)^2, 0, h)[1]
r_vol(h) = first(quadgk(x -> pi*r1(x)^2, 0, h))
s_vol(h) = first(quadgk(x -> pi*s1(x)^2, 0, h))
```
* For the straight-sided glass find $h$ so that the volume is $450$.
* For the straight-sided glass find $h$ so that the volume is $450$.
```{julia}
@@ -1193,7 +1215,7 @@ h450 = find_zero(h -> r_vol(h) - 450, 10)
numericq(h450)
```
* For the straight-sided glass find $h$ so that the volume is $225$ (half full).
* For the straight-sided glass find $h$ so that the volume is $225$ (half full).
```{julia}
@@ -1202,7 +1224,7 @@ h225 = find_zero(h -> r_vol(h) - 225, 10)
numericq(h225)
```
* For the straight-sided glass, what is the percentage of the total height when the glass is half full. (For a cylinder it would just be 50.)
* For the straight-sided glass, what is the percentage of the total height when the glass is half full. (For a cylinder it would just be 50.)
```{julia}
@@ -1210,7 +1232,7 @@ numericq(h225)
numericq(h225/h450 * 100, 2, units="percent")
```
* People often confuse the half-way by height amount for the half way by volume, as it is for the cylinder. Take the height for the straight-sided glass filled with $450$ mm, divide it by $2$, then compute the percentage of volume at the half way height to the original.
* People often confuse the half-way by height amount for the half way by volume, as it is for the cylinder. Take the height for the straight-sided glass filled with $450$ mm, divide it by $2$, then compute the percentage of volume at the half way height to the original.
```{julia}
@@ -1221,7 +1243,7 @@ numericq(r_vol(h450/2)/450*100, 2, units="percent")
---
* For the curved-sided glass find $h$ so that the volume is $450$.
* For the curved-sided glass find $h$ so that the volume is $450$.
```{julia}
@@ -1230,7 +1252,7 @@ h_450 = find_zero(h -> s_vol(h) - 450, 10)
numericq(h_450)
```
* For the curved-sided glass find $h$ so that the volume is $225$ (half full).
* For the curved-sided glass find $h$ so that the volume is $225$ (half full).
```{julia}
@@ -1239,7 +1261,7 @@ h_225 = find_zero(h -> s_vol(h) - 225, 10)
numericq(h_225)
```
* For the curved-sided glass, what is the percentage of the total height when the glass is half full. (For a cylinder it would just be 50.)
* For the curved-sided glass, what is the percentage of the total height when the glass is half full. (For a cylinder it would just be 50.)
```{julia}
@@ -1247,7 +1269,7 @@ numericq(h_225)
numericq(h_225/h_450 * 100, 2, units="percent")
```
* People often confuse the half-way by height amount for the half way by volume, as it is for the cylinder. Take the height for the curved-sided glass filled with $450$ mm, divide it by $2$, then compute the percentage of volume at the half way height to the original.
* People often confuse the half-way by height amount for the half way by volume, as it is for the cylinder. Take the height for the curved-sided glass filled with $450$ mm, divide it by $2$, then compute the percentage of volume at the half way height to the original.
```{julia}
@@ -1343,13 +1365,6 @@ numericq(val)
The region enclosed by the graphs of $y=x^3 - 1$ and $y=x-1$ are rotated around the $y$ axis. What is the volume of the solid?
```{julia}
#| hold: true
@syms x
plot(x^3 - 1, 0, 1, legend=false)
plot!(x-1)
```
```{julia}
#| hold: true
#| echo: false
@@ -1363,11 +1378,13 @@ numericq(val)
###### Question
Rotate the region bounded by $y=e^x$, the line $x=\log(2)$ and the first quadrant ($x,y \geq 0$) about the line $x=\log(2)$.
Rotate the region bounded by $y=e^x$, the line $x=\ln(2)$ and the first quadrant ($x,y \geq 0$) about the line $x=\log(2)$, as illustrated in @fig-rotate-e-to-x-around-log-2
::: {#fig-rotate-e-to-x-around-log-2}
```{julia}
#| echo: false
let
gr()
p = plot(exp, -0.1, log(2.2); legend=false, ylim = (-0.3, 2.3))
hline!(p, [0], color=:black)
vline!(p, [0], color=:black)
@@ -1381,12 +1398,17 @@ let
bs(t) = (exp(log(2)) - 4b) + b*sin(t)
plot!(p, as.(ts), bs.(ts), linewidth=1, color=:black, arrow=(:closed, 2.0))
plotly()
p
end
```
(Be careful, the radius in the formula $V=\int_a^b \pi r(u)^2 du$ is from the line $x=\log(2)$, further, the constraint $x \geq 0$ needs attention.)
Rotate a region around the line $x=\ln(2)$
:::
(Be careful, the radius in the formula $V=\int_a^b \pi r(u)^2 du$ is from the line $x=\ln(2)$, further, the constraint $x \geq 0$ needs attention.)
```{julia}
@@ -1428,11 +1450,12 @@ You can integrate in the length along the line $y=x$ ($u$ from $0$ to $\sqrt{2}$
theta = pi/4 ## we write y=x as y = x * tan(pi/4) for more generality, as this allows other slants.
f(x) = x^2
𝒙(u) = find_zero(x -> u*sin(theta) - 1/tan(theta) * (x - u*cos(theta)) - f(x), (u*cos(theta), 1))
𝒓(u) = sqrt((u*cos(theta) - 𝒙(u))^2 + (u*sin(theta) - f(𝒙(u)))^2)
𝑥(u) = find_zero(x -> u*sin(theta) - 1/tan(theta) * (x - u*cos(theta)) - f(x), (u*cos(theta), 1))
𝑟(u) = sqrt((u*cos(theta) - 𝑥(u))^2 + (u*sin(theta) - f(𝑥(u)))^2)
```
(Though in this case you can also find `r(u)` using the quadratic formula.)
(Though in this case you can also find `𝑟(u)` using the quadratic formula.)
With this, find the volume.
@@ -1442,7 +1465,7 @@ With this, find the volume.
#| hold: true
#| echo: false
a, b = 0, sqrt(2)
val, _ = quadgk(u -> pi*𝒓(u)^2, a, b)
val, _ = quadgk(u -> pi*𝑟(u)^2, a, b)
numericq(val)
```
@@ -1455,10 +1478,13 @@ Repeat (find the volume) only this time with the function $f(x) = x^{20}$.
```{julia}
#| hold: true
#| echo: false
a, b = 0, sqrt(2)
f(x) = x^20
xval(u) = find_zero(x -> u*sin(theta) - 1/tan(theta) * (x - u*cos(theta)) - f(x), (0,sqrt(2)))
rad(u) = sqrt((u*cos(theta) - xval(u))^2 + (u*sin(theta) - f(xval(u)))^2)
val, _ = quadgk(u -> pi*rad(u)^2, a, b)
numericq(val)
let
theta = pi/4
a, b = 0, sqrt(2)
f(x) = x^20
x(u) = find_zero(x -> u*sin(theta) - 1/tan(theta) * (x - u*cos(theta)) - f(x), (0,sqrt(2)))
r(u) = sqrt((u*cos(theta) - x(u))^2 + (u*sin(theta) - f(x(u)))^2)
val, _ = quadgk(u -> pi*r(u)^2, a, b)
numericq(val)
end
```