use quarto, not Pluto to render pages

This commit is contained in:
jverzani committed 2022-07-24 16:38:24 -04:00
1 parent 93c993206a
commit 7b37ca828c
879 files changed
+793311 -2678

No files matched your search

@@ -0,0 +1,15 @@
{
"hash": "f4f62ace976f0d269fa9d19ecc043032",
"result": {
"markdown": "# Variables\n\n\n\n## Assignment\n\n\n\n![Screenshot of a calculator provided by the Google search engine.](../precalc/figures/calculator.png)\n\n\n\nThe Google calculator has a button `Ans` to refer to the answer to the previous evaluation. This is a form of memory. The last answer is stored in a specific place in memory for retrieval when `Ans` is used. In some calculators, more advanced memory features are possible. For some, it is possible to push values onto a stack of values for them to be referred to at a later time. This proves useful for complicated expressions, say, as the expression can be broken into smaller intermediate steps to be computed. These values can then be appropriately combined. This strategy is a good one, though the memory buttons can make its implementation a bit cumbersome.\n\n\nWith `Julia`, as with other programming languages, it is very easy to refer to past evaluations. This is done by *assignment* whereby a computed value stored in memory is associated with a name. The name can be used to look up the value later. Assignment does not change the value of the object being assigned, it only introduces a reference to it.\n\n\nAssignment in `Julia` is handled by the equals sign and takes the general form `variable_name = value`. For example, here we assign values to the variables `x` and `y`\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\nx = sqrt(2)\ny = 42\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n```\n42\n```\n:::\n:::\n\n\nIn an assignment, the right hand side is always returned, so it appears nothing has happened. However, the values are there, as can be checked by typing their name\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\nx\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n```\n1.4142135623730951\n```\n:::\n:::\n\n\nJust typing a variable name (without a trailing semicolon) causes the assigned value to be displayed.\n\n\nVariable names can be reused, as here, where we redefine `x`:\n\n::: {.cell hold='true' execution_count=6}\n``` {.julia .cell-code}\nx = 2\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n2\n```\n:::\n:::\n\n\n:::{.callout-note}\n## Note\nThe `Pluto` interface for `Julia` is idiosyncratic, as variables are *reactive*. This interface allows changes to a variable `x` to propogate to all other cells referring to `x`. Consequently, the variable name can only be assigned *once* per notebook **unless** the name is in some other namespace, which can be arranged by including the assignment inside a function or a `let` block.\n\n:::\n\n`Julia` is referred to as a \"dynamic language\" which means (in most cases) that a variable can be reassigned with a value of a different type, as we did with `x` where first it was assigned to a floating point value then to an integer value. (Though we meet some cases - generic functions - where `Julia` balks at reassigning a variable if the type if different.)\n\n\nMore importantly than displaying a value, is the use of variables to build up more complicated expressions. For example, to compute\n\n\n\n$$\n\\frac{1 + 2 \\cdot 3^4}{5 - 6/7}\n$$\n\n\nwe might break it into the grouped pieces implied by the mathematical notation:\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\ntop = 1 + 2*3^4\nbottom = 5 - 6/7\ntop/bottom\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n```\n39.34482758620689\n```\n:::\n:::\n\n\n### Examples\n\n\n##### Example\n\n\nImagine we have the following complicated expression related to the trajectory of a [projectile](http://www.researchgate.net/publication/230963032_On_the_trajectories_of_projectiles_depicted_in_early_ballistic_woodcuts) with wind resistance:\n\n\n\n$$\n\t\\left(\\frac{g}{k v_0\\cos(\\theta)} + \\tan(\\theta) \\right) t + \\frac{g}{k^2}\\ln\\left(1 - \\frac{k}{v_0\\cos(\\theta)} t \\right)\n$$\n\n\nHere $g$ is the gravitational constant $9.8$ and $v_0$, $\\theta$ and $k$ parameters, which we take to be $200$, $45$ degrees, and $1/2$ respectively. With these values, the above expression can be computed when $s=100$:\n\n::: {.cell execution_count=8}\n``` {.julia .cell-code}\ng = 9.8\nv0 = 200\ntheta = 45\nk = 1/2\nt = 100\na = v0 * cosd(theta)\n(g/(k*a) + tand(theta))* t + (g/k^2) * log(1 - (k/a)*t)\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```\n96.75771791632161\n```\n:::\n:::\n\n\nBy defining a new variable `a` to represent a value that is repeated a few times in the expression, the last command is greatly simplified. Doing so makes it much easier to check for accuracy against the expression to compute.\n\n\n##### Example\n\n\nA common expression in mathematics is a polynomial expression, for example $-16s^2 + 32s - 12$. Translating this to `Julia` at $s =3$ we might have:\n\n::: {.cell execution_count=9}\n``` {.julia .cell-code}\ns = 3\n-16*s^2 + 32*s - 12\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n```\nLine truncated
"supporting": [
"variables_files/figure-html"
],
"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"
]
}
}
}