Merge branch 'main' into v0.24

This commit is contained in:
jverzani
2025-04-23 13:39:27 -04:00
13 changed files with 32 additions and 29 deletions

View File

@@ -80,7 +80,7 @@ Pluto has a built-in package management system that manages the installation of
"Project [Jupyter](https://jupyter.org/) exists to develop open-source software, open-standards, and services for interactive computing across dozens of programming languages." The `IJulia` package allows `Julia` to be one of these programming languages. This package must be installed prior to use.
The Jupyter Project provides two web-based interfaces to `Julia`: the Jupyter notebook and the newer JupyterLab. The [binder](https://mybinder.org/) project use Juptyer notebooks for their primary interface to `Julia`. To use a binder notebook, follow this link:
The Jupyter Project provides two web-based interfaces to `Julia`: the Jupyter notebook and the newer JupyterLab. The [binder](https://mybinder.org/) project use Jupyter notebooks for their primary interface to `Julia`. To use a binder notebook, follow this link:
[launch binder](https://mybinder.org/v2/gh/CalculusWithJulia/CwJScratchPad.git/master)

View File

@@ -981,7 +981,7 @@ vcat([diff.(ex, [u,v])' for ex in F(u,v)]...)
### Divergence
Numerically, the divergence can be computed from the Jacobian by adding the diagonal elements. This is a numerically inefficient, as the other partial derivates must be found and discarded, but this is generally not an issue for these notes. The following uses `tr` (the trace from the `LinearAlgebra` package) to find the sum of a diagonal.
Numerically, the divergence can be computed from the Jacobian by adding the diagonal elements. This is a numerically inefficient, as the other partial derivatives must be found and discarded, but this is generally not an issue for these notes. The following uses `tr` (the trace from the `LinearAlgebra` package) to find the sum of a diagonal.
```{julia}

View File

@@ -207,7 +207,7 @@ The authors note in a supplement to their paper that over 15,700 species and sub
(3.02 * 10^15 + 1.34*10^15) * 100 / 22
```
The answer is in *scientific notation$ and reads as $1.89\dots \cdot 10^16$.
The answer is in *scientific notation* and reads as $1.98\ldots \cdot 10^{16}$.
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,
@@ -244,7 +244,7 @@ With the Google Calculator, typing `1 + 2 x 3 =` will give the value $7$, but *i
In `Julia`, the entire expression is typed in before being evaluated, so the usual conventions of mathematics related to the order of operations may be used. These are colloquially summarized by the acronym [PEMDAS](http://en.wikipedia.org/wiki/Order_of_operations).
> **PEMDAS**. This acronym stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. The order indicates which operation has higher precedence, or should happen first. This isn't exactly the case, as "M" and "D" have the same precedence, as do "A" and "S". In the case of two operations with equal precedence, *associativity* is used to decide which to do. For the operations `+`, `-`, `*`, `/` the associativity is left to right, as in the left one is done first, then the right. However, `^` has right associativity, so `4^3^2` is `4^(3^2)` and not `(4^3)^2`. (Be warned that some calculators - and spread sheets, such as Excel - will treat this expression with left associativity.)
> **PEMDAS**. This acronym stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. The order indicates which operation has higher precedence, or should happen first. This isn't exactly the case, as "M" and "D" have the same precedence, as do "A" and "S". In the case of two operations with equal precedence, *associativity* is used to decide which to do. For the operations `-`, `/` the associativity is left to right, as in the left one is done first, then the right. However, `^` has right associativity, so `4^3^2` is `4^(3^2)` and not `(4^3)^2` (Be warned that some calculators - and spread sheets, such as Excel - will treat this expression with left associativity). But, `+` and `*` don't have associativity, so `1+2+3` can be `(1+2)+3` or `1+(2+3)`.
@@ -598,13 +598,13 @@ The user is expected to have a sense that they need to be careful when their val
::: {.callout-note}
## Bit-level details
We can see in the following, using using the smaller 8-bit type, what goes on internally with successive powers of `2`: the bit pattern is found by shifting the previous one over to the left, consistent with what happens at the bit level when multiplying by `2`:
We can see in the following, using the smaller 8-bit type, what goes on internally with successive powers of `2`: the bit pattern is found by shifting the previous one over to the left, consistent with what happens at the bit level when multiplying by `2`:
```
[bitstring(Int8(2)^i) for i in 1:8]
```
The last line is similar to what happens to `2^64` which is also `0`, as seen. The second to last line requires some understanding of how integers are represented internally. Of the 8 bits, the last 7 represent which powers of `2` (`2^6`, `2^5`, ..., `2^1`, `2^0`) are included. The first `1` represents `-2^7`. So all zeros, as we see `2^8` is, means `0`, but `"10000000"` means `-2^7`. The largest *positive* number would be represented as `"01111111"` or ``2^6 + 2^5 + \cdots + 2^1 + 2^0 = 2^7 - 1``. These values can be seen using `typemin` and `typemax`:
The last line is similar to what happens to `2^64` which is also `0`, as seen. The second to last line requires some understanding of how integers are represented internally. Of the 8 bits, the last 7 represent which powers of `2` (`2^6`, `2^5`, ..., `2^1`, `2^0`) are included. The first `1` represents `-2^7`. So all zeros, as we see `2^8` is, means `0`, but `"10000000"` means `-2^7`. The largest *positive* number would be represented as `"01111111"` or $2^6 + 2^5 + \cdots + 2^1 + 2^0 = 2^7 - 1$. These values can be seen using `typemin` and `typemax`:
```{julia}
typemin(Int8), typemax(Int8)
@@ -1170,7 +1170,7 @@ choices = [
"`10e21`",
"`1e22`",
"`10_000_000_000_000_000_000_000`"]
explanation = "With an *integer* base, `10^21` overflows. For typical integers, only `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."
explanation = "With an *integer* base, `10^21` overflows. For typical integers, only `10^18` is defined as expected. Once `10^19` is entered the mathematical value is larger than 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)
```

View File

@@ -1305,7 +1305,7 @@ With this we can answer agequestions, such as:
> How many stars can we see in the sky?
Star [magnitude](https://en.wikipedia.org/wiki/Magnitude_(astronomy)) measures the brightness of celestial objects, with the sun on a log scale so that a magnitude $1$ star is $100$ times brighter than a magnitude $6$ star. The sun has a value around $-27$, Sirius (the brightest visible star) around $-1.46), Venus around $-5$. We will take a magnitude of $6$ or brighter for visibility. (magnitudes less than $6$). The value of $N(6)$ is then
Star [magnitude](https://en.wikipedia.org/wiki/Magnitude_(astronomy)) measures the brightness of celestial objects, with the sun on a log scale so that a magnitude $1$ star is $100$ times brighter than a magnitude $6$ star. The sun has a value around $-27$, Sirius (the brightest visible star) around $-1.46$), Venus around $-5$. We will take a magnitude of $6$ or brighter for visibility. (magnitudes less than $6$). The value of $N(6)$ is then
```{julia}
q(m) = -0.0003*m^3 + 0.0019*m^2 + 0.484*m - 3.82
@@ -1355,7 +1355,7 @@ If a star of magnitude $5$ difference is $100$ times brighter, what is the scale
```{julia}
#| echo: false
explanation = raw"""
The base $a$ solve $\log_a(x + 5) / \log_a(x) = 100$. The logs can be combined and then $a$ can be solved for.
The base $a$ solve $\log_a(100x) - \log_a(x) = 5$. The logs can be combined and then $a$ can be solved for.
"""
choices = [raw"$5$",raw"$\sqrt[5]{100}$", raw"$\sqrt{100}$"]
answer = 2

View File

@@ -182,7 +182,7 @@ x &= \sqrt{(1-y)/y}, \quad 0 < y \leq 1.
\end{align*}
$$
Then $f^{-1}(x) = \sqrt{(1-x)/x}$ where $0 < x \leq 1$. The somewhat complicated restriction for the the domain coincides with the range of $f(x)$. We shall see next that this is no coincidence.
Then $f^{-1}(x) = \sqrt{(1-x)/x}$ where $0 < x \leq 1$. The somewhat complicated restriction for the domain coincides with the range of $f(x)$. We shall see next that this is no coincidence.
## Formal properties of the inverse function
@@ -198,7 +198,7 @@ plot(f, 0, 4, legend=false)
plot!([2,2,0], [0,f(2),f(2)])
```
The graph is shown over the interval $(0,4)$, but the *domain* of $f(x)$ is all $x \geq 0$. The *range* of $f(x)$ is clearly $2 \leq x \leq \infty$.
The graph is shown over the interval $(0,4)$, but the *domain* of $f(x)$ is all $x \geq 0$. The *range* of $f(x)$ is clearly $2 \leq y \leq \infty$.
The lines layered on the plot show how to associate an $x$ value to a $y$ value or vice versa (as $f(x)$ is one-to-one). The domain then of the inverse function is all the $y$ values for which a corresponding $x$ value exists: this is clearly all values bigger or equal to $2$. The *range* of the inverse function can be seen to be all the images for the values of $y$, which would be all $x \geq 0$. This gives the relationship:
@@ -283,7 +283,7 @@ The slope of $f(x) = 9/5 \cdot x + 32$ is clearly $9/5$ and the slope of the inv
Now consider the graph of the *tangent line* to a function. This concept will be better defined later, for now, it is a line "tangent" to the graph of $f(x)$ at a point $x=c$.
For concreteness, we consider $f(x) = \sqrt{x}$ at $c=2$. The tangent line will have slope $1/(2\sqrt{2})$ and will go through the point $(2, f(2)$. We graph the function, its tangent line, and their inverses:
For concreteness, we consider $f(x) = \sqrt{x}$ at $c=2$. The tangent line will have slope $1/(2\sqrt{2})$ and will go through the point $(2, f(2))$. We graph the function, its tangent line, and their inverses:
```{julia}

View File

@@ -97,7 +97,7 @@ julia> 2 + 2
* An IDE. For programmers, an integrated development environment is often used to manage bigger projects. `Julia` has `Juno` and `VSCode`.
* A notebook. The [Project Juptyer](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Juypter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc.
* A notebook. The [Project Jupyter](https://jupyter.org/) provides a notebook interface for interacting with `Julia` and a more `IDE` style `jupyterlab` interface. A jupyter notebook has cells where commands are typed and immediately following is the printed output returned by `Julia`. The output of a cell depends on the state of the kernel when the cell is computed, not the order of the cells in the notebook. Cells have a number attached, showing the execution order. The `Juypter` notebook is used by `binder` and can be used locally through the `IJulia` package. This notebook has the ability to display many different types of outputs in addition to plain text, such as images, marked up math text, etc.
* The [Pluto](https://github.com/fonsp/Pluto.jl) package provides a *reactive* notebook interface. Reactive means when one "cell" is modified and executed, the new values cascade to all other dependent cells which in turn are updated. This is very useful for exploring a parameter space, say. Pluto notebooks can be exported as HTML files which make them easy to read online and by clever design embed the `.jl` file that can run through `Pluto` if it is downloaded.

View File

@@ -94,7 +94,7 @@ Well, almost... When `Inf` or `NaN` are involved, this may not hold, for example
So adding or subtracting most any finite value from an inequality will preserve the inequality, just as it does for equations.
What about addition and multiplication?
What about multiplication?
Consider the case $a < b$ and $c > 0$. Then $ca < cb$. Here we investigate using $3$ random values (which will be positive):
@@ -231,7 +231,7 @@ Read aloud this would be "minus $7$ is less than $x$ minus $5$ **and** $x$ minus
The "and" equations can be combined as above with a natural notation. However, an equation like $\lvert x - 5\rvert > 7$ would emphasize an **or** and be "$x$ minus $5$ less than minus $7$ **or** $x$ minus $5$ greater than $7$". Expressing this requires some new notation.
The *boolean shortcut operators* `&&` and `||` implement "and" and "or." (There are also *bitwise* boolean operators `&` and `|`, but we only describe the former.)
The *boolean shortcut operators* `&&` and `||` implement "and" and "or". (There are also *bitwise* boolean operators `&` and `|`, but we only describe the former.)
Thus we could write $-7 < x-5 < 7$ as

View File

@@ -88,7 +88,7 @@ These values are *very* small numbers, but not exactly $0$, as they are mathemat
---
The only common issue is with powers. We saw this previously when discussing a distinction between `2^64` and `2.0^64. `Julia` tries to keep a predictable output from the input types (not their values). Here are the two main cases that arise where this can cause unexpected results:
The only common issue is with powers. We saw this previously when discussing a distinction between `2^64` and `2.0^64`. `Julia` tries to keep a predictable output from the input types (not their values). Here are the two main cases that arise where this can cause unexpected results:
* integer bases and integer exponents can *easily* overflow. Not only `m^n` is always an integer, it is always an integer with a fixed storage size computed from the sizes of `m` and `n`. So the powers can quickly get too big. This can be especially noticeable on older $32$-bit machines, where too big is $2^{32} = 4,294,967,296$. On $64$-bit machines, this limit is present but much bigger.
@@ -643,7 +643,7 @@ Finding the value through division introduces a floating point deviation. Which
```{julia}
#| echo: false
as = [`1/10^21`, `1e-21`]
as = ["1/10^21", "1e-21"]
explanation = "The scientific notation is correct. Due to integer overflow `10^21` is not the same number as `10.0^21`."
buttonq(as, 2; explanation)
```

View File

@@ -899,7 +899,7 @@ buttonq(["Yes", "No"], 1; explanation)
###### Question
Make this parametric plot for the specific values of the parameters `k` and `l`. What shape best describes it?
Make this parametric plot for the specific values of the parameters `R`, `r`, and `rho`. What shape best describes it?
```{julia}

View File

@@ -749,7 +749,7 @@ If this sum has a remainder of 0 when dividing by 10, the credit card number is
iszero(rem(z,10))
```
Darn. A typo. is `4137 8947 1175 5804` a possible credit card number?
Darn. A typo. is `4137 8047 1175 5804` a possible credit card number?
```{julia}
#| hold: true

View File

@@ -280,7 +280,7 @@ plot!(h, label="h")
A model for the length of a day in New York City must take into account periodic seasonal effects. A simple model might be a sine curve. However, there would need to be many modifications: Obvious ones would be that the period would need to be about $365$ days, the oscillation around $12$ and the amplitude of the oscillations no more than $12$.
We can be more precise. According to [dateandtime.info](http://dateandtime.info/citysunrisesunset.php?id=5128581) in $2015$ the longest day will be June $21$st when there will be $15$h $5$m $46$s of sunlight, the shortest day will be December $21$st when there will be $9$h $15$m $19$s of sunlight. On January $1$, there will be $9$h $19$m $44$s of sunlight.
We can be more precise. According to [dateandtime.info](http://dateandtime.info/citysunrisesunset.php?id=5128581) in $2015$ the longest day will be June $21$st when there will be $15$h $8$m $55$s of sunlight, the shortest day will be December $21$st when there will be $9$h $18$m $23$s of sunlight. On March $21$st, there will be $12$h $13$m $42$s of sunlight.
A model for a transformed sine curve is
@@ -294,12 +294,12 @@ Where $b$ is related to the amplitude, $c$ the shift and the period is $T=2\pi/d
```{julia}
a = 12
b = ((15 + 5/60 + 46/60/60) - (9 + 19/60 + 44/60/60)) / 2
a = 12 + 13/60 + 42/60/60
b = ((15 + 8/60 + 55/60/60) - (9 + 18/60 + 23/60/60)) / 2
d = 2pi/365
```
If we let January $1$ be $x=0$ then the first day of spring, March $21$, is day $80$ (`Date(2017, 3, 21) - Date(2017, 1, 1) + 1`). This day aligns with the shift of the sine curve. This shift is $80$:
If we let January $1$st be $x=0$ then the first day of spring, March $21$st, is day $80$ (`Date(2015, 3, 21) - Date(2015, 1, 1) + Day(1)`). This day aligns with the shift of the sine curve. This shift is $80$:
```{julia}
@@ -314,15 +314,15 @@ newyork(t) = up(stretch(over(scale(sin, d), c), b), a)(t)
plot(newyork, -20, 385)
```
To test, if we match up with the model powering [dateandtime.info](http://dateandtime.info/citysunrisesunset.php?id=5128581) we note that it predicts "$15$h $0$m $4$s" on July $4$, $2015$. This is day $185$ (`Date(2015, 7, 4) - Date(2015, 1, 1) + 1`). Our model prediction has a difference of
To test, if we match up with the model powering [dateandtime.info](http://dateandtime.info/citysunrisesunset.php?id=5128581) we note that it predicts "$12$h $10$m $38$s" on September $23$th, $2015$. This is day $266$ (`Date(2015, 9, 23) - Date(2015, 1, 1) + Day(1)`). Our model prediction has a difference of
```{julia}
datetime = 15 + 0/60 + 4/60/60
delta = (newyork(185) - datetime) * 60
datetime = 12 + 10/60 + 38/60/60
delta = (newyork(266) - datetime) * 60
```
This is off by a fair amount - almost $12$ minutes. Clearly a trigonometric model, based on the assumption of circular motion of the earth around the sun, is not accurate enough for precise work, but it does help one understand how summer days are longer than winter days and how the length of a day changes fastest at the spring and fall equinoxes.
This is off by a fair amount - almost $8$ minutes. Clearly a trigonometric model, based on the assumption of circular motion of the earth around the sun, is not accurate enough for precise work, but it does help one understand how summer days are longer than winter days and how the length of a day changes fastest at the spring and fall equinoxes.
##### Example: the pipeline operator

View File

@@ -264,7 +264,7 @@ plt = plot(legend=false, size=fig_size)
arrow!(p0, [2,3], color="black")
arrow!(p0, [2,0], color="orange")
arrow!(p0+[2,0], [0,3], color="orange")
annotate!(plt, collect(zip([.25, 1,1,1.75], [.25, 1.85,.25,1], [L"t",L"r", L"r \cdot \cos(t)", L"r \cdot \sin(t)"]))) #["θ","r", "r ⋅ cos(θ)", "r ⋅ sin(θ)"]
annotate!(plt, collect(zip([.25, 1,1,1.75], [.15, 1.85,.25,1], [L"\theta",L"r", L"r \cdot \cos(\theta)", L"r \cdot \sin(\theta)"]))) #["θ","r", "r ⋅ cos(θ)", "r ⋅ sin(θ)"]
imgfile = tempname() * ".png"
png(plt, imgfile)