use quarto, not Pluto to render pages

This commit is contained in:
jverzani
2022-07-24 16:38:24 -04:00
parent 93c993206a
commit 7b37ca828c
879 changed files with 793311 additions and 2678 deletions

View File

@@ -12,10 +12,10 @@ using ForwardDiff
```julia; echo=false; results="hidden"
using CalculusWithJulia.WeaveSupport
const frontmatter = (
title = "2D and 3D plots in Julia with Plots",
description = "Calculus with Julia: 2D and 3D plots in Julia with Plots",
tags = ["CalculusWithJulia", "differentiable_vector_calculus", "2d and 3d plots in julia with plots"],
frontmatter = (
title = "2D and 3D plots in Julia with Plots",
description = "Calculus with Julia: 2D and 3D plots in Julia with Plots",
tags = ["CalculusWithJulia", "differentiable_vector_calculus", "2d and 3d plots in julia with plots"],
);
nothing
```
@@ -69,7 +69,8 @@ ts = range(0, 2pi, length=100)
plot(unzip(r₂.(ts))...)
```
As a convenience, `CalculusWithJulia` provides `plot_parametric` to produce this plot. The interval is specified with the `a..b` notation, the points to plot are adaptively chosen:
As a convenience, `CalculusWithJulia` provides `plot_parametric` to produce this plot. The interval is specified with the `a..b` notation of `IntervalSets` (which is available when the `CalculusWithJulia` package is loaded), the points to plot are adaptively chosen:
```julia
plot_parametric(0..2pi, r₂) # interval first
@@ -340,7 +341,7 @@ surface(xs, ys, zs)
note("The above may not work with all backends for `Plots`, even if those that support 3D graphics.")
```
For convenience, the `plot_parametric` function from `CalculusWithJulia` can produce these plots using interval notation and a function:
For convenience, the `plot_parametric` function from `CalculusWithJulia` can produce these plots using interval notation, `a..b`, and a function:
```julia; hold=true
F(theta, phi) = [X(1, theta, phi), Y(1, theta, phi), Z(1, theta, phi)]

View File

