The package provides an algorithm for the creation of candidates and the means to solve when possible. The `integrate` function is the main entry point. It returns three values: `solved`, `unsolved`, and `err`. The `unsolved` is the part of the integrand which can not be solved through this package. It is `0` for a given problem when `integrate` is successful in identifying an antiderivative, in which case `solved` is the answer. The value of `err` is a bound on the numerical error introduced by the algorithm.
::: {.callout-note}
### This is currently broken
The following isn't working with `SymbolicNumericIntegration` version `v"1.4.0"`. For now, the cells are not evaluated.
:::
To see, we have:
```{julia}
#| eval: false
using SymbolicNumericIntegration
@variables x
@ -852,6 +860,7 @@ The second term is `0`, as this integrand has an identified antiderivative.
```{julia}
#| eval: false
integrate(exp(x^2) + sin(x))
```
@ -862,6 +871,7 @@ Powers of trig functions have antiderivatives, as can be deduced using integrati
```{julia}
#| eval: false
u,v,w = integrate(sin(x)^5)
```
@ -869,6 +879,7 @@ The derivative of `u` matches up to some numeric tolerance:
```{julia}
#| eval: false
Symbolics.derivative(u, x) - sin(x)^5
```
@ -879,6 +890,7 @@ The integration of rational functions (ratios of polynomials) can be done algori
of charge $q$ at the origin around the unit circle would be computed through:
# Line and Surface Integrals
{{< include ../_common_code.qmd >}}
This section uses these add-on packages:
```{julia}
using CalculusWithJulia
using Plots
using QuadGK
using SymPy
using HCubature
```
---
This section discusses generalizations to the one- and two-dimensional definite integral. These two integrals integrate a function over a one or two dimensional region (e.g., $[a,b]$ or $[a,b]\times[c,d]$). The generalization is to change this region to a one-dimensional piece of path in $R^n$ or a two-dimensional surface in $R^3$.
To fix notation, consider $\int_a^b f(x)dx$ and $\int_a^b\int_c^d g(x,y) dy dx$. In defining both, a Riemann sum is involved, these involve a partition of $[a,b]$ or $[a,b]\times[c,d]$ and terms like $f(c_i) \Delta{x_i}$ and $g(c_i, d_j) \Delta{x_i}\Delta{y_j}$. The $\Delta$s the diameter of an intervals $I_i$ or $J_j$. Consider now two parameterizations: $\vec{r}(t)$ for $t$ in $[a,b]$ and $\Phi(u,v)$ for $(u,v)$ in $[a,b]\times[c,d]$. One is a parameterization of a space curve, $\vec{r}:R\rightarrow R^n$; the other a parameterization of a surface, $\Phi:R^2 \rightarrow R^3$. The *image* of $I_i$ or $I_i\times{J_j}$ under $\vec{r}$ and $\Phi$, respectively, will look *almost* linear if the intervals are small enough, so, at least on the microscopic level. A Riemann term can be based around this fact, provided it is understood how much the two parameterizations change the interval $I_i$ or region $I_i\times{J_j}$.
This chapter will quantify this change, describing it in terms of associated vectors to $\vec{r}$ and $\Phi$, yielding formulas for an integral of a *scalar* function along a path or over a surface. Furthermore, these integrals will be generalized to give meaning to physically useful interactions between the path or surface and a vector field.
## Line integrals
In [arc length](../integrals/arc-length.html) a formula to give the arc-length of the graph of a univariate function or parameterized curve in $2$ dimensions is given in terms of an integral. The intuitive approximation involved segments of the curve. To review, let $\vec{r}(t)$, $a \leq t \leq b$, describe a curve, $C$, in $R^n$, $n \geq 2$. Partition $[a,b]$ into $a=t_0 < t_1 < \cdots < t_{n-1} < t_n = b$.
Consider the path segment connecting $\vec{r}(t_{i-1})$ to $\vec{r}(t_i)$. If the partition of $[a,b]$ is microscopically small, this path will be *approximated* by $\vec{r}(t_i) - \vec{r}(t_{i-1})$. This difference in turn is approximately $\vec{r}'(t_i) (t_i - t_{i-1}) = \vec{r}'(t_i) \Delta{t}_i$, provided $\vec{r}$ is differentiable.
If $f:R^n \rightarrow R$ is a scalar function. Taking right-hand end points, we can consider the Riemann sum $\sum (f\circ\vec{r})(t_i) \|\vec{r}'(t_i)\| \Delta{t}_i$. For integrable functions, this sum converges to the *line integral* defined as a one-dimensional integral for a given parameterization:
$$
\int_a^b f(\vec{r}(t)) \| \vec{r}'(t) \| dt.
$$
The weight $\| \vec{r}'(t) \|$ can be interpreted by how much the parameterization stretches (or contracts) an interval $[t_{i-1},t_i]$ when mapped to its corresponding path segment.
---
The curve $C$ can be parameterized many different ways by introducing a function $s(t)$ to change the time. If we use the arc-length parameterization with $\gamma(0) = a$ and $\gamma(l) = b$, where $l$ is the arc-length of $C$, then we have by change of variables $t = \gamma(s)$ that
The last line, as the derivative is the unit tangent vector, $T$, with norm $1$.
This shows that the line integral is *not* dependent on the parameterization. The notation $\int_C f ds$ is used to represent the line integral of a scalar function, the $ds$ emphasizing an implicit parameterization of $C$ by arc-length. When $C$ is a closed curve, the $\oint_C fds$ is used to indicate that.
### Example
When $f$ is identically $1$, the line integral returns the arc length. When $f$ varies, then the line integral can be interpreted a few ways. First, if $f \geq 0$ and we consider a sheet hung from the curve $f\circ \vec{r}$ and cut to just touch the ground, the line integral gives the area of this sheet, in the same way an integral gives the area under a positive curve.
If the composition $f \circ \vec{r}$ is viewed as a density of the arc (as though it were constructed out of some non-uniform material), then the line integral can be seen to return the mass of the arc.
Suppose $\rho(x,y,z) = 5 - z$ gives the density of an arc where the arc is parameterized by $\vec{r}(t) = \langle \cos(t), 0, \sin(t) \rangle$, $0 \leq t \leq \pi$. (A half-circular arc.) Find the mass of the arc.
```{julia}
rho(x,y,z) = 5 - z
rho(v) = rho(v...)
r(t) = [cos(t), 0, sin(t)]
@syms t
rp = diff.(r(t),t) # r'
area = integrate((rho ∘ r)(t) * norm(rp), (t, 0, PI))
```
Continuing, we could find the center of mass by integrating $\int_C z (f\circ \vec{r}) \|r'\| dt$:
Let $f(x,y,z) = x\sin(y)\cos(z)$ and $C$ the path described by $\vec{r}(t) = \langle t, t^2, t^3\rangle$ for $0 \leq t \leq \pi$. Find the line integral $\int_C fds$.
We find the numeric value with:
```{julia}
#| hold: true
f(x,y,z) = x*sin(y)*cos(z)
f(v) = f(v...)
r(t) = [t, t^2, t^3]
integrand(t) = (f ∘ r)(t) * norm(r'(t))
quadgk(integrand, 0, pi)
```
##### Example
Imagine the $z$ axis is a wire and in the $x$-$y$ plane the unit circle is a path. If there is a magnetic field, $B$, then the field will induce a current to flow along the wire. [Ampere's](https://tinyurl.com/y4gl9pgu) circuital law states $\oint_C B\cdot\hat{T} ds = \mu_0 I$, where $\mu_0$ is a constant and $I$ the current. If the magnetic field is given by $B=(x^2+y^2)^{1/2}\langle -y,x,0\rangle$ compute $I$ in terms of $\mu_0$.
We have the path is parameterized by $\vec{r}(t) = \langle \cos(t), \sin(t), 0\rangle$, and so $\hat{T} = \langle -\sin(t), \cos(t), 0\rangle$ and the integrand, $B\cdot\hat{T}$ is
which is $1$ on the path $C$. So $\int_C B\cdot\hat{T} ds = \int_C ds = 2\pi$. So the current satisfies $2\pi = \mu_0 I$, so $I = (2\pi)/\mu_0$.
(Ampere's law is more typically used to find $B$ from an current, then $I$ from $B$, for special circumstances. The Biot-Savart does this more generally.)
### Line integrals and vector fields; work and flow
As defined above, the line integral is defined for a scalar function, but this can be generalized. If $F:R^n \rightarrow R^n$ is a vector field, then each component is a scalar function, so the integral $\int (F\circ\vec{r}) \|\vec{r}'\| dt$ can be defined component by component to yield a vector.
However, it proves more interesting to define an integral incorporating how properties of the path interact with the vector field. The key is $\vec{r}'(t) dt = \hat{T} \| \vec{r}'(t)\|dt$ describes both the magnitude of how the parameterization stretches an interval but also a direction the path is taking. This direction allows interaction with the vector field.
The canonical example is [work](https://en.wikipedia.org/wiki/Work_(physics)), which is a measure of a force times a distance. For an object following a path, the work done is still a force times a distance, but only that force in the direction of the motion is considered. (The *constraint force* keeping the object on the path does no work.) Mathematically, $\hat{T}$ describes the direction of motion along a path, so the work done in moving an object over a small segment of the path is $(F\cdot\hat{T}) \Delta{s}$. Adding up incremental amounts of work leads to a Riemann sum for a line integral involving a vector field.
> The *work* done in moving an object along a path $C$ by a force field, $F$, is given by the integral
In the $n=2$ case, there is another useful interpretation of the line integral. In this dimension the normal vector, $\hat{N}$, is well defined in terms of the tangent vector, $\hat{T}$, through a rotation: $\langle a,b\rangle^t = \langle b,-a\rangle$. (The negative, $\langle -b,a\rangle$ is also a candidate, the difference in this choice would lead to a sign difference in the answer.) This allows the definition of a different line integral, called a flow integral, as detailed later:
Let $F(x,y,z) = \langle x - y, x^2 - y^2, x^2 - z^2 \rangle$ and $\vec{r}(t) = \langle t, t^2, t^3 \rangle$. Find the work required to move an object along the curve described by $\vec{r}$ between $0$ and $1$.
```{julia}
#| hold: true
F(x,y,z) = [x-y, x^2 - y^2, x^2 - z^2]
F(v) = F(v...)
r(t) = [t, t^2, t^3]
@syms t::real
integrate((F ∘ r)(t) ⋅ diff.(r(t), t), (t, 0, 1))
```
##### Example
Let $C$ be a closed curve. For a closed curve, the work integral is also termed the *circulation*. For the vector field $F(x,y) = \langle -y, x\rangle$ compute the circulation around the triangle with vertices $(-1,0)$, $(1,0)$, and $(0,1)$.
We have three integrals using $\vec{r}_1(t) = \langle -1+2t, 0\rangle$, $\vec{r}_2(t) = \langle 1-t, t\rangle$ and $\vec{r}_3(t) = \langle -t, 1-t \rangle$, all from $0$ to $1$. (Check that the parameterization is counter clockwise.)
The circulation then is:
```{julia}
#| hold: true
r1(t) = [-1 + 2t, 0]
r2(t) = [1-t, t]
r3(t) = [-t, 1-t]
F(x,y) = [-y, x]
F(v) = F(v...)
integrand(r) = t -> (F ∘ r)(t) ⋅ r'(t)
C1 = quadgk(integrand(r1), 0, 1)[1]
C2 = quadgk(integrand(r2), 0, 1)[1]
C3 = quadgk(integrand(r3), 0, 1)[1]
C1 + C2 + C3
```
That this is non-zero reflects a feature of the vector field. In this case, the vector field spirals around the origin, and the circulation is non zero.
##### Example
Let $F$ be the force of gravity exerted by a mass $M$ on a mass $m$ a distance $\vec{r}$ away, that is $F(\vec{r}) = -(GMm/\|\vec{r}\|^2)\hat{r}$.
Let $\vec{r}(t) = \langle 1-t, 0, t\rangle$, $0 \leq t \leq 1$. For concreteness, we take $G M m$ to be $10$. Then the work to move the mass is given by:
```{julia}
uvec(v) = v/norm(v) # unit vector
GMm = 10
Fₘ(r) = - GMm /norm(r)^2 * uvec(r)
rₘ(t) = [1-t, 0, t]
quadgk(t -> (Fₘ ∘ rₘ)(t) ⋅ rₘ'(t), 0, 1)
```
Hmm, a value of $0$. That's a bit surprising at first glance. Maybe it had something to do with the specific path chosen. To investigate, we connect the start and endpoints with a circular arc, instead of a straight line:
```{julia}
rₒ(t) = [cos(t), 0, sin(t)]
quadgk(t -> (Fₘ ∘ rₒ)(t) ⋅ rₒ'(t), 0, 1)
```
Still $0$. We will see next that this is not surprising if something about $F$ is known.
:::{.callout-note}
## Note
The [Washington Post](https://www.washingtonpost.com/outlook/everything-you-thought-you-knew-about-gravity-is-wrong/2019/08/01/627f3696-a723-11e9-a3a6-ab670962db05_story.html") had an article by Richard Panek with the quote "Well, yes — depending on what we mean by 'attraction.' Two bodies of mass don’t actually exert some mysterious tugging on each other. Newton himself tried to avoid the word 'attraction' for this very reason. All (!) he was trying to do was find the math to describe the motions both down here on Earth and up there among the planets (of which Earth, thanks to Copernicus and Kepler and Galileo, was one)." The point being the formula above is a mathematical description of the force, but not an explanation of how the force actually is transferred.
:::
#### Work in a *conservative* vector field
Let $f: R^n \rightarrow R$ be a scalar function. Its gradient, $\nabla f$ is a *vector field*. For a *scalar* function, we have by the chain rule:
W = \int_a^b \nabla{f}(\vec{r}(t)) \cdot \frac{d\vec{r}}{dt} dt =
\int_a^b \frac{d(f \circ \vec{r})}{dt} dt =
(f\circ\vec{r})\mid_{t = a}^b =
(f\circ\vec{r})(b) - (f\circ\vec{r})(a),
$$
using the Fundamental Theorem of Calculus.
The main point above is that *if* the vector field is the gradient of a scalar field, then the work done depends *only* on the endpoints of the path and not the path itself.
> **Conservative vector field**: If $F$ is a vector field defined in an *open* region $R$; $A$ and $B$ are points in $R$ and *if* for *any* curve $C$ in $R$ connecting $A$ to $B$, the line integral of $F \cdot \vec{T}$ over $C$ depends *only* on the endpoint $A$ and $B$ and not the path, then the line integral is called *path indenpendent* and the field is called a *conservative field*.
The force of gravity is the gradient of a scalar field. As such, the two integrals above which yield $0$ could have been computed more directly. The particular scalar field is $f = -GMm/\|\vec{r}\|$, which goes by the name the gravitational *potential* function. As seen, $f$ depends only on magnitude, and as the endpoints of the path in the example have the same distance to the origin, the work integral, $(f\circ\vec{r})(b) - (f\circ\vec{r})(a)$ will be $0$.
##### Example
Coulomb's law states that the electrostatic force between two charged particles is proportional to the product of their charges and *inversely* proportional to square of the distance between the two particles. That is,
$$
F = k\frac{ q q_0}{\|\vec{r}\|^2}\frac{\vec{r}}{\|\vec{r}\|}.
$$
This is similar to gravitational force and is a *conservative force*. We saw that a line integral for work in a conservative force depends only on the endpoints. Verify, that for a closed loop the work integral will yield $0$.
Take as a closed loop the unit circle, parameterized by arc-length by $\vec{r}(t) = \langle \cos(t), \sin(t)\rangle$. The unit tangent will be $\hat{T} = \vec{r}'(t) = \langle -\sin(t), \cos(t) \rangle$. The work to move a particle of charge $q_0$ about a particle of charge $q$ at the origin around the unit circle would be computed through:
As mentioned, for limits that depend on specific values of parameters `SymPy` may have issues. As an example, `SymPy` has an issue with this limit, whose answer depends on the value of $k$"
As mentioned, for limits that depend on specific values of parameters `SymPy` may have issues. As an example, `SymPy` has an issue with the following limit, whose answer depends on the value of $k$"
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.