15 lines
57 KiB
JSON
15 lines
57 KiB
JSON
{
|
||
"hash": "cb2889a42c1f9d801c5e2cbf4b5737cd",
|
||
"result": {
|
||
"markdown": "# Linearization\n\n\n\nThis section uses these add-on packages:\n\n``` {.julia .cell-code}\nusing CalculusWithJulia\nusing Plots\nusing SymPy\nusing TaylorSeries\nusing DualNumbers\n```\n\n\n\n\n---\n\n\nThe derivative of $f(x)$ has the interpretation as the slope of the tangent line. The tangent line is the line that best approximates the function at the point.\n\n\nUsing the point-slope form of a line, we see that the tangent line to the graph of $f(x)$ at $(c,f(c))$ is given by:\n\n\n\n$$\ny = f(c) + f'(c) \\cdot (x - c).\n$$\n\n\nThis is written as an equation, though we prefer to work with functions within `Julia`. Here we write such a function as an operator - it takes a function `f` and returns a function representing the tangent line.\n\n``` {.julia .cell-code}\ntangent(f, c) = x -> f(c) + f'(c) * (x - c)\n```\n\n\n(Recall, the `->` indicates that an anonymous function is being generated.)\n\n\nThis function along with the `f'` notation for automatic derivatives is defined in the `CalculusWithJulia` package.\n\n\nWe make some graphs with tangent lines:\n\n::: {.cell hold='true' execution_count=5}\n``` {.julia .cell-code}\nf(x) = x^2\nplot(f, -3, 3)\nplot!(tangent(f, -1))\nplot!(tangent(f, 2))\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n{}\n:::\n:::\n\n\nThe graph shows that near the point, the line and function are close, but this need not be the case away from the point. We can express this informally as\n\n\n\n$$\nf(x) \\approx f(c) + f'(c) \\cdot (x-c)\n$$\n\n\nwith the understanding this applies for $x$ \"close\" to $c$.\n\n\nUsually for the applications herein, instead of $x$ and $c$ the two points are $x+\\Delta_x$ and $x$. This gives:\n\n\n> *Linearization*: $\\Delta_y = f(x +\\Delta_x) - f(x) \\approx f'(x) \\Delta_x$, for small $\\Delta_x$.\n\n\n\nThis section gives some implications of this fact and quantifies what \"close\" can mean.\n\n\n##### Example\n\n\nThere are several approximations that are well known in physics, due to their widespread usage:\n\n\n * That $\\sin(x) \\approx x$ around $x=0$:\n\n::: {.cell hold='true' execution_count=6}\n``` {.julia .cell-code}\nplot(sin, -pi/2, pi/2)\nplot!(tangent(sin, 0))\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n{}\n:::\n:::\n\n\nSymbolically:\n\n::: {.cell hold='true' execution_count=7}\n``` {.julia .cell-code}\n@syms x\nc = 0\nf(x) = sin(x)\nf(c) + diff(f(x),x)(c) * (x - c)\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nx\n\\]\n</span>\n```\n:::\n:::\n\n\n * That $\\log(1 + x) \\approx x$ around $x=0$:\n\n::: {.cell hold='true' execution_count=8}\n``` {.julia .cell-code}\nf(x) = log(1 + x)\nplot(f, -1/2, 1/2)\nplot!(tangent(f, 0))\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n{}\n:::\n:::\n\n\nSymbolically:\n\n::: {.cell hold='true' execution_count=9}\n``` {.julia .cell-code}\n@syms x\nc = 0\nf(x) = log(1 + x)\nf(c) + diff(f(x),x)(c) * (x - c)\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\\[\nx\n\\]\n</span>\n```\n:::\n:::\n\n\n(The `log1p` function implements a more accurate version of this function when numeric values are needed.)\n\n\n * That $1/(1-x) \\approx x$ around $x=0$:\n\n::: {.cell hold='true' execution_count=10}\n``` {.julia .cell-code}\nf(x) = 1/(1-x)\nplot(f, -1/2, 1/2)\nplot!(tangent(f, 0))\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n{}\n:::\n:::\n\n\nSymbolically:\n\n::: {.cell hold='true' execution_count=11}\n``` {.julia .cell-code}\n@syms x\nc = 0\nf(x) = 1 / (1 - x)\nf(c) + diff(f(x),x)(c) * (x - c)\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n```{=html}\n<span class=\"math-left-align\" style=\"padding-left: 4px; width:0; float:left;\"> \n\\[\nx + 1.0\n\\]\n</span>\n```\n:::\n:::\n\n\n * That $(1+x)^n \\approx 1 + nx$ around $x = 0$. For example, with $n=5$\n\n::: {.cell hold='true' execution_count=12}\n``` {.julia .cell-code}\nn = 5\nf(x) = (1+x)^n # f'(0) = n = n(1+x)^(n-1) at x=0\nplot(f, -1/2, 1/2)\nplot!(tangent(f, 0))\n```\n\n::: {.cell-output .cell-output-display execution_count=12}\n{}\n:::\n:::\n\n\nSymbolically:\n\n::: {.cell hold='true' execution_count=13}\n``` {.julia .cell-code}\n@syms x, n::real\nc = 0\nf(x) = (1 + x)^n\nf(c) + diff(f(x),x)(x=>c) * (x - c)\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\\[\nn x + 1\n\\]\n</span>\n```\n:::\n:::\n\n\n---\n\nIn each of these cases, a more complicated non-linear function is well approximated in a region of interest by a simple linear function.\n\n\n## Numeric approximations\n\n::: {.cell hold='true' execution_count=14}\n\n::: {.cell-output .cell-output-display execution_count=14}\n{}\n:::\n:::\n\n\nThe plot shows the tangent line with slope $dy/dx$ and the actual change in $y$, $\\Delta y$, for some specified $\\Delta x$. The small gap above the sine curve is the error were the value of the sine approximated using the drawn tangent line. We can see that approximating the value of $\\Delta y = \\sin(c+\\Delta x) - \\sin(c)$ with the often easier to compute $(dy/dx) \\cdot \\Delta x = f'(c)\\Delta x$ - for small enough values of $\\Delta x$ - is not going to be too far off provided $\\Delta x$ is not too large.\n\n\nThis approximation is known as linearization. It can be used both in theoretical computations and in pratical applications. To see how effective it is, we look at some examples.\n\n\n##### Example\n\n\nIf $f(x) = \\sin(x)$, $c=0$ and $\\Delta x= 0.1$ then the values for the actual change in the function values and the value of $\\Delta y$ are:\n\n::: {.cell execution_count=15}\n``` {.julia .cell-code}\nf(x) = sin(x)\nc, deltax = 0, 0.1\nf(c + deltax) - f(c), f'(c) * deltax\n```\n\n::: {.cell-output .cell-output-display execution_count=15}\n```\n(0.09983341664682815, 0.1)\n```\n:::\n:::\n\n\nThe values are pretty close. But what is $0.1$ radians? Lets use degrees. Suppose we have $\\Delta x = 10^\\circ$:\n\n::: {.cell execution_count=16}\n``` {.julia .cell-code}\ndeltax⁰ = 10*pi/180\nactual = f(c + deltax⁰) - f(c)\napprox = f'(c) * deltax⁰\nactual, approx\n```\n\n::: {.cell-output .cell-output-display execution_count=16}\n```\n(0.17364817766693033, 0.17453292519943295)\n```\n:::\n:::\n\n\nThey agree until the third decimal value. The *percentage error* is just $1/2$ a percent:\n\n::: {.cell execution_count=17}\n``` {.julia .cell-code}\n(approx - actual) / actual * 100\n```\n\n::: {.cell-output .cell-output-display execution_count=17}\n```\n0.5095057975210231\n```\n:::\n:::\n\n\n### Relative error or relative change\n\n\nThe relative error is defined by\n\n\n\n$$\n\\big| \\frac{\\text{actual} - \\text{approximate}}{\\text{actual}} \\big|.\n$$\n\n\nHowever, typically with linearization, we talk about the *relative change*, not relative error, as the denominator is easier to compute. This is\n\n\n\n$$\n\\frac{f(x + \\Delta_x) - f(x)}{f(x)} = \\frac{\\Delta_y}{f(x)} \\approx\n\\frac{f'(x) \\cdot \\Delta_x}{f(x)}\n$$\n\n\nThe *percentage change* multiplies by $100$.\n\n\n##### Example\n\n\nWhat is the relative change in surface area of a sphere if the radius changes from $r$ to $r + dr$?\n\n\nWe have $S = 4\\pi r^2$ so the approximate relative change, $dy/S$ is given, using the derivative $dS/dr = 8\\pi r$, by\n\n\n\n$$\n\\frac{8\\pi\\cdot r\\cdot dr}{4\\pi r^2} = 2r\\cdot dr.\n$$\n\n\n##### Example\n\n\nWe are traveling $60$ miles. At $60$ miles an hour, we will take $60$ minutes (or one hour). How long will it take at $70$ miles an hour? (Assume you can't divide, but, instead, can only multiply!)\n\n\nWell the answer is $60/70$ hours or $60/70 \\cdot 60$ minutes. But we can't divide, so we turn this into a multiplication problem via some algebra:\n\n\n\n$$\n\\frac{60}{70} = \\frac{60}{60 + 10} = \\frac{1}{1 + 10/60} = \\frac{1}{1 + 1/6}.\n$$\n\n\nOkay, so far no calculator was needed. We wrote $70 = 60 + 10$, as we know that $60/60$ is just $1$. This almost gets us there. If we really don't want to divide, we can get an answer by using the tangent line approximation for $1/(1+x)$ around $x=0$. This is $1/(1+x) \\approx 1 - x$. (You can check by finding that $f'(0) = -1$.) Thus, our answer is approximately $5/6$ of an hour or 50 minutes.\n\n\nHow much in error are we?\n\n::: {.cell execution_count=18}\n``` {.julia .cell-code}\nabs(50 - 60/70*60) / (60/70*60) * 100\n```\n\n::: {.cell-output .cell-output-display execution_count=18}\n```\n2.7777777777777684\n```\n:::\n:::\n\n\nThat's about $3$ percent. Not bad considering we could have done all the above in our head while driving without taking our eyes off the road to use the calculator on our phone for a division.\n\n\n##### Example\n\n\nA $10$cm by $10$cm by $10$cm cube will contain $1$ liter ($1000$cm$^3$). In manufacturing such a cube, the side lengths are actually $10.1$ cm. What will be the volume in liters? Compute this with a linear approximation to $(10.1)^3$.\n\n\nHere $f(x) = x^3$ and we are asked to approximate $f(10.1)$. Letting $c=10$, we have:\n\n\n\n$$\nf(c + \\Delta) \\approx f(c) + f'(c) \\cdot \\Delta = 1000 + f'(c) \\cdot (0.1)\n$$\n\n\nComputing the derivative can be done easily, we get for our answer:\n\n::: {.cell execution_count=19}\n``` {.julia .cell-code}\nfp(x) = 3*x^2\nc₀, Delta = 10, 0.1\napprox₀ = 1000 + fp(c₀) * Delta\n```\n\n::: {.cell-output .cell-output-display execution_count=19}\n```\n1030.0\n```\n:::\n:::\n\n\nThis is a relative error as a percent of:\n\n::: {.cell execution_count=20}\n``` {.julia .cell-code}\nactual₀ = 10.1^3\n(actual₀ - approx₀)/actual₀ * 100\n```\n\n::: {.cell-output .cell-output-display execution_count=20}\n```\n0.029214763452615394\n```\n:::\n:::\n\n\nThe manufacturer may be interested instead in comparing the volume of the actual object to the $1$ liter target. They might use the approximate value for this comparison, which would yield:\n\n::: {.cell execution_count=21}\n``` {.julia .cell-code}\n(1000 - approx₀)/approx₀ * 100\n```\n\n::: {.cell-output .cell-output-display execution_count=21}\n```\n-2.912621359223301\n```\n:::\n:::\n\n\nThis is off by about $3$ percent. Not so bad for some applications, devastating for others.\n\n\n##### Example: Eratosthenes and the circumference of the earth\n\n\n[Eratosthenes](https://en.wikipedia.org/wiki/Eratosthenes) is said to have been the first person to estimate the radius (or by relation the circumference) of the earth. The basic idea is based on the difference of shadows cast by the sun. Suppose Eratosthenes sized the circumference as $252,000$ *stadia*. Taking $1$`stadia as``160``meters and the actual radius of the earth as``6378.137``kilometers, we can convert to see that Eratosthenes estimated the radius as``6417``.\n\n\nIf Eratosthenes were to have estimated the volume of a spherical earth, what would be his approximate percentage change between his estimate and the actual?\n\n\nUsing $V = 4/3 \\pi r^3$ we get $V' = 4\\pi r^2$:\n\n::: {.cell execution_count=22}\n``` {.julia .cell-code}\nrₑ = 6417\nrₐ = 6378.137\nΔᵣ = rₑ - rₐ\nVₛ(r) = 4/3 * pi * r^3\nΔᵥ = Vₛ'(rₑ) * Δᵣ\nΔᵥ / Vₛ(rₑ) * 100\n```\n\n::: {.cell-output .cell-output-display execution_count=22}\n```\n1.8168770453483072\n```\n:::\n:::\n\n\n##### Example: a simple pendulum\n\n\nA *simple* pendulum is comprised of a massless \"bob\" on a rigid \"rod\" of length $l$. The rod swings back and forth making an angle $\\theta$ with the perpendicular. At rest $\\theta=0$, here we have $\\theta$ swinging with $\\lvert\\theta\\rvert \\leq \\theta_0$ for some $\\theta_0$.\n\n\nAccording to [Wikipedia](http://tinyurl.com/yz5sz7e) - and many introductory physics book - while swinging, the angle $\\theta$ varies with time following this equation:\n\n\n\n$$\n\\theta''(t) + \\frac{g}{l} \\sin(\\theta(t)) = 0.\n$$\n\n\nThat is, the second derivative of $\\theta$ is proportional to the sine of $\\theta$ where the proportionality constant involves $g$ from gravity and the length of the \"rod.\"\n\n\nThis would be much easier if the second derivative were proportional to the angle $\\theta$ and not its sine.\n\n\n[Huygens](http://en.wikipedia.org/wiki/Christiaan_Huygens) used the approximation of $\\sin(x) \\approx x$, noted above, to say that when the angle is not too big, we have the pendulum's swing obeying $\\theta''(t) = -g/l \\cdot t$. Without getting too involved in why, we can verify by taking two derivatives that $\\theta_0\\sin(\\sqrt{g/l}\\cdot t)$ will be a solution to this modified equation.\n\n\nWith this solution, the motion is periodic with constant amplitude (assuming frictionless behaviour), as the sine function is. More surprisingly, the period is found from $T = 2\\pi/(\\sqrt{g/l}) = 2\\pi \\sqrt{l/g}$. It depends on $l$ - longer \"rods\" take more time to swing back and forth - but does not depend on the how wide the pendulum is swinging between (provided $\\theta_0$ is not so big the approximation of $\\sin(x) \\approx x$ fails). This latter fact may be surprising, though not to Galileo who discovered it.\n\n\n## Differentials\n\n\nThe Leibniz notation for a derivative is $dy/dx$ indicating the change in $y$ as $x$ changes. It proves convenient to decouple this using *differentials* $dx$ and $dy$. What do these notations mean? They measure change along the tangent line in same way $\\Delta_x$ and $\\Delta_y$ measure change for the function. The differential $dy$ depends on both $x$ and $dx$, it being defined by $dy=f'(x)dx$. As tangent lines locally represent a function, $dy$ and $dx$ are often associated with an *infinitesimal* difference.\n\n\nTaking $dx = \\Delta_x$, as in the previous graphic, we can compare $dy$ – the change along the tangent line given by $dy/dx \\cdot dx$ – and $\\Delta_y$ – the change along the function given by $f(x + \\Delta_x) - f(x)$. The linear approximation, $f(x + \\Delta_x) - f(x)\\approx f'(x)dx$, says that\n\n\n\n$$\n\\Delta_y \\approx dy; \\quad \\text{ when } \\Delta_x = dx\n$$\n\n\n## The error in approximation\n\n\nHow good is the approximation? Graphically we can see it is pretty good for the graphs we choose, but are there graphs out there for which the approximation is not so good? Of course. However, we can say this (the [Lagrange](http://en.wikipedia.org/wiki/Taylor%27s_theorem) form of a more general Taylor remainder theorem):\n\n\n> Let $f(x)$ be twice differentiable on $I=(a,b)$, $f$ is continuous on $[a,b]$, and $a < c < b$. Then for any $x$ in $I$, there exists some value $\\xi$ between $c$ and $x$ such that $f(x) = f(c) + f'(c)(x-c) + (f''(\\xi)/2)\\cdot(x-c)^2$.\n\n\n\nThat is, the error is basically a constant depending on the concavity of $f$ times a quadratic function centered at $c$.\n\n\nFor $\\sin(x)$ at $c=0$ we get $\\lvert\\sin(x) - x\\rvert = \\lvert-\\sin(\\xi)\\cdot x^2/2\\rvert$. Since $\\lvert\\sin(\\xi)\\rvert \\leq 1$, we must have this bound: $\\lvert\\sin(x) - x\\rvert \\leq x^2/2$.\n\n\nCan we verify? Let's do so graphically:\n\n::: {.cell hold='true' execution_count=23}\n``` {.julia .cell-code}\nh(x) = abs(sin(x) - x)\ng(x) = x^2/2\nplot(h, -2, 2, label=\"h\")\nplot!(g, -2, 2, label=\"f\")\n```\n\n::: {.cell-output .cell-output-display execution_count=23}\n{}\n:::\n:::\n\n\nThe graph shows a tight bound near $0$ and then a bound over this viewing window.\n\n\nSimilarly, for $f(x) = \\log(1 + x)$ we have the following at $c=0$:\n\n\n\n$$\nf'(x) = 1/(1+x), \\quad f''(x) = -1/(1+x)^2.\n$$\n\n\nSo, as $f(c)=0$ and $f'(c) = 1$, we have\n\n\n\n$$\n\\lvert f(x) - x\\rvert \\leq \\lvert f''(\\xi)\\rvert \\cdot \\frac{x^2}{2}\n$$\n\n\nWe see that $\\lvert f''(x)\\rvert$ is decreasing for $x > -1$. So if $-1 < x < c$ we have\n\n\n\n$$\n\\lvert f(x) - x\\rvert \\leq \\lvert f''(x)\\rvert \\cdot \\frac{x^2}{2} = \\frac{x^2}{2(1+x)^2}.\n$$\n\n\nAnd for $c=0 < x$, we have\n\n\n\n$$\n\\lvert f(x) - x\\rvert \\leq \\lvert f''(0)\\rvert \\cdot \\frac{x^2}{2} = x^2/2.\n$$\n\n\nPlotting we verify the bound on $|\\log(1+x)-x|$:\n\n::: {.cell hold='true' execution_count=24}\n``` {.julia .cell-code}\nh(x) = abs(log(1+x) - x)\ng(x) = x < 0 ? x^2/(2*(1+x)^2) : x^2/2\nplot(h, -0.5, 2, label=\"h\")\nplot!(g, -0.5, 2, label=\"g\")\n```\n\n::: {.cell-output .cell-output-display execution_count=24}\n{}\n:::\n:::\n\n\nAgain, we see the very close bound near $0$, which widens at the edges of the viewing window.\n\n\n### Why is the remainder term as it is?\n\n\nTo see formally why the remainder is as it is, we recall the mean value theorem in the extended form of Cauchy. Suppose $c=0$, $x > 0$, and let $h(x) = f(x) - (f(0) + f'(0) x)$ and $g(x) = x^2$. Then we have that there exists a $e$ with $0 < e < x$ such that\n\n\n\n$$\n\\text{error} = h(x) - h(0) = (g(x) - g(0)) \\frac{h'(e)}{g'(e)} = x^2 \\cdot \\frac{1}{2} \\cdot \\frac{f'(e) - f'(0)}{e} =\nx^2 \\cdot \\frac{1}{2} \\cdot f''(\\xi).\n$$\n\n\nThe value of $\\xi$, from the mean value theorem applied to $f'(x)$, satisfies $0 < \\xi < e < x$, so is in $[0,x].$\n\n\n### The big (and small) \"oh\"\n\n\n`SymPy` can find the tangent line expression as a special case of its `series` function (which implements [Taylor series](../taylor_series_polynomials.html)). The `series` function needs an expression to approximate; a variable specified, as there may be parameters in the expression; a value $c$ for *where* the expansion is taken, with default $0$; and a number of terms, for this example $2$ for a constant and linear term. (There is also an optional `dir` argument for one-sided expansions.)\n\n\nHere we see the answer provided for $e^{\\sin(x)}$:\n\n::: {.cell execution_count=25}\n``` {.julia .cell-code}\n@syms x\nseries(exp(sin(x)), x, 0, 2)\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\\[\n1 + x + O\\left(x^{2}\\right)\n\\]\n</span>\n```\n:::\n:::\n\n\nThe expression $1 + x$ comes from the fact that `exp(sin(0))` is $1$, and the derivative `exp(sin(0)) * cos(0)` is *also* $1$. But what is the $\\mathcal{O}(x^2)$?\n\n\nWe know the answer is *precisely* $f''(\\xi)/2 \\cdot x^2$ for some $\\xi$, but were we only concerned about the scale as $x$ goes to zero that when $f''$ is continuous that the error when divided by $x^2$ goes to some finite value ($f''(0)/2$). More generally, if the error divided by $x^2$ is *bounded* as $x$ goes to $0$, then we say the error is \"big oh\" of $x^2$.\n\n\nThe [big](http://en.wikipedia.org/wiki/Big_O_notation) \"oh\" notation, $f(x) = \\mathcal{O}(g(x))$, says that the ratio $f(x)/g(x)$ is bounded as $x$ goes to $0$ (or some other value $c$, depending on the context). A little \"oh\" (e.g., $f(x) = \\mathcal{o}(g(x))$) would mean that the limit $f(x)/g(x)$ would be $0$, as $x\\rightarrow 0$, a much stronger assertion.\n\n\nBig \"oh\" and little \"oh\" give us a sense of how good an approximation is without being bogged down in the details of the exact value. As such they are useful guides in focusing on what is primary and what is secondary. Applying this to our case, we have this rough form of the tangent line approximation valid for functions having a continuous second derivative at $c$:\n\n\n\n$$\nf(x) = f(c) + f'(c)(x-c) + \\mathcal{O}((x-c)^2).\n$$\n\n\n##### Example: the algebra of tangent line approximations\n\n\nSuppose $f(x)$ and $g(x)$ are represented by their tangent lines about $c$, respectively:\n\n\n\n$$\n\\begin{align*}\nf(x) &= f(c) + f'(c)(x-c) + \\mathcal{O}((x-c)^2), \\\\\ng(x) &= g(c) + g'(c)(x-c) + \\mathcal{O}((x-c)^2).\n\\end{align*}\n$$\n\n\nConsider the sum, after rearranging we have:\n\n\n\n$$\n\\begin{align*}\nf(x) + g(x) &= \\left(f(c) + f'(c)(x-c) + \\mathcal{O}((x-c)^2)\\right) + \\left(g(c) + g'(c)(x-c) + \\mathcal{O}((x-c)^2)\\right)\\\\\n&= \\left(f(c) + g(c)\\right) + \\left(f'(c)+g'(c)\\right)(x-c) + \\mathcal{O}((x-c)^2).\n\\end{align*}\n$$\n\n\nThe two big \"Oh\" terms become just one as the sum of a constant times $(x-c)^2$ plus a constant time $(x-c)^2$ is just some other constant times $(x-c)^2$. What we can read off from this is the term multiplying $(x-c)$ is just the derivative of $f(x) + g(x)$ (from the sum rule), so this too is a tangent line approximation.\n\n\nIs it a coincidence that a basic algebraic operation with tangent lines approximations produces a tangent line approximation? Let's try multiplication:\n\n\n\n$$\n\\begin{align*}\nf(x) \\cdot g(x) &= [f(c) + f'(c)(x-c) + \\mathcal{O}((x-c)^2)] \\cdot [g(c) + g'(c)(x-c) + \\mathcal{O}((x-c)^2)]\\\\\n&=[(f(c) + f'(c)(x-c)] \\cdot [g(c) + g'(c)(x-c)] + (f(c) + f'(c)(x-c) \\cdot \\mathcal{O}((x-c)^2)) + g(c) + g'(c)(x-c) \\cdot \\mathcal{O}((x-c)^2)) + [\\mathcal{O}((x-c)^2))]^2\\\\\n&= [(f(c) + f'(c)(x-c)] \\cdot [g(c) + g'(c)(x-c)] + \\mathcal{O}((x-c)^2)\\\\\n&= f(c) \\cdot g(c) + [f'(c)\\cdot g(c) + f(c)\\cdot g'(c)] \\cdot (x-c) + [f'(c)\\cdot g'(c) \\cdot (x-c)^2 + \\mathcal{O}((x-c)^2)] \\\\\n&= f(c) \\cdot g(c) + [f'(c)\\cdot g(c) + f(c)\\cdot g'(c)] \\cdot (x-c) + \\mathcal{O}((x-c)^2)\n\\end{align*}\n$$\n\n\nThe big \"oh\" notation just sweeps up many things including any products of it *and* the term $f'(c)\\cdot g'(c) \\cdot (x-c)^2$. Again, we see from the product rule that this is just a tangent line approximation for $f(x) \\cdot g(x)$.\n\n\nThe basic mathematical operations involving tangent lines can be computed just using the tangent lines when the desired accuracy is at the tangent line level. This is even true for composition, though there the outer and inner functions may have different \"$c$\"s.\n\n\nKnowing this can simplify the task of finding tangent line approximations of compound expressions.\n\n\nFor example, suppose we know that at $c=0$ we have these formula where $a \\approx b$ is a shorthand for the more formal $a=b + \\mathcal{O}(x^2)$:\n\n\n\n$$\n\\sin(x) \\approx x, \\quad e^x \\approx 1 + x, \\quad \\text{and}\\quad 1/(1+x) \\approx 1 - x.\n$$\n\n\nThen we can immediately see these tangent line approximations about $x=0$:\n\n\n\n$$\ne^x \\cdot \\sin(x) \\approx (1+x) \\cdot x = x + x^2 \\approx x,\n$$\n\n\nand\n\n\n\n$$\n\\frac{\\sin(x)}{e^x} \\approx \\frac{x}{1 + x} \\approx x \\cdot(1-x) = x-x^2 \\approx x.\n$$\n\n\nSince $\\sin(0) = 0$, we can use these to find the tangent line approximation of\n\n\n\n$$\ne^{\\sin(x)} \\approx e^x \\approx 1 + x.\n$$\n\n\nNote that $\\sin(\\exp(x))$ is approximately $\\sin(1+x)$ but not approximately $1+x$, as the expansion for $\\sin$ about $1$ is not simply $x$.\n\n\n### The TaylorSeries package\n\n\nThe `TaylorSeries` packages will do these calculations in a manner similar to how `SymPy` transforms a function and a symbolic variable into a symbolic expression.\n\n\nFor example, we have\n\n::: {.cell execution_count=26}\n``` {.julia .cell-code}\nt = Taylor1(Float64, 1)\n```\n\n::: {.cell-output .cell-output-display execution_count=26}\n```\n 1.0 t + 𝒪(t²)\n```\n:::\n:::\n\n\nThe number type and the order is specified to the constructor. Linearization is order $1$, other orders will be discussed later. This variable can now be composed with mathematical functions and the linearization of the function will be returned:\n\n::: {.cell execution_count=27}\n``` {.julia .cell-code}\nsin(t), exp(t), 1/(1+t)\n```\n\n::: {.cell-output .cell-output-display execution_count=27}\n```\n( 1.0 t + 𝒪(t²), 1.0 + 1.0 t + 𝒪(t²), 1.0 - 1.0 t + 𝒪(t²))\n```\n:::\n:::\n\n\n::: {.cell execution_count=28}\n``` {.julia .cell-code}\nsin(t)/exp(t), exp(sin(t))\n```\n\n::: {.cell-output .cell-output-display execution_count=28}\n```\n( 1.0 t + 𝒪(t²), 1.0 + 1.0 t + 𝒪(t²))\n```\n:::\n:::\n\n\n##### Example: Automatic differentiation\n\n\nAutomatic differentiation (forward mode) essentially uses this technique. A \"dual\" is introduced which has terms $a +b\\epsilon$ where $\\epsilon^2 = 0$. The $\\epsilon$ is like $x$ in a linear expansion, so the `a` coefficient encodes the value and the `b` coefficient reflects the derivative at the value. Numbers are treated like a variable, so their \"b coefficient\" is a `1`. Here then is how `0` is encoded:\n\n::: {.cell execution_count=29}\n``` {.julia .cell-code}\nDual(0, 1)\n```\n\n::: {.cell-output .cell-output-display execution_count=29}\n```\n0 + 1ɛ\n```\n:::\n:::\n\n\nThen what is $\\(x)$? It should reflect both $(\\sin(0), \\cos(0))$ the latter being the derivative of $\\sin$. We can see this is *almost* what is computed behind the scenes through:\n\n::: {.cell hold='true' execution_count=30}\n``` {.julia .cell-code}\nx = Dual(0, 1)\n@code_lowered sin(x)\n```\n\n::: {.cell-output .cell-output-display execution_count=30}\n\n::: {.ansi-escaped-output}\n```{=html}\n<pre>CodeInfo(\n<span class=\"ansi-bright-black-fg\">1 ─</span> x = DualNumbers.value(z)\n<span class=\"ansi-bright-black-fg\">│ </span> xp = DualNumbers.epsilon(z)\n<span class=\"ansi-bright-black-fg\">│ </span> %3 = DualNumbers.sin(x)\n<span class=\"ansi-bright-black-fg\">│ </span> %4 = xp\n<span class=\"ansi-bright-black-fg\">│ </span> %5 = DualNumbers.cos(x)\n<span class=\"ansi-bright-black-fg\">│ </span> %6 = %4 * %5\n<span class=\"ansi-bright-black-fg\">│ </span> %7 = DualNumbers.Dual(%3, %6)\n<span class=\"ansi-bright-black-fg\">└──</span> return %7\n)</pre>\n```\n:::\n\n:::\n:::\n\n\nThis 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`.)\n\n\nSimilarly, we can see what happens to `log(x)` at `1` (encoded by `Dual(1,1)`):\n\n::: {.cell hold='true' execution_count=31}\n``` {.julia .cell-code}\nx = Dual(1, 1)\n@code_lowered log(x)\n```\n\n::: {.cell-output .cell-output-display execution_count=31}\n\n::: {.ansi-escaped-output}\n```{=html}\n<pre>CodeInfo(\n<span class=\"ansi-bright-black-fg\">1 ─</span> x = DualNumbers.value(z)\n<span class=\"ansi-bright-black-fg\">│ </span> xp = DualNumbers.epsilon(z)\n<span class=\"ansi-bright-black-fg\">│ </span> %3 = DualNumbers.log(x)\n<span class=\"ansi-bright-black-fg\">│ </span> %4 = xp\n<span class=\"ansi-bright-black-fg\">│ </span> %5 = 1 / x\n<span class=\"ansi-bright-black-fg\">│ </span> %6 = %4 * %5\n<span class=\"ansi-bright-black-fg\">│ </span> %7 = DualNumbers.Dual(%3, %6)\n<span class=\"ansi-bright-black-fg\">└──</span> return %7\n)</pre>\n```\n:::\n\n:::\n:::\n\n\nWe 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 `%4` differs, it reflecting the derivative of the function.\n\n\n## Questions\n\n\n###### Question\n\n\nWhat is the right linear approximation for $\\sqrt{1 + x}$ near $0$?\n\n::: {.cell hold='true' execution_count=32}\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='17466537924534489082' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_17466537924534489082\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17466537924534489082_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17466537924534489082\"\n id=\"radio_17466537924534489082_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + (1/2) \\cdot x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17466537924534489082_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17466537924534489082\"\n id=\"radio_17466537924534489082_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 - (1/2) \\cdot x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17466537924534489082_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17466537924534489082\"\n id=\"radio_17466537924534489082_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + x^{1/2}\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17466537924534489082_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17466537924534489082\"\n id=\"radio_17466537924534489082_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + 1/2\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='17466537924534489082_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_17466537924534489082\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 1;\n var msgBox = document.getElementById('17466537924534489082_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_17466537924534489082\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_17466537924534489082\")\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\nWhat is the right linear approximation for $(1 + x)^k$ near $0$?\n\n::: {.cell hold='true' execution_count=33}\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='17507395460573168060' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_17507395460573168060\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17507395460573168060_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17507395460573168060\"\n id=\"radio_17507395460573168060_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + x^k\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17507395460573168060_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17507395460573168060\"\n id=\"radio_17507395460573168060_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + k\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17507395460573168060_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17507395460573168060\"\n id=\"radio_17507395460573168060_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 - k \\cdot x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17507395460573168060_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17507395460573168060\"\n id=\"radio_17507395460573168060_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + k \\cdot x\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='17507395460573168060_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_17507395460573168060\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 4;\n var msgBox = document.getElementById('17507395460573168060_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_17507395460573168060\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_17507395460573168060\")\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\nWhat is the right linear approximation for $\\cos(\\sin(x))$ near $0$?\n\n::: {.cell hold='true' execution_count=34}\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='17388172503463809428' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_17388172503463809428\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17388172503463809428_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17388172503463809428\"\n id=\"radio_17388172503463809428_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17388172503463809428_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17388172503463809428\"\n id=\"radio_17388172503463809428_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 - x^2/2\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17388172503463809428_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17388172503463809428\"\n id=\"radio_17388172503463809428_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(1\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_17388172503463809428_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_17388172503463809428\"\n id=\"radio_17388172503463809428_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(x\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='17388172503463809428_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_17388172503463809428\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 3;\n var msgBox = document.getElementById('17388172503463809428_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_17388172503463809428\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_17388172503463809428\")\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\nWhat is the right linear approximation for $\\tan(x)$ near $0$?\n\n::: {.cell hold='true' execution_count=35}\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='16609923048795162895' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_16609923048795162895\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_16609923048795162895_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_16609923048795162895\"\n id=\"radio_16609923048795162895_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 - x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_16609923048795162895_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_16609923048795162895\"\n id=\"radio_16609923048795162895_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_16609923048795162895_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_16609923048795162895\"\n id=\"radio_16609923048795162895_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(1\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_16609923048795162895_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_16609923048795162895\"\n id=\"radio_16609923048795162895_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + x\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='16609923048795162895_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_16609923048795162895\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('16609923048795162895_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_16609923048795162895\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_16609923048795162895\")\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\nWhat is the right linear approximation of $\\sqrt{25 + x}$ near $x=0$?\n\n::: {.cell hold='true' execution_count=36}\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='5858734404270288908' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5858734404270288908\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5858734404270288908_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5858734404270288908\"\n id=\"radio_5858734404270288908_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 - (1/2) \\cdot x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5858734404270288908_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5858734404270288908\"\n id=\"radio_5858734404270288908_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(5 \\cdot (1 + (1/2) \\cdot (x/25))\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5858734404270288908_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5858734404270288908\"\n id=\"radio_5858734404270288908_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(1 + x\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5858734404270288908_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5858734404270288908\"\n id=\"radio_5858734404270288908_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(25\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='5858734404270288908_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_5858734404270288908\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('5858734404270288908_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5858734404270288908\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5858734404270288908\")\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\nLet $f(x) = \\sqrt{x}$. Find the actual error in approximating $f(26)$ by the value of the tangent line at $(25, f(25))$ at $x=26$.\n\n::: {.cell hold='true' execution_count=37}\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='17812931405383772427' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_17812931405383772427\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"17812931405383772427\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='17812931405383772427_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"17812931405383772427\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 0.0009804864072151531) <= 0.001);\n var msgBox = document.getElementById('17812931405383772427_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_17812931405383772427\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_17812931405383772427\")\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\nAn estimate of some quantity was $12.34$ the actual value was $12$. What was the *percentage error*?\n\n::: {.cell hold='true' execution_count=38}\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='6311614915903402577' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_6311614915903402577\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"6311614915903402577\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='6311614915903402577_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"6311614915903402577\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 2.833333333333332) <= 0.001);\n var msgBox = document.getElementById('6311614915903402577_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_6311614915903402577\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_6311614915903402577\")\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\nFind the percentage error in estimating $\\sin(5^\\circ)$ by $5 \\pi/180$.\n\n::: {.cell hold='true' execution_count=39}\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='2254795534943209696' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_2254795534943209696\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"2254795534943209696\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='2254795534943209696_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"2254795534943209696\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 0.12703678331200158) <= 0.001);\n var msgBox = document.getElementById('2254795534943209696_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_2254795534943209696\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_2254795534943209696\")\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 side length of a square is measured roughly to be $2.0$ cm. The actual length $2.2$ cm. What is the difference in area (in absolute values) as *estimated* by a tangent line approximation.\n\n::: {.cell hold='true' execution_count=40}\n\n::: {.cell-output .cell-output-display execution_count=40}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='15037203957059983690' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_15037203957059983690\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"15037203957059983690\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='15037203957059983690_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"15037203957059983690\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 0.7999999999999998) <= 0.001);\n var msgBox = document.getElementById('15037203957059983690_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_15037203957059983690\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_15037203957059983690\")\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 [Birthday problem](https://en.wikipedia.org/wiki/Birthday_problem) computes the probability that in a group of $n$ people, under some assumptions, that no two share a birthday. Without trying to spoil the problem, we focus on the calculus specific part of the problem below:\n\n\n\n$$\n\\begin{align*}\np\n&= \\frac{365 \\cdot 364 \\cdot \\cdots (365-n+1)}{365^n} \\\\\n&= \\frac{365(1 - 0/365) \\cdot 365(1 - 1/365) \\cdot 365(1-2/365) \\cdot \\cdots \\cdot 365(1-(n-1)/365)}{365^n}\\\\\n&= (1 - \\frac{0}{365})\\cdot(1 -\\frac{1}{365})\\cdot \\cdots \\cdot (1-\\frac{n-1}{365}).\n\\end{align*}\n$$\n\n\nTaking logarithms, we have $\\log(p)$ is\n\n\n\n$$\n\\log(1 - \\frac{0}{365}) + \\log(1 -\\frac{1}{365})+ \\cdots + \\log(1-\\frac{n-1}{365}).\n$$\n\n\nNow, use the tangent line approximation for $\\log(1 - x)$ and the sum formula for $0 + 1 + 2 + \\dots + (n-1)$ to simplify the value of $\\log(p)$:\n\n::: {.cell hold='true' execution_count=41}\n\n::: {.cell-output .cell-output-display execution_count=41}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='12045164786041990837' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_12045164786041990837\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12045164786041990837_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12045164786041990837\"\n id=\"radio_12045164786041990837_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(-n(n-1)/2/365\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12045164786041990837_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12045164786041990837\"\n id=\"radio_12045164786041990837_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(-n(n-1)/2\\cdot 365\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12045164786041990837_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12045164786041990837\"\n id=\"radio_12045164786041990837_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(-n^2/(2\\cdot 365)\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12045164786041990837_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12045164786041990837\"\n id=\"radio_12045164786041990837_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n \\(-n^2 / 2 \\cdot 365\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='12045164786041990837_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_12045164786041990837\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 1;\n var msgBox = document.getElementById('12045164786041990837_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_12045164786041990837\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_12045164786041990837\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\nIf $n = 10$, what is the approximation for $p$ (not $\\log(p)$)?\n\n::: {.cell hold='true' execution_count=42}\n\n::: {.cell-output .cell-output-display execution_count=42}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='7304358481197848893' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_7304358481197848893\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"7304358481197848893\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='7304358481197848893_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"7304358481197848893\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 0.8840093219278197) <= 0.001);\n var msgBox = document.getElementById('7304358481197848893_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_7304358481197848893\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_7304358481197848893\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\nIf $n=100$, what is the approximation for $p$ (not $\\log(p)$?\n\n::: {.cell hold='true' execution_count=43}\n\n::: {.cell-output .cell-output-display execution_count=43}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='2176047214208863571' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_2176047214208863571\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"2176047214208863571\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='2176047214208863571_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"2176047214208863571\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 1.2889999979257225e-6) <= 0.01);\n var msgBox = document.getElementById('2176047214208863571_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_2176047214208863571\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_2176047214208863571\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n",
|
||
"supporting": [
|
||
"linearization_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"
|
||
]
|
||
}
|
||
}
|
||
} |