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

@@ -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