2022-08-26 14:45:24 -04:00

15 lines
53 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"hash": "5c7dc5f0c344e20d52b8e4b867058dfc",
"result": {
"markdown": "# ODEs\n\n\n\nThis section uses these add-on packages:\n\n``` {.julia .cell-code}\nusing CalculusWithJulia\nusing Plots\nusing SymPy\n```\n\n\n\n\n---\n\n\nSome relationships are easiest to describe in terms of rates or derivatives. For example:\n\n\n * Knowing the speed of a car and how long it has been driving can summarize the car's location.\n * One of Newton's famous laws, $F=ma$, describes the force on an object of mass $m$ in terms of the acceleration. The acceleration is the derivative of velocity, which in turn is the derivative of position. So if we know the rates of change of $v(t)$ or $x(t)$, we can differentiate to find $F$.\n * Newton's law of [cooling](http://tinyurl.com/z4lmetp). This describes the temperature change in an object due to a difference in temperature with the object's surroundings. The formula being, $T'(t) = -r \\left(T(t) - T_a \\right)$, where $T(t)$ is temperature at time $t$ and $T_a$ the ambient temperature.\n * [Hooke's law](http://tinyurl.com/kbz7r8l) relates force on an object to the position on the object, through $F = k x$. This is appropriate for many systems involving springs. Combined with Newton's law $F=ma$, this leads to an equation that $x$ must satisfy: $m x''(t) = k x(t)$.\n\n\n## Motion with constant acceleration\n\n\nLet's consider the case of constant acceleration. This describes how nearby objects fall to earth, as the force due to gravity is assumed to be a constant, so the acceleration is the constant force divided by the constant mass.\n\n\nWith constant acceleration, what is the velocity?\n\n\nAs mentioned, we have $dv/dt = a$ for any velocity function $v(t)$, but in this case, the right hand side is assumed to be constant. How does this restrict the possible functions, $v(t)$, that the velocity can be?\n\n\nHere we can integrate to find that any answer must look like the following for some constant of integration:\n\n\n\n$$\nv(t) = \\int \\frac{dv}{dt} dt = \\int a dt = at + C.\n$$\n\n\nIf we are given the velocity at a fixed time, say $v(t_0) = v_0$, then we can use the definite integral to get:\n\n\n\n$$\nv(t) - v(t_0) = \\int_{t_0}^t a dt = at - a t_0.\n$$\n\n\nSolving, gives:\n\n\n\n$$\nv(t) = v_0 + a (t - t_0).\n$$\n\n\nThis expresses the velocity at time $t$ in terms of the initial velocity, the constant acceleration and the time duration.\n\n\nA natural question might be, is this the *only* possible answer? There are a few useful ways to think about this.\n\n\nFirst, suppose there were another, say $u(t)$. Then define $w(t)$ to be the difference: $w(t) = v(t) - u(t)$. We would have that $w'(t) = v'(t) - u'(t) = a - a = 0$. But from the mean value theorem, a function whose derivative is *continuously* $0$, will necessarily be a constant. So at most, $v$ and $u$ will differ by a constant, but if both are equal at $t_0$, they will be equal for all $t$.\n\n\nSecond, since the derivative of any solution is a continuous function, it is true by the fundamental theorem of calculus that it *must* satisfy the form for the antiderivative. The initial condition makes the answer unique, as the indeterminate $C$ can take only one value.\n\n\nSummarizing, we have\n\n\n> If $v(t)$ satisfies the equation: $v'(t) = a$, $v(t_0) = v_0,$ then the unique solution will be $v(t) = v_0 + a (t - t_0)$.\n\n\n\nNext, what about position? Here we know that the time derivative of position yields the velocity, so we should have that the unknown position function satisfies this equation and initial condition:\n\n\n\n$$\nx'(t) = v(t) = v_0 + a (t - t_0), \\quad x(t_0) = x_0.\n$$\n\n\nAgain, we can integrate to get an answer for any value $t$:\n\n\n\n$$\n\\begin{align*}\nx(t) - x(t_0) &= \\int_{t_0}^t \\frac{dv}{dt} dt \\\\\n&= (v_0t + \\frac{1}{2}a t^2 - at_0 t) |_{t_0}^t \\\\\n&= (v_0 - at_0)(t - t_0) + \\frac{1}{2} a (t^2 - t_0^2).\n\\end{align*}\n$$\n\n\nThere 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:\n\n\n\n$$\nx(t) = x_0 + v_0 t + \\frac{1}{2} at^2.\n$$\n\n\nAgain, the mean value theorem can show that with the initial value specified this is the only possible solution.\n\n\n## First-order initial-value problems\n\n\nThe two problems just looked at can be summarized by the following. We are looking for solutions to an equation of the form (taking $y$ and $x$ as the variables, in place of $x$ and $t$):\n\n\n\n$$\ny'(x) = f(x), \\quad y(x_0) = y_0.\n$$\n\n\nThis is called an *ordinary differential equation* (ODE), as it is an equation involving the ordinary derivative of an unknown function, $y$.\n\n\nThis is called a first-order, ordinary differential equation, as there is only the first derivative involved.\n\n\nThis is called an initial-value problem, as the value at the initial point $x_0$ is specified as part of the problem.\n\n\n#### Examples\n\n\nLet's look at a few more examples, and then generalize.\n\n\n##### Example: Newton's law of cooling\n\n\nConsider the ordinary differential equation given by Newton's law of cooling:\n\n\n\n$$\nT'(t) = -r (T(t) - T_a), \\quad T(0) = T_0\n$$\n\n\nThis equation is also first order, as it involves just the first derivative, but notice that on the right hand side is the function $T$, not the variable being differentiated against, $t$.\n\n\nAs we have a difference on the right hand side, we rename the variable through $U(t) = T(t) - T_a$. Then, as $U'(t) = T'(t)$, we have the equation:\n\n\n\n$$\nU'(t) = -r U(t), \\quad U(0) = U_0.\n$$\n\n\nThis shows that the rate of change of $U$ depends on $U$. Large postive values indicate a negative rate of change - a push back towards the origin, and large negative values of $U$ indicate a positive rate of change - again, a push back towards the origin. We shouldn't be surprised to either see a steady decay towards the origin, or oscillations about the origin.\n\n\nWhat will we find? This equation is different from the previous two equations, as the function $U$ appears on both sides. However, we can rearrange to get:\n\n\n\n$$\n\\frac{dU}{dt}\\frac{1}{U(t)} = -r.\n$$\n\n\nThis suggests integrating both sides, as before. Here we do the \"$u$\"-substitution $u = U(t)$, so $du = U'(t) dt$:\n\n\n\n$$\n-rt + C = \\int \\frac{dU}{dt}\\frac{1}{U(t)} dt =\n\\int \\frac{1}{u}du = \\log(u).\n$$\n\n\nSolving gives: $u = U(t) = e^C e^{-rt}$. Using the initial condition forces $e^C = U(t_0) = T(0) - T_a$ and so our solution in terms of $T(t)$ is:\n\n\n\n$$\nT(t) - T_a = (T_0 - T_a) e^{-rt}.\n$$\n\n\nIn words, the initial difference in temperature of the object and the environment exponentially decays to $0$.\n\n\nThat is, as $t > 0$ goes to $\\infty$, the right hand will go to $0$ for $r > 0$, so $T(t) \\rightarrow T_a$ - the temperature of the object will reach the ambient temperature. The rate of this is largest when the difference between $T(t)$ and $T_a$ is largest, so when objects are cooling the statement \"hotter things cool faster\" is appropriate.\n\n\nA 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.\n\n::: {.cell execution_count=4}\n\n::: {.cell-output .cell-output-display execution_count=5}\n![](odes_files/figure-html/cell-5-output-1.svg){}\n:::\n:::\n\n\nThe above is implicitly assuming that there could be no other solution, than the one we found. Is that really the case? We will see that there is a theorem that can answer this, but in this case, the trick of taking the difference of two equations satisfying the equation leads to the equation $W'(t) = r W(t), \\text{ and } W(0) = 0$. This equation has a general solution of $W(t) = Ce^{rt}$ and the initial condition forces $C=0$, so $W(t) = 0$, as before. Hence, the initial-value problem for Newton's law of cooling has a unique solution.\n\n\nIn general, the equation could be written as (again using $y$ and $x$ as the variables):\n\n\n\n$$\ny'(x) = g(y), \\quad y(x_0) = y_0\n$$\n\n\nThis is called an *autonomous*, first-order ODE, as the right-hand side does not depend on $x$ (except through $y(x)$).\n\n\nLet $F(y) = \\int_{y_0}^y du/g(u)$, then a solution to the above is $F(y) = x - x_0$, assuming $1/g(u)$ is integrable.\n\n\n##### Example: Toricelli's law\n\n\n[Toricelli's Law](http://tinyurl.com/hxvf3qp) describes the speed a jet of water will leave a vessel through an opening below the surface of the water. The formula is $v=\\sqrt{2gh}$, where $h$ is the height of the water above the hole and $g$ the gravitational constant. This arises from equating the kinetic energy gained, $1/2 mv^2$ and potential energy lost, $mgh$, for the exiting water.\n\n\nAn application of Torricelli's law is to describe the volume of water in a tank over time, $V(t)$. Imagine a cylinder of cross sectional area $A$ with a hole of cross sectional diameter $a$ at the bottom, Then $V(t) = A h(t)$, with $h$ giving the height. The change in volume over $\\Delta t$ units of time must be given by the value $a v(t) \\Delta t$, or\n\n\n\n$$\nV(t+\\Delta t) - V(t) = -a v(t) \\Delta t = -a\\sqrt{2gh(t)}\\Delta t\n$$\n\n\nThis suggests the following formula, written in terms of $h(t)$ should apply:\n\n\n\n$$\nA\\frac{dh}{dt} = -a \\sqrt{2gh(t)}.\n$$\n\n\nRearranging, this gives an equation\n\n\n\n$$\n\\frac{dh}{dt} \\frac{1}{\\sqrt{h(t)}} = -\\frac{a}{A}\\sqrt{2g}.\n$$\n\n\nIntegrating both sides yields:\n\n\n\n$$\n2\\sqrt{h(t)} = -\\frac{a}{A}\\sqrt{2g} t + C.\n$$\n\n\nIf $h(0) = h_0 = V(0)/A$, we can solve for $C = 2\\sqrt{h_0}$, or\n\n\n\n$$\n\\sqrt{h(t)} = \\sqrt{h_0} -\\frac{1}{2}\\frac{a}{A}\\sqrt{2g} t.\n$$\n\n\nSetting $h(t)=0$ and solving for $t$ shows that the time to drain the tank would be $(2A)/(a\\sqrt{2g})\\sqrt{h_0}$.\n\n\n##### Example\n\n\nConsider now the equation\n\n\n\n$$\ny'(x) = y(x)^2, \\quad y(x_0) = y_0.\n$$\n\n\nThis is called a *non-linear* ordinary differential equation, as the $y$ variable on the right hand side presents itself in a non-linear form (it is squared). These equations may have solutions that are not defined for all times.\n\n\nThis particular problem can be solved as before by moving the $y^2$ to the left hand side and integrating to yield:\n\n\n\n$$\ny(x) = - \\frac{1}{C + x},\n$$\n\n\nand with the initial condition:\n\n\n\n$$\ny(x) = \\frac{y_0}{1 - y_0(x - x_0)}.\n$$\n\n\nThis answer can demonstrate *blow-up*. That is, in a finite range for $x$ values, the $y$ value can go to infinity. For example, if the initial conditions are $x_0=0$ and $y_0 = 1$, then $y(x) = 1/(1-x)$ is only defined for $x \\geq x_0$ on $[0,1)$, as at $x=1$ there is a vertical asymptote.\n\n\n## Separable equations\n\n\nWe've seen equations of the form $y'(x) = f(x)$ and $y'(x) = g(y)$ both solved by integrating. The same tricks will work for equations of the form $y'(x) = f(x) \\cdot g(y)$. Such equations are called *separable*.\n\n\nBasically, we equate up to constants\n\n\n\n$$\n\\int \\frac{dy}{g(y)} = \\int f(x) dx.\n$$\n\n\nFor example, suppose we have the equation\n\n\n\n$$\n\\frac{dy}{dx} = x \\cdot y(x), \\quad y(x_0) = y_0.\n$$\n\n\nThen we can find a solution, $y(x)$ through:\n\n\n\n$$\n\\int \\frac{dy}{y} = \\int x dx,\n$$\n\n\nor\n\n\n\n$$\n\\log(y) = \\frac{x^2}{2} + C\n$$\n\n\nWhich yields:\n\n\n\n$$\ny(x) = e^C e^{\\frac{1}{2}x^2}.\n$$\n\n\nSubstituting in $x_0$ yields a value for $C$ in terms of the initial information $y_0$ and $x_0$.\n\n\n## Symbolic solutions\n\n\nDifferential equations are classified according to their type. Different types have different methods for solution, when a solution exists.\n\n\nThe first-order initial value equations we have seen can be described generally by\n\n\n\n$$\n\\begin{align*}\ny'(x) &= F(y,x),\\\\\ny(x_0) &= x_0.\n\\end{align*}\n$$\n\n\nSpecial cases include:\n\n\n * *linear* if the function $F$ is linear in $y$;\n * *autonomous* if $F(y,x) = G(y)$ (a function of $y$ alone);\n * *separable* if $F(y,x) = G(y)H(x)$.\n\n\nAs seen, separable equations are approached by moving the \"$y$\" terms to one side, the \"$x$\" terms to the other and integrating. This also applies to autonomous equations then. There are other families of equation types that have exact solutions, and techniques for solution, summarized at this [Wikipedia page](http://tinyurl.com/zywzz4q).\n\n\nRather than go over these various families, we demonstrate that `SymPy` can solve many of these equations symbolically.\n\n\nThe `solve` function in `SymPy` solves equations for unknown *variables*. As a differential equation involves an unknown *function* there is a different function, `dsolve`. The basic idea is to describe the differential equation using a symbolic function and then call `dsolve` to solve the expression.\n\n\nSymbolic functions are defined by the `@syms` macro (also see `?symbols`) using parentheses to distinguish a function from a variable:\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\n@syms x u() # a symbolic variable and a symbolic function\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n```\n(x, u)\n```\n:::\n:::\n\n\nWe will solve the following, known as the *logistic equation*:\n\n\n\n$$\nu'(x) = a u(1-u), \\quad a > 0\n$$\n\n\nBefore 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:\n\n::: {.cell execution_count=6}\n``` {.julia .cell-code}\n@syms a::positive\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n(a,)\n```\n:::\n:::\n\n\nTo specify a derivative of `u` in our equation we can use `diff(u(x),x)` but here, for visual simplicity, use the `Differential` operator, as follows:\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\nD = Differential(x)\neqn = D(u)(x) ~ a * u(x) * (1 - u(x)) # use l \\Equal[tab] r, Eq(l,r), or just l - r\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n\\frac{d}{d x} u{\\left(x \\right)} = a \\left(1 - u{\\left(x \\right)}\\right) u{\\left(x \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\nIn the above, we evaluate the symbolic function at the variable `x` through the use of `u(x)` in the expression. The equation above uses `~` to combine the left- and right-hand sides as an equation in `SymPy`. (A unicode equals is also available for this task). This is a shortcut for `Eq(l,r)`, but even just using `l - r` would suffice, as the default assumption for an equation is that it is set to `0`.\n\n\nThe `Differential` operation is borrowed from the `ModelingToolkit` package, which will be introduced later.\n\n\nTo finish, we call `dsolve` to find a solution (if possible):\n\n::: {.cell execution_count=8}\n``` {.julia .cell-code}\nout = dsolve(eqn)\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nu{\\left(x \\right)} = \\frac{1}{C_{1} e^{- a x} + 1}\n\\]\n</span>\n```\n:::\n:::\n\n\nThis 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.\n\n\nThe limits are confirmed by investigating the limits of the right-hand:\n\n::: {.cell execution_count=9}\n``` {.julia .cell-code}\nlimit(rhs(out), x => oo), limit(rhs(out), x => -oo)\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n```\n(1, 0)\n```\n:::\n:::\n\n\nWe can confirm that the solution is always increasing, hence trapped within $[0,1]$ by observing that the derivative is positive when `C₁` is positive:\n\n\n\n```{juila}\ndiff(rhs(out),x)\n```\n\n\nSuppose 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`:\n\n::: {.cell execution_count=10}\n``` {.julia .cell-code}\neq = rhs(out) # just the right hand side\nC1 = first(setdiff(free_symbols(eq), (x,a))) # fish out constant, it is not x or a\nc1 = solve(eq(x=>0) - 1//2, C1)\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n```\n1-element Vector{Sym}:\n 1\n```\n:::\n:::\n\n\nAnd we plug in with:\n\n::: {.cell execution_count=11}\n``` {.julia .cell-code}\neq(C1 => c1[1])\n```\n\n::: {.cell-output .cell-output-display execution_count=12}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n\\frac{1}{1 + e^{- a x}}\n\\]\n</span>\n```\n:::\n:::\n\n\nThat's a lot of work. The `dsolve` function in `SymPy` allows initial conditions to be specified for some equations. In this case, ours is $x_0=0$ and $y_0=1/2$. The extra arguments passed in through a dictionary to the `ics` argument:\n\n::: {.cell execution_count=12}\n``` {.julia .cell-code}\nx0, y0 = 0, Sym(1//2)\ndsolve(eqn, u(x), ics=Dict(u(x0) => y0))\n```\n\n::: {.cell-output .cell-output-display execution_count=13}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nu{\\left(x \\right)} = \\frac{1}{1 + e^{- a x}}\n\\]\n</span>\n```\n:::\n:::\n\n\n(The one subtlety is the need to write the rational value as a symbolic expression, as otherwise it will get converted to a floating point value prior to being passed along.)\n\n\n##### Example: Hooke's law\n\n\nIn the first example, we solved for position, $x(t)$, from an assumption of constant acceleration in two steps. The equation relating the two is a second-order equation: $x''(t) = a$, so two constants are generated. That a second-order equation could be reduced to two first-order equations is not happy circumstance, as it can always be done. Rather than show the technique though, we demonstrate that `SymPy` can also handle some second-order ODEs.\n\n\nHooke's law relates the force on an object to its position via $F=ma = -kx$, or $x''(t) = -(k/m)x(t)$.\n\n\nSuppose $k > 0$. Then we can solve, similar to the above, with:\n\n::: {.cell execution_count=13}\n``` {.julia .cell-code}\n@syms k::positive m::positive\nD2 = D ∘ D # takes second derivative through composition\neqnh = D2(u)(x) ~ -(k/m)*u(x)\ndsolve(eqnh)\n```\n\n::: {.cell-output .cell-output-display execution_count=14}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nu{\\left(x \\right)} = C_{1} \\sin{\\left(\\frac{\\sqrt{k} x}{\\sqrt{m}} \\right)} + C_{2} \\cos{\\left(\\frac{\\sqrt{k} x}{\\sqrt{m}} \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\nHere we find two constants, as anticipated, for we would guess that two integrations are needed in the solution.\n\n\nSuppose the spring were started by pulling it down to a bottom and releasing. The initial position at time $0$ would be $a$, say, and initial velocity $0$. Here we get the solution specifying initial conditions on the function and its derivative (expressed through `u'`):\n\n::: {.cell execution_count=14}\n``` {.julia .cell-code}\ndsolve(eqnh, u(x), ics = Dict(u(0) => -a, D(u)(0) => 0))\n```\n\n::: {.cell-output .cell-output-display execution_count=15}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nu{\\left(x \\right)} = - a \\cos{\\left(\\frac{\\sqrt{k} x}{\\sqrt{m}} \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\nWe get that the motion will follow $u(x) = -a \\cos(\\sqrt{k/m}x)$. This is simple oscillatory behavior. As the spring stretches, the force gets large enough to pull it back, and as it compresses the force gets large enough to push it back. The amplitude of this oscillation is $a$ and the period $2\\pi/\\sqrt{k/m}$. Larger $k$ values mean shorter periods; larger $m$ values mean longer periods.\n\n\n##### Example: the pendulum\n\n\nThe simple gravity [pendulum](http://tinyurl.com/h8ys6ts) is an idealization of a physical pendulum that models a \"bob\" with mass $m$ swinging on a massless rod of length $l$ in a frictionless world governed only by the gravitational constant $g$. The motion can be described by this differential equation for the angle, $\\theta$, made from the vertical:\n\n\n\n$$\n\\theta''(t) + \\frac{g}{l}\\sin(\\theta(t)) = 0\n$$\n\n\nCan this second-order equation be solved by `SymPy`?\n\n::: {.cell execution_count=15}\n``` {.julia .cell-code}\n@syms g::positive l::positive theta()=>\"θ\"\neqnp = D2(theta)(x) + g/l*sin(theta(x))\n```\n\n::: {.cell-output .cell-output-display execution_count=16}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n\\frac{g \\sin{\\left(θ{\\left(x \\right)} \\right)}}{l} + \\frac{d^{2}}{d x^{2}} θ{\\left(x \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\nTrying to do so, can cause `SymPy` to hang or simply give up and repeat its input; no easy answer is forthcoming for this equation.\n\n\nIn general, for the first-order initial value problem characterized by $y'(x) = F(y,x)$, there are conditions ([Peano](http://tinyurl.com/h663wba) and [Picard-Lindelof](http://tinyurl.com/3rbde5e)) that can guarantee the existence (and uniqueness) of equation locally, but there may not be an accompanying method to actually find it. This particular problem has a solution, but it can not be written in terms of elementary functions.\n\n\nHowever, as [Huygens](https://en.wikipedia.org/wiki/Christiaan_Huygens) first noted, if the angles involved are small, then we approximate the solution through the linearization $\\sin(\\theta(t)) \\approx \\theta(t)$. The resulting equation for an approximate answer is just that of Hooke:\n\n\n\n$$\n\\theta''(t) + \\frac{g}{l}\\theta(t) = 0\n$$\n\n\nHere, the solution is in terms of sines and cosines, with period given by $T = 2\\pi/\\sqrt{k} = 2\\pi\\cdot\\sqrt{l/g}$. The answer does not depend on the mass, $m$, of the bob nor the amplitude of the motion, provided the small-angle approximation is valid.\n\n\nIf we pull the bob back an angle $a$ and release it then the initial conditions are $\\theta(0) = a$ and $\\theta'(a) = 0$. This gives the solution:\n\n::: {.cell execution_count=16}\n``` {.julia .cell-code}\neqnp₁ = D2(u)(x) + g/l * u(x)\ndsolve(eqnp₁, u(x), ics=Dict(u(0) => a, D(u)(0) => 0))\n```\n\n::: {.cell-output .cell-output-display execution_count=17}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nu{\\left(x \\right)} = a \\cos{\\left(\\frac{\\sqrt{g} x}{\\sqrt{l}} \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\n##### Example: hanging cables\n\n\nA chain hangs between two supports a distance $L$ apart. What shape will it take if there are no forces outside of gravity acting on it? What about if the force is uniform along length of the chain, like a suspension bridge? How will the shape differ then?\n\n\nLet $y(x)$ describe the chain at position $x$, with $0 \\leq x \\leq L$, say. We consider first the case of the chain with no force save gravity. Let $w(x)$ be the density of the chain at $x$, taken below to be a constant.\n\n\nThe chain is in equilibrium, so tension, $T(x)$, in the chain will be in the direction of the derivative. Let $V$ be the vertical component and $H$ the horizontal component. With only gravity acting on the chain, the value of $H$ will be a constant. The value of $V$ will vary with position.\n\n\nAt a point $x$, there is $s(x)$ amount of chain with weight $w \\cdot s(x)$. The tension is in the direction of the tangent line, so:\n\n\n\n$$\n\\tan(\\theta) = y'(x) = \\frac{w s(x)}{H}.\n$$\n\n\nIn terms of an increment of chain, we have:\n\n\n\n$$\n\\frac{w ds}{H} = d(y'(x)).\n$$\n\n\nThat is, the ratio of the vertical and horizontal tensions in the increment are in balance with the differential of the derivative.\n\n\nBut $ds = \\sqrt{dx^2 + dy^2} = \\sqrt{dx^2 + y'(x)^2 dx^2} = \\sqrt{1 + y'(x)^2}dx$, so we can simplify to:\n\n\n\n$$\n\\frac{w}{H}\\sqrt{1 + y'(x)^2}dx =y''(x)dx.\n$$\n\n\nThis yields the second-order equation:\n\n\n\n$$\ny''(x) = \\frac{w}{H} \\sqrt{1 + y'(x)^2}.\n$$\n\n\nWe enter this into `Julia`:\n\n::: {.cell execution_count=17}\n``` {.julia .cell-code}\n@syms w::positive H::positive y()\neqnc = D2(y)(x) ~ (w/H) * sqrt(1 + y'(x)^2)\n```\n\n::: {.cell-output .cell-output-display execution_count=18}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n\\frac{d^{2}}{d x^{2}} y{\\left(x \\right)} = \\frac{w \\sqrt{\\left(\\frac{d}{d x} y{\\left(x \\right)}\\right)^{2} + 1}}{H}\n\\]\n</span>\n```\n:::\n:::\n\n\nUnfortunately, `SymPy` needs a bit of help with this problem, by breaking the problem into steps.\n\n\nFor the first step we solve for the derivative. Let $u = y'$, then we have $u'(x) = (w/H)\\sqrt{1 + u(x)^2}$:\n\n::: {.cell execution_count=18}\n``` {.julia .cell-code}\neqnc₁ = subs(eqnc, D(y)(x) => u(x))\n```\n\n::: {.cell-output .cell-output-display execution_count=19}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n\\frac{d}{d x} u{\\left(x \\right)} = \\frac{w \\sqrt{u^{2}{\\left(x \\right)} + 1}}{H}\n\\]\n</span>\n```\n:::\n:::\n\n\nand can solve via:\n\n::: {.cell execution_count=19}\n``` {.julia .cell-code}\noutc = dsolve(eqnc₁)\n```\n\n::: {.cell-output .cell-output-display execution_count=20}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nu{\\left(x \\right)} = \\sinh{\\left(C_{1} + \\frac{w x}{H} \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\nSo $y'(x) = u(x) = \\sinh(C_1 + w \\cdot x/H)$. This can be solved by direct integration as there is no $y(x)$ term on the right hand side.\n\n::: {.cell execution_count=20}\n``` {.julia .cell-code}\nD(y)(x) ~ rhs(outc)\n```\n\n::: {.cell-output .cell-output-display execution_count=21}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n\\frac{d}{d x} y{\\left(x \\right)} = \\sinh{\\left(C_{1} + \\frac{w x}{H} \\right)}\n\\]\n</span>\n```\n:::\n:::\n\n\nWe see a simple linear transformation involving the hyperbolic sine. To avoid, `SymPy` struggling with the above equation, and knowing the hyperbolic sine is the derivative of the hyperbolic cosine, we anticipate an answer and verify it:\n\n::: {.cell execution_count=21}\n``` {.julia .cell-code}\nyc = (H/w)*cosh(C1 + w*x/H)\ndiff(yc, x) == rhs(outc) # == not \\Equal[tab]\n```\n\n::: {.cell-output .cell-output-display execution_count=22}\n```\ntrue\n```\n:::\n:::\n\n\nThe shape is a hyperbolic cosine, known as the catenary.\n\n![The cables of an unloaded suspension bridge have a different shape than a loaded suspension bridge. As seen, the cables in this [figure](https://www.brownstoner.com/brooklyn-life/verrazano-narrows-bridge-anniversary-historic-photos/) would be modeled by a catenary. ](../ODEs/figures/verrazano-narrows-bridge-anniversary-historic-photos-2.jpeg)\n\n\n\n---\n\nIf the chain has a uniform load like a suspension bridge with a deck sufficient to make the weight of the chain negligible, then how does the above change? Then the vertical tension comes from $Udx$ and not $w ds$, so the equation becomes instead:\n\n\n\n$$\n\\frac{Udx}{H} = d(y'(x)).\n$$\n\n\nThis $y''(x) = U/H$, a constant. So it's answer will be a parabola.\n\n\n##### Example: projectile motion in a medium\n\n\nThe first example describes projectile motion without air resistance. If we use $(x(t), y(t))$ to describe position at time $t$, the functions satisfy:\n\n\n\n$$\nx''(t) = 0, \\quad y''(t) = -g.\n$$\n\n\nThat is, the $x$ position - where no forces act - has $0$ acceleration, and the $y$ position - where the force of gravity acts - has constant acceleration, $-g$, where $g=9.8m/s^2$ is the gravitational constant. These equations can be solved to give:\n\n\n\n$$\nx(t) = x_0 + v_0 \\cos(\\alpha) t, \\quad y(t) = y_0 + v_0\\sin(\\alpha)t - \\frac{1}{2}g \\cdot t^2.\n$$\n\n\nFurthermore, we can solve for $t$ from $x(t)$, to get an equation describing $y(x)$. Here are all the steps:\n\n::: {.cell hold='true' execution_count=23}\n``` {.julia .cell-code}\n@syms x0::real y0::real v0::real alpha::real g::real\n@syms t x u()\na1 = dsolve(D2(u)(x) ~ 0, u(x), ics=Dict(u(0) => x0, D(u)(0) => v0 * cos(alpha)))\na2 = dsolve(D2(u)(x) ~ -g, u(x), ics=Dict(u(0) => y0, D(u)(0) => v0 * sin(alpha)))\nts = solve(t - rhs(a1), x)[1]\ny = simplify(rhs(a2)(t => ts))\nsympy.Poly(y, x).coeffs()\n```\n\n::: {.cell-output .cell-output-display execution_count=24}\n```\n3-element Vector{Sym}:\n -g/2\n v₀⋅sin(α)\n y₀\n```\n:::\n:::\n\n\nThough `y` is messy, it can be seen that the answer is a quadratic polynomial in $x$ yielding the familiar parabolic motion for a trajectory. The output shows the coefficients.\n\n\nIn a resistive medium, there are drag forces at play. If this force is proportional to the velocity, say, with proportion $\\gamma$, then the equations become:\n\n\n\n$$\n\\begin{align*}\nx''(t) &= -\\gamma x'(t), & \\quad y''(t) &= -\\gamma y'(t) -g, \\\\\nx(0) &= x_0, &\\quad y(0) &= y_0,\\\\\nx'(0) &= v_0\\cos(\\alpha),&\\quad y'(0) &= v_0 \\sin(\\alpha).\n\\end{align*}\n$$\n\n\nWe now attempt to solve these.\n\n::: {.cell execution_count=24}\n``` {.julia .cell-code}\n@syms alpha::real, γ::postive, t::positive, v()\n@syms x_0::real y_0::real v_0::real\nDₜ = Differential(t)\neq₁ = Dₜ(Dₜ(u))(t) ~ - γ * Dₜ(u)(t)\neq₂ = Dₜ(Dₜ(v))(t) ~ -g - γ * Dₜ(v)(t)\n\na₁ = dsolve(eq₁, ics=Dict(u(0) => x_0, Dₜ(u)(0) => v_0 * cos(alpha)))\na₂ = dsolve(eq₂, ics=Dict(v(0) => y_0, Dₜ(v)(0) => v_0 * sin(alpha)))\n\nts = solve(x - rhs(a₁), t)[1]\nyᵣ = rhs(a₂)(t => ts)\n```\n\n::: {.cell-output .cell-output-display execution_count=25}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n- \\frac{g \\log{\\left(\\frac{v_{0} \\cos{\\left(\\alpha \\right)}}{v_{0} \\cos{\\left(\\alpha \\right)} - x γ + x_{0} γ} \\right)}}{γ^{2}} + \\frac{g + v_{0} γ \\sin{\\left(\\alpha \\right)} + y_{0} γ^{2}}{γ^{2}} + \\frac{\\left(- g - v_{0} γ \\sin{\\left(\\alpha \\right)}\\right) \\left(v_{0} \\cos{\\left(\\alpha \\right)} - x γ + x_{0} γ\\right)}{v_{0} γ^{2} \\cos{\\left(\\alpha \\right)}}\n\\]\n</span>\n```\n:::\n:::\n\n\nThis gives $y$ as a function of $x$.\n\n\nThere are a lot of symbols. Lets simplify by using constants $x_0=y_0=0$:\n\n::: {.cell execution_count=25}\n``` {.julia .cell-code}\nyᵣ₁ = yᵣ(x_0 => 0, y_0 => 0)\n```\n\n::: {.cell-output .cell-output-display execution_count=26}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\n- \\frac{g \\log{\\left(\\frac{v_{0} \\cos{\\left(\\alpha \\right)}}{v_{0} \\cos{\\left(\\alpha \\right)} - x γ} \\right)}}{γ^{2}} + \\frac{g + v_{0} γ \\sin{\\left(\\alpha \\right)}}{γ^{2}} + \\frac{\\left(- g - v_{0} γ \\sin{\\left(\\alpha \\right)}\\right) \\left(v_{0} \\cos{\\left(\\alpha \\right)} - x γ\\right)}{v_{0} γ^{2} \\cos{\\left(\\alpha \\right)}}\n\\]\n</span>\n```\n:::\n:::\n\n\nWhat is the trajectory? We see that the `log` function part will have issues when $-\\gamma x + v_0 \\cos(\\alpha) = 0$.\n\n\nIf we fix some parameters, we can plot.\n\n::: {.cell execution_count=26}\n``` {.julia .cell-code}\nv₀, γ₀, α = 200, 1/2, pi/4\nsoln = yᵣ₁(v_0=>v₀, γ=>γ₀, alpha=>α, g=>9.8)\nplot(soln, 0, v₀ * cos(α) / γ₀ - 1/10, legend=false)\n```\n\n::: {.cell-output .cell-output-display execution_count=27}\n![](odes_files/figure-html/cell-27-output-1.svg){}\n:::\n:::\n\n\nWe can see that the resistance makes the path quite non-symmetric.\n\n\n## Visualizing a first-order initial value problem\n\n\nThe solution, $y(x)$, is known through its derivative. A useful tool to visualize the solution to a first-order differential equation is the [slope field](http://tinyurl.com/jspzfok) (or direction field) plot, which at different values of $(x,y)$, plots a vector with slope given through $y'(x)$.The `vectorfieldplot` of the `CalculusWithJulia` package can be used to produce these.\n\n\nFor example, in a previous example we found a solution to $y'(x) = x\\cdot y(x)$, coded as\n\n::: {.cell execution_count=27}\n``` {.julia .cell-code}\nF(y, x) = y*x\n```\n\n::: {.cell-output .cell-output-display execution_count=28}\n```\nF (generic function with 1 method)\n```\n:::\n:::\n\n\nSuppose $x_0=1$ and $y_0=1$. Then a direction field plot is drawn through:\n\n::: {.cell hold='true' execution_count=28}\n``` {.julia .cell-code}\n@syms x y\nx0, y0 = 1, 1\n\nplot(legend=false)\nvectorfieldplot!((x,y) -> [1, F(y,x)], xlims=(x0, 2), ylims=(y0-5, y0+5))\n\nf(x) = y0*exp(-x0^2/2) * exp(x^2/2)\nplot!(f, linewidth=5)\n```\n\n::: {.cell-output .cell-output-display execution_count=29}\n![](odes_files/figure-html/cell-29-output-1.svg){}\n:::\n:::\n\n\nIn 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)$.\n\n\n:::{.callout-note}\n## Note\nThe order of variables in $F(y,x)$ is conventional with the equation $y'(x) = F(y(x),x)$.\n\n:::\n\nThe plots are also useful for illustrating solutions for different initial conditions:\n\n::: {.cell hold='true' execution_count=29}\n``` {.julia .cell-code}\np = plot(legend=false)\nx0, y0 = 1, 1\n\nvectorfieldplot!((x,y) -> [1,F(y,x)], xlims=(x0, 2), ylims=(y0-5, y0+5))\nfor y0 in -4:4\n f(x) = y0*exp(-x0^2/2) * exp(x^2/2)\n plot!(f, x0, 2, linewidth=5)\nend\np\n```\n\n::: {.cell-output .cell-output-display execution_count=30}\n![](odes_files/figure-html/cell-30-output-1.svg){}\n:::\n:::\n\n\nSuch solutions are called [integral curves](https://en.wikipedia.org/wiki/Integral_curve). These graphs illustrate the fact that the slope field is tangent to the graph of any integral curve.\n\n\n## Questions\n\n\n##### Question\n\n\nUsing `SymPy` to solve the differential equation\n\n\n\n$$\nu' = \\frac{1-x}{u}\n$$\n\n\ngives\n\n::: {.cell hold='true' execution_count=30}\n``` {.julia .cell-code}\n@syms x u()\ndsolve(D(u)(x) - (1-x)/u(x))\n```\n\n::: {.cell-output .cell-output-display execution_count=31}\n```\n2-element Vector{Sym}:\n Eq(u(x), -sqrt(C1 - x^2 + 2*x))\n Eq(u(x), sqrt(C1 - x^2 + 2*x))\n```\n:::\n:::\n\n\nThe two answers track positive and negative solutions. For the initial condition, $u(-1)=1$, we have the second one is appropriate: $u(x) = \\sqrt{C_1 - x^2 + 2x}$. At $-1$ this gives: $1 = \\sqrt{C_1-3}$, so $C_1 = 4$.\n\n\nThis value is good for what values of $x$?\n\n::: {.cell hold='true' execution_count=31}\n\n::: {.cell-output .cell-output-display execution_count=32}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='5635977567625130536' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5635977567625130536\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5635977567625130536_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5635977567625130536\"\n id=\"radio_5635977567625130536_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\([-1, \\infty)\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5635977567625130536_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5635977567625130536\"\n id=\"radio_5635977567625130536_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\([-1, 4]\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5635977567625130536_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5635977567625130536\"\n id=\"radio_5635977567625130536_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\([1-\\sqrt{5}, 1 + \\sqrt{5}]\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5635977567625130536_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5635977567625130536\"\n id=\"radio_5635977567625130536_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\([-1, 0]\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='5635977567625130536_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_5635977567625130536\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 3;\n var msgBox = document.getElementById('5635977567625130536_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5635977567625130536\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5635977567625130536\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nSuppose $y(x)$ satisfies\n\n\n\n$$\ny'(x) = y(x)^2, \\quad y(1) = 1.\n$$\n\n\nWhat is $y(3/2)$?\n\n::: {.cell hold='true' execution_count=32}\n\n::: {.cell-output .cell-output-display execution_count=33}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='13199528731879142586' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_13199528731879142586\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"13199528731879142586\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='13199528731879142586_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"13199528731879142586\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 2.0) <= 0.001);\n var msgBox = document.getElementById('13199528731879142586_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_13199528731879142586\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_13199528731879142586\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nSolve the initial value problem\n\n\n\n$$\ny' = 1 + x^2 + y(x)^2 + x^2 y(x)^2, \\quad y(0) = 1.\n$$\n\n\nUse your answer to find $y(1)$.\n\n::: {.cell hold='true' execution_count=33}\n\n::: {.cell-output .cell-output-display execution_count=34}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='1647016783607910138' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_1647016783607910138\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"1647016783607910138\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='1647016783607910138_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"1647016783607910138\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - -1.6386248637145369) <= 0.001);\n var msgBox = document.getElementById('1647016783607910138_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_1647016783607910138\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_1647016783607910138\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nA population is modeled by $y(x)$. The rate of population growth is generally proportional to the population ($k y(x)$), but as the population gets large, the rate is curtailed $(1 - y(x)/M)$.\n\n\nSolve the initial value problem\n\n\n\n$$\ny'(x) = k\\cdot y(x) \\cdot (1 - \\frac{y(x)}{M}),\n$$\n\n\nwhen $k=1$, $M=100$, and $y(0) = 20$. Find the value of $y(5)$.\n\n::: {.cell hold='true' execution_count=34}\n\n::: {.cell-output .cell-output-display execution_count=35}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='2008653517269664025' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_2008653517269664025\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"2008653517269664025\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='2008653517269664025_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"2008653517269664025\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 97.37555469386476455991468766438340038789284601247847344470307065781047878026761) <= 0.001);\n var msgBox = document.getElementById('2008653517269664025_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_2008653517269664025\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_2008653517269664025\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nSolve the initial value problem\n\n\n\n$$\ny'(t) = \\sin(t) - \\frac{y(t)}{t}, \\quad y(\\pi) = 1\n$$\n\n\nFind the value of the solution at $t=2\\pi$.\n\n::: {.cell hold='true' execution_count=35}\n\n::: {.cell-output .cell-output-display execution_count=36}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='5385449791152543627' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5385449791152543627\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"5385449791152543627\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='5385449791152543627_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"5385449791152543627\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - -1) <= 0);\n var msgBox = document.getElementById('5385449791152543627_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5385449791152543627\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5385449791152543627\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nSuppose $u(x)$ satisfies:\n\n\n\n$$\n\\frac{du}{dx} = e^{-x} \\cdot u(x), \\quad u(0) = 1.\n$$\n\n\nFind $u(5)$ using `SymPy`.\n\n::: {.cell hold='true' execution_count=36}\n\n::: {.cell-output .cell-output-display execution_count=37}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='5049080165024045291' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5049080165024045291\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"5049080165024045291\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='5049080165024045291_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"5049080165024045291\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 2.700027756117370154212487619404962557343246917590398528605527399056158996408393) <= 0.001);\n var msgBox = document.getElementById('5049080165024045291_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5049080165024045291\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5049080165024045291\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nThe differential equation with boundary values\n\n\n\n$$\n\\frac{r^2 \\frac{dc}{dr}}{dr} = 0, \\quad c(1)=2, c(10)=1,\n$$\n\n\ncan be solved with `SymPy`. What is the value of $c(5)$?\n\n::: {.cell hold='true' execution_count=37}\n\n::: {.cell-output .cell-output-display execution_count=38}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='4306212598336269569' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_4306212598336269569\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_4306212598336269569_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_4306212598336269569\"\n id=\"radio_4306212598336269569_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(8/9\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_4306212598336269569_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_4306212598336269569\"\n id=\"radio_4306212598336269569_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(10/9\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_4306212598336269569_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_4306212598336269569\"\n id=\"radio_4306212598336269569_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(3/2\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_4306212598336269569_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_4306212598336269569\"\n id=\"radio_4306212598336269569_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(9/10\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='4306212598336269569_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_4306212598336269569\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('4306212598336269569_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_4306212598336269569\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_4306212598336269569\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n##### Question\n\n\nThe example with projectile motion in a medium has a parameter $\\gamma$ modeling the effect of air resistance. If `y` is the answer - as would be the case if the example were copy-and-pasted in - what can be said about `limit(y, gamma=>0)`?\n\n::: {.cell hold='true' execution_count=38}\n\n::: {.cell-output .cell-output-display execution_count=39}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='5649833150035496445' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5649833150035496445\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5649833150035496445_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5649833150035496445\"\n id=\"radio_5649833150035496445_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n The limit is a quadratic polynomial in <code>x</code>, mirroring the first part of that example.\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5649833150035496445_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5649833150035496445\"\n id=\"radio_5649833150035496445_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n The limit does not exist there is a singularity as seen by setting <code>gamma&#61;0</code>.\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5649833150035496445_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5649833150035496445\"\n id=\"radio_5649833150035496445_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n The limit does not exist, but the limit to <code>oo</code> gives a quadratic polynomial in <code>x</code>, mirroring the first part of that example.\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='5649833150035496445_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_5649833150035496445\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 1;\n var msgBox = document.getElementById('5649833150035496445_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5649833150035496445\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5649833150035496445\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n",
"supporting": [
"odes_files"
],
"filters": [],
"includes": {
"include-in-header": [
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\" integrity=\"sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==\" crossorigin=\"anonymous\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js\" integrity=\"sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==\" crossorigin=\"anonymous\"></script>\n<script type=\"application/javascript\">define('jquery', [],function() {return window.jQuery;})</script>\n"
]
}
}
}