use quarto, not Pluto to render pages
This commit is contained in:
@@ -16,7 +16,7 @@ const frontmatter = (
|
||||
description = "Calculus with Julia: The `DifferentialEquations` suite",
|
||||
tags = ["CalculusWithJulia", "odes", "the `differentialequations` suite"],
|
||||
);
|
||||
fig_size = (600, 400)
|
||||
fig_size = (800, 600)
|
||||
nothing
|
||||
```
|
||||
|
||||
@@ -152,12 +152,8 @@ end
|
||||
|
||||
The notation `du` is suggestive of both the derivative and a small increment. The mathematical formulation follows the derivative, the numeric solution uses a time step and increments the solution over this time step. The `Tsit5()` solver, used here, adaptively chooses a time step, `dt`; were the `Euler` method used, this time step would need to be explicit.
|
||||
|
||||
```julia; echo=false
|
||||
note("""
|
||||
The `sir!` function has the trailing `!` indicating -- by convention -- it *mutates* its first value, `du`. In this case, through an assignment, as in `du[1]=ds`. This could use some explanation. The *binding* `du` refers to the *container* holding the ``3`` values, whereas `du[1]` refers to the first value in that container. So `du[1]=ds` changes the first value, but not the *binding* of `du` to the container. That is, `du` mutates. This would be quite different were the call `du = [ds,di,dr]` which would create a new *binding* to a new container and not mutate the values in the original container.
|
||||
""", title="Mutation not re-binding")
|
||||
```
|
||||
|
||||
!!! note "Mutation not re-binding"
|
||||
The `sir!` function has the trailing `!` indicating -- by convention -- it *mutates* its first value, `du`. In this case, through an assignment, as in `du[1]=ds`. This could use some explanation. The *binding* `du` refers to the *container* holding the ``3`` values, whereas `du[1]` refers to the first value in that container. So `du[1]=ds` changes the first value, but not the *binding* of `du` to the container. That is, `du` mutates. This would be quite different were the call `du = [ds,di,dr]` which would create a new *binding* to a new container and not mutate the values in the original container.
|
||||
|
||||
With the update function defined, the problem is setup and a solution found with in the same manner:
|
||||
|
||||
@@ -289,12 +285,8 @@ end
|
||||
|
||||
This function ``W`` is just a constant above, but can be easily modified as desired.
|
||||
|
||||
```julia; echo=false
|
||||
note("""
|
||||
The "standard" trick is to take a second order ODE like ``u''(t)=u`` and turn this into two coupled ODEs by using a new name: ``v=u'(t)`` and then ``v'(t) = u(t)``. In this application, there are ``4`` equations, as we have *both* ``x''`` and ``y''`` being so converted. The first and second components of ``du`` are new variables, the third and fourth show the original equation.
|
||||
""", title="A second-order ODE is a coupled first-order ODE")
|
||||
```
|
||||
|
||||
!!! note "A second-order ODE is a coupled first-order ODE"
|
||||
The "standard" trick is to take a second order ODE like ``u''(t)=u`` and turn this into two coupled ODEs by using a new name: ``v=u'(t)`` and then ``v'(t) = u(t)``. In this application, there are ``4`` equations, as we have *both* ``x''`` and ``y''`` being so converted. The first and second components of ``du`` are new variables, the third and fourth show the original equation.
|
||||
|
||||
The initial conditions are specified through:
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ const frontmatter = (
|
||||
description = "Calculus with Julia: Euler's method",
|
||||
tags = ["CalculusWithJulia", "odes", "euler's method"],
|
||||
);
|
||||
fig_size = (600, 400)
|
||||
fig_size = (800, 600)
|
||||
nothing
|
||||
```
|
||||
|
||||
@@ -829,6 +829,6 @@ choices = [
|
||||
"The solution is identical to that of the approximation found by linearization of the sine term",
|
||||
"The solution has a constant amplitude, but its period is slightly *shorter* than that of the approximate solution found by linearization",
|
||||
"The solution has a constant amplitude, but its period is slightly *longer* than that of the approximate solution found by linearization"]
|
||||
ans = 4
|
||||
radioq(choices, ans, keep_order=true)
|
||||
answ = 4
|
||||
radioq(choices, answ, keep_order=true)
|
||||
```
|
||||
|
||||
@@ -93,8 +93,11 @@ x'(t) = v(t) = v_0 + a (t - t_0), \quad x(t_0) = x_0.
|
||||
Again, we can integrate to get an answer for any value $t$:
|
||||
|
||||
```math
|
||||
x(t) - x(t_0) = \int_{t_0}^t \frac{dv}{dt} dt = (v_0t + \frac{1}{2}a t^2 - at_0 t) |_{t_0}^t =
|
||||
(v_0 - at_0)(t - t_0) + \frac{1}{2} a (t^2 - t_0^2).
|
||||
\begin{align*}
|
||||
x(t) - x(t_0) &= \int_{t_0}^t \frac{dv}{dt} dt \\
|
||||
&= (v_0t + \frac{1}{2}a t^2 - at_0 t) |_{t_0}^t \\
|
||||
&= (v_0 - at_0)(t - t_0) + \frac{1}{2} a (t^2 - t_0^2).
|
||||
\end{align*}
|
||||
```
|
||||
|
||||
There are three constants: the initial value for the independent variable, $t_0$, and the two initial values for the velocity and position, $v_0, x_0$. Assuming $t_0 = 0$, we can simplify the above to get a formula familiar from introductory physics:
|
||||
@@ -174,13 +177,15 @@ A graph of the solution for $T_0=200$ and $T_a=72$ and $r=1/2$ is made
|
||||
as follows. We've added a few line segments from the defining formula,
|
||||
and see that they are indeed tangent to the solution found for the differential equation.
|
||||
|
||||
```julia; hold=true; echo=false
|
||||
T0, Ta, r = 200, 72, 1/2
|
||||
f(u, t) = -r*(u - Ta)
|
||||
v(t) = Ta + (T0 - Ta) * exp(-r*t)
|
||||
p = plot(v, 0, 6, linewidth=4, legend=false)
|
||||
[plot!(p, x -> v(a) + f(v(a), a) * (x-a), 0, 6) for a in 1:2:5]
|
||||
p
|
||||
```julia; echo=false
|
||||
let
|
||||
T0, Ta, r = 200, 72, 1/2
|
||||
f(u, t) = -r*(u - Ta)
|
||||
v(t) = Ta + (T0 - Ta) * exp(-r*t)
|
||||
p = plot(v, 0, 6, linewidth=4, legend=false)
|
||||
[plot!(p, x -> v(a) + f(v(a), a) * (x-a), 0, 6) for a in 1:2:5]
|
||||
p
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
@@ -725,10 +730,8 @@ plot!(f, linewidth=5)
|
||||
|
||||
In general, if the first-order equation is written as $y'(x) = F(y,x)$, then we plot a "function" that takes $(x,y)$ and returns an $x$ value of $1$ and a $y$ value of $F(y,x)$, so the slope is $F(y,x)$.
|
||||
|
||||
```julia; echo=false
|
||||
note(L"""The order of variables in $F(y,x)$ is conventional with the equation $y'(x) = F(y(x),x)$.
|
||||
""")
|
||||
```
|
||||
!!! note
|
||||
The order of variables in $F(y,x)$ is conventional with the equation $y'(x) = F(y(x),x)$.
|
||||
|
||||
|
||||
The plots are also useful for illustrating solutions for different initial conditions:
|
||||
@@ -780,8 +783,8 @@ choices = [
|
||||
"``[-1, 4]``",
|
||||
"``[-1, 0]``",
|
||||
"``[1-\\sqrt{5}, 1 + \\sqrt{5}]``"]
|
||||
ans = 4
|
||||
radioq(choices, ans)
|
||||
answ = 4
|
||||
radioq(choices, answ)
|
||||
```
|
||||
|
||||
|
||||
@@ -891,8 +894,8 @@ eqn = diff(x^2*D(u)(x), x)
|
||||
out = dsolve(eqn, u(x), ics=Dict(u(1)=>2, u(10) => 1)) |> rhs
|
||||
out(5) # 10/9
|
||||
choices = ["``10/9``", "``3/2``", "``9/10``", "``8/9``"]
|
||||
ans = 1
|
||||
radioq(choices, ans)
|
||||
answ = 1
|
||||
radioq(choices, answ)
|
||||
```
|
||||
|
||||
|
||||
@@ -909,6 +912,6 @@ choices = [
|
||||
"The limit does not exist, but the limit to `oo` gives a quadratic polynomial in `x`, mirroring the first part of that example.",
|
||||
"The limit does not exist -- there is a singularity -- as seen by setting `gamma=0`."
|
||||
]
|
||||
ans = 1
|
||||
radioq(choices, ans)
|
||||
answ = 1
|
||||
radioq(choices, answ)
|
||||
```
|
||||
|
||||
@@ -15,7 +15,7 @@ const frontmatter = (
|
||||
description = "Calculus with Julia: The problem-algorithm-solve interface",
|
||||
tags = ["CalculusWithJulia", "odes", "the problem-algorithm-solve interface"],
|
||||
);
|
||||
fig_size = (600, 400)
|
||||
fig_size = (800, 600)
|
||||
nothing
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user