@@ -13,7 +13,7 @@ using QuadGK
```julia; echo=false; results="hidden"
using CalculusWithJulia.WeaveSupport
const frontmatter = (
frontmatter = (
title = "Polar Coordinates and Curves",
description = "Calculus with Julia: Polar Coordinates and Curves",
tags = ["CalculusWithJulia", "differentiable_vector_calculus", "polar coordinates and curves"],
@@ -143,7 +143,7 @@ rs = r.(ts)
plot(ts, rs, proj=:polar, legend=false)
```
To avoid having to create values for $\theta$ and values for $r$, the `CalculusWithJulia` package provides a helper function, `plot_polar`. To distinguish it from other functions provided by `Plots`, the calling pattern is different. It specifies an interval to plot over by `a..b` and puts that first, followed by `r`. Other keyword arguments are passed onto a `plot` call.
To avoid having to create values for $\theta$ and values for $r$, the `CalculusWithJulia` package provides a helper function, `plot_polar`. To distinguish it from other functions provided by `Plots`, the calling pattern is different. It specifies an interval to plot over by `a..b` and puts that first (this notation for closed intervals is from `IntervalSets`), followed by `r`. Other keyword arguments are passed onto a `plot` call.
We will use this in the following, as the graphs are a bit more familiar and the calling pattern similar to how we have plotted functions.
@@ -634,8 +634,8 @@ choices = [
"a circle",
"a line"
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
@@ -649,8 +649,8 @@ choices = [
"a circle",
"a line"
]
ans = 2
radioq(choices, ans, keep_order=true)
answ = 2
radioq(choices, answ, keep_order=true)
```
@@ -664,8 +664,8 @@ choices = [
"a circle",
"a line"
]
ans = 3
radioq(choices, ans, keep_order=true)
answ = 3
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -681,8 +681,8 @@ choices = [
"``\\pi/2``",
"``1``"
]
ans=1
radioq(choices, ans)
answ=1
radioq(choices, answ)
```
###### Question

View File

@@ -10,6 +10,11 @@ using SymPy
using Roots
using QuadGK
using JSON
```
Also, these methods from the `Contour` package:
```julia
import Contour: contours, levels, level, lines, coordinates
```
@@ -155,9 +160,8 @@ surface(xs, ys, 𝒇)
The `surface` function will generate the surface.
```julia; echo=false
note("""Using `surface` as a function name is equivalent to `plot(xs, ys, f, seriestype=:surface)`.""")
```
!!! note
Using `surface` as a function name is equivalent to `plot(xs, ys, f, seriestype=:surface)`.
We can also use `surface(xs, ys, zs)` where `zs` is not a vector, but
rather a *matrix* of values corresponding to a grid described by the
@@ -548,7 +552,6 @@ r2₁(t) = [γ₁(t)..., 0]
plot_parametric!(0..1/2, r2₁, linewidth=5, color=:black) # in the $x$-$y$ plane
```
The vector valued function `r3(t) = [γ(t)..., f(γ(t))]` takes the ``2``-dimensional path specified by $\vec\gamma(t)$ and adds a third, $x$, direction by composing the position with `f`. In this way, a ``2``-D path is visualized with a ``3``-D path. This viewpoint can be reversed, as desired.
However, the composition, $f\circ\vec\gamma$, is a univariate function, so this can also be visualized by
@@ -709,11 +712,8 @@ partial_x(f, y) = x -> ForwardDiff.derivative(u -> f(u,y), x)
```
```julia; echo=false
note("""
For vector-valued functions, we can overide the syntax `'` using `Base.adjoint`, as `'` is treated as a postfix operator in `Julia` for the `adjoint` operation. The symbol `\\nabla` is also available in `Julia`, but it is not an operator, so can't be used as mathematically written `∇f` (this could be used as a name though). In `CalculusWithJulia` a definition is made so essentially `∇(f) = x -> ForwardDiff.gradient(f, x)`. It does require parentheses to be called, as in `∇(f)`.
""")
```
!!! note
For vector-valued functions, we can overide the syntax `'` using `Base.adjoint`, as `'` is treated as a postfix operator in `Julia` for the `adjoint` operation. The symbol `\\nabla` is also available in `Julia`, but it is not an operator, so can't be used as mathematically written `∇f` (this could be used as a name though). In `CalculusWithJulia` a definition is made so essentially `∇(f) = x -> ForwardDiff.gradient(f, x)`. It does require parentheses to be called, as in `∇(f)`.
#### Symbolic expressions
@@ -1409,8 +1409,8 @@ From the graph, is the value of $f(1/2, 1)$ positive or negative?
```julia; hold=true; echo=false
choices = ["positive", "negative"]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
@@ -1421,8 +1421,8 @@ choices = [
L"The line $x=0$",
L"The line $y=0$"
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
Consider the contour plot
@@ -1449,8 +1449,8 @@ L"is around $(0.7, 0)$ and with a value less than $-0.4$",
L"is around $(-2.0, 0)$ and with a value less than $-0.4$",
L"is around $(2.0, 0)$ and with a value less than $-0.4$"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
From this graph, where is the surface steeper?
@@ -1462,8 +1462,8 @@ L"near $(1/2, 0)$",
L"near $(3/4, 0)$",
L"near $(1, 0)$"
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -1483,8 +1483,8 @@ choices = [
L"Yes, the closed loops near $(-1.5, 0)$ and $(1.5, 0)$ will contain these",
L"No, the vertical lines parallel to $x=0$ show this function to be flat"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Imagine hiking on this surface within this region. Could you traverse from left to right without having to go up or down?
@@ -1519,8 +1519,8 @@ choices = [
"running essentially parallel to the contour lines",
"running essentially perpendicular to the contour lines"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Why?
@@ -1530,8 +1530,8 @@ choices = [
"By being essentially parallel, the steepness of the roadway can be kept to a passable level",
"By being essentially perpendicular, the road can more quickly climb up the mountain"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
The pass is at about 2700 meters. As shown towards the top and bottom of the figure the contour lines show increasing heights, and to the left and right decreasing heights. The shape of the [pass](https://en.wikipedia.org/wiki/Mountain_pass) would look like:
@@ -1541,8 +1541,8 @@ choices = [
"A saddle-like shape, called a *col* or *gap*",
"A upside down bowl-like shape like the top of a mountain"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1561,8 +1561,8 @@ L"When $i(\vec{x}) = 0$",
L"When any of $f(\vec{x})$, $g(\vec{x})$, or $i(\vec{x})$ are zero",
L"The limit exists everywhere, as the function $f$, $g$, $h$, and $i$ have limits at $\vec{c}$ by assumption"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1602,8 +1602,8 @@ raw"`` \langle \cos(2y), \cos(y) \rangle``",
raw"`` \langle \sin(x), \sin(2x) \rangle``",
raw"`` \sin(x)\cos(2y)``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Compute $f_y$
@@ -1615,8 +1615,8 @@ raw"`` \langle 2\sin(x), \sin(2x) \rangle``",
raw"`` \langle -2\sin(2y), -\sin(y) \rangle``",
raw"`` - \sin(2x)\sin(y)``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1654,16 +1654,16 @@ The gradient is:
```julia; hold=true; echo=false
choices = ["two dimensional", "three dimensional"]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
The surface is:
```julia; hold=true; echo=false
choices = ["two dimensional", "three dimensional"]
ans = 2
radioq(choices, ans, keep_order=true)
answ = 2
radioq(choices, answ, keep_order=true)
```
The gradient points in the direction of greatest increase of $f$. If a person were on a hill described by $z=f(x,y)$, what three dimensional vector would they follow to go the steepest way up the hill?
@@ -1674,8 +1674,8 @@ choices = [
raw"`` \langle -f_x, -f_y, 1 \rangle``",
raw"`` \langle f_x, f_y \rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
##### Question
@@ -1700,8 +1700,8 @@ choices = [
raw"`` (f\circ\vec\gamma)(x,y)``",
raw"`` \vec\gamma(x,y)``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
A climber leaves base camp at $t_0$. At time $t > t_0$, what describes her elevation?
@@ -1712,8 +1712,8 @@ choices = [
raw"`` \vec\gamma(t)``",
raw"`` f(t)``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
What does the vector-valued function $\vec{r}(t) = \langle x(t), y(t), (f\circ\vec\gamma(t))\rangle$ describe:
@@ -1723,8 +1723,8 @@ choices = [
"The three dimensional position of the climber",
"The climbers gradient, pointing in the direction of greatest ascent"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
In the figure, the climbers are making a switch back, so as to avoid the steeper direct ascent. Mathematically $\nabla{f}(\vec\gamma(t)) \cdot \vec\gamma'(t)$ describes the directional derivative that they follow. Using $\|\vec{u}\cdot\vec{v}\| = \|\vec{u}\|\|\vec{v}\|\cos(\theta)$, does this route:
@@ -1735,8 +1735,8 @@ choices = [
L"Keep $\cos(\theta)$ as close to $1$ as possible, so the slope taken is as big as possible",
L"Keep $̧\cos(\theta)$ as close to $0$ as possible, so that they climbers don't waste energy going up and down"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Suppose our climber reaches the top at time $t$. What would be $(f\circ\vec\gamma)'(t)$, assuming the derivative exists?
@@ -1747,8 +1747,8 @@ choices = [
L"It would be $\langle f_x, f_y\rangle$ and point towards the sky, the direction of greatest ascent",
"It would not exist, as there would not be enough oxygen to compute it"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1765,8 +1765,8 @@ raw"`` |\hat{T} \cdot \hat{P}| \leq \cos(π/18)``",
raw"`` |\hat{T} \cdot \hat{P}| \leq \sin(\pi/18)``",
raw"`` |\hat{T} \cdot \hat{P}| \leq \pi/18``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
The normal to the surface $z=f(x,y)$ is *not* the normal to the trail tread. Suppose $\vec{N}(t)$ is a function that returns this. At the same point $\vec\gamma(t)$, let $\vec{M} = \langle -f_x, -f_y, 0\rangle$ be a vector in 3 dimensions pointing downhill. Let "hats" indicate unit vectors. The outward slope is $\pi/2$ minus the angle between $\hat{N}$ and $\hat{M}$. What condition will ensure this angle is $5$ degrees ($\pi/36$ radians)?
@@ -1777,8 +1777,8 @@ choices = [
raw"`` |\hat{N} \cdot \hat{M}| \leq \sin(\pi/2 - \pi/18)``",
raw"`` |\hat{N} \cdot \hat{M}| \leq \pi/2 - \pi/18``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1797,8 +1797,8 @@ choices = [
raw"`` 2 \cos{\left (3 \right )} - 7 \sin{\left (3 \right )}``",
raw"`` 4 x^{2} y \sin{\left (x - y^{2} \right )} - x^{2} \sin{\left (x - y^{2} \right )} + 2 x \cos{\left (x - y^{2} \right )}``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1813,8 +1813,8 @@ choices = [
"Yes, by definition",
L"No, not unless $\vec{v}$ were a unit vector"
]
ans = 2
radioq(choices, ans)
answ = 2
radioq(choices, answ)
```
###### Question
@@ -1831,8 +1831,8 @@ choices = [
raw"`` \langle 4x^3, 2z, 2y\rangle``",
raw"`` \langle x^3 + 2x + 2x, 2y+ y^3, 2x\rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
The value of $\vec\gamma'(t)$ is:
@@ -1843,8 +1843,8 @@ choices = [
raw"`` 1 + 2y + 3t^2``",
raw"`` \langle 1,2, 3 \rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
The value of $(f\circ\vec\gamma)'(t)$ is found by:
@@ -1855,8 +1855,8 @@ choices = [
L"Taking the dot product of $\nabla{f}(\vec\gamma'(t))$ and $\vec\gamma(t)$",
L"Taking the dot product of $\nabla{f}(x,y,z)$ and $\vec\gamma'(t)$"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1887,8 +1887,8 @@ choices = [
"The green one",
"The red one"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1915,8 +1915,8 @@ choices = [
"The green one",
"The red one"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1947,8 +1947,8 @@ choices = [
L"Linear means $H$ is linear, so $g(\vec{x})$ describes a plane",
L"Linear means $H$ is the $0$ matrix, so the gradient couldn't have been $\vec{0}$"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Suppose, $H$ has the magic property that for *any* vector $\vec{v}^tH\vec{v} < 0$. What does this imply:
@@ -1959,8 +1959,8 @@ choices = [
L"That $g(\vec{x}) = f(\vec{c})$",
L"That $g(\vec{x}) \leq f(\vec{c})$"
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -1974,8 +1974,8 @@ choices = [
raw"`` \partial^4{f}/\partial{x^2}\partial{y^2}``",
raw"`` \partial^4{f}/\partial{x^1}\partial{y^3}``"
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -1993,8 +1993,8 @@ choices = [
raw"`` f_{yy}``"
]
x,y=1/2, 2
val, ans = findmax([6x*y, 3x^2, 6*y, 6x, 0])
radioq(choices, ans, keep_order=true)
val, answ = findmax([6x*y, 3x^2, 6*y, 6x, 0])
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -2024,15 +2024,15 @@ Whereas,
At $(0,0)$ what is $ \frac{\partial \frac{\partial f}{\partial x}}{ \partial y}$?
```julia; hold=true; echo=false
ans = -1
numericq(ans)
answ = -1
numericq(answ)
```
At $(0,0)$ what is $ \frac{\partial \frac{\partial f}{\partial y}}{ \partial x}$?
```julia; hold=true; echo=false
ans = 1
numericq(ans)
answ = 1
numericq(answ)
```
Away from $(0,0)$ the mixed partial is $\frac{x^{6} + 9 x^{4} y^{2} - 9 x^{2} y^{4} - y^{6}}{x^{6} + 3 x^{4} y^{2} + 3 x^{2} y^{4} + y^{6}}$.
@@ -2043,8 +2043,8 @@ choices = [
L"This is not continuous at $(0,0)$, still the limit along the two paths $x=0$ and $y=0$ are equivalent.",
L"This is not continuous at $(0,0)$, as the limit along the two paths $x=0$ and $y=0$ are not equivalent."
]
ans = 3
radioq(choices, ans)
answ = 3
radioq(choices, answ)
```
###### Question
@@ -2096,8 +2096,8 @@ L"The Burgers equation: $f_t + ff_x = f_{xx}$; describes waves at the beach whic
L"The KdV equation: $f_t + 6ff_x+ f_{xxx} = 0$; models water waves in a narrow channel",
L"The Schrodinger equation: $f_t = (i\hbar/(2m))f_xx$; used to describe a quantum particle of mass $m$"
]
ans = 3
radioq(ode_choices, ans, keep_order=true)
answ = 3
radioq(ode_choices, answ, keep_order=true)
```
@@ -2106,8 +2106,8 @@ radioq(ode_choices, ans, keep_order=true)
What equation does the function $f(t, x) = sin(x-t) + sin(x+t)$ satisfy?
```julia; hold=true; echo=false
ans = 1
radioq(ode_choices, ans, keep_order=true)
answ = 1
radioq(ode_choices, answ, keep_order=true)
```
@@ -2116,14 +2116,14 @@ radioq(ode_choices, ans, keep_order=true)
What equation does the function $f(t, x) = e^{-(x+t)^2}$ satisfy?
```julia; hold=true; echo=false
ans = 4
radioq(ode_choices, ans, keep_order=true)
answ = 4
radioq(ode_choices, answ, keep_order=true)
```
What equation does the function $f(x,y) = \cos(x) + \sin(y)$ satisfy?
```julia; hold=true; echo=false
ans = 5
radioq(ode_choices, ans, keep_order=true)
answ = 5
radioq(ode_choices, answ, keep_order=true)
```

View File

@@ -8,6 +8,11 @@ using CalculusWithJulia
using Plots
using SymPy
using Roots
```
And the following from the `Contour` package:
```julia
import Contour: contours, levels, level, lines, coordinates
```
@@ -109,8 +114,8 @@ pt = [a, b, 0]
scatter!(unzip([pt])...)
arrow!(pt, [1,0,0], linestyle=:dash)
arrow!(pt, [0,1,0], linestyle=:dash)
```
#### Alternate forms
The equation for the tangent plane is often expressed in a more explicit form. For $n=2$, if we set $dx = x-a$ and $dy=y-a$, then the equation for the plane becomes:
@@ -915,8 +920,10 @@ Another might be the vertical squared distance to the line:
```math
d2(\alpha, \beta) = (y_1 - l(x_1))^2 + (y_2 - l(x_2))^2 + (y_3 - l(x_3))^2 =
(y1 - (\alpha + \beta x_1))^2 + (y3 - (\alpha + \beta x_3))^2 + (y3 - (\alpha + \beta x_3))^2
\begin{align*}
d2(\alpha, \beta) &= (y_1 - l(x_1))^2 + (y_2 - l(x_2))^2 + (y_3 - l(x_3))^2 \\
&= (y1 - (\alpha + \beta x_1))^2 + (y3 - (\alpha + \beta x_3))^2 + (y3 - (\alpha + \beta x_3))^2
\end{align*}
```
Another might be the *shortest* distance to the line:
@@ -1011,8 +1018,8 @@ gammas₂ = [1.0]
for n in 1:5
xn = xs₂[end]
gamma = gammas₂[end]
xn1 = xn - gamma * gradient(f₂)(xn)
gamma = gammas₂[end]
xn1 = xn - gamma * gradient(f₂)(xn)
dx, dy = xn1 - xn, gradient(f₂)(xn1) - gradient(f₂)(xn)
gamman1 = abs( (dx ⋅ dy) / (dy ⋅ dy) )
@@ -1133,10 +1140,8 @@ fxx, d
Consequently we have a local maximum at this critical point.
```julia; echo=false
note(""" The `Optim.jl` package provides efficient implementations of these two numeric methods, and others. """)
```
!!! note
The `Optim.jl` package provides efficient implementations of these two numeric methods, and others.
## Constrained optimization, Lagrange multipliers
@@ -1557,11 +1562,13 @@ This theorem can be generalized to scalar functions, but the notation can be cum
Following [Folland](https://sites.math.washington.edu/~folland/Math425/taylor2.pdf) we use *multi-index* notation. Suppose $f:R^n \rightarrow R$, and let $\alpha=(\alpha_1, \alpha_2, \dots, \alpha_n)$. Then define the following notation:
```math
|\alpha| = \alpha_1 + \cdots + \alpha_n, \quad
\alpha! = \alpha_1!\alpha_2!\cdot\cdots\cdot\alpha_n!,\quad
\vec{x}^\alpha = x_1^{\alpha_1}x_2^{\alpha_2}\cdots x_n^{\alpha^n}, \quad
\partial^\alpha f = \partial_1^{\alpha_1}\partial_2^{\alpha_2}\cdots \partial_n^{\alpha_n} f =
\frac{\partial^{|\alpha|}f}{\partial x_1^{\alpha_1} \partial x_2^{\alpha_2} \cdots \partial x_n^{\alpha_n}}.
\begin{align*}
|\alpha| &= \alpha_1 + \cdots + \alpha_n, \\
\alpha! &= \alpha_1!\alpha_2!\cdot\cdots\cdot\alpha_n!, \\
\vec{x}^\alpha &= x_1^{\alpha_1}x_2^{\alpha_2}\cdots x_n^{\alpha^n}, \\
\partial^\alpha f &= \partial_1^{\alpha_1}\partial_2^{\alpha_2}\cdots \partial_n^{\alpha_n} f \\
& = \frac{\partial^{|\alpha|}f}{\partial x_1^{\alpha_1} \partial x_2^{\alpha_2} \cdots \partial x_n^{\alpha_n}}.
\endalign*}
```
This notation makes many formulas from one dimension carry over to higher dimensions. For example, the binomial theorem says:
@@ -1781,8 +1788,8 @@ choices = [
raw"`` 2x + y - 2z = 1``",
raw"`` x + 2y + 3z = 6``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1798,8 +1805,8 @@ choices = [
raw"`` y^2 + y, x^2 + x``",
raw"`` \langle 2y + y^2, 2x + x^2``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Is this the Hessian of $f$?
@@ -1830,8 +1837,8 @@ choices = [
L"The function $f$ has a saddle point, as $d < 0$",
L"Nothing can be said, as $d=0$"
]
ans = 2
radioq(choices, ans, keep_order=true)
answ = 2
radioq(choices, answ, keep_order=true)
```
@@ -1885,8 +1892,8 @@ choices = [
L"Nothing can be said, as $d=0$",
L"The test does not apply, as $\nabla{f}$ is not $0$ at this point."
]
ans = 3
radioq(choices, ans, keep_order=true)
answ = 3
radioq(choices, answ, keep_order=true)
```
Which is true of $f$ at $(0, -1/2)$:
@@ -1899,8 +1906,8 @@ choices = [
L"Nothing can be said, as $d=0$",
L"The test does not apply, as $\nabla{f}$ is not $0$ at this point."
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
@@ -1914,8 +1921,8 @@ choices = [
L"Nothing can be said, as $d=0$",
L"The test does not apply, as $\nabla{f}$ is not $0$ at this point."
]
ans = 5
radioq(choices, ans, keep_order=true)
answ = 5
radioq(choices, answ, keep_order=true)
```
@@ -1962,8 +1969,8 @@ choices =[
"It is the determinant of the Hessian",
L"It isn't, $b^2-4ac$ is from the quadratic formula"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Which condition on $a$, $b$, and $c$ will ensure a *local maximum*:
@@ -1974,8 +1981,8 @@ choices = [
L"That $a<0$ and $ac-b^2 > 0$",
L"That $ac-b^2 < 0$"
]
ans = 2
radioq(choices, ans, keep_order=true)
answ = 2
radioq(choices, answ, keep_order=true)
```
Which condition on $a$, $b$, and $c$ will ensure a saddle point?
@@ -1987,8 +1994,8 @@ choices = [
L"That $a<0$ and $ac-b^2 > 0$",
L"That $ac-b^2 < 0$"
]
ans = 3
radioq(choices, ans, keep_order=true)
answ = 3
radioq(choices, answ, keep_order=true)
```
@@ -2016,8 +2023,8 @@ choices = [
raw"`` \langle 2x, y^2\rangle``",
raw"`` \langle x^2, 2y \rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Due to the form of the gradient of the constraint, finding when $\nabla{f} = \lambda \nabla{g}$ is the same as identifying when this ratio $|f_x/f_y|$ is $1$. The following solves for this by checking each point on the constraint:

View File

@@ -170,15 +170,12 @@ zs = [Z(theta, phi) for theta in thetas, phi in phis]
surface(xs, ys, zs) ## see note
```
```julis; echo=false
note("""Only *some* backends for `Plots` will produce this type of plot. Both `plotly()` and `pyplot()` will, but not `gr()`.
""")
```
!!! note
Only *some* backends for `Plots` will produce this type of plot. Both `plotly()` and `pyplot()` will, but not `gr()`.
```julia; echo=false
note("""Note: PyPlot can be used directly to make these surface plots: `import PyPlot; PyPlot.plot_surface(xs,ys,zs)`""")
```
!!! note
PyPlot can be used directly to make these surface plots: `import PyPlot; PyPlot.plot_surface(xs,ys,zs).
Instead of the comprehension, broadcasting can be used
@@ -856,8 +853,8 @@ choices = [
"Yes",
"No, it is the transpose"
]
ans=2
radioq(choices, ans, keep_order=true)
answ=2
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -879,8 +876,8 @@ choices = [
"Yes",
"No, it is the transpose"
]
ans=1
radioq(choices, ans, keep_order=true)
answ=1
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -907,8 +904,8 @@ choices = [
"The determinant of the Hessian.",
"The determinant of the gradient."
]
ans = 1
radioq(choices, ans, keep_order=true)
answ = 1
radioq(choices, answ, keep_order=true)
```
@@ -920,8 +917,8 @@ choices = [
"`det(hessian(F(lambda, phi), [lambda, phi]))`",
"`det(gradient(F(lambda, phi), [lambda, phi]))`"
]
ans=1
radioq(choices, ans, keep_order=true)
answ=1
radioq(choices, answ, keep_order=true)
```
###### Question
@@ -934,8 +931,8 @@ choices = [
raw"`` 2x^3y/ (z\cos(z) + \sin(z) + 1)``",
raw"`` 3x^2y^2``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -949,8 +946,8 @@ choices = [
raw"`` \frac{x \left(2 x^{2} - y^{2} z^{2}{\left (x,y \right )}\right)}{\left(x^{2} y^{2} - 2 z^{2}{\left (x,y \right )}\right) z{\left (x,y \right )}}``",
raw"`` \frac{x \left(2 x^{2} - z^{2}{\left (x,y \right )}\right)}{\left(x^{2} - 2 z^{2}{\left (x,y \right )}\right) z{\left (x,y \right )}}``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -965,8 +962,8 @@ choices = [
raw"`` S/r``",
raw"`` R``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Let $\phi = r^k$. What is $\nabla{\phi}$?
@@ -977,8 +974,8 @@ choices = [
raw"`` kr^k R``",
raw"`` k r^{k-2} S``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Based on your last answer, are all radial fields $R/r^n$, $n\geq 0$ gradients of scalar functions?
@@ -995,8 +992,8 @@ choices = [
raw"`` S/r``",
raw"`` S``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Express $S/r^n = \langle F_x, F_y\rangle$. For which $n$ is $\partial{F_y}/\partial{x} - \partial{F_x}/\partial{y} = 0$?
@@ -1008,8 +1005,8 @@ L"As the left-hand side becomes $(-n+2)r^{-n}$, only $n=2$.",
L"All $n \geq 0$",
L"No values of $n$"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
(The latter is of interest, as only when the expression is $0$ will the vector field be the gradient of a scalar function.)

View File

@@ -7,20 +7,26 @@ using CalculusWithJulia
using Plots
using SymPy
using Roots
using DifferentialEquations
using LinearAlgebra
using QuadGK
```
and
```julia
import DifferentialEquations
import DifferentialEquations: ODEProblem, Tsit5
```
```julia; echo=false; results="hidden"
using CalculusWithJulia.WeaveSupport
const frontmatter = (
title = "Vector-valued functions, ``f:R \\rightarrow R^n``",
description = "Calculus with Julia: Vector-valued functions, ``f:R \\rightarrow R^n``",
tags = ["CalculusWithJulia", "differentiable_vector_calculus", "vector-valued functions, ``f:R \\rightarrow r^n``"],
frontmatter = (
title = "Vector-valued functions, ``f:R \\rightarrow R^n``",
description = "Calculus with Julia: Vector-valued functions, ``f:R \\rightarrow R^n``",
tags = ["CalculusWithJulia", "differentiable_vector_calculus", "vector-valued functions, ``f:R \\rightarrow r^n``"],
);
import PlutoUI
nothing
```
@@ -150,7 +156,6 @@ ts = range(0, 6pi, length=200)
plot(unzip(g.(ts))..., camera=(0, 90))
```
The graph of $h$ shows that this function parameterizes a line in space. The line segment for $-2 \leq t \leq 2$ is shown below:
```julia; hold=true
@@ -163,18 +168,17 @@ plot(unzip(h.(ts))...)
While the `unzip` function is easy to understand as a function that reshapes data from one format into one that `plot` can use, it's usage is a bit cumbersome.
The `CalculusWithJulia` package provides a function `plot_parametric` which hides the use of `unzip` and the splatting within a function definition.
The function borrows a calling style for `Makie`. The interval to plot over is specified first using `a..b` notation (from `IntervalSets`), then the function is specified. Additional keyword arguments are passed along to `plot`.
The function borrows a calling style for `Makie`. The interval to plot
over is specified first using `a..b` notation (which specifies a
closed interval in the `IntervalSets` package), then the function is
specified. Additional keyword arguments are passed along to `plot`.
```julia;
plot_parametric(-2..2, h)
```
```julia; echo=false
note("""
Defining plotting functions in `Julia` for `Plots` is facilitated by the `RecipesBase` package. There are two common choices: creating a new function for plotting, as is done with `plot_parametric` and `plot_polar`; or creating a new type so that `plot` can dispatch to an appropriate plotting method. The latter would also be a reasonable choice, but wasn't taken here. In any case, each can be avoided by creating the appropriate values for `xs` and `ys` (and possibly `zs`).
""")
```
!!! note
Defining plotting functions in `Julia` for `Plots` is facilitated by the `RecipesBase` package. There are two common choices: creating a new function for plotting, as is done with `plot_parametric` and `plot_polar`; or creating a new type so that `plot` can dispatch to an appropriate plotting method. The latter would also be a reasonable choice, but wasn't taken here. In any case, each can be avoided by creating the appropriate values for `xs` and `ys` (and possibly `zs`).
##### Example
@@ -313,76 +317,83 @@ In 1935 [Marcel Duchamp](https://arthur.io/art/marcel-duchamp/rotorelief-no-10-c
* each nested circle is drawn after its center is rotated by ``\theta`` radian;
* an animation captures the movement for display.
```julia; hold=true;
```julia
let
# https://exploratorium.tumblr.com/post/33140874462/marcel-duchamp-rotoreliefs-duchamp-recognized
# coordinates and colors selected by gimp from
# https://arthur.io/art/marcel-duchamp/rotorelief-no-10-cage-modele-depose-verso
circs = [466 548 513 505 556 554 # x₁,y₁,x₂,y₂,x₂,y₃
414 549 511 455 595 549
365 545 507 408 635 548
319 541 506 361 673 546
277 543 509 317 711 546
236 539 507 272 747 551
201 541 504 230 781 550
166 541 503 189 816 544
140 542 499 153 848 538
116 537 496 119 879 538
96 539 501 90 905 534
81 530 500 67 930 530
72 525 498 51 949 529
66 520 500 36 966 527
60 515 499 25 982 526
35 509 499 11 1004 525 # outer edge, c₀
]
circs = [466 548 513 505 556 554 # x₁,y₁,x₂,y₂,x₂,y₃
414 549 511 455 595 549
365 545 507 408 635 548
319 541 506 361 673 546
277 543 509 317 711 546
236 539 507 272 747 551
201 541 504 230 781 550
166 541 503 189 816 544
140 542 499 153 848 538
116 537 496 119 879 538
96 539 501 90 905 534
81 530 500 67 930 530
72 525 498 51 949 529
66 520 500 36 966 527
60 515 499 25 982 526
35 509 499 11 1004 525 # outer edge, c₀
]
greenblue= RGB(8/100, 58/100, 53/100)
grey = RGB(76/100, 74/100, 72/100)
white = RGB(88/100, 85/100, 81/100)
greenblue= RGB(8/100, 58/100, 53/100)
grey = RGB(76/100, 74/100, 72/100)
white = RGB(88/100, 85/100, 81/100)
# solve for center of circle, radius for each
@syms h::positive k::positive r::positive
function solve_i(i)
eqs = [(p[1] - h)^2 + (p[2]-k)^2 ~ r^2 for
p ∈ (circs[i,1:2], circs[i,3:4], circs[i,5:6])]
d = solve(eqs)[1]
(x=float(d[h]), y=float(d[k]), r=float(d[r]))
end
c₀, cs... = solve_i.(16:-1:1) # c₀ is centered
# solve for center of circle, radius for each
@syms h::positive k::positive r::positive
function solve_i(i)
eqs = [(p[1] - h)^2 + (p[2]-k)^2 ~ r^2 for
p ∈ (circs[i,1:2], circs[i,3:4], circs[i,5:6])]
d = solve(eqs)[1]
(x=float(d[h]), y=float(d[k]), r=float(d[r]))
end
c₀, cs... = solve_i.(16:-1:1) # c₀ is centered
function duchamp_rotorelief_10(θ)
p = plot(legend=false,
axis=nothing, xaxis=false, yaxis=false,
aspect_ratio=:equal)
function duchamp_rotorelief_10(θ)
p = plot(legend=false,
axis=nothing, xaxis=false, yaxis=false,
aspect_ratio=:equal)
O = [c₀.x, c₀.y]
θ̂ = [cos(θ), sin(θ)]
O = [c₀.x, c₀.y]
θ̂ = [cos(θ), sin(θ)]
circle!(O, c₀.r, # outer ring is c₀
linewidth=2,
color=grey, fill=white,
seriestype=:shape)
circle!(O, c₀.r, # outer ring is c₀
linewidth=2,
color=grey, fill=white,
seriestype=:shape)
for (i,c) ∈ enumerate(cs) # add nested rings
rᵢ = sqrt((c₀.x - c.x)^2+(c₀.y - c.y)^2)
P = O + rᵢ * θ̂ # rotate about origin by θ
circle!(P, c.r,
linewidth = i == 1 ? 1 : i <= 3 ? 2 : 3,
color=greenblue)
end
p
for (i,c) ∈ enumerate(cs) # add nested rings
rᵢ = sqrt((c₀.x - c.x)^2+(c₀.y - c.y)^2)
P = O + rᵢ * θ̂ # rotate about origin by θ
circle!(P, c.r,
linewidth = i == 1 ? 1 : i <= 3 ? 2 : 3,
color=greenblue)
end
p
# animate using Plots.@animate macro
anim = @animate for θ ∈ range(0, -2π, length=60)
duchamp_rotorelief_10(θ)
end
fname = tempname() * ".gif"
gif(anim, fname, fps = 40)
end
```
# animate using Plots.@animate macro
anim = @animate for θ ∈ range(0, -2π, length=60)
duchamp_rotorelief_10(θ)
end
fname = tempname() * ".gif"
gif(anim, fname, fps = 40)
PlutoUI.LocalResource(fname) # to display w/in Pluto
```julia; echo=false
#import PlutoUI
#PlutoUI.LocalResource(fname) # to display w/in Pluto
nothing
```
##### Example
@@ -1279,6 +1290,7 @@ ts = range(t_span..., length=1001)
surface(unzip(r_0.(ts, θs'))...)
```
## Arc length
In [Arc length](../integrals/arc_length.html) there is a discussion of how to find the arc length of a parameterized curve in ``2`` dimensions. The general case is discussed by [Destafano](https://randomproofs.files.wordpress.com/2010/11/arc_length.pdf) who shows:
@@ -1456,7 +1468,8 @@ Here, when $b$ gets large, the curve looks more and more "straight" and the tors
[Levi and Tabachnikov](https://projecteuclid.org/download/pdf_1/euclid.em/1259158427) consider the trajectories of the front and rear bicycle wheels. Recall the notation previously used: $\vec{F}(t)$ for the front wheel, and $\vec{B}(t)$ for the rear wheel trajectories. Consider now their parameterization by arc length, using $u$ for the arc-length parameter for $\vec{F}$ and $v$ for $\vec{B}$. We define $\alpha(u)$ to be the steering angle of the bicycle. This can be found as the angle between the tangent vector of the path of $\vec{F}$ with the vector $\vec{B} - \vec{F}$. Let $\kappa$ be the curvature of the front wheel and $k$ the curvature of the back wheel.
```julia; hold=true; echo=false
```julia; echo=false
let
a = 1
F(t) = [cos(pi/2 - t), 2sin(pi/2-t)]
p = (a, F)
@@ -1486,6 +1499,7 @@ annotate!([(-.5,1.5,L"k"),
(.85, 1.3, L"\alpha")])
plt
end
```
Levi and Tabachnikov prove in their Proposition 2.4:
@@ -1510,10 +1524,12 @@ when a curve is parameterized by arc length, the curvature is more directly comp
The tangent vector is of unit length, when parametrized by arc length. This implies its derivative will be orthogonal. If $\vec{r}(t)$ is a parameterization by arc length, then the curvature formula simplifies as:
```math
\kappa(s) = \frac{\| \vec{r}'(s) \times \vec{r}''(s) \|}{\|\vec{r}'(s)\|^3} =
\frac{\| \vec{r}'(s) \times \vec{r}''(s) \|}{1} =
\| \vec{r}'(s) \| \| \vec{r}''(s) \| \sin(\theta) =
1 \| \vec{r}''(s) \| 1 = \| \vec{r}''(s) \|.
\begin{align*}
\kappa(s) &= \frac{\| \vec{r}'(s) \times \vec{r}''(s) \|}{\|\vec{r}'(s)\|^3} \\
&= \frac{\| \vec{r}'(s) \times \vec{r}''(s) \|}{1} \\
&= \| \vec{r}'(s) \| \| \vec{r}''(s) \| \sin(\theta) \\
&= 1 \| \vec{r}''(s) \| 1 = \| \vec{r}''(s) \|.
\end{align*}
```
@@ -1867,24 +1883,27 @@ Let ``r`` be the radius of a circle and for concreteness we position it at ``(-r
* Between angles ``\pi/2`` and until the horse's ``y`` position is ``0`` when the tether is taut the boundary of what can be eaten is described by the involute.
* The horse can't eat from withing the circle or radius ``r``.
```julia; hold=true; echo=false
r,R = 1, 10
R = max(R, pi*r) # R 1/2 circumference
```julia; echo=false
let
r,R = 1, 10
R = max(R, pi*r) # R ≥ 1/2 circumference
γ(θ) = -2r*cos(θ) * [cos(θ), sin(θ)] # parameterize the circle of radius r
involute(t) = γ(t) + γ'(t)/norm(γ'(t))* (R - quadgk(u -> norm(γ'(u)), pi/2, t)[1])
t₀ = find_zero(t -> round(involute(t)[2], digits=4), (3pi/4, pi))
γ(θ) = -2r*cos(θ) * [cos(θ), sin(θ)] # parameterize the circle of radius r
involute(t) = γ(t) + γ'(t)/norm(γ'(t))* (R - quadgk(u -> norm(γ'(u)), pi/2, t)[1])
t₀ = find_zero(t -> round(involute(t)[2], digits=4), (3pi/4, pi))
p = plot(; legend=false)
plot_polar!(0..(pi/2), t -> R) # unobstructed -> quarter circle
plot_parametric!((pi/2)..t₀, involute)
plot_parametric!((pi/2)..pi, γ)
plot!([0,R],[0,0])
p = plot(; legend=false)
plot_polar!(0..(pi/2), t -> R) # unobstructed -> quarter circle
plot_parametric!((pi/2)..t₀, involute)
plot_parametric!((pi/2)..pi, γ)
plot!([0,R],[0,0])
end
```
To solve for the area we parameterize the circle of radius ``r`` between ``\pi/2`` and when the involute would cross the ``x`` axis. We use `find_zero` to identify the value.
```julia; hold=true
```julia
let
r,R = 160/(2π), 160
R = max(R, pi*r) # R ≥ 1/2 circumference
γ(θ) = -2r*cos(θ) * [cos(θ), sin(θ)]
@@ -1899,6 +1918,7 @@ x(t) = (h=1e-4; (involute(t+h)[1]-involute(t-h)[1])/(2h))
A₂ = quadgk(t -> -y(t)*x(t), pi/2, t₀)[1] # A₂ = -∫ y dx, as counterclockwise parameterization
A₃ = (1/2) * π * r^2
2 * (A₁ + A₂ - A₃)
end
```
The calculation for ``A_1`` and ``A_3`` are from the familiar formula for the area of a circle. However, ``A_2`` requires the formula for area above the ``x`` axis when the curve is parameterized: ``A = -\int_a^b y(t) x'(t) dt``, given how the curve is parameterized. As written, the automatic derivative of the numeric integral gives an error, so a central-difference approximation is used for ``x'(t)``.
@@ -1920,8 +1940,8 @@ choices = [
q"[0.0782914, 0.292893 ]",
q"[0.181172, 0.5]",
q"[0.570796, 1.0]"]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
And the position at $\pi/2$?
@@ -1932,8 +1952,8 @@ choices = [
q"[0.0782914, 0.292893 ]",
q"[0.181172, 0.5]",
q"[0.570796, 1.0]"]
ans = 3
radioq(choices, ans)
answ = 3
radioq(choices, answ)
```
###### Question
@@ -1946,8 +1966,8 @@ choices = [
" ``\\langle Rt - R\\sin(t),~ R - R\\cos(t) \\rangle``",
" ``\\langle -r\\sin(t),~ -r\\cos(t) \\rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1961,8 +1981,8 @@ choices = [
" ``1 - \\cos(t)``",
" ``1 + \\cos(t) + \\cos(2t)``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1995,8 +2015,8 @@ q"[1,1]",
q"[2,0]",
q"[0,0]"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
What is the derivative at $t=\pi$?
@@ -2008,8 +2028,8 @@ q"[1,1]",
q"[2,0]",
q"[0,0]"
]
ans = 2
radioq(choices, ans)
answ = 2
radioq(choices, answ)
```
###### Question
@@ -2023,8 +2043,8 @@ choices = [
" ``R``",
" ``R^2``"
]
ans = 3
radioq(choices, ans, keep_order=true)
answ = 3
radioq(choices, answ, keep_order=true)
```
@@ -2053,8 +2073,8 @@ choices = [
" ``1``",
" ``t + t^2``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Numerically find the arc length.
@@ -2089,8 +2109,8 @@ choices = [
"greater than the curvature at ``t=0``",
"less than the curvature at ``t=0``",
"the same as the curvature at ``t=0``"]
ans = 2
radioq(choices, ans)
answ = 2
radioq(choices, answ)
```
The curvature as $t\rightarrow \infty$ will be
@@ -2101,8 +2121,8 @@ choices = [
" ``\\infty``",
" ``1``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
----
@@ -2116,8 +2136,8 @@ choices = [
" ``2``",
" ``1``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -2132,8 +2152,8 @@ x0 = [0,0,5]
v0 = [120, -2, 2]
a = [0, 16, -32]
r(t) = x0 + v0*t + 1/2*a*t^2
ans = 60/v0[1]
numericq(ans)
answ = 60/v0[1]
numericq(answ)
```
At $t=1/4$ the ball is half-way to home. If the batter reads the ball at this point, where in the $y$ direction is the ball?
@@ -2144,8 +2164,8 @@ v0 = [120, -2, 2]
a = [0, 16, -32]
r(t) = x0 + v0*t + 1/2*a*t^2
t = 1/4
ans = r(t)[2]
numericq(ans)
answ = r(t)[2]
numericq(answ)
```
At $t=1/2$ has the ball moved more than ``1/2`` foot in the $y$ direction?
@@ -2156,8 +2176,8 @@ v0 = [120, -2, 2]
a = [0, 16, -32]
r(t) = x0 + v0*t + 1/2*a*t^2
t = 1/2
ans = abs(r(t)[2]) > 1/2
yesnoq(ans)
answ = abs(r(t)[2]) > 1/2
yesnoq(answ)
```
@@ -2201,8 +2221,8 @@ choices = [
" ``2\\tan(\\theta)``",
" ``\\tan(\\theta)``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Using the polar form of a circle, the length between the origin and $B$ is given by $2\cos(\theta-\pi/2) = 2\sin(\theta)$. Using this, what is the $y$ coordinate of $B$?
@@ -2214,8 +2234,8 @@ choices = [
" ``2``",
" ``\\sin(\\theta)``"
]
ans=1
radioq(choices, ans)
answ=1
radioq(choices, answ)
```
@@ -2229,8 +2249,8 @@ choices = [
" ``t^n + t^{n+1}``",
" ``\\sqrt{n^2 + t^2}``"
]
ans=1
radioq(choices, ans)
answ=1
radioq(choices, answ)
```
For $n=2$, the arc length of $\vec{r}$ can be found exactly. What is the arc-length between $0 \leq t \leq a$?
@@ -2241,8 +2261,8 @@ choices = [
" ``\\frac{2 a^{\\frac{5}{2}}}{5}``",
" ``\\sqrt{a^2 + 4}``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -2257,30 +2277,32 @@ choices = [
" ``\\pi/2``",
" ``2``"
]
ans = 2
radioq(choices, ans, keep_order=true)
answ = 2
radioq(choices, answ, keep_order=true)
```
###### Question
```julia; hold=true; echo=false
t0, t1 = pi/12, pi/3
tspan = (t0, t1) # time span to consider
```julia; echo=false
let
t0, t1 = pi/12, pi/3
tspan = (t0, t1) # time span to consider
a = 1
r(theta) = -cos(theta) + 4*2cos(theta)*sin(theta)^2
F(t) = r(t) * [cos(t), sin(t)]
p = (a, F) # combine parameters
a = 1
r(theta) = -cos(theta) + 4*2cos(theta)*sin(theta)^2
F(t) = r(t) * [cos(t), sin(t)]
p = (a, F) # combine parameters
B0 = F(0) - [0, a] # some initial position for the back
prob = ODEProblem(bicycle, B0, tspan, p)
B0 = F(0) - [0, a] # some initial position for the back
prob = ODEProblem(bicycle, B0, tspan, p)
out = solve(prob, reltol=1e-6, Tsit5())
out = solve(prob, reltol=1e-6, Tsit5())
plt = plot(unzip(F, t0, t1)..., legend=false, color=:red)
plot!(plt, unzip(t->out(t), t0, t1)..., color=:blue)
plt = plot(unzip(F, t0, t1)..., legend=false, color=:red)
plot!(plt, unzip(t->out(t), t0, t1)..., color=:blue)
end
```
@@ -2291,8 +2313,8 @@ choices = [
"The front wheel",
"The back wheel"
]
ans=1
radioq(choices, ans)
answ=1
radioq(choices, answ)
```
@@ -2300,22 +2322,24 @@ radioq(choices, ans)
###### Question
```julia; hold=true; echo=false
t0, t1 = 0.0, pi/3
tspan = (t0, t1) # time span to consider
```julia; echo=false
let
t0, t1 = 0.0, pi/3
tspan = (t0, t1) # time span to consider
a = 1
r(t) = 3a * cos(2t)cos(t)
F(t) = r(t) * [cos(t), sin(t)]
p = (a, F) # combine parameters
a = 1
r(t) = 3a * cos(2t)cos(t)
F(t) = r(t) * [cos(t), sin(t)]
p = (a, F) # combine parameters
B0 = F(0) - [0, a] # some initial position for the back
prob = ODEProblem(bicycle, B0, tspan, p)
B0 = F(0) - [0, a] # some initial position for the back
prob = ODEProblem(bicycle, B0, tspan, p)
out = solve(prob, reltol=1e-6, Tsit5())
out = solve(prob, reltol=1e-6, Tsit5())
plt = plot(unzip(F, t0, t1)..., legend=false, color=:blue)
plot!(plt, unzip(t->out(t), t0, t1)..., color=:red)
plt = plot(unzip(F, t0, t1)..., legend=false, color=:blue)
plot!(plt, unzip(t->out(t), t0, t1)..., color=:red)
end
```
@@ -2326,8 +2350,8 @@ choices = [
"The front wheel",
"The back wheel"
]
ans=2
radioq(choices, ans)
answ=2
radioq(choices, answ)
```
@@ -2357,8 +2381,8 @@ If a car is on a straight road, then $\kappa=0$. Is the acceleration along the $
choices = [
"The ``\\hat{T}`` direction",
"The ``\\hat{N}`` direction"]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Suppose no gas or brake is applied for a duration of time. The tangential acceleration will be $0$. During this time, which of these must be $0$?
@@ -2369,8 +2393,8 @@ choices = [
" ``ds/dt``",
" ``d^2s/dt^2``"
]
ans = 3
radioq(choices, ans, keep_order=true)
answ = 3
radioq(choices, answ, keep_order=true)
```
In going around a corner (with non-zero curvature), which is true?
@@ -2381,8 +2405,8 @@ choices = [
"The acceleration in the normal direction depends only on the curvature and not the speed (``ds/dt``)",
"The acceleration in the normal direction depends only on the speed (``ds/dt``) and not the curvature"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -2409,8 +2433,8 @@ choices = [
" ``1 + 2t``",
" ``1 - 2t``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
* Compute $k(t)$
@@ -2422,8 +2446,8 @@ choices = [
" ``8t``",
" ``-8t``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
* Compute $X(t)$
@@ -2435,8 +2459,8 @@ choices = [
" ``t - 2(8t)/(1-2t)``",
" ``t - 1(1+4t^2)/2``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
* Compute $Y(t)$
@@ -2448,8 +2472,8 @@ choices = [
" ``t^2 - 1(1+4t^2)/2``",
" ``t^2 - 2t(1+4t^2)/2``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -2477,6 +2501,6 @@ choices = [
"An ellipse of the form ``\\langle a\\cos(t), b\\sin(t)``",
"A cyloid of the form ``c\\langle t + \\sin(t), 1 - \\cos(t)\\rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```

View File

@@ -363,9 +363,9 @@ Starting with three vectors, we can create three orthogonal vectors using projec
Let's begin with three vectors in $R^3$:
```julia;
u = [1, 2, 3]
v = [1, 1, 2]
w = [1, 2, 4]
u = [1, 2, 3]
v = [1, 1, 2]
w = [1, 2, 4]
```
We can find a vector from `v` orthogonal to `u` using:
@@ -374,14 +374,14 @@ We can find a vector from `v` orthogonal to `u` using:
unit_vec(u) = u / norm(u)
projection(u, v) = (u ⋅ unit_vec(v)) * unit_vec(v)
v⃗⟂ = v - projection(v, u)
w⃗⟂ = w - projection(w, u) - projection(w, v⃗⟂)
v = v - projection(v, u)
w = w - projection(w, u) - projection(w, v)
```
We can verify the orthogonality through:
```julia;
u ⋅ v⃗⟂, u ⋅ w⃗⟂, v⃗⟂ ⋅ w⃗⟂
u ⋅ v, u ⋅ w, v ⋅ w
```
This only works when the three vectors do not all lie in the same plane. In general, this is the beginning of the [Gram-Schmidt](https://en.wikipedia.org/wiki/Gram-Schmidt_process) process for creating *orthogonal* vectors from a collection of vectors.
@@ -839,11 +839,8 @@ The volume of a parallelepiped is the area of a base parallelogram times the hei
that is, the area of the parallelepiped. Wait, what about $(\vec{v}\times\vec{u})\cdot\vec{w}$? That will have an opposite sign. Yes, in the above, there is an assumption that $\vec{n}$ and $\vec{w}$ have a an angle between them within $[0, \pi/2]$, otherwise an absolute value must be used, as volume is non-negative.
```julia; echo=false
note(L"""
The triple-scalar product, $\vec{u}\cdot(\vec{v}\times\vec{w})$, gives the volume of the parallelepiped up to sign. If the sign of this is positive, the ``3`` vectors are said to have a *positive* orientation, if the triple-scalar product is negative, the vectors have a *negative* orientation.
""", title="Orientation")
```
!!! note "Orientation"
The triple-scalar product, $\vec{u}\cdot(\vec{v}\times\vec{w})$, gives the volume of the parallelepiped up to sign. If the sign of this is positive, the ``3`` vectors are said to have a *positive* orientation, if the triple-scalar product is negative, the vectors have a *negative* orientation.
#### Algebraic properties
@@ -1046,8 +1043,8 @@ Are `v` and `w` orthogonal?
```julia; hold=true; echo=false
u,v,w = [1,2,3], [4,3,2], [5,2,1]
ans = dot(v,w) == 0
yesnoq(ans)
answ = dot(v,w) == 0
yesnoq(answ)
```
Find the angle between `u` and `w`:
@@ -1068,8 +1065,8 @@ choices = [
"`[-1, 6, -7]`",
"`[-4, 14, -8]`"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
Find the area of the parallelogram formed by `v` and `w`
@@ -1114,8 +1111,8 @@ choices = [
"An object of type `Base.Iterators.Zip` that is only realized when used",
"A vector of values `[(1, 5), (2, 4), (3, 2)]`"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
What does `prod.(zip(u,v))` return?
@@ -1125,8 +1122,8 @@ choices = [
"A vector of values `[5, 8, 6]`",
"An object of type `Base.Iterators.Zip` that when realized will produce a vector of values"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1143,8 +1140,8 @@ choices = [
"``0``",
"Can't say in general"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1167,8 +1164,8 @@ choices = [
"``x + 2y + z = 0``",
"``x + 2y + 3z = 6``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1181,8 +1178,8 @@ choices = [
" ``\\vec{v}`` is in plane ``P_1``, as it is orthogonal to ``\\vec{n}_1`` and ``P_2`` as it is orthogonal to ``\\vec{n}_2``, hence it is parallel to both planes.",
" ``\\vec{n}_1`` and ``\\vec{n_2}`` are unit vectors, so the cross product gives the projection, which must be orthogonal to each vector, hence in the intersection"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1195,8 +1192,8 @@ choices = [
"``\\langle 12, 12 \\rangle``",
"``12 \\langle 1, 0 \\rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
If the vector to 3 o'clock is removed, (call this $\langle 1, 0 \rangle$) what expresses the sum of *all* the remaining vectors?
@@ -1207,8 +1204,8 @@ choices = [
"``\\langle 1, 0 \\rangle``",
"``\\langle 11, 11 \\rangle``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1221,8 +1218,8 @@ choices = [
"``\\vec{u} + \\vec{v}``",
"``\\vec{u}\\cdot\\vec{v} + \\vec{v}\\cdot \\vec{v}``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
As the two are equal, which interpretation is true?
@@ -1233,8 +1230,8 @@ choices = [
"The vector ``\\vec{w}`` must also be a unit vector",
"the two are orthogonal"
]
ans=1
radioq(choices, ans)
answ=1
radioq(choices, answ)
```
@@ -1251,8 +1248,8 @@ choices = [
"``\\vec{u}\\cdot\\vec{v} = 2``",
"``\\vec{u}\\cdot\\vec{v} = -(\\vec{u}\\cdot\\vec{u} \\vec{v}\\cdot\\vec{v})``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
@@ -1274,8 +1271,8 @@ choices = [
"The vectors are *orthogonal*, so these are all zero",
"The vectors are all unit lengths, so these are all 1"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1311,8 +1308,8 @@ choices = [
"``n_1 (\\hat{v_1}\\times\\hat{N}) = n_2 (\\hat{v_2}\\times\\hat{N})``",
"``n_1 (\\hat{v_1}\\times\\hat{N}) = -n_2 (\\hat{v_2}\\times\\hat{N})``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```
###### Question
@@ -1334,6 +1331,6 @@ choices = [
"``\\vec{a}``",
"``\\vec{a} + \\vec{b} + \\vec{c}``"
]
ans = 1
radioq(choices, ans)
answ = 1
radioq(choices, answ)
```