merge main
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
[deps]
|
||||
CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
|
||||
MonteCarloMeasurements = "0987c9cc-fe09-11e8-30f0-b96dd679fdca"
|
||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
|
||||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
|
||||
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
|
||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||
TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d"
|
||||
|
||||
@@ -411,7 +411,7 @@ p = [γ => 0.0,
|
||||
prob = ODEProblem(sys, u0, TSPAN, p, jac=true)
|
||||
sol = solve(prob,Tsit5())
|
||||
|
||||
plot(t -> sol(t)[3], t -> sol(t)[4], TSPAN..., legend=false)
|
||||
plot(t -> sol(t)[1], t -> sol(t)[3], TSPAN..., legend=false)
|
||||
```
|
||||
|
||||
The toolkit will automatically generate fast functions and can perform transformations (such as is done by `ode_order_lowering`) before passing along to the numeric solves.
|
||||
|
||||
@@ -340,7 +340,7 @@ The first-order initial value equations we have seen can be described generally
|
||||
$$
|
||||
\begin{align*}
|
||||
y'(x) &= F(y,x),\\
|
||||
y(x_0) &= x_0.
|
||||
y(x_0) &= y_0.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -375,7 +375,7 @@ $$
|
||||
u'(x) = a u(1-u), \quad a > 0
|
||||
$$
|
||||
|
||||
Before beginning, we look at the form of the equation. When $u=0$ or $u=1$ the rate of change is $0$, so we expect the function might be bounded within that range. If not, when $u$ gets bigger than $1$, then the slope is negative and when $u$ gets less than $0$, the slope is positive, so there will at least be a drift back to the range $[0,1]$. Let's see exactly what happens. We define a parameter, restricting `a` to be positive:
|
||||
Before beginning, we look at the form of the equation. When $u=0$ or $u=1$ the rate of change is $0$, so we expect the function might be bounded within that range. If not, when $u$ gets bigger than $1$, then the slope is negative and though the slope is negative too when $u<0$, but for a realistic problem, it always be $u\ge0$. so we focus $u$ on the range $[0,1]$. Let's see exactly what happens. We define a parameter, restricting `a` to be positive:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -403,7 +403,7 @@ To finish, we call `dsolve` to find a solution (if possible):
|
||||
out = dsolve(eqn)
|
||||
```
|
||||
|
||||
This answer - to a first-order equation - has one free constant, `C_1`, which can be solved for from an initial condition. We can see that when $a > 0$, as $x$ goes to positive infinity the solution goes to $1$, and when $x$ goes to negative infinity, the solution goes to $0$ and otherwise is trapped in between, as expected.
|
||||
This answer - to a first-order equation - has one free constant, `C₁`, which can be solved for from an initial condition. We can see that when $a > 0$, as $x$ goes to positive infinity the solution goes to $1$, and when $x$ goes to negative infinity, the solution goes to $0$ and otherwise is trapped in between, as expected.
|
||||
|
||||
|
||||
The limits are confirmed by investigating the limits of the right-hand:
|
||||
@@ -420,7 +420,7 @@ We can confirm that the solution is always increasing, hence trapped within $[0,
|
||||
diff(rhs(out),x)
|
||||
```
|
||||
|
||||
Suppose that $u(0) = 1/2$. Can we solve for $C_1$ symbolically? We can use `solve`, but first we will need to get the symbol for `C_1`:
|
||||
Suppose that $u(0) = 1/2$. Can we solve for $C_1$ symbolically? We can use `solve`, but first we will need to get the symbol for `C₁`:
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version: "0.24"
|
||||
engine: julia
|
||||
engines: ['julia']
|
||||
|
||||
project:
|
||||
type: book
|
||||
|
||||
@@ -5,12 +5,19 @@ DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
|
||||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
ImplicitEquations = "95701278-4526-5785-aba3-513cca398f19"
|
||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
|
||||
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
|
||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||
QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
|
||||
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
|
||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||
TaylorSeries = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
|
||||
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
|
||||
TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d"
|
||||
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
|
||||
|
||||
@@ -195,7 +195,7 @@ To identify how wide a viewing window should be, for the rational function the a
|
||||
|
||||
```{julia}
|
||||
cps = find_zeros(f', -10, 10)
|
||||
poss_ips = find_zero(f'', (-10, 10))
|
||||
poss_ips = find_zeros(f'', (-10, 10))
|
||||
extrema(union(cps, poss_ips))
|
||||
```
|
||||
|
||||
@@ -340,7 +340,7 @@ radioq(choices, answ)
|
||||
###### Question
|
||||
|
||||
|
||||
Consider the function $p(x) = x + 2x^3 + 3x^3 + 4x^4 + 5x^5 +6x^6$. Which interval shows more than a $U$-shaped graph that dominates for large $x$ due to the leading term being $6x^6$?
|
||||
Consider the function $p(x) = x + 2x^2 + 3x^3 + 4x^4 + 5x^5 +6x^6$. Which interval shows more than a $U$-shaped graph that dominates for large $x$ due to the leading term being $6x^6$?
|
||||
|
||||
|
||||
(Find an interval that contains the zeros, critical points, and inflection points.)
|
||||
@@ -494,7 +494,7 @@ Does a plot over $[0,50]$ show qualitatively similar behaviour?
|
||||
```{julia}
|
||||
#| hold: true
|
||||
#| echo: false
|
||||
yesnoq(true)
|
||||
yesnoq("no")
|
||||
```
|
||||
|
||||
Exponential growth has $P''(t) = P_0 a^t \log(a)^2 > 0$, so has no inflection point. By plotting over a sufficiently wide interval, can you answer: does the logistic growth model have an inflection point?
|
||||
|
||||
@@ -432,7 +432,7 @@ $$
|
||||
\frac{\log(x+h) - \log(x)}{h} = \frac{1}{h}\log(\frac{x+h}{x}) = \log((1+h/x)^{1/h}).
|
||||
$$
|
||||
|
||||
As noted earlier, Cauchy saw the limit as $u$ goes to $0$ of $f(u) = (1 + u)^{1/u}$ is $e$. Re-expressing the above we can get $1/h \cdot \log(f(h/x))$. The limit as $h$ goes to $0$ of this is found from the composition rules for limits: as $\lim_{h \rightarrow 0} f(h/x) = e^{1/x}$, and since $\log(x)$ is continuous at $e^{1/x}$ we get this expression has a limit of $1/x$.
|
||||
As noted earlier, Cauchy saw the limit as $u$ goes to $0$ of $f(u) = (1 + u)^{1/u}$ is $e$. Re-expressing the above we can get $1/x \cdot \log(f(h/x))$. The limit as $h$ goes to $0$ of this is found from the composition rules for limits: as $\lim_{h \rightarrow 0} f(h/x) = e$, and since $\log(x)$ is continuous at $e$ we get this expression has a limit of $1/x$.
|
||||
|
||||
|
||||
We verify through:
|
||||
@@ -775,7 +775,7 @@ f'(\square) &= 2(\square) & g'(x) &= \frac{1}{2}x^{-1/2}
|
||||
$$
|
||||
|
||||
|
||||
We use $\square$ for the argument of `f'` to emphasize that $g(x)$ is the needed value, not just $x$:
|
||||
We use $\square$ for the argument of $f'$ to emphasize that $g(x)$ is the needed value, not just $x$:
|
||||
|
||||
|
||||
$$
|
||||
@@ -1651,7 +1651,7 @@ $$
|
||||
\frac{d(f\circ g)}{dx}\mid_{x=1}
|
||||
&= \lim_{h\rightarrow 0} \frac{f(g(1) + g'(1)h)-f(g(1))}{h}\\
|
||||
&= \lim_{h\rightarrow 0} \frac{f(g(1) + g'(1)h)-f(g(1))}{g'(1)h} \cdot g'(1)\\
|
||||
&= \lim_{h\rightarrow 0} (f\circ g)'(g(1)) \cdot g'(1).
|
||||
&= \lim_{h\rightarrow 0} f'(g(1)) \cdot g'(1).
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ g(x) = sqrt(abs(x^2 - 1))
|
||||
cps = find_zeros(g', -2, 2)
|
||||
```
|
||||
|
||||
We see the three values $-1$, $0$, $1$ that correspond to the two zeros and the relative minimum of $x^2 - 1$. We could graph things, but instead we characterize these values using a sign chart. A piecewise continuous function can only change sign when it crosses $0$ or jumps over $0$. The derivative will be continuous, except possibly at the three values above, so is piecewise continuous.
|
||||
We see the three values $-1$, $0$, $1$ that correspond to the two zeros and the relative maximum of $x^2 - 1$. We could graph things, but instead we characterize these values using a sign chart. A piecewise continuous function can only change sign when it crosses $0$ or jumps over $0$. The derivative will be continuous, except possibly at the three values above, so is piecewise continuous.
|
||||
|
||||
|
||||
A sign chart picks convenient values between crossing points to test if the function is positive or negative over those intervals. When computing by hand, these would ideally be values for which the function is easily computed. On the computer, this isn't a concern; below the midpoint is chosen:
|
||||
@@ -328,7 +328,7 @@ At $x=0$ we have to the left and right signs found by
|
||||
fp(-pi/2), fp(pi/2)
|
||||
```
|
||||
|
||||
Both are negative. The derivative does not change sign at $0$, so the critical point is neither a relative minimum or maximum.
|
||||
Both are negative. The derivative does not change sign at $0$, so the critical point is neither a relative minimum nor maximum.
|
||||
|
||||
|
||||
What about at $2\pi$? We do something similar:
|
||||
@@ -338,7 +338,7 @@ What about at $2\pi$? We do something similar:
|
||||
fp(2pi - pi/2), fp(2pi + pi/2)
|
||||
```
|
||||
|
||||
Again, both negative. The function $f(x)$ is just decreasing near $2\pi$, so again the critical point is neither a relative minimum or maximum.
|
||||
Again, both negative. The function $f(x)$ is just decreasing near $2\pi$, so again the critical point is neither a relative minimum nor maximum.
|
||||
|
||||
|
||||
A graph verifies this:
|
||||
@@ -454,7 +454,7 @@ We won't work with these definitions in this section, rather we will characteriz
|
||||
|
||||
|
||||
|
||||
A proof of this makes use of the same trick used to establish the mean value theorem from Rolle's theorem. Assume $f'$ is increasing and let $g(x) = f(x) - (f(a) + M \cdot (x-a))$, where $M$ is the slope of the secant line between $a$ and $b$. By construction $g(a) = g(b) = 0$. If $f'(x)$ is increasing, then so is $g'(x) = f'(x) + M$. By its definition above, showing $f$ is concave up is the same as showing $g(x) \leq 0$. Suppose to the contrary that there is a value where $g(x) > 0$ in $[a,b]$. We show this can't be. Assuming $g'(x)$ always exists, after some work, Rolle's theorem will ensure there is a value where $g'(c) = 0$ and $(c,g(c))$ is a relative maximum, and as we know there is at least one positive value, it must be $g(c) > 0$. The first derivative test then ensures that $g'(x)$ will increase to the left of $c$ and decrease to the right of $c$, since $c$ is at a critical point and not an endpoint. But this can't happen as $g'(x)$ is assumed to be increasing on the interval.
|
||||
A proof of this makes use of the same trick used to establish the mean value theorem from Rolle's theorem. Assume $f'$ is increasing and let $g(x) = f(x) - (f(a) + M \cdot (x-a))$, where $M$ is the slope of the secant line between $a$ and $b$. By construction $g(a) = g(b) = 0$. If $f'(x)$ is increasing, then so is $g'(x) = f'(x) + M$. By its definition above, showing $f$ is concave up is the same as showing $g(x) \leq 0$. Suppose to the contrary that there is a value where $g(x) > 0$ in $[a,b]$. We show this can't be. Assuming $g'(x)$ always exists, after some work, Rolle's theorem will ensure there is a value where $g'(c) = 0$ and $(c,g(c))$ is a relative maximum, and as we know there is at least one positive value, it must be $g(c) > 0$. The first derivative test then ensures that $g'(x)$ will be positive to the left of $c$ and negative to the right of $c$, since $c$ is at a critical point and not an endpoint. But this can't happen as $g'(x)$ is assumed to be increasing on the interval.
|
||||
|
||||
|
||||
The relationship between increasing functions and their derivatives – if $f'(x) > 0$ on $I$, then $f$ is increasing on $I$ – gives this second characterization of concavity when the second derivative exists:
|
||||
@@ -503,8 +503,8 @@ Concave up functions are "opening" up, and often clearly $U$-shaped, though that
|
||||
|
||||
If $c$ is a critical point of $f(x)$ with $f''(c)$ existing in a neighborhood of $c$, then
|
||||
|
||||
* $f$ will have a relative maximum at the critical point $c$ if $f''(c) > 0$,
|
||||
* $f$ will have a relative minimum at the critical point $c$ if $f''(c) < 0$, and
|
||||
* $f$ will have a relative minimum at the critical point $c$ if $f''(c) > 0$,
|
||||
* $f$ will have a relative maximum at the critical point $c$ if $f''(c) < 0$, and
|
||||
* *if* $f''(c) = 0$ the test is *inconclusive*.
|
||||
|
||||
:::
|
||||
@@ -799,6 +799,8 @@ scatter!(ips, ex.(ips), marker=(5, :brown3, :star5))
|
||||
The black circle denotes what?
|
||||
|
||||
```{julia}
|
||||
#| hold: true
|
||||
#| echo: false
|
||||
choices = [raw"A zero of $f$",
|
||||
raw"A critical point of $f$",
|
||||
raw"An inflection point of $f$"]
|
||||
@@ -806,21 +808,11 @@ answ = 1
|
||||
radioq(choices, answ)
|
||||
```
|
||||
|
||||
|
||||
The black circle denotes what?
|
||||
|
||||
```{julia}
|
||||
choices = [raw"A zero of $f$",
|
||||
raw"A critical point of $f$",
|
||||
raw"An inflection point of $f$"]
|
||||
answ = 1
|
||||
radioq(choices, answ)
|
||||
```
|
||||
|
||||
|
||||
The green diamond denotes what?
|
||||
|
||||
```{julia}
|
||||
#| hold: true
|
||||
#| echo: false
|
||||
choices = [raw"A zero of $f$",
|
||||
raw"A critical point of $f$",
|
||||
raw"An inflection point of $f$"]
|
||||
@@ -832,6 +824,8 @@ radioq(choices, answ)
|
||||
The red stars denotes what?
|
||||
|
||||
```{julia}
|
||||
#| hold: true
|
||||
#| echo: false
|
||||
choices = [raw"Zeros of $f$",
|
||||
raw"Critical points of $f$",
|
||||
raw"Inflection points of $f$"]
|
||||
|
||||
@@ -416,7 +416,7 @@ $$
|
||||
6x - (6y \frac{dy}{dx} \cdot \frac{dy}{dx} + 3y^2 \frac{d^2y}{dx^2}) = 0.
|
||||
$$
|
||||
|
||||
Again, if must be that $d^2y/dx^2$ appears as a linear factor, so we can solve for it:
|
||||
Again, it must be that $d^2y/dx^2$ appears as a linear factor, so we can solve for it:
|
||||
|
||||
|
||||
$$
|
||||
@@ -456,7 +456,7 @@ eqn = K(x,y)
|
||||
eqn1 = eqn(y => u(x))
|
||||
dydx = solve(diff(eqn1,x), diff(u(x), x))[1] # 1 solution
|
||||
d2ydx2 = solve(diff(eqn1, x, 2), diff(u(x),x, 2))[1] # 1 solution
|
||||
eqn2 = d2ydx2(diff(u(x), x) => dydx, u(x) => y)
|
||||
eqn2 = subs(d2ydx2, diff(u(x), x) => dydx, u(x) => y)
|
||||
simplify(eqn2)
|
||||
```
|
||||
|
||||
@@ -637,7 +637,7 @@ Okay, now we need to put this value back into our expression for the `x` value a
|
||||
|
||||
|
||||
```{julia}
|
||||
xstar = N(cps[2](y => ystar, a =>3, b => 3, L => 3))
|
||||
xstar = N(cps[2](y => ystar, a =>3, b => 3))
|
||||
```
|
||||
|
||||
Our minimum is at `(xstar, ystar)`, as this graphic shows:
|
||||
|
||||
@@ -115,7 +115,7 @@ $$
|
||||
\lim_{x \rightarrow 0} \frac{e^x - e^{-x}}{x}.
|
||||
$$
|
||||
|
||||
It too is of the indeterminate form $0/0$. The derivative of the top is $e^x + e^{-x}$, which is $2$ when $x=0$, so the ratio of $f'(0)/g'(0)$ is seen to be $2$ By continuity, the limit of the ratio of the derivatives is $2$. Then by L'Hospital's rule, the limit above is $2$.
|
||||
It too is of the indeterminate form $0/0$. The derivative of the top is $e^x + e^{-x}$, which is $2$ when $x=0$, so the ratio of $f'(0)/g'(0)$ is seen to be $2$. By continuity, the limit of the ratio of the derivatives is $2$. Then by L'Hospital's rule, the limit above is $2$.
|
||||
|
||||
|
||||
* Sometimes, L'Hospital's rule must be applied twice. Consider this limit:
|
||||
@@ -820,7 +820,7 @@ $$
|
||||
#| hold: true
|
||||
#| echo: false
|
||||
choices = [
|
||||
"``e^{-2/\\pi}``",
|
||||
"``e^{2/\\pi}``",
|
||||
"``{2\\pi}``",
|
||||
"``1``",
|
||||
"``0``",
|
||||
|
||||
@@ -642,7 +642,7 @@ x = Dual(0, 1)
|
||||
@code_lowered sin(x)
|
||||
```
|
||||
|
||||
This output of `@code_lowered` can be confusing, but this simple case needn't be. Working from the end we see an assignment to a variable named `%7` of `Dual(%3, %6)`. The value of `%3` is `sin(x)` where `x` is the value `0` above. The value of `%6` is `cos(x)` *times* the value `1` above (the `xp`), which reflects the *chain* rule being used. (The derivative of `sin(u)` is `cos(u)*du`.) So this dual number encodes both the function value at `0` and the derivative of the function at `0`.)
|
||||
This output of `@code_lowered` can be confusing, but this simple case needn't be. Working from the end we see an assignment to a variable named `%3` of `Dual(%6, %12)`. The value of `%6` is `sin(x)` where `x` is the value `0` above. The value of `%12` is `cos(x)` *times* the value `1` above (the `xp`), which reflects the *chain* rule being used. (The derivative of `sin(u)` is `cos(u)*du`.) So this dual number encodes both the function value at `0` and the derivative of the function at `0`.
|
||||
|
||||
|
||||
Similarly, we can see what happens to `log(x)` at `1` (encoded by `Dual(1,1)`):
|
||||
@@ -654,14 +654,14 @@ x = Dual(1, 1)
|
||||
@code_lowered log(x)
|
||||
```
|
||||
|
||||
We can see the derivative again reflects the chain rule, it being given by `1/x * xp` where `xp` acts like `dx` (from assignments `%5` and `%4`). Comparing the two outputs, we see only the assignment to `%5` differs, it reflecting the derivative of the function.
|
||||
We can see the derivative again reflects the chain rule, it being given by `1/x * xp` where `xp` acts like `dx` (from assignments `%9` and `%8`). Comparing the two outputs, we see only the assignment to `%9` differs, it reflecting the derivative of the function.
|
||||
|
||||
## Curvature
|
||||
|
||||
The curvature of a function will be a topic in a later section on differentiable vector calculus, but the concept of linearization can be used to give an earlier introduction.
|
||||
|
||||
|
||||
The tangent line linearizes the function, it begin the best linear approximation to the graph of the function at the point. The slope of the tangent line is the limi of the slopes of different secant lines. Consider now, the orthogonal concept, the *normal line* at a point. This is a line perpendicular to the tangent line that goes through the point on the curve.
|
||||
The tangent line linearizes the function, it begin the best linear approximation to the graph of the function at the point. The slope of the tangent line is the limit of the slopes of different secant lines. Consider now, the orthogonal concept, the *normal line* at a point. This is a line perpendicular to the tangent line that goes through the point on the curve.
|
||||
|
||||
At a point $(c,f(c))$ the slope of the normal line is $-1/f'(c)$.
|
||||
|
||||
@@ -680,7 +680,7 @@ Rearranging, we have
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
-f'(c)(y-f(c) &= x-c\\
|
||||
-f'(c)(y-f(c)) &= x-c\\
|
||||
-f'(c+h)(y-f(c+h)) &= x-(c+h)
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -330,7 +330,7 @@ Let $f(x)$ be differentiable on $(a,b)$ and continuous on $[a,b]$. Then there ex
|
||||
This says for any secant line between $a < b$ there will be a parallel tangent line at some $c$ with $a < c < b$ (all provided $f$ is differentiable on $(a,b)$ and continuous on $[a,b]$).
|
||||
|
||||
|
||||
Figure @fig-mean-value-theorem illustrates the theorem. The orange line is the secant line. A parallel line tangent to the graph is guaranteed by the mean value theorem. In this figure, there are two such lines, rendered using red.
|
||||
Figure @fig-mean-value-theorem illustrates the theorem. The blue line is the secant line. A parallel line tangent to the graph is guaranteed by the mean value theorem. In this figure, there are two such lines, rendered using brown.
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -69,7 +69,7 @@ x₃ = (babylon ∘ babylon ∘ babylon)(2//1)
|
||||
x₃, x₃^2.0
|
||||
```
|
||||
|
||||
This is now accurate to the sixth decimal point. That is about as far as we, or the Bablyonians, would want to go by hand. Using rational numbers quickly grows out of hand. The next step shows the explosion.
|
||||
This is now accurate to the sixth decimal point. That is about as far as we, or the Babylonians, would want to go by hand. Using rational numbers quickly grows out of hand. The next step shows the explosion.
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -212,7 +212,7 @@ In practice, the algorithm is implemented not by repeating the update step a fix
|
||||
|
||||
Newton looked at this same example in 1699 (B.T. Polyak, *Newton's method and its use in optimization*, European Journal of Operational Research. 02/2007; 181(3):1086-1096.; and Deuflhard *Newton Methods for Nonlinear Problems: Affine Invariance and Adaptive Algorithms*) though his technique was slightly different as he did not use the derivative, *per se*, but rather an approximation based on the fact that his function was a polynomial.
|
||||
|
||||
We can read that he guessed the answer was ``2 + p``, as there is a sign change between $2$ and $3$. Newton put this guess into the polynomial to get after simplification ``p^3 + 6p^2 + 10p - 1``. This has an **approximate** zero found by solving the linear part ``10p-1 = 0``. Taking ``p = 0.1`` he then can say the answer looks like ``2 + p + q`` and repeat to get ``q^3 + 6.3\cdot q^2 + 11.23 \cdot q + 0.061 = 0``. Again taking just the linear part estimates `q = 0.005431...`. After two steps the estimate is `2.105431...`. This can be continued by expressing the answer as ``2 + p + q + r`` and then solving for an estimate for ``r``.
|
||||
We can read that he guessed the answer was ``2 + p``, as there is a sign change between $2$ and $3$. Newton put this guess into the polynomial to get after simplification ``p^3 + 6p^2 + 10p - 1``. This has an **approximate** zero found by solving the linear part ``10p-1 = 0``. Taking ``p = 0.1`` he then can say the answer looks like ``2 + p + q`` and repeat to get ``q^3 + 6.3q^2 + 11.23q + 0.061 = 0``. Again taking just the linear part estimates `q = -0.005431...`. After two steps the estimate is `2.094568...`. This can be continued by expressing the answer as ``2 + p + q + r`` and then solving for an estimate for ``r``.
|
||||
|
||||
Raphson (1690) proposed a simplification avoiding the computation of new polynomials, hence the usual name of the Newton-Raphson method. Simpson introduced derivatives into the formulation and systems of equations.
|
||||
|
||||
@@ -696,7 +696,7 @@ If $M$ were just a constant and we suppose $e_0 = 10^{-1}$ then $e_1$ would be l
|
||||
To identify $M$, let $\alpha$ be the zero of $f$ to be approximated. Assume
|
||||
|
||||
|
||||
* The function $f$ has at continuous second derivative in a neighborhood of $\alpha$.
|
||||
* The function $f$ has a continuous second derivative in a neighborhood of $\alpha$.
|
||||
* The value $f'(\alpha)$ is *non-zero* in the neighborhood of $\alpha$.
|
||||
|
||||
|
||||
@@ -865,7 +865,7 @@ The function $f(x) = x^{20} - 1$ has two bad behaviours for Newton's
|
||||
method: for $x < 1$ the derivative is nearly $0$ and for $x>1$ the
|
||||
second derivative is very big. In this illustration, we have an
|
||||
initial guess of $x_0=8/9$. As the tangent line is fairly flat, the
|
||||
next approximation is far away, $x_1 = 1.313\dots$. As this guess is
|
||||
next approximation is far away, $x_1 = 1.313\dots$. As this guess
|
||||
is much bigger than $1$, the ratio $f(x)/f'(x) \approx
|
||||
x^{20}/(20x^{19}) = x/20$, so $x_i - f(x_i)/f'(x_i) \approx (19/20)x_i$
|
||||
yielding slow, linear convergence until $f''(x_i)$ is moderate. For
|
||||
@@ -1033,7 +1033,7 @@ Let $f(x) = x^2 - 3^x$. This has derivative $2x - 3^x \cdot \log(3)$. Starting w
|
||||
f(x) = x^2 - 3^x;
|
||||
fp(x) = 2x - 3^x*log(3);
|
||||
val = Roots.newton(f, fp, 0);
|
||||
numericq(val, 1e-14)
|
||||
numericq(val, 1e-1)
|
||||
```
|
||||
|
||||
###### Question
|
||||
@@ -1424,7 +1424,7 @@ yesnoq("no")
|
||||
###### Question
|
||||
|
||||
|
||||
Quadratic convergence of Newton's method only applies to *simple* roots. For example, we can see (using the `verbose=true` argument to the `Roots` package's `newton` method, that it only takes $4$ steps to find a zero to $f(x) = \cos(x) - x$ starting at $x_0 = 1$. But it takes many more steps to find the same zero for $f(x) = (\cos(x) - x)^2$.
|
||||
Quadratic convergence of Newton's method only applies to *simple* roots. For example, we can see (using the `verbose=true` argument to the `Roots` package's `newton` method), that it only takes $4$ steps to find a zero to $f(x) = \cos(x) - x$ starting at $x_0 = 1$. But it takes many more steps to find the same zero for $f(x) = (\cos(x) - x)^2$.
|
||||
|
||||
|
||||
How many?
|
||||
@@ -1454,7 +1454,7 @@ implicit_plot(f, xlims=(-2,2), ylims=(-2,2), legend=false)
|
||||
Can we find which point on its graph has the largest $y$ value?
|
||||
|
||||
|
||||
This would be straightforward *if* we could write $y(x) = \dots$, for then we would simply find the critical points and investiate. But we can't so easily solve for $y$ interms of $x$. However, we can use Newton's method to do so:
|
||||
This would be straightforward *if* we could write $y(x) = \dots$, for then we would simply find the critical points and investigate. But we can't so easily solve for $y$ interms of $x$. However, we can use Newton's method to do so:
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -639,21 +639,21 @@ It is hard to tell which would minimize time without more work. To check a case
|
||||
|
||||
|
||||
```{julia}
|
||||
x_straight = t(r1 =>2r0, b=>0, x=>out[1], a=>1, L=>2, r0 => 1) # for x=L
|
||||
x_straight = subs(t, r1 =>2r0, b=>0, x=>out[1], a=>1, L=>2, r0 => 1) # for x=L
|
||||
```
|
||||
|
||||
Compared to the smaller ($x=\sqrt{3}a/3$):
|
||||
|
||||
|
||||
```{julia}
|
||||
x_angle = t(r1 =>2r0, b=>0, x=>out[2], a=>1, L=>2, r0 => 1)
|
||||
x_angle = subs(t, r1 =>2r0, b=>0, x=>out[2], a=>1, L=>2, r0 => 1)
|
||||
```
|
||||
|
||||
What about $x=0$?
|
||||
|
||||
|
||||
```{julia}
|
||||
x_bent = t(r1 =>2r0, b=>0, x=>0, a=>1, L=>2, r0 => 1)
|
||||
x_bent = subs(t, r1 =>2r0, b=>0, x=>0, a=>1, L=>2, r0 => 1)
|
||||
```
|
||||
|
||||
The value of $x=\sqrt{3}a/3$ minimizes time:
|
||||
@@ -671,7 +671,7 @@ Will this approach always be true? Consider different parameters, say we switch
|
||||
|
||||
```{julia}
|
||||
pts = [0, out...]
|
||||
m,i = findmin([t(r1 =>2r0, b=>0, x=>u, a=>2, L=>1, r0 => 1) for u in pts]) # min, index
|
||||
m,i = findmin([subs(t, r1 =>2r0, b=>0, x=>u, a=>2, L=>1, r0 => 1) for u in pts]) # min, index
|
||||
m, pts[i]
|
||||
```
|
||||
|
||||
@@ -997,7 +997,7 @@ A rain gutter is constructed from a 30" wide sheet of tin by bending it into thi
|
||||
2 * (1/2 * 10*cos(pi/4) * 10 * sin(pi/4)) + 10*sin(pi/4) * 10
|
||||
```
|
||||
|
||||
Find a value in degrees that gives the maximum. (The first task is to write the area in terms of $\theta$.
|
||||
Find a value in degrees that gives the maximum. (The first task is to write the area in terms of $\theta$.)
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -1049,7 +1049,7 @@ plot!(p, [0, 30,30,0], [0,10,30,0], color=:orange)
|
||||
annotate!(p, [(x,y,l) for (x,y,l) in zip([15, 5, 31, 31], [1.5, 3.5, 5, 20], ["x=30", "θ", "10", "20"])])
|
||||
```
|
||||
|
||||
What value of $x$ gives the largest angle $\theta$? (In degrees.)
|
||||
What value of the largest angle $\theta$ that $x$ gives? (In degrees.)
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -1094,7 +1094,7 @@ radioq(choices, answ)
|
||||
##### Question
|
||||
|
||||
|
||||
Let $x_1$, $x_2$, $x_n$ be a set of unspecified numbers in a data set. Form the expression $s(x) = (x-x_1)^2 + \cdots (x-x_n)^2$. What is the smallest this can be (in $x$)?
|
||||
Let $x_1$, $x_2$, $\dots, x_n$ be a set of unspecified numbers in a data set. Form the expression $s(x) = (x-x_1)^2 + \cdots + (x-x_n)^2$. What is the smallest this can be (in $x$)?
|
||||
|
||||
|
||||
We approach this using `SymPy` and $n=10$
|
||||
@@ -1108,7 +1108,7 @@ s(x) = sum((x-xi)^2 for xi in xs)
|
||||
cps = solve(diff(s(x), x), x)
|
||||
```
|
||||
|
||||
Run the above code. Baseed on the critical points found, what do you guess will be the minimum value in terms of the values $x_1$, $x_2, \dots$?
|
||||
Run the above code. Based on the critical points found, what do you guess will be the minimum value in terms of the values $x_1$, $x_2, \dots$?
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -1117,7 +1117,7 @@ Run the above code. Baseed on the critical points found, what do you guess will
|
||||
choices=[
|
||||
"The mean, or average, of the values",
|
||||
"The median, or middle number, of the values",
|
||||
L"The square roots of the values squared, $(x_1^2 + \cdots x_n^2)^2$"
|
||||
L"The square roots of the values squared, $(x_1^2 + \cdots + x_n^2)^2$"
|
||||
]
|
||||
answ = 1
|
||||
radioq(choices, answ)
|
||||
@@ -1126,7 +1126,7 @@ radioq(choices, answ)
|
||||
###### Question
|
||||
|
||||
|
||||
Minimize the function $f(x) = 2x + 3/x$ over $(0, \infty)$.
|
||||
Find $x$ to minimize the function $f(x) = 2x + 3/x$ over $(0, \infty)$.
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -1190,7 +1190,7 @@ The width is:
|
||||
w(h) = 12_000 / h
|
||||
S(w, h) = (w- 2*8) * (h - 2*32)
|
||||
S(h) = S(w(h), h)
|
||||
hstar =find_zero(D(S), 500)
|
||||
hstar = find_zero(D(S), 200)
|
||||
wstar = w(hstar)
|
||||
numericq(wstar)
|
||||
```
|
||||
@@ -1204,7 +1204,7 @@ The height is?
|
||||
w(h) = 12_000 / h
|
||||
S(w, h) = (w- 2*8) * (h - 2*32)
|
||||
S(h) = S(w(h), h)
|
||||
hstar =find_zero(D(S), 500)
|
||||
hstar = find_zero(D(S), 200)
|
||||
numericq(hstar)
|
||||
```
|
||||
|
||||
@@ -1482,7 +1482,7 @@ a = find_zero(y', 1)
|
||||
numericq(a)
|
||||
```
|
||||
|
||||
Numerically find the value of $a$ that minimizes the length of the line seqment $PQ$.
|
||||
Numerically find the value of $a$ that minimizes the length of the line segment $PQ$.
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -118,7 +118,7 @@ The term "best" is deserved, as any other straight line will differ at least in
|
||||
$$
|
||||
\begin{align*}
|
||||
\frac{F'(\xi)}{G'(\xi)} &=
|
||||
\frac{f'(\xi) - f''(\xi)(\xi-x) - f(\xi)\cdot 1}{2(\xi-x)} \\
|
||||
\frac{f'(\xi) - f''(\xi)(\xi-x) - f'(\xi)\cdot 1}{2(\xi-x)} \\
|
||||
&= -f''(\xi)/2\\
|
||||
&= \frac{F(c) - F(x)}{G(c) - G(x)}\\
|
||||
&= \frac{f(c) - f'(c)(c-x) - (f(x) - f'(x)(x-x))}{(c-x)^2 - (x-x)^2} \\
|
||||
@@ -445,7 +445,7 @@ This can be solved to give this relationship:
|
||||
|
||||
|
||||
$$
|
||||
\frac{d^2\theta}{dt^2} = - \frac{g}{R}\theta.
|
||||
\frac{d^2\theta}{dt^2} = \frac{g}{R}\theta.
|
||||
$$
|
||||
|
||||
The solution to this "equation" can be written (in some parameterization) as $\theta(t)=A\cos \left(\omega t+\phi \right)$. This motion is the well-studied simple [harmonic oscillator](https://en.wikipedia.org/wiki/Harmonic_oscillator), a model for a simple pendulum.
|
||||
@@ -721,7 +721,7 @@ The height of a [GPS satellite](http://www.gps.gov/systems/gps/space/) is about
|
||||
|
||||
|
||||
```{julia}
|
||||
Hₛ = 12250 * 1609.34 # 1609 meters per mile
|
||||
Hₛ = 12550 * 1609.34 # 1609 meters per mile
|
||||
HRₛ = Hₛ/R
|
||||
|
||||
Prealₛ = P0 * (1 + HRₛ)^(3/2)
|
||||
@@ -753,7 +753,7 @@ Finally, we show how to use the `Unitful` package. This package allows us to def
|
||||
m, mi, kg, s, hr = u"m", u"mi", u"kg", u"s", u"hr"
|
||||
|
||||
G = 6.67408e-11 * m^3 / kg / s^2
|
||||
H = uconvert(m, 12250 * mi) # unit convert miles to meter
|
||||
H = uconvert(m, 12550 * mi) # unit convert miles to meter
|
||||
R = uconvert(m, 3959 * mi)
|
||||
M = 5.972e24 * kg
|
||||
|
||||
@@ -858,8 +858,8 @@ For notational purposes, let $g(x)$ be the inverse function for $f(x)$. Assume *
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
f(x_0 + \Delta_x) &= f(x_0) + a_1 \Delta_x + a_2 (\Delta_x)^2 + \cdots a_n (\Delta_x)^n + \dots\\
|
||||
g(y_0 + \Delta_y) &= g(y_0) + b_1 \Delta_y + b_2 (\Delta_y)^2 + \cdots b_n (\Delta_y)^n + \dots
|
||||
f(x_0 + \Delta_x) &= f(x_0) + a_1 \Delta_x + a_2 (\Delta_x)^2 + \cdots + a_n (\Delta_x)^n + \dots\\
|
||||
g(y_0 + \Delta_y) &= g(y_0) + b_1 \Delta_y + b_2 (\Delta_y)^2 + \cdots + b_n (\Delta_y)^n + \dots
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -897,7 +897,7 @@ $$
|
||||
(This is following [Liptaj](https://vixra.org/pdf/1703.0295v1.pdf)).
|
||||
|
||||
|
||||
We will use `SymPy` to take this limit for the first `4` derivatives. Here is some code that expands $x + \Delta_x = g(f(x_0 + \Delta_x))$ and then uses `SymPy` to solve:
|
||||
We will use `SymPy` to take this limit for the first `4` derivatives. Here is some code that expands $x_0 + \Delta_x = g(f(x_0 + \Delta_x))$ and then uses `SymPy` to solve:
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -8,11 +8,16 @@ DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
|
||||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
|
||||
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
|
||||
QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
ScatteredInterpolation = "3f865c0f-6dca-5f4d-999b-29fe1e7e3c92"
|
||||
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
|
||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||
TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d"
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
[deps]
|
||||
CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882"
|
||||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
|
||||
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
|
||||
QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
|
||||
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
|
||||
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
|
||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||
TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d"
|
||||
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
|
||||
UnitfulUS = "7dc9378f-8956-57ef-a780-aa31cc70ff3d"
|
||||
|
||||
@@ -493,14 +493,14 @@ What looks at first glance to be just a slightly more complicated equation is th
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
s(u) &= \int_0^u \sqrt{(-\sin(t))^2 + b\cos(t)^2} dt\\
|
||||
&= \int_0^u \sqrt{\sin(t)^2 + \cos(t)^2 + c\cos(t)^2} dt \\
|
||||
&=\int_0^u \sqrt{1 + c\cos(t)^2} dt.
|
||||
s(u) &= \int_0^u \sqrt{(-\sin(t))^2 + (b\cos(t))^2} dt\\
|
||||
&= \int_0^u \sqrt{\sin(t)^2 + \cos(t)^2 + C\cos(t)^2} dt \\
|
||||
&=\int_0^u \sqrt{1 + C\cos(t)^2} dt.
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
|
||||
But, despite it not looking too daunting, this integral is not tractable through our techniques and has an answer involving elliptic integrals. We can work numerically though. Letting $a=1$ and $b=2$, we have the arc length is given by:
|
||||
Where $C = 2c + c^2$ is a constant. But, despite it not looking too daunting, this integral is not tractable through our techniques and has an answer involving elliptic integrals. We can work numerically though. Letting $a=1$ and $b=2$, we have the arc length is given by:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -710,7 +710,7 @@ For the latter claim, integrating in the $y$ variable gives
|
||||
$$
|
||||
\begin{align*}
|
||||
\int_u^c (f(x)-h) dx &= \int_h^m (c - f_1^{-1}(y)) dy\\
|
||||
&> \int_h^m (c - f_2^{-1}(y)) dy\\
|
||||
&> \int_h^m (f_2^{-1}(y) - c) dy\\
|
||||
&= \int_c^v (f(x)-h) dx
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -17,7 +17,7 @@ using Roots
|
||||
---
|
||||
|
||||
|
||||
The question of area has long fascinated human culture. As children, we learn early on the formulas for the areas of some geometric figures: a square is $b^2$, a rectangle $b\cdot h$ a triangle $1/2 \cdot b \cdot h$ and for a circle, $\pi r^2$. The area of a rectangle is often the intuitive basis for illustrating multiplication. The area of a triangle has been known for ages. Even complicated expressions, such as [Heron's](http://tinyurl.com/mqm9z) formula which relates the area of a triangle with measurements from its perimeter have been around for 2000 years. The formula for the area of a circle is also quite old. Wikipedia dates it as far back as the [Rhind](http://en.wikipedia.org/wiki/Rhind_Mathematical_Papyrus) papyrus for 1700 BC, with the approximation of $256/81$ for $\pi$.
|
||||
The question of area has long fascinated human culture. As children, we learn early on the formulas for the areas of some geometric figures: a square is $b^2$, a rectangle $b\cdot h$, a triangle $1/2 \cdot b \cdot h$ and for a circle, $\pi r^2$. The area of a rectangle is often the intuitive basis for illustrating multiplication. The area of a triangle has been known for ages. Even complicated expressions, such as [Heron's](http://tinyurl.com/mqm9z) formula which relates the area of a triangle with measurements from its perimeter have been around for 2000 years. The formula for the area of a circle is also quite old. Wikipedia dates it as far back as the [Rhind](http://en.wikipedia.org/wiki/Rhind_Mathematical_Papyrus) papyrus for 1700 BC, with the approximation of $256/81$ for $\pi$.
|
||||
|
||||
|
||||
The modern approach to area begins with a non-negative function $f(x)$ over an interval $[a,b]$. The goal is to compute the area under the graph. That is, the area between $f(x)$ and the $x$-axis between $a \leq x \leq b$.
|
||||
@@ -480,9 +480,9 @@ This is just the area of a trapezoid with heights $a$ and $b$ and side length
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
S &= x_1 \cdot (x_1 - x_0) + x_2 \cdot (x_2 - x_1) + \cdots x_n \cdot (x_n - x_{n-1}) \\
|
||||
&= (a + 1\frac{b-a}{n}) \cdot \frac{b-a}{n} + (a + 2\frac{b-a}{n}) \cdot \frac{b-a}{n} + \cdots (a + n\frac{b-a}{n}) \cdot \frac{b-a}{n}\\
|
||||
&= n \cdot a \cdot (\frac{b-a}{n}) + (1 + 2 + \cdots n) \cdot (\frac{b-a}{n})^2 \\
|
||||
S &= x_1 \cdot (x_1 - x_0) + x_2 \cdot (x_2 - x_1) + \cdots + x_n \cdot (x_n - x_{n-1}) \\
|
||||
&= (a + 1\frac{b-a}{n}) \cdot \frac{b-a}{n} + (a + 2\frac{b-a}{n}) \cdot \frac{b-a}{n} + \cdots + (a + n\frac{b-a}{n}) \cdot \frac{b-a}{n}\\
|
||||
&= n \cdot a \cdot (\frac{b-a}{n}) + (1 + 2 + \cdots + n) \cdot (\frac{b-a}{n})^2 \\
|
||||
&= n \cdot a \cdot (\frac{b-a}{n}) + \frac{n(n+1)}{2} \cdot (\frac{b-a}{n})^2 \\
|
||||
& \rightarrow a \cdot(b-a) + \frac{(b-a)^2}{2} \\
|
||||
&= \frac{b^2}{2} - \frac{a^2}{2}.
|
||||
@@ -729,7 +729,7 @@ An immediate consequence would be $\int_{-\pi}^\pi \sin(x) = 0$, as would $\int_
|
||||
##### Example
|
||||
|
||||
|
||||
Numerically estimate the definite integral $\int_0^e x\log(x) dx$. (We redefine the function to be $0$ at $0$, so it is continuous.)
|
||||
Numerically estimate the definite integral $\int_0^2 x\log(x) dx$. (We redefine the function to be $0$ at $0$, so it is continuous.)
|
||||
|
||||
|
||||
We have to be a bit careful with the Riemann sum, as the left Riemann sum will have an issue at $0=x_0$ (`0*log(0)`) returns `NaN` which will poison any subsequent arithmetic operations, so the value returned will be `NaN` and not an approximate answer. We could define our function with a check:
|
||||
@@ -860,7 +860,7 @@ $$
|
||||
\frac{b-a}{6}(f(x_1) + 4f(x_2) + f(x_3)).
|
||||
$$
|
||||
|
||||
This formula will actually be exact for any 3rd degree polynomial. In fact an entire family of similar approximations using $n$ points can be made exact for any polynomial of degree $n-1$ or lower. But with non-evenly spaced points, even better results can be found.
|
||||
This formula will actually be exact for any 2nd degree polynomial. In fact an entire family of similar approximations using $n$ points can be made exact for any polynomial of degree $n-1$ or lower. But with non-evenly spaced points, even better results can be found.
|
||||
|
||||
|
||||
The formulas for an approximation to the integral $\int_{-1}^1 f(x) dx$ discussed so far can be written as:
|
||||
|
||||
@@ -494,7 +494,7 @@ box(f⁻¹(x₀-1Δ), x₀-2Δ, 1 - f⁻¹(x₀-1Δ), Δ, colᵣ)
|
||||
box(f⁻¹(x₀-2Δ), x₀-3Δ, 1 - f⁻¹(x₀-2Δ), Δ, colᵣ)
|
||||
```
|
||||
|
||||
The figure above suggests that the area under $f(x)$ over $[a,b]$ could be represented as the area between the curves $f^{-1}(y)$ and $y=b$ from $[f(a), f(b)]$.
|
||||
The figure above suggests that the area under $f(x)$ over $[a,b]$ could be represented as the area between the curves $f^{-1}(y)$ and $x=b$ from $[f(a), f(b)]$.
|
||||
|
||||
|
||||
---
|
||||
@@ -552,7 +552,7 @@ p = plot(xs, ys; line=(3, :black), ylims=(0,4), legend=false)
|
||||
scatter!(p, xs, ys; marker=(7, :circle))
|
||||
```
|
||||
|
||||
Going further, we draw the four trapezoids using different colors depending on the sign of the `xs[i+1] - xs[[i]` terms:
|
||||
Going further, we draw the four trapezoids using different colors depending on the sign of the `xs[i+1] - xs[i]` terms:
|
||||
|
||||
```{julia}
|
||||
for i in 1:4
|
||||
@@ -563,7 +563,7 @@ end
|
||||
p
|
||||
```
|
||||
|
||||
The yellow trapezoids appear to be colored green, as they completely overlap with parts of the blue trapezoids and blue and yellow make green. As the signs of the differences of the $x$ values is different, these areas add to $0$ in the sum, leaving just the area of the interior when the sum is computed.
|
||||
The yellow trapezoids appear to be colored grey, as they completely overlap with parts of the blue trapezoids and blue and yellow make grey with lights. As the signs of the differences of the $x$ values is different, these areas add to $0$ in the sum, leaving just the area of the interior when the sum is computed.
|
||||
|
||||
For this particular figure, the enclosed area is
|
||||
|
||||
@@ -964,9 +964,10 @@ end
|
||||
What does this imply:
|
||||
|
||||
```{julia}
|
||||
#| hold: true
|
||||
#| echo: false
|
||||
choices = ["The two enclosed areas should be equal",
|
||||
"The two enclosed areas are clearly different, as they do not overap"],
|
||||
"The two enclosed areas are clearly different, as they do not overap"]
|
||||
radioq(choices, 1)
|
||||
```
|
||||
"
|
||||
|
||||
|
||||
@@ -503,7 +503,7 @@ numericq(val)
|
||||
###### Question
|
||||
|
||||
|
||||
Find the center of mass of the region in the first quadrant bounded by the function $f(x) = x^3(1-x)^4$.
|
||||
Find the center of mass in the $x$ variable of the region in the first quadrant bounded by the function $f(x) = x^3(1-x)^4$.
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -589,7 +589,7 @@ The answer will either be at a critical point, at $0$ or as $x$ goes to $\infty$
|
||||
|
||||
|
||||
$$
|
||||
[\text{erf}(x)]' = \frac{2}{\pi}e^{-x^2}.
|
||||
[\text{erf}(x)]' = \frac{2}{\sqrt{\pi}}e^{-x^2}.
|
||||
$$
|
||||
|
||||
Oh, this is never $0$, so there are no critical points. The maximum occurs at $0$ or as $x$ goes to $\infty$. Clearly at $0$, we have $\text{erf}(0)=0$, so the answer will be as $x$ goes to $\infty$.
|
||||
@@ -755,7 +755,7 @@ A junior engineer at `Treadmillz.com` is tasked with updating the display of cal
|
||||
**********
|
||||
```
|
||||
|
||||
In this example display there was 1 calorie burned in the first minute, then 2, then 5, 5, 4, 3, 2, 2, 1. The total is $24$.
|
||||
In this example display there was 1 calorie burned in the first minute, then 2, then 5, 5, 4, 4, 3, 2, 2, 1. The total is $29$.
|
||||
|
||||
|
||||
In her work the junior engineer found this old function for updating the display
|
||||
@@ -814,7 +814,7 @@ end
|
||||
Then the "area" represented by the dots stays fixed over this time frame.
|
||||
|
||||
|
||||
The engineer then thought a bit more, as the form of her answer seemed familiar. She decides to parameterize it in terms of $t$ and found with $h=1/n$: `c(t) = (C(t) - C(t-h))/h`. Ahh - the derivative approximation. But then what is the "area"? It is no longer just the sum of the dots, but in terms of the functions she finds that each column represents $c(t)\cdot h$, and the sum is just $c(t_1)h + c(t_2)h + \cdots c(t_n)h$ which looks like an approximate integral.
|
||||
The engineer then thought a bit more, as the form of her answer seemed familiar. She decides to parameterize it in terms of $t$ and found with $h=1/n$: `c(t) = (C(t) - C(t-h))/h`. Ahh - the derivative approximation. But then what is the "area"? It is no longer just the sum of the dots, but in terms of the functions she finds that each column represents $c(t)\cdot h$, and the sum is just $c(t_1)h + c(t_2)h + \cdots + c(t_n)h$ which looks like an approximate integral.
|
||||
|
||||
|
||||
If the display were to reach the modern age and replace LED "dots" with a higher-pixel display, then the function to display would be $c(t) = C'(t)$ and the area displayed would be $\int_{t-10}^t c(u) du$.
|
||||
|
||||
@@ -161,7 +161,7 @@ $$
|
||||
= \int_{\log(e)}^{\log(M)} \frac{1}{u^{2}} du
|
||||
= \frac{-1}{u} \big|_{1}^{\log(M)}
|
||||
= \frac{-1}{\log(M)} - \frac{-1}{1}
|
||||
= 1 - \frac{1}{M}.
|
||||
= 1 - \frac{1}{\log(M)}.
|
||||
$$
|
||||
|
||||
As $M$ goes to $\infty$, this will converge to $1$.
|
||||
|
||||
@@ -95,7 +95,7 @@ end
|
||||
|
||||
@fig-integration-by-parts shows a parametric plot of $(u(t),v(t))$ for $a \leq t \leq b$..
|
||||
|
||||
The total shaded area, a rectangle, is $u(b)v(b)$, the area of $A$ and $B$ combined is just $u(b)v(b) - u(a)v(a)$ or $[u(x)v(x)]\big|_a^b$. We will show that that $A$ is $\int_a^b v(x)u'(x)dx$ and $B$ is $\int_a^b u(x)v'(x)dx$ giving the formula
|
||||
The total shaded area, a rectangle, is $u(b)v(b)$, the area of $A$ and $B$ combined is just $u(b)v(b) - u(a)v(a)$ or $[u(x)v(x)]\big|_a^b$. We will show that $A$ is $\int_a^b v(x)u'(x)dx$ and $B$ is $\int_a^b u(x)v'(x)dx$ giving the formula.
|
||||
|
||||
We can compute $A$ by a change of variables with $x=u^{-1}(t)$ (so $u'(x)dx = dt$):
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ answ = 2
|
||||
radioq(choices, answ, keep_order=true)
|
||||
```
|
||||
|
||||
If $m < n$, then why can we cancel out the $(x-c)^n$ and not have a concern?
|
||||
If $m < n$, then why can we cancel out the $(x-c)^m$ and not have a concern?
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -263,7 +263,7 @@ ws = unzip(S.(us,vs'))
|
||||
surface(ws..., alpha=0.75)
|
||||
```
|
||||
|
||||
We compare this answer to that of the frustum of a cone with radii $1$ and $(3/2)^2$, formed by rotating the line segment connecting $(0,f(0))$ with $(3/2,f(3/2))$. From looking at the graph of the surface, these values should be comparable. The surface area of the cone part is $\pi (r_1^2 + r_0^2) / \sin(\theta) = \pi (r_1 + r_0) \cdot \sqrt{(\Delta h)^2 + (r_1-r_0)^2}$.
|
||||
We compare this answer to that of the frustum of a cone with radii $1$ and $(3/2)^2$, formed by rotating the line segment connecting $(0,f(0))$ with $(3/2,f(3/2))$. From looking at the graph of the surface, these values should be comparable. The surface area of the cone part is $\pi (r_1^2 - r_0^2) / \sin(\theta) = \pi (r_1 + r_0) \cdot \sqrt{(\Delta h)^2 + (r_1-r_0)^2}$.
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -354,7 +354,7 @@ That is, the surface area is simply the circumference of the circle traced out b
|
||||
##### Example
|
||||
|
||||
|
||||
The surface area of of an open cone can be computed, as the arc length is $\sqrt{h^2 + r^2}$ and the centroid of the line is a distance $r/2$ from the axis. This gives SA$=2\pi (r/2) \sqrt{h^2 + r^2} = \pi r \sqrt{h^2 + r^2}$.
|
||||
The surface area of an open cone can be computed, as the arc length is $\sqrt{h^2 + r^2}$ and the centroid of the line is a distance $r/2$ from the axis. This gives SA$=2\pi (r/2) \sqrt{h^2 + r^2} = \pi r \sqrt{h^2 + r^2}$.
|
||||
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -5,6 +5,7 @@ This section uses these packages:
|
||||
```{julia}
|
||||
using SymPy
|
||||
using Plots
|
||||
using Roots
|
||||
plotly()
|
||||
```
|
||||
|
||||
@@ -165,7 +166,7 @@ A = simplify(integrate(nl - f(x), (x, q, a)));
|
||||
#| code-fold: true
|
||||
#| code-summary: "Show the code"
|
||||
@syms k::nonnegative
|
||||
V = simplify(integrate(PI * (nl - f(x) - k)^2, (x, q, a)));
|
||||
V = simplify(integrate(2PI*(nl-f(x))*(a - x + k),(x, q, a)));
|
||||
```
|
||||
|
||||
----
|
||||
@@ -218,7 +219,7 @@ L = integrate(sqrt(1 + fp(x)^2), (x, q, a));
|
||||
|
||||
----
|
||||
|
||||
> 5. The $y$ coordinate of the midpoint ofthe line segment $PQ$
|
||||
> 5. The $y$ coordinate of the midpoint of the line segment $PQ$
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -300,7 +301,7 @@ end
|
||||
#| code-summary: "Show the code"
|
||||
# use parametric and 2π ∫ u(t) √(u'(t)^2 + v'(t)^2) dt
|
||||
uu(x) = a - x
|
||||
vv(x) = f(uu(x))
|
||||
vv(x) = f(a - uu(x))
|
||||
SA = 2PI * integrate(uu(x) * sqrt(diff(uu(x),x)^2 + diff(vv(x),x)^2), (x, q, a));
|
||||
```
|
||||
|
||||
@@ -394,11 +395,11 @@ plot!([a₀,q₀,q₀,a₀-f(a₀)/fp(a₀),a₀],
|
||||
# v1, v2, v3 = [[x[i]-x[1],y[i]-y[1], 0] for i in 2:4]
|
||||
# area = 1//2 * last(cross(v3,v2) + cross(v2, v1)) # 1/2 area of parallelogram
|
||||
# print(simplify(area))
|
||||
# -(x₁ - x₂)*(y₁ - y₃)/2 + (x₁ - x₃)*(y₁ - y₂)/2 - (x₁ - x₃)*(y₁ - y₄)/2 + (x₁ - x₄)*(y₁ - y₃)/2
|
||||
# (x₁ - x₂)*(y₁ - y₃)/2 - (x₁ - x₃)*(y₁ - y₂)/2 + (x₁ - x₃)*(y₁ - y₄)/2 - (x₁ - x₄)*(y₁ - y₃)/2
|
||||
tl₀ = a - f(a) / fp(a)
|
||||
x₁,x₂,x₃,x₄ = (a,q,q,tl₀)
|
||||
y₁, y₂, y₃, y₄ = (f(a), f(q), 0, 0)
|
||||
quadrilateral = -(x₁ - x₂)*(y₁ - y₃)/2 + (x₁ - x₃)*(y₁ - y₂)/2 - (x₁ - x₃)*(y₁ - y₄)/2 + (x₁ - x₄)*(y₁ - y₃)/2;
|
||||
quadrilateral = (x₁ - x₂)*(y₁ - y₃)/2 - (x₁ - x₃)*(y₁ - y₂)/2 + (x₁ - x₃)*(y₁ - y₄)/2 - (x₁ - x₄)*(y₁ - y₃)/2;
|
||||
```
|
||||
----
|
||||
|
||||
@@ -415,7 +416,7 @@ article_answers = (1/(2sqrt(2)), 1/2, sqrt(3/10), 0.558480, 0.564641,
|
||||
#| echo: false
|
||||
# check
|
||||
problems = ("1a"=>yvalue, "1b"=>lseg, "1c"=>hd,
|
||||
"2a" => A, "2b" => V,
|
||||
"2a" => A, "2b" => V(k=>1),
|
||||
"3" => yₘ,
|
||||
"4" => L,
|
||||
"5" => mp,
|
||||
@@ -429,7 +430,7 @@ problems = ("1a"=>yvalue, "1b"=>lseg, "1c"=>hd,
|
||||
)
|
||||
≈ₒ(a,b) = isapprox(a, b; atol=1e-5, rtol=sqrt(eps()))
|
||||
∂ = Differential(a)
|
||||
solutions = [k => only(solve(∂(p) ~ 0, a)) for (k,p) in problems]
|
||||
solutions = [k => (find_zero(∂(p), 0.5)) for (k,p) in problems]
|
||||
[(sol=k, correct=(any(isapprox.(s, article_answers; atol=1e-5)))) for (k,s) ∈ solutions]
|
||||
nothing
|
||||
```
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882"
|
||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
|
||||
Richardson = "708f8203-808e-40c0-ba2d-98a6953ed40d"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
|
||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||
TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d"
|
||||
|
||||
@@ -1028,7 +1028,7 @@ nothing
|
||||
{width=50%}
|
||||
|
||||
In 1638, according to Amir D. [Aczel](http://books.google.com/books?id=kvGt2OlUnQ4C&pg=PA28&lpg=PA28&dq=mersenne+cannon+ball+tests&source=bl&ots=wEUd7e0jFk&sig=LpFuPoUvODzJdaoug4CJsIGZZHw&hl=en&sa=X&ei=KUGcU6OAKJCfyASnioCoBA&ved=0CCEQ6AEwAA#v=onepage&q=mersenne%20cannon%20ball%20tests&f=false), an experiment was performed in the French Countryside. A monk, Marin Mersenne, launched a cannonball straight up into the air in an attempt to help Descartes prove facts about the rotation of the earth. Though the experiment was not successful, Mersenne later observed that the time for the cannonball to go up was greater than the time to come down. ["Vertical Projection in a Resisting Medium: Reflections on Observations of Mersenne".](http://www.maa.org/publications/periodicals/american-mathematical-monthly/american-mathematical-monthly-contents-junejuly-2014)
|
||||
In 1638, according to Amir D. [Aczel](http://books.google.com/books?id=kvGt2OlUnQ4C&pg=PA28&lpg=PA28&dq=mersenne+cannon+ball+tests&source=bl&ots=wEUd7e0jFk&sig=LpFuPoUvODzJdaoug4CJsIGZZHw&hl=en&sa=X&ei=KUGcU6OAKJCfyASnioCoBA&ved=0CCEQ6AEwAA#v=onepage&q=mersenne%20cannon%20ball%20tests&f=false), an experiment was performed in the French Countryside. A monk, Marin Mersenne, launched a cannonball straight up into the air in an attempt to help Descartes prove facts about the rotation of the earth. Though the experiment was not successful, Mersenne later observed that the time for the cannonball to go up was less than the time to come down. ["Vertical Projection in a Resisting Medium: Reflections on Observations of Mersenne".](http://www.maa.org/publications/periodicals/american-mathematical-monthly/american-mathematical-monthly-contents-junejuly-2014)
|
||||
|
||||
|
||||
This isn't the case for simple ballistic motion where the time to go up is equal to the time to come down. We can "prove" this numerically. For simple ballistic motion:
|
||||
|
||||
@@ -161,7 +161,7 @@ for (x, y, n, col) ∈ zip(xs, ys, ns, (blue, green, purple, red))
|
||||
end
|
||||
|
||||
caption = L"""
|
||||
The ratio of the circumference of a circle to its diameter, $\pi$, can be approximated from above and below by computing the perimeters of the inscribed $n$-gons. Archimedes computed the perimeters for $n$ being $12$, $24$, $48$, and $96$ to determine that $3~1/7 \leq \pi \leq 3~10/71$.
|
||||
The ratio of the circumference of a circle to its diameter, $\pi$, can be approximated from above and below by computing the perimeters of the inscribed $n$-gons. Archimedes computed the perimeters for $n$ being $12$, $24$, $48$, and $96$ to determine that $3~10/71 \leq \pi \leq 3~1/7$.
|
||||
"""
|
||||
plotly()
|
||||
ImageFile(p, caption)
|
||||
|
||||
@@ -876,7 +876,7 @@ numericq(-1)
|
||||
###### Question
|
||||
|
||||
|
||||
As mentioned, for limits that depend on specific values of parameters `SymPy` may have issues. As an example, `SymPy` has an issue with the following limit, whose answer depends on the value of $k$"
|
||||
As mentioned, for limits that depend on specific values of parameters `SymPy` may have issues. As an example, `SymPy` has an issue with the following limit, whose answer depends on the value of "$k$"
|
||||
|
||||
|
||||
$$
|
||||
@@ -1017,7 +1017,7 @@ radioq(choices, answ, keep_order=true)
|
||||
Suppose a sequence of points $x_n$ converges to $a$ in the limiting sense. For a function $f(x)$, the sequence of points $f(x_n)$ may or may not converge. One alternative definition of a [limit](https://en.wikipedia.org/wiki/Limit_of_a_function#In_terms_of_sequences) due to Heine is that $\lim_{x \rightarrow a}f(x) = L$ if *and* only if **all** sequences $x_n \rightarrow a$ have $f(x_n) \rightarrow L$.
|
||||
|
||||
|
||||
Consider the function $f(x) = \sin(1/x)$, $a=0$, and the two sequences implicitly defined by $1/x_n = \pi/2 + n \cdot (2\pi)$ and $y_n = 3\pi/2 + n \cdot(2\pi)$, $n = 0, 1, 2, \dots$.
|
||||
Consider the function $f(x) = \sin(1/x)$, $a=0$, and the two sequences implicitly defined by $1/x_n = \pi/2 + n \cdot (2\pi)$ and $1/y_n = 3\pi/2 + n \cdot(2\pi)$, $n = 0, 1, 2, \dots$.
|
||||
|
||||
|
||||
What is $\lim_{x_n \rightarrow 0} f(x_n)$?
|
||||
|
||||
@@ -68,7 +68,7 @@ For more control, the command line and `IJulia` provide access to the function i
|
||||
] status
|
||||
```
|
||||
|
||||
External packages are *typically* installed from GitHub and if they are regisered, installation is as easy as calling `add`:
|
||||
External packages are *typically* installed from GitHub and if they are registered, installation is as easy as calling `add`:
|
||||
|
||||
|
||||
```{julia}
|
||||
|
||||
@@ -4,12 +4,17 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
|
||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
|
||||
Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
|
||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
|
||||
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
|
||||
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
|
||||
QuizQuestions = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
|
||||
RealPolynomialRoots = "87be438c-38ae-47c4-9398-763eabe5c3be"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
|
||||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
|
||||
TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d"
|
||||
|
||||
@@ -19,7 +19,7 @@ The [`Julia`](http://www.julialang.org) programming language is well suited as a
|
||||
|
||||
`Julia` is an *open source* project which allows anyone with a supported computer to use it free of charge.
|
||||
|
||||
To install locally, the [downloads](https://julialang.org/downloads/) page has directions to use the `juliaup` utility for managing an installation. There are also links to several different binaries for manual installation. Additionally, the downloads page contains a link to a docker image. `Julia` can also be compiled from source.
|
||||
To install locally, the [downloads](https://julialang.org/downloads/) page has directions to use the `Juliaup` utility for managing an installation. There are also links to several different binaries for manual installation. Additionally, the downloads page contains a link to a docker image. `Julia` can also be compiled from source.
|
||||
|
||||
|
||||
`Julia` can also be run through the web.
|
||||
@@ -280,7 +280,7 @@ Values will be promoted to a common type (or type `Any` if none exists). For exa
|
||||
(Vectors are used as a return type from some functions, as such, some familiarity is needed.)
|
||||
|
||||
|
||||
Other common container types are variations of vectors (higher-dimensional arrays, offset arrays, etc.) tuples (for heterogeneous, immutable, indexed values); named tuples (which add a name to each value in a tuple); and dictionaries (for associative relationships between a key and a value).
|
||||
Other common container types are variables of vectors (higher-dimensional arrays, offset arrays, etc.) tuples (for heterogeneous, immutable, indexed values); named tuples (which add a name to each value in a tuple); and dictionaries (for associative relationships between a key and a value).
|
||||
|
||||
|
||||
Regular arithmetic sequences can be defined by either:
|
||||
|
||||
@@ -26,7 +26,7 @@ On top of these, we have special subsets, such as the natural numbers $\{1, 2, \
|
||||
Mathematically, these number systems are naturally nested within each other as integers are rational numbers which are real numbers, which can be viewed as part of the complex numbers.
|
||||
|
||||
|
||||
Calculators typically have just one type of number - floating point values. These model the real numbers. `Julia`, on the other hand, has a rich type system, and within that has many different number types. There are types that model each of the four main systems above, and within each type, specializations for how these values are stored.
|
||||
Calculators typically have just one type of number - floating point values. These model the real numbers. `Julia`, on the other hand, has a rich type system, and within that has several different number types. There are types that model each of the four main systems above, and within each type, specializations for how these values are stored.
|
||||
|
||||
|
||||
Most of the details will not be of interest to all, and will be described later.
|
||||
|
||||
@@ -39,7 +39,7 @@ A *polynomial* is a sum of monomials. After combining terms with same powers, a
|
||||
|
||||
|
||||
$$
|
||||
a_n x^n + a_{n-1}x^{n-1} + \cdots a_1 x + a_0, \quad a_n \neq 0
|
||||
a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1 x + a_0, \quad a_n \neq 0
|
||||
$$
|
||||
|
||||
```{julia}
|
||||
@@ -343,7 +343,7 @@ pp = lambdify(p)
|
||||
pp(2)
|
||||
```
|
||||
|
||||
The `lambdify` function uses the name of the similar `SymPy` function which is named after Python's convention of calling anoynmous function "lambdas." The use above is straightforward. Only slightly more complicated is the use when there are multiple symbolic values. For example:
|
||||
The `lambdify` function uses the name of the similar `SymPy` function which is named after Python's convention of calling anonymous function "lambdas." The use above is straightforward. Only slightly more complicated is the use when there are multiple symbolic values. For example:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -379,7 +379,7 @@ This graph illustrates the key features of polynomial graphs:
|
||||
|
||||
|
||||
* there may be values for `x` where the graph crosses the $x$ axis (real roots of the polynomial);
|
||||
* there may be peaks and valleys (local maxima and local minima)
|
||||
* there may be peaks and valleys (local maxima and local minima);
|
||||
* except for constant polynomials, the ultimate behaviour for large values of $|x|$ is either both sides of the graph going to positive infinity, or negative infinity, or as in this graph one to the positive infinity and one to negative infinity. In particular, there is no *horizontal asymptote*.
|
||||
|
||||
|
||||
@@ -513,7 +513,7 @@ This observation is the start of Descartes' rule of [signs](http://sepwww.stanfo
|
||||
Among numerous others, there are two common ways of representing a non-zero polynomial:
|
||||
|
||||
|
||||
* expanded form, as in $a_n x^n + a_{n-1}x^{n-1} + \cdots a_1 x + a_0, a_n \neq 0$; or
|
||||
* expanded form, as in $a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1 x + a_0, a_n \neq 0$; or
|
||||
* factored form, as in $a\cdot(x-r_1)\cdot(x-r_2)\cdots(x-r_n), a \neq 0$.
|
||||
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ A polynomial with real coefficients may or may not have real roots. The followin
|
||||
The study of polynomial roots is an old one. In $1637$ Descartes published a *simple* method to determine an upper bound on the number of *positive* real roots of a polynomial.
|
||||
|
||||
|
||||
> [Descartes' rule of signs](http://en.wikipedia.org/wiki/Descartes%27_rule_of_signs): if $p=a_n x^n + a_{n-1}x^{n-1} + \cdots a_1x + a_0$ then the number of positive real roots is either equal to the number of sign differences between consecutive nonzero coefficients, or is less than it by an even number. Repeated roots are counted separately.
|
||||
> [Descartes' rule of signs](http://en.wikipedia.org/wiki/Descartes%27_rule_of_signs): if $p=a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0$ then the number of positive real roots is either equal to the number of sign differences between consecutive nonzero coefficients, or is less than it by an even number. Repeated roots are counted separately.
|
||||
|
||||
|
||||
|
||||
@@ -553,7 +553,7 @@ N.(solve(j ~ 0, x))
|
||||
### Cauchy's bound on the magnitude of the real roots.
|
||||
|
||||
|
||||
Descartes' rule gives a bound on how many real roots there may be. Cauchy provided a bound on how large they can be. Assume our polynomial is monic (if not, divide by $a_n$ to make it so, as this won't effect the roots). Then any real root is no larger in absolute value than $|a_0| + |a_1| + |a_2| + \cdots + |a_n|$, (this is expressed in different ways.)
|
||||
Descartes' rule gives a bound on how many real roots there may be. Cauchy provided a bound on how large they can be. Assume our polynomial is monic (if not, divide by $a_n$ to make it so, as this won't effect the roots). Then any real root is no larger in absolute value than $|a_0| + |a_1| + |a_2| + \cdots + |a_{n-1}| + 1$, (this is expressed in different ways.)
|
||||
|
||||
|
||||
To see precisely [why](https://captainblack.wordpress.com/2009/03/08/cauchys-upper-bound-for-the-roots-of-a-polynomial/) this bound works, suppose $x$ is a root with $|x| > 1$ and let $h$ be the bound. Then since $x$ is a root, we can solve $a_0 + a_1x + \cdots + 1 \cdot x^n = 0$ for $x^n$ as:
|
||||
|
||||
@@ -454,18 +454,18 @@ numericq(4)
|
||||
The identification of a collection of coefficients with a polynomial depends on an understood **basis**. A basis for the polynomials of degree $n$ or less, consists of a minimal collection of polynomials for which all the polynomials of degree $n$ or less can be expressed through a combination of sums of terms, each of which is just a coefficient times a basis member. The typical basis is the $n+1$ polynomials $1, x, x^2, \dots, x^n$. However, though every basis must have $n+1$ members, they need not be these.
|
||||
|
||||
|
||||
A basis used by [Lagrange](https://en.wikipedia.org/wiki/Lagrange_polynomial) is the following. Let there be $n+1$ points distinct points $x_0, x_1, \dots, x_n$. For each $i$ in $0$ to $n$ define
|
||||
A basis used by [Lagrange](https://en.wikipedia.org/wiki/Lagrange_polynomial) is the following. Let there be $n+1$ distinct points $x_0, x_1, \dots, x_n$. For each $i$ in $0$ to $n$ define
|
||||
|
||||
|
||||
$$
|
||||
l_i(x) = \prod_{0 \leq j \leq n; j \ne i} \frac{x-x_j}{x_i - x_j} =
|
||||
\frac{(x-x_1)\cdot(x-x_2)\cdot \cdots \cdot (x-x_{i-1}) \cdot (x-x_{i+1}) \cdot \cdots \cdot (x-x_n)}{(x_i-x_1)\cdot(x_i-x_2)\cdot \cdots \cdot (x_i-x_{i-1}) \cdot (x_i-x_{i+1}) \cdot \cdots \cdot (x_i-x_n)}.
|
||||
\frac{(x-x_0)\cdot(x-x_1)\cdot \cdots \cdot (x-x_{i-1}) \cdot (x-x_{i+1}) \cdot \cdots \cdot (x-x_n)}{(x_i-x_0)\cdot(x_i-x_1)\cdot \cdots \cdot (x_i-x_{i-1}) \cdot (x_i-x_{i+1}) \cdot \cdots \cdot (x_i-x_n)}.
|
||||
$$
|
||||
|
||||
That is $l_i(x)$ is a product of terms like $(x-x_j)/(x_i-x_j)$ *except* when $j=i$.
|
||||
|
||||
|
||||
What is is the value of $l_0(x_0)$?
|
||||
What is the value of $l_0(x_0)$?
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -578,7 +578,7 @@ choices = [
|
||||
It is ``0\cdot T_0(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = 0``
|
||||
"""
|
||||
raw"""
|
||||
It is ``0\cdot T_0(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = -2 - 8\cdot x + 4\cdot x^2 + 12\cdot x^3```
|
||||
It is ``0\cdot T_0(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = -2 - 8\cdot x + 4\cdot x^2 + 12\cdot x^3``
|
||||
"""]
|
||||
radioq(choices, 3)
|
||||
```
|
||||
|
||||
@@ -159,7 +159,7 @@ Similarly, a plot over $[-100, -10]$ would show decay towards $0$, though in tha
|
||||
We can easily do most of this analysis without needing a computer or algebra. First, we should know the four eventual shapes of a polynomial, that the graph of $y=mx$ is a line with slope $m$, the graph of $y = c$ is a constant line at height $c$, and the graph of $y=c/x^m$, $m > 0$ will decay towards $0$ as $x \rightarrow \pm\infty$. The latter should be clear, as $x^m$ gets big, so its reciprocal goes towards $0$.
|
||||
|
||||
|
||||
The factored form, as $p$ is presented, is a bit hard to work with, rather we use the expanded form, which we get through the `cancel` function
|
||||
The factored form, as $h$ is presented, is a bit hard to work with, rather we use the expanded form, which we get through the `cancel` function
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -179,7 +179,7 @@ The terms $(1 - 4/x + 5/x^2 - 2/x^3)$ and $(1 - 9/x^2)$ go towards $1$ as $x \ri
|
||||
Just by looking at the ratio of the two leading terms, the behaviour as $x \rightarrow \pm \infty$ can be discerned. If this ratio is of:
|
||||
|
||||
|
||||
* the form $c x^m$ with $m > 1$ then the shape will follow the polynomial growth of of the monomial $c x^m$.
|
||||
* the form $c x^m$ with $m > 1$ then the shape will follow the polynomial growth of the monomial $c x^m$.
|
||||
* the form $c x^m$ with $m=1$ then there will be a line with slope $c$ as a *slant asymptote*.
|
||||
* the form $cx^0$ with $m=0$ (or just $c$) then there will be a *horizontal asymptote* $y=c$.
|
||||
* the form $c/x^{m}$ with $m > 0$ then there will be a horizontal asymptote $y=0$, or the $y$ axis.
|
||||
@@ -266,7 +266,7 @@ $$
|
||||
\frac{(x-2)^3\cdot(x-4)\cdot(x-3)}{(x-5)^4 \cdot (x-6)^2}.
|
||||
$$
|
||||
|
||||
By looking at the powers we can see that the leading term of the numerator will the $x^5$ and the leading term of the denominator $x^6$. The ratio is $1/x^1$. As such, we expect the $x$-axis as a horizontal asymptote:
|
||||
By looking at the powers we can see that the leading term of the numerator will the $x^5$ and the leading term of the denominator $x^6$. The ratio is $1/x^1$. As such, we expect the $x$-axis as a horizontal asymptote.
|
||||
|
||||
|
||||
#### Partial fractions
|
||||
|
||||
@@ -168,7 +168,7 @@ sin(theta)^2
|
||||
```
|
||||
|
||||
|
||||
These values are floating point approximations, as can be seen clearly in the computation of `sin(pi/2)`, which is mathematically $0$. Symbolic math can be usedby using `PI` for `pi` if exactness matters:
|
||||
These values are floating point approximations, as can be seen clearly in the computation of `cos(pi/2)`, which is mathematically $0$. Symbolic math can be used by using `PI` for `pi` if exactness matters:
|
||||
|
||||
```{julia}
|
||||
cos.([0, PI/6, PI/4, PI/3, PI/2])
|
||||
@@ -732,7 +732,7 @@ $$
|
||||
\cos((n+1)\theta) = 2 \cos(\theta) \cos(n\theta) - \cos((n-1)\theta).
|
||||
$$
|
||||
|
||||
Let $T_n(x) = \cos(n \arccos(x))$. Note $T_1(x) = \cos(x)$. By identifying $\theta$ with $\arccos(x)$ for $-1 \leq x \leq 1$, we get a relation between these functions:
|
||||
Let $T_n(x) = \cos(n \arccos(x))$. Note $T_1(x) = x$. By identifying $\theta$ with $\arccos(x)$ for $-1 \leq x \leq 1$, we get a relation between these functions:
|
||||
|
||||
|
||||
$$
|
||||
|
||||
Reference in New Issue
Block a user