This commit is contained in:
jverzani
2024-05-22 07:55:20 -04:00
parent f710cded15
commit 771bb06aa3
50 changed files with 120 additions and 426 deletions

View File

@@ -400,7 +400,7 @@ Mathematically these are irrational values with decimal expansions that do not r
:::{.callout-warning}
## Warning
In most cases. There are occasional (basically rare) spots where using `pi` by itself causes an eror where `1*pi` will not. The reason is `1*pi` will create a floating point value from the irrational object, `pi`.
In most cases. There are occasional (basically rare) spots where using `pi` by itself causes an error where `1*pi` will not. The reason is `1*pi` will create a floating point value from the irrational object, `pi`.
:::
@@ -763,7 +763,7 @@ numericq(val)
###### Question
Wich of the following is a valid `Julia` expression for
Which of the following is a valid `Julia` expression for
$$
@@ -1132,7 +1132,7 @@ Attempting to compute this, we have:
```{julia}
c = 299_792_458; # the speed of light
G = 6.67430e-11; # Gravitational constant
h = 6.62607015e-34; # Planck's contant
h = 6.62607015e-34; # Planck's constant
h_bar = h / (2*pi);
planck_length = sqrt(h_bar * G / c^3)
```

View File

@@ -146,7 +146,7 @@ The value of `2^n` and `2.0^n` is different in `Julia`. The former remains an in
##### Example
The famous [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number) numbers are $1,1,2,3,5,8,13,\dots$, where $F_{n+1}=F_n+F_{n-1}$. These numbers increase. To see how fast, if we *guess* that the growth is eventually exponential and assume $F_n \approx c \cdot a^n$, then our equation is approximately $ca^{n+1} = ca^n + ca^{n-1}$. Factoring out common terms gives $ca^{n-1} \cdot (a^2 - a - 1) = 0$. The term $a^{n-1}$ is always positive, so any solution would satisfy $a^2 - a -1 = 0$. The positve solution is $(1 + \sqrt{5})/2 \approx 1.618$
The famous [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number) numbers are $1,1,2,3,5,8,13,\dots$, where $F_{n+1}=F_n+F_{n-1}$. These numbers increase. To see how fast, if we *guess* that the growth is eventually exponential and assume $F_n \approx c \cdot a^n$, then our equation is approximately $ca^{n+1} = ca^n + ca^{n-1}$. Factoring out common terms gives $ca^{n-1} \cdot (a^2 - a - 1) = 0$. The term $a^{n-1}$ is always positive, so any solution would satisfy $a^2 - a -1 = 0$. The positive solution is $(1 + \sqrt{5})/2 \approx 1.618$
That is evidence that the $F_n \approx c\cdot 1.618^n$. (See [Relation to golden ratio](https://en.wikipedia.org/wiki/Fibonacci_number#Relation_to_the_golden_ratio) for a related, but more explicit exact formula.

View File

@@ -82,7 +82,7 @@ For typical cases like the three above, there isn't really much new to learn.
## Note
The equals sign in `Julia` always indicates either an assignment or a mutation of the object on the left side. The definition of a function above is an *assignment*, in that a function is added (or modified) in a table holding the methods associated with the function's name.
The equals sign restricts the expressions available on the *left*-hand side to a) a variable name, for assignment; b) mutating an object at an index, as in `xs[1]`; c) mutating a property of a stuct; or d) a function assignment following this form `function_name(args...)`.
The equals sign restricts the expressions available on the *left*-hand side to a) a variable name, for assignment; b) mutating an object at an index, as in `xs[1]`; c) mutating a property of a struct; or d) a function assignment following this form `function_name(args...)`.
Whereas function definitions and usage in `Julia` mirrors standard math notation; equations in math are not so mirrored in `Julia`. In mathematical equations, the left-hand of an equation is typically a complicated algebraic expression. Not so with `Julia`, where the left hand side of the equals sign is prescribed and quite limited.
@@ -276,7 +276,7 @@ The line `return x^2`, could have just been `x^2` as it is the last (and) only l
:::{.callout-note}
## Note
The `return` keyword is not a function, so is not called with parentheses. An emtpy `return` statement will return a value of `nothing`.
The `return` keyword is not a function, so is not called with parentheses. An empty `return` statement will return a value of `nothing`.
:::
@@ -1271,7 +1271,7 @@ A mathematical interval is a set of values of the form
* an open interval: $a < x < b$, or $(a,b)$;
* a closed interval: $a \leq x \leq b$, or $[a,b]$;
* or a half-open interval: $a < x \leq b$ or $a \leq x < b$, repectively $(a,b]$ or $[a,b)$.
* or a half-open interval: $a < x \leq b$ or $a \leq x < b$, respectively $(a,b]$ or $[a,b)$.
They all contain all real numbers between the endpoints, the distinction is whether the endpoints are included or not.
@@ -1332,7 +1332,7 @@ Guess why or why not?
#| hold: true
#| echo: false
choices = ["Well it does, because ``[0,1]`` is the range",
"""It does not. The bound found is a provably known bound. The small deviation is due to the possible errors in evalution of the `sin` function near the floating point approximation of `pi`,
"""It does not. The bound found is a provably known bound. The small deviation is due to the possible errors in evaluation of the `sin` function near the floating point approximation of `pi`,
"""]
radioq(choices, 2)
```

View File

@@ -61,13 +61,13 @@ julia> 2 + 2
* 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.
The `Pluto` interface has some idiosyncracies that need explanation:
The `Pluto` interface has some idiosyncrasies that need explanation:
* Cells can only have one command within them. Multiple-command cells must be contained in a `begin` block or a `let` block.
* By default, the cells are *reactive*. This means when a variable in one cell is changed, then any references to that variable are also updated like a spreadsheet. This is fantastic for updating several computations at once. However it means variable names can not be repeated within a page. Pedagogically, it is convenient to use variable names and function names (e.g., `x` and `f`) repeatedly, but this is only possible *if* they are within a `let` block or a function body.
* To not repeat names, but to be able to reference a value from cell-to-cell, some Unicode variants are used within a page. Visually these look familiar, but typing the names requires some understanding of Unicode input. The primary usages is *bold italic* (e.g., `\bix[tab]` or `\bif[tab]`) or *bold face* (e.g. `\bfx[tab]` or `\bff[tab]`).
* The notebooks snapshot the packages they depend on, which is great for reproducability, but may mean older versions are silently used.
* The notebooks snapshot the packages they depend on, which is great for reproducibility, but may mean older versions are silently used.
## Augmenting base `Julia`
@@ -121,7 +121,7 @@ In a terminal setting, there is a package mode, entered by typing `]` as the lea
Packages can be updated through the command `Pkg.update()`, and removed with `Pkg.rm(pkgname)`.
By default packages are installed in a common area. It may be desirable to keep packages for projects isolated. For this the `Pkg.activate` command can be used. This feature allows a means to have reproducible environments even if `Julia` or the packages used are upgraded, possibly introducing incompatabilities.
By default packages are installed in a common area. It may be desirable to keep packages for projects isolated. For this the `Pkg.activate` command can be used. This feature allows a means to have reproducible environments even if `Julia` or the packages used are upgraded, possibly introducing incompatibilities.
For these notes, the following packages, among others, are used:
@@ -150,7 +150,7 @@ In a `Jupyter` notebook or `Pluto` notebook, commands are typed into a notebook
Commands are executed by using `shift-enter` or a run button near the cell.
In `Jupyter` multiple commands per cell are allowed. In `Pluto`, a `begin` or `let` block is used to collect multiple commmands into a single cell. Commands may be separated by new lines or semicolons.
In `Jupyter` multiple commands per cell are allowed. In `Pluto`, a `begin` or `let` block is used to collect multiple commands into a single cell. Commands may be separated by new lines or semicolons.
On a given line, anything **after** a `#` is a *comment* and is not processed.

View File

@@ -352,7 +352,7 @@ plot(0:pi/4:2pi, sin)
#### NaN values
At times it is not desirable to draw lines between each succesive point. For example, if there is a discontinuity in the function or if there were a vertical asymptote, such as what happens at $0$ with $f(x) = 1/x$.
At times it is not desirable to draw lines between each successive point. For example, if there is a discontinuity in the function or if there were a vertical asymptote, such as what happens at $0$ with $f(x) = 1/x$.
The most straightforward plot is dominated by the vertical asymptote at $x=0$:
@@ -667,7 +667,7 @@ Playing with the toy makes a few things become clear:
These all apply to parametric plots, as the Etch A Sketch trace is no more than a plot of $(f(t), g(t))$ over some range of values for $t$, where $f$ describes the movement in time of the left knob and $g$ the movement in time of the right.
Now, we revist the last problem in the context of this. We saw in the last problem that the parametric graph was nearly a line - so close the eye can't really tell otherwise. That means that the growth in both $f(t) = t^3$ and $g(t)=t - \sin(t)$ for $t$ around $0$ are in a nearly fixed ratio, as otherwise the graph would have more curve in it.
Now, we revisit the last problem in the context of this. We saw in the last problem that the parametric graph was nearly a line - so close the eye can't really tell otherwise. That means that the growth in both $f(t) = t^3$ and $g(t)=t - \sin(t)$ for $t$ around $0$ are in a nearly fixed ratio, as otherwise the graph would have more curve in it.
##### Example: Spirograph

View File

@@ -137,7 +137,7 @@ When `SymPy` is installed through the package manager, the underlying `Python` l
:::{.callout-note}
## Note
The [`Symbolics`](../alternatives/symbolics) package is a rapidly developing `Julia`-only packge that provides symbolic math options.
The [`Symbolics`](../alternatives/symbolics) package is a rapidly developing `Julia`-only package that provides symbolic math options.
:::

View File

@@ -366,7 +366,7 @@ solve(x^5 - x + 1)
Related to `solve` is the specialized `roots` function for identifying roots, Unlike solve, it will identify multiplicities.
For a polynomial with only one indeterminate the usage is straight foward:
For a polynomial with only one indeterminate the usage is straight forward:
```{julia}
@@ -533,7 +533,7 @@ An immediate consequence, is that a polynomial whose coefficients are all non-ne
Applying this to the polynomial $x^5 -x + 1$ we get That the coefficients have signs: `+ 0 0 0 - +` which collapses to the sign pattern `+`, `-`, `+`. This pattern has two changes of sign. The number of *positive* real roots is either $2$ or $0$. In fact there are $0$ for this case.
What about negative roots? Cleary, any negative root of $p$ is a positive root of $q(x) = p(-x)$, as the graph of $q$ is just that of $p$ flipped through the $y$ axis. But the coefficients of $q$ are the same as $p$, except for the odd-indexed coefficients ($a_1, a_3, \dots$) have a changed sign. Continuing with our example, for $q(x) = -x^5 + x + 1$ we get the new sign pattern `-`, `+`, `+` which yields one sign change. That is, there *must* be a negative real root, and indeed there is, $x \approx -1.1673$.
What about negative roots? Clearly, any negative root of $p$ is a positive root of $q(x) = p(-x)$, as the graph of $q$ is just that of $p$ flipped through the $y$ axis. But the coefficients of $q$ are the same as $p$, except for the odd-indexed coefficients ($a_1, a_3, \dots$) have a changed sign. Continuing with our example, for $q(x) = -x^5 + x + 1$ we get the new sign pattern `-`, `+`, `+` which yields one sign change. That is, there *must* be a negative real root, and indeed there is, $x \approx -1.1673$.
With this knowledge, we could have known that in an earlier example the graph of `p = x^7 - 16129x^2 + 254x - 1` which indicated two positive real roots was misleading, as there must be $1$ or $3$ by a count of the sign changes.
@@ -1001,7 +1001,7 @@ Now consider the case $p_0 > 0$. There are two possibilities either `pos(p)` is
So there is parity between `var(p)` and `pos(p)`: if $p$ is monic and $p_0 < 0$ then both `var(p)` and `pos(p)` are both odd; and if $p_0 > 0$ both `var(p)` and `pos(p)` are both even.
Descartes' rule of signs will be established if it can be shown that `var(p)` is at least as big as `pos(p)`. Supppose $r$ is a positive real root of $p$ with $p = (x-r)q$. We show that `var(p) > var(q)` which can be repeatedly applied to show that if $p=(x-r_1)\cdot(x-r_2)\cdot \cdots \cdot (x-r_l) q$, where the $r_i$s are the postive real roots, then `var(p) >= l + var(q) >= l = pos(p)`.
Descartes' rule of signs will be established if it can be shown that `var(p)` is at least as big as `pos(p)`. Supppose $r$ is a positive real root of $p$ with $p = (x-r)q$. We show that `var(p) > var(q)` which can be repeatedly applied to show that if $p=(x-r_1)\cdot(x-r_2)\cdot \cdots \cdot (x-r_l) q$, where the $r_i$s are the positive real roots, then `var(p) >= l + var(q) >= l = pos(p)`.
As $p = (x-c)q$ we must have the leading term is $p_nx^n = x \cdot q_{n-1} x^{n-1}$ so $q_{n-1}$ will also be `+` under our monic assumption. Looking at a possible pattern for the signs of $q$, we might see the following unfinished synthetic division table for a specific $q$:
@@ -1014,7 +1014,7 @@ As $p = (x-c)q$ we must have the leading term is $p_nx^n = x \cdot q_{n-1} x^{n-
+ - - - + - + + 0
```
But actually, we can fill in more, as the second row is formed by multiplying a postive $c$:
But actually, we can fill in more, as the second row is formed by multiplying a positive $c$:
```{verbatim}

View File

@@ -108,7 +108,7 @@ A polynomial in factored form, as `r` above is, can be constructed from its root
fromroots([2,2,1,-1])
```
The `fromroots` function is basically the [factor thereom](https://en.wikipedia.org/wiki/Factor_theorem) which links the factored form of the polynomial with the roots of the polynomial: $(x-k)$ is a factor of $p$ if and only if $k$ is a root of $p$. By combining a factor of the type $(x-k)$ for each specified root, the polynomial can be constructed by multiplying its factors. For example, using `prod` and a generarator, we would have:
The `fromroots` function is basically the [factor theorem](https://en.wikipedia.org/wiki/Factor_theorem) which links the factored form of the polynomial with the roots of the polynomial: $(x-k)$ is a factor of $p$ if and only if $k$ is a root of $p$. By combining a factor of the type $(x-k)$ for each specified root, the polynomial can be constructed by multiplying its factors. For example, using `prod` and a generarator, we would have:
```{julia}

View File

@@ -600,7 +600,7 @@ We can simplify a few: For example, when $n=0$ we see immediately that $T_0(x) =
A few things become clear from the above two representations:
* Starting from $T_0(x) = 1$ and $T_1(x)=x$ and using the recursive defintion of $T_{n+1}$ we get a family of polynomials where $T_n(x)$ is a degree $n$ polynomial. These are defined for all $x$, not just $-1 \leq x \leq 1$.
* Starting from $T_0(x) = 1$ and $T_1(x)=x$ and using the recursive definition of $T_{n+1}$ we get a family of polynomials where $T_n(x)$ is a degree $n$ polynomial. These are defined for all $x$, not just $-1 \leq x \leq 1$.
* Using the initial definition, we see that the zeros of $T_n(x)$ all occur within $[-1,1]$ and happen when $n\arccos(x) = k\pi + \pi/2$, or $x=\cos((2k+1)/n \cdot \pi/2)$ for $k=0, 1, \dots, n-1$.
@@ -717,7 +717,7 @@ radioq(choices, answ, keep_order=true)
###### Question
The cosine function is a simple tranformation of the sine function. Which one?
The cosine function is a simple transformation of the sine function. Which one?
```{julia}
@@ -787,7 +787,7 @@ numericq(val)
###### Question
For any postive integer $n$ the equation $\cos(x) - nx = 0$ has a solution in $[0, \pi/2]$. Graphically estimate the value when $n=10$.
For any positive integer $n$ the equation $\cos(x) - nx = 0$ has a solution in $[0, \pi/2]$. Graphically estimate the value when $n=10$.
```{julia}

View File

@@ -59,7 +59,7 @@ x = 2
:::{.callout-note}
## Note
The `Pluto` interface for `Julia` is idiosyncratic, as variables are *reactive*. This interface allows changes to a variable `x` to propogate to all other cells referring to `x`. Consequently, the variable name can only be assigned *once* per notebook **unless** the name is in some other namespace, which can be arranged by including the assignment inside a function or a `let` block.
The `Pluto` interface for `Julia` is idiosyncratic, as variables are *reactive*. This interface allows changes to a variable `x` to propagate to all other cells referring to `x`. Consequently, the variable name can only be assigned *once* per notebook **unless** the name is in some other namespace, which can be arranged by including the assignment inside a function or a `let` block.
:::

View File

@@ -702,7 +702,7 @@ The style generally employed here is to use plural variable names for a collecti
## Other container types
Vectors in `Julia` are a container, one of many different types. Another useful type for programming purposes are *tuples*. If a vector is formed by placing comma-separated values within a `[]` pair (e.g., `[1,2,3]`), a tuple is formed by placing comma-separated values withing a `()` pair. A tuple of length $1$ uses a convention of a trailing comma to distinguish it from a parenthesized expression (e.g. `(1,)` is a tuple, `(1)` is just the value `1`).
Vectors in `Julia` are a container, one of many different types. Another useful type for programming purposes are *tuples*. If a vector is formed by placing comma-separated values within a `[]` pair (e.g., `[1,2,3]`), a tuple is formed by placing comma-separated values within a `()` pair. A tuple of length $1$ uses a convention of a trailing comma to distinguish it from a parenthesized expression (e.g. `(1,)` is a tuple, `(1)` is just the value `1`).
:::{.callout-note}
## Well, actually...