for theta in range(0, stop=i/10*2pi, length=10*i )
path3d!(p,sin(theta)*dr, cos(theta)*dr, df)
end
p
end
n = 10
anim = @animate for i=1:n
sa_approx_graph(i)
end
imgfile = tempname() * ".gif"
gif(anim, imgfile, fps = 1)
caption = L"""
Surface of revolution of $f(x) = 2 - x^2$ about the $y$ axis. The lines segments are the images of rotating the secant line connecting $(1/2, f(1/2))$ and $(3/4, f(3/4))$. These trace out the frustum of a cone which approximates the corresponding surface area of the surface of revolution. In the limit, this approximation becomes exact and a formula for the surface area of surfaces of revolution can be used to compute the value.
"""
ImageFile(imgfile, caption)
```
#### Examples
Lets see that the surface area of an open cone follows from this
formula, even though we just saw how to get this value.
A cone be be envisioned as rotating the function $f(x) = x\tan(\theta)$ between $0$ and $h$ around the $x$ axis. This integral yields the surface area:
This integral is done by a trig substitution, but gets involved. We let `SymPy` do it:
```julia;
@syms x
F = integrate(2 * PI * x^2 * sqrt(1 + (2x)^2), x)
```
We show `F`, only to demonstrate that indeed the integral is a bit
involved. The actual surface area follows from a *definite* integral, which we get through the fundamental theorem of calculus:
```julia;
F(1) - F(0)
```
### Plotting surfaces of revolution
The commands to plot a surface of revolution will be described more clearly later; for now we present them as simply a pattern to be followed in case plots are desired. Suppose the curve in the ``x-y`` plane is given parametrically by ``(g(u), f(u))`` for ``a \leq u \leq b``.
To be concrete, we parameterize the circle centered at ``(6,0)`` with radius ``2`` by:
plot!([0,0],[-3,3], color=:red, linewidth=5) # y axis emphasis
plot!([3,9], [0,0], color=:green, linewidth=5) # x axis emphasis
```
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)`` in the form `[x0,x1]` and `[y0,y1]`.
Now, to rotate this about the ``y`` axis, creating a surface plot, we have the following pattern:
```julia
S(u,v) = [g(u)*cos(v), g(u)*sin(v), f(u)]
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], [0,0], [-3,3], color=:red, linewidth=5) # y axis emphasis
```
The `unzip` function is not part of base `Julia`, rather part of
`CalculusWithJulia`. 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 and errors on 3d graphics with `pyplot()`.
To rotate this about the ``x`` axis, we have this pattern:
```julia; hold=true
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'))
surface(ws..., legend=false)
plot!([3,9], [0,0],[0,0], color=:green, linewidth=5) # x axis emphasis
```
The above pattern covers the case of rotating the graph of a function ``f(x)`` of ``a,b`` by taking ``g(t)=t``.
##### Example
Rotate the graph of $x^x$ from $0$ to $3/2$ around the $x$ axis. What is the surface area generated?
We work numerically for this one, as no antiderivative is forthcoming. Recall, the accompanying `CalculusWithJulia` package defines `f'` to return the automatic derivative through the `ForwardDiff` package.
```julia; hold=true
f(x) = x^x
a, b = 0, 3/2
val, _ = quadgk(x -> 2pi * f(x) * sqrt(1 + f'(x)^2), a, b)
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.)
```julia; hold=true
g(u) = u
f(u) = u^u
S(u,v) = [g(u)*cos(v), g(u)*sin(v), f(u)]
us = range(0, 3/2, length=100)
vs = range(0, pi, length=100) # not 2pi (to see inside)
ws = unzip(S.(us,vs'))
surface(ws..., alpha=0.75)
```
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}$.
```julia; hold=true
f(x) = x^x
r0, r1 = f(0), f(3/2)
pi * (r1 + r0) * sqrt((3/2)^2 + (r1-r0)^2)
```
##### Example
What is the surface area generated by Gabriel's Horn, the solid formed by
rotating $1/x$ for $x \geq 1$ around the $x$ axis?
The limit as $M$ gets large is of interest. The only term that might get out of hand is `asinh(M)`. We check its limit:
```julia;
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:
```julia;
limit(ex, M => oo)
```
This figure would have infinite surface, were it possible to actually construct an infinitely long solid. (But it has been shown to have *finite* volume.)
##### Example
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.
```julia; hold=true
g(t) = 2(1 + cos(t)) * cos(t)
f(t) = 2(1 + cos(t)) * sin(t)
plot(g, f, 0, 1pi)
```
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)$.