This commit is contained in:
jverzani 2023-03-28 11:02:18 -04:00
parent 377c9f0238
commit ed5434bb1c
13 changed files with 187 additions and 32 deletions

View File

@ -92,6 +92,12 @@ DONE * modify sympy's show method
## TODO
* Old and new astronomy; : Proctor, Richard Anthony, 1837-1888 : Free Download, Borrow, and Streaming : Internet Archive
https://archive.org/details/oldnewastronomy00procuoft
https://ia800908.us.archive.org/16/items/oldnewastronomy00procuoft/oldnewastronomy00procuoft.pdf has interesting epicycle figures on p 186/886. Could add these in.
* ImageFile -> ![]() as much as possible
* use pandoc references(?)
* mermaid, ojs?
@ -103,3 +109,19 @@ DONE * remove pinned header
DONE * clean up directory
DONE (?) * JSXGraph files
WON'T DO * download links to Pluto .jl files (if we have .jmd, but we might deprecate...) For *now* .jmd is derprecated; though we keep the files around ....
## Cone, general
# https://discourse.julialang.org/t/general-plotting-code-for-cone-in-3d-with-glmakie-or-plots/92104/3
basecurve(u) = [cos(u), sin(u) + sin(u/2), 0]
Vertex = [0, 3/4, 3]
function Cone(u, t)
x, y, z = basecurve(u)
t * ([x,y,z] - Vertex) + Vertex
end
us = range(0, 2pi, length=50)
ts = range(0, 1, length=50)
xyzs = Cone.(us, ts')
surface(CalculusWithJulia.unzip(xyzs))

View File

@ -668,6 +668,16 @@ answ = 3
radioq(choices, answ)
```
###### Question
Consider the function `f(x) = airyai(x)`. What is the value of $f''(x) - x\cdot f(x)$ at $x=\pi$?
```{julia}
#| echo: false
numericq(0; hint=raw"Any value of $x$ will produce the same answer")
```
###### Question

View File

@ -373,7 +373,7 @@ surface(xs, ys, zs)
:::{.callout-note}
## 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, `a..b`, and a function:
@ -384,6 +384,31 @@ F(theta, phi) = [X(1, theta, phi), Y(1, theta, phi), Z(1, theta, phi)]
plot_parametric(0..pi, 0..pi/2, F)
```
##### Example, the general cone
The general equation of cone consists of a vertex, $V$, and a base curve. The cone consists of all line segments connecting $V$ to the base curve, here parameterized and in the $x-y$ plane: $r(u) = \langle x(u), y(u), 0 \rangle$. The equations for the cone are:
$$
\frac{x - V_x}{x(u)-V_x} = \frac{y - V_y}{y(u)-V_y} = \frac{z - V_z}{z(u)-V_z} = t,
$$
where $t \in [0,1]$ This gives a vector-valued function
$$
F(u, t) = t * (r(u) - V) + V, \quad \alpha \leq u \leq \beta, 0 \leq t \leq 1.
$$
To illustrate, we have:
```{julia}
# cf. https://discourse.julialang.org/t/general-plotting-code-for-cone-in-3d-with-glmakie-or-plots/92104/3
basecurve(u) = [cos(u), sin(u) + sin(u/2), 0]
Vertex = [0, 3/4, 3]
Cone(u, t) = t * (basecurve(u) - Vertex) + Vertex
plot_parametric(0..2pi, 0..1, Cone)
```
### Plotting F(x,y, z) = c

View File

@ -232,6 +232,7 @@ plot_parametric(0..2pi, f, legend=false)
scatter!([0],[0], markersize=4)
```
##### Example

View File

@ -11,7 +11,7 @@ This is a set of notes for learning
programming language with an easy to learn syntax that is well suited
for this task.
Read "[Getting started with Julia](./misc/getting_started_with_julia.html)" to learn how to install and customize `Julia` for following along with these notes. Read "[Julia interfaces](.misc/julia_interfaces.html) to review different ways to interact with a `Julia` installation.
Read "[Getting started with Julia](./misc/getting_started_with_julia.html)" to learn how to install and customize `Julia` for following along with these notes. Read "[Julia interfaces](./misc/julia_interfaces.html) to review different ways to interact with a `Julia` installation.
Since the mid 90s there has been a push to teach calculus using many
different points of view. The

View File

@ -716,6 +716,9 @@ endpoints(ys, x) = callf.(ys, Ref(x))
xs)
```
The one issue with the above is the tolerances should increase for each outer integration. Otherwise, a certain precision is expected for a noisier integrand. This isn't an issue for many integrands, but can become one.
##### Example

View File

@ -608,26 +608,23 @@ 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 the Riemann sum for us with an extra argument to specifying one of four methods for computing $c_i$:
Before continuing, we define a function to compute Riemann sums for us with an extra argument to specifying one of four methods for computing $c_i$:
```{julia}
#| eval: false
function riemann(f::Function, a::Real, b::Real, n::Int; method="right")
if method == "right"
meth = f -> (lr -> begin l,r = lr; f(r) * (r-l) end)
elseif method == "left"
meth = f -> (lr -> begin l,r = lr; f(l) * (r-l) end)
elseif method == "trapezoid"
meth = f -> (lr -> begin l,r = lr; (1/2) * (f(l) + f(r)) * (r-l) end)
elseif method == "simpsons"
meth = f -> (lr -> begin l,r=lr; (1/6) * (f(l) + 4*(f((l+r)/2)) + f(r)) * (r-l) end)
end
xs = range(a, b, n+1)
pairs = zip(xs[begin:end-1], xs[begin+1:end]) # (x₀,x₁), …, (xₙ₋₁,xₙ)
sum(meth(f), pairs)
riemann(f, a, b, n; method="right") = riemann(f, range(a,b,n+1); method=method)
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))),
)
_riemann(Ms[Symbol(method)], f, xs)
end
function _riemann(M, f, xs)
xs = zip(Iterators.drop(xs, 1), Iterators.rest(xs, 1))
sum(M(f, a, b) * (b-a) for (a,b) ∈ xs)
end
```

View File

@ -276,6 +276,20 @@ find_zero(m -> area(m) - 1, (0, 1))
(Which is a nice combination of using `find_zeros`, `quadgk` and `find_zero` to answer a problem.)
##### Example
In an early 2023 article appearing in the [New York Times](https://www.nytimes.com/2023/02/02/opinion/covid-pandemic-deaths.html) a discussion on *excess* deaths was presented. @fig-excess-deaths shows two curves from which the number of excess deaths can be computed.
::: {#fig-excess-deaths}
![Excess deaths](./figures/excess-deaths.png)
Illustration of excess deaths. Figure from a Feb. 2023 New York Times article
:::
Consider the curve marked *Actual deaths*. The number of deaths per year is the sum over each day of the number of deaths per each day. Approximating this number with a curve and setting 1 day equal to 1 unit, the number of deaths is basically $\int_0^{365} d(t) dt$. This curve is *usually*, say, $u(t)$, so the expected number of deaths would be $\int_0^{365} u(t) dt$. The difference, $\int_0^{365} (d(t) - u(t))dt$ is interpreted as the number of *excess deaths*. This methodology has been used to estimate the true number of deaths attributable to the COVID-19 pandemic.
##### Example
@ -740,11 +754,11 @@ Doubling the answer above gives a value that Galileo had struggled with for many
#| echo: false
imgfile="figures/companion-curve-bisects-rectangle.png"
caption = """
Roberval, avoiding a trignometric integral, instead used symmetry to show that the area under the companion curve was half the area of the rectangle, which in this figure is ``2\\pi``.
Roberval, avoiding a trignometric integral, instead used symmetry to show that the area under the companion curve was half the area of the rectangle, which in this figure is `2pi`.
"""
# ImageFile(:integrals, imgfile, caption)
nothing
```
![Roberval, avoiding a trignometric integral, instead used symmetry to show that the area under the companion curve was half the area of the rectangle, which in this figure is ``2\\pi``.
![Roberval, avoiding a trignometric integral, instead used symmetry to show that the area under the companion curve was half the area of the rectangle, which in this figure is $2\pi$.
](./figures/companion-curve-bisects-rectangle.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

View File

@ -190,32 +190,46 @@ A right triangle has sides $a=11$ and $b=12$. Find the length of the hypotenus
##### Example
An article in the [Washington Post](https://www.washingtonpost.com/climate-environment/2022/09/19/ants-population-20-quadrillion/) describes estimates for the number of ants on earth.
A overview of a research paper published in [theconversation.com](https://theconversation.com/earth-harbours-20-000-000-000-000-000-ants-and-they-weigh-more-than-wild-birds-and-mammals-combined-190831) reviews six authors' work on estimating the number of ants currently on earth. This was covered in an
article in the [Washington Post](https://www.washingtonpost.com/climate-environment/2022/09/19/ants-population-20-quadrillion/).
They describe the number of ants two ways:
The authors describe the number of ants two ways:
* There are $20$ *trillion* ants.
* There are $12$ megatons of ants
* There are $20 \cdot 10^{15}$ (20 *quadrillion* or 20 thousand million millions) ants.
With this how many ants make up a pound?
* There is an estimated total biomass of $12$ megatons of *dry* carbon.
Below we use the underscore as a separator, which is parsed as commas are to separate groups of numbers. The calculation is the number of ants divided by the number of pounds of ants (one megaton is $1$ million pounds):
The authors note in a supplement to their paper that over 15,700 species and subspecies of ants have been named. To get a good estimate, 489 studies of ant populations were combined spanning all continents and major habitats. The studies identify the number of *foraging* ants and combined yield the estimates for the *epigaeic ant abundance* ($3.02 \cdot 10^{15}$) and the *arboreal ant abundance* ($1.34\cdot 10^{15}$). Using an estimate of 22% of ants in a colony are foraging, they get the following estimate for the number of ants:
```{julia}
20_000_000_000_000_000 / (1_000_000 * 12 * 2000)
(3.02 * 10^15 + 1.34*10^15) * 100 / 22
```
Or not quite a million per pound.
Using a pound is $2.2$ killograms or $2,200$ grams, we can this many ants per gram:
Shifting the decimal point, this gives a value rounded to $20\cdot 10^{15}$ ants.
The authors used a value for the *dry weight* of an average (and representative) single ant. What was that value? (Which they indicate is perhaps unreliable,
as, for example, small-bodied ants may be much more abundant than large-bodied ants). We assume below that one "megaton" is $1$ million *metric* tons; a metric ton is $1,000$ kilograms; and a kilogram $1,000$ grams:
```{julia}
20_000_000_000_000_000 / (1_000_000 * 12 * 2000) / 2200
(12 * 1_000_000 * 1_000 * 1_000) / 20_000_000_000_000_000
```
Such combinations will be easier to check for correctness when variable names are assigned the respective values.
Which translates to an *average* dry *carbon* weight of $0.6/1000$ grams, that is $0.6$ milligrams ($0.62$ mg C was actually used).
The authors write that insects are generally considered to have a dry weight of 30% wet weight, and a carbon weight of 50% dry weight, so the weight in grams of an *average* living ant would be multiplied by $2$ and then $10/3$:
```{julia}
(12 * 1_000_000 * 1_000 * 1_000) / 20_000_000_000_000_000 * (2 * 10/3)
```
That is 4 milligrams, or 250 ants per gram on average.
Numeric combinations, as above, will be easier to check for correctness when variable names are assigned to the respective values.
Using the underscore, as above, to separate groups of digits, is helpful, as an alternate to scientific notation, when working with large numbers.
@ -1094,7 +1108,21 @@ answ=1
radioq(choices, answ)
```
##### Question
[Sagan's](https://en.wiktionary.org/wiki/Sagan%27s_number) number is defined to be the total number of stars in the observable universe. How big is it? A *sextillion* is 7 groups of three 0's after a leading 1. One estimate is $10$ sextillion. How might this be entered into `Julia`? Select the one that *doesn't* work:
```{julia}
choices = [
"`10*10^21`",
"`10*10.0^21`",
"`10e21`",
"`1e22`",
"`10_000_000_000_000_000_000_000`"]
explanation = "With an *integer* base, `10^21` overflows. For typical integers, onmly `10^18` is defined as expected. Once `10^19` is entered the mathematical value is larger the the `typemax` for `Int64` and so the value *wraps* around. The number written out with underscores to separate groups of 0s is parsed as an integer with 128 bits, not 64."
buttonq(choices, 1; explanation=explanation)
The estimate of 10 sextillion for Sagan's number was made in 1980, a more modern estimate is 30 times larger.
##### Question

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -459,6 +459,13 @@ plot!(x -> -x^4, -3,3, legend=false, xticks=false, yticks=false, subplot=3, titl
plot!(x -> -x^5, -3,3, legend=false, xticks=false, yticks=false, subplot=4, title="n > odd, aₙ < 0")
```
##### Example
This graphic shows some of the above:
[![you tube](https://img.youtube.com/vi/OFzqDatEvCo/3.jpg)](https://m.youtube.com/watch?v=OFzqDatEvCo)
##### Example

View File

@ -111,6 +111,54 @@ a = v0 * cosd(theta)
By defining a new variable `a` to represent a value that is repeated a few times in the expression, the last command is greatly simplified. Doing so makes it much easier to check for accuracy against the expression to compute.
##### Example
A [grass swale](https://stormwater.pca.state.mn.us/index.php?title=Design_criteria_for_dry_swale_(grass_swale)) is a design to manage surface water flow resulting from a storm. Swales detain, filter, and infiltrate runoff limiting erosion in the process.
![Swale cross section](precalc/swale.png)
There are a few mathematical formula that describe the characteristics of swale:
The area is given by:
$$
A = (b + d/\tan(\theta)) d
$$
The *wetted* perimeter is given by
$$
P = b + 2 d/\sin(\theta)
$$
The *hydraulic radius* is given by
$$
R = \frac{b\cdot d \sin(\theta) + d^2 \cos(\theta)}{b\sin(\theta) + 2d}.
$$
Finally, the *flow quantity* is given by *Manning's* formula:
$$
Q = vA = \frac{R^{2/3} S^{1/2}}{n}, \quad R = \frac{A}{P}.
$$
With $n$ being Manning's coefficient, $v$ the velocity in feet per second, and $S$ being the slope. Velocity and slope are correlated.
Manning's coefficient depends on the height of the vegetation in the grass swale. It is $0.025$ when the depth of flow is similar to the vegetation height.
Given all this, compute the flow quantity when $S = 2/90$, $n=0.025$ and $v=1/10$ for a swale with characteristics $b=1$, $\theta=\pi/4$, $d=1$.
```{julia}
b, theta, d = 1, pi/4, 1
n, S = 0.025, 2/90
A = (b + d/tan(theta)) * d
P = b + 2d/sin(theta)
R = A / P
Q = R^(2/3) * S^(1/2) / n
```
##### Example