many edits

This commit is contained in:
jverzani
2024-04-26 18:26:12 -04:00
parent 6e807edb46
commit 4f924557ad
45 changed files with 326 additions and 296 deletions

View File

@@ -369,8 +369,10 @@ Any partition $a =x_0 < x_1 < \cdots < x_n=b$ is related to a partition of $[a-c
\begin{align*}
f(c_1 -c) \cdot (x_1 - x_0) &+ f(c_2 -c) \cdot (x_2 - x_1) + \cdots + f(c_n -c) \cdot (x_n - x_{n-1}) = \\
& f(d_1) \cdot(x_1-c - (x_0-c)) + f(d_2) \cdot(x_2-c - (x_1-c)) + \cdots + f(d_n) \cdot(x_n-c - (x_{n-1}-c)).
f(c_1 -c) \cdot (x_1 - x_0) &+ f(c_2 -c) \cdot (x_2 - x_1) + \cdots\\
&\quad + f(c_n -c) \cdot (x_n - x_{n-1})\\
&= f(d_1) \cdot(x_1-c - (x_0-c)) + f(d_2) \cdot(x_2-c - (x_1-c)) + \cdots\\
&\quad + f(d_n) \cdot(x_n-c - (x_{n-1}-c)).
\end{align*}
@@ -636,15 +638,15 @@ With this, we can easily find an approximate answer. We wrote the function to us
```{julia}
𝒇(x) = exp(x)
riemann(𝒇, 0, 5, 10) # S_10
f(x) = exp(x)
riemann(f, 0, 5, 10) # S_10
```
Or with more intervals in the partition
```{julia}
riemann(𝒇, 0, 5, 50_000)
riemann(f, 0, 5, 50_000)
```
(The answer is $e^5 - e^0 = 147.4131591025766\dots$, which shows that even $50,000$ partitions is not enough to guarantee many digits of accuracy.)
@@ -719,7 +721,7 @@ We have to be a bit careful with the Riemann sum, as the left Riemann sum will h
```{julia}
𝒉(x) = x > 0 ? x * log(x) : 0.0
h(x) = x > 0 ? x * log(x) : 0.0
```
This is actually inefficient, as the check for the size of `x` will slow things down a bit. Since we will call this function 50,000 times, we would like to avoid this, if we can. In this case just using the right sum will work:
@@ -910,7 +912,8 @@ $$
$$
```{julia}
quadgk(x -> x^x, 0, 2)
u(x) = x^x
quadgk(u, 0, 2)
```
$$

View File

@@ -79,14 +79,15 @@ For this problem we need to identify $a$ and $b$. These are found numerically th
```{julia}
a,b = find_zeros(x -> f(x) - g(x), -3, 3)
h(x) = f(x) - g(x)
a,b = find_zeros(h, -3, 3)
```
The answer then can be found numerically:
```{julia}
quadgk(x -> f(x) - g(x), a, b)[1]
first(quadgk(h, a, b))
```
##### Example
@@ -99,18 +100,18 @@ A plot shows the areas:
```{julia}
𝒇(x) = sin(x)
𝒈(x) = cos(x)
plot(𝒇, 0, 2pi)
plot!(𝒈)
f(x) = sin(x)
g(x) = cos(x)
plot(f, 0, 2pi)
plot!(g)
```
There is a single interval when $f \geq g$ and this can be found algebraically using basic trigonometry, or numerically:
```{julia}
𝒂,𝒃 = find_zeros(x -> 𝒇(x) - 𝒈(x), 0, 2pi) # pi/4, 5pi/4
quadgk(x -> 𝒇(x) - 𝒈(x), 𝒂, 𝒃)[1]
a, b = find_zeros(x -> f(x) - g(x), 0, 2pi) # pi/4, 5pi/4
quadgk(x -> f(x) - g(x), a, b)[1]
```
##### Example
@@ -177,15 +178,15 @@ For concreteness, let $f(x) = 2-x^2$ and $[a,b] = [-1, 1/2]$, as in the figure.
```{julia}
𝐟(x) = 2 - x^2
𝐚, 𝐛 = -1, 1/2
𝐜 = (𝐚 + 𝐛)/2
f(x) = 2 - x^2
a, b = -1, 1/2
𝐜 = (a + b)/2
sac, sab, scb = secant(𝐟, 𝐚, 𝐜), secant(𝐟, 𝐚, 𝐛), secant(𝐟, 𝐜, 𝐛)
sac, sab, scb = secant(f, a, 𝐜), secant(f, a, b), secant(f, 𝐜, b)
f1(x) = min(sac(x), scb(x))
f2(x) = sab(x)
A1 = quadgk(x -> f1(x) - f2(x), 𝐚, 𝐛)[1]
A1 = quadgk(x -> f1(x) - f2(x), a, b)[1]
```
As we needed three secant lines, we used the `secant` function from `CalculusWithJulia` to create functions representing each. Once that was done, we used the `min` function to facilitate integrating over the top bounding curve, alternatively, we could break the integral over $[a,c]$ and $[c,b]$.
@@ -195,7 +196,7 @@ The area of the parabolic segment is more straightforward.
```{julia}
A2 = quadgk(x -> 𝐟(x) - f2(x), 𝐚, 𝐛)[1]
A2 = quadgk(x -> f(x) - f2(x), a, b)[1]
```
Finally, if Archimedes was right, this relationship should bring about $0$ (or something within round-off error):

View File

@@ -202,7 +202,7 @@ $$
\int_{-\pi/2}^{\pi/2} \cos(x) dx = F(\pi/2) - F(-\pi/2) = 1 - (-1) = 2.
$$
### An alternate notation for $F(b) - F(a)$
### An alternate notation
The expression $F(b) - F(a)$ is often written in this more compact form:
@@ -617,7 +617,7 @@ We need to figure out when this is $0$. For that, we use some numeric math.
```{julia}
F(x) = exp(-x^2) * quadgk(t -> exp(t^2), 0, x)[1]
Fp(x) = -2x*F(x) + 1
Fp(x) = -2x * F(x) + 1
cps = find_zeros(Fp, -4, 4)
```

View File

@@ -34,8 +34,9 @@ function make_sqrt_x_graph(n)
a = 1/2^n
xs = range(1/2^8, stop=b, length=250)
x1s = range(a, stop=b, length=50)
@syms x
f(x) = 1/sqrt(x)
val = N(integrate(f, 1/2^n, b))
val = N(integrate(f(x), (x, 1/2^n, b)))
title = "area under f over [1/$(2^n), $b] is $(rpad(round(val, digits=2), 4))"
plt = plot(f, range(a, stop=b, length=251), xlim=(0,b), ylim=(0, 15), legend=false, size=fig_size, title=title)

View File

@@ -440,10 +440,10 @@ Apply the formula to a parameterized circle to ensure, the signed area is proper
```{julia}
#| hold: true
@syms 𝒓 t
𝒙 = 𝒓 * cos(t)
𝒚 = 𝒓 * sin(t)
-integrate(𝒚 * diff(𝒙, t), (t, 0, 2PI))
@syms r t
x = r * cos(t)
y = r * sin(t)
-integrate(y * diff(x, t), (t, 0, 2PI))
```
We see the expected answer for the area of a circle.
@@ -461,9 +461,9 @@ Working symbolically, we have one arch given by the following described in a *cl
```{julia}
#| hold: true
@syms t
𝒙 = t - sin(t)
𝒚 = 1 - cos(t)
integrate(𝒚 * diff(𝒙, t), (t, 0, 2PI))
x = t - sin(t)
y = 1 - cos(t)
integrate(y * diff(x, t), (t, 0, 2PI))
```
([Galileo](https://mathshistory.st-andrews.ac.uk/Curves/Cycloid/) was thwarted in finding this answer exactly and resorted to constructing one from metal to *estimate* the value.)

View File

@@ -261,15 +261,15 @@ We again just let `SymPy` do the work. A partial fraction decomposition is given
```{julia}
𝒒 = (x^2 - 2x - 3)
apart(1/𝒒)
q = (x^2 - 2x - 3)
apart(1/q)
```
We see what should yield two logarithmic terms:
```{julia}
integrate(1/𝒒, x)
integrate(1/q, x)
```
:::{.callout-note}