clean up
This commit is contained in:
1 parent
ac87e089ca
commit
5ee2963688
636 files changed
+18
-719782
No files matched your search
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"hash": "0688f9677291aaad536d8daba1424261",
|
||||
"result": {
|
||||
"markdown": "# Ranges and Sets\n\n\n\n::: {.cell results='hidden' execution_count=2}\n\n::: {.cell-output .cell-output-stderr}\n```\nWARNING: redefinition of constant frontmatter. This may fail, cause incorrect answers, or produce other errors.\n```\n:::\n:::\n\n\n## Arithmetic sequences\n\n\nSequences of numbers are prevalent in math. A simple one is just counting by ones:\n\n\n\n$$\n1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \\dots\n$$\n\n\nOr counting by sevens:\n\n\n\n$$\n7, 14, 21, 28, 35, 42, 49, \\dots\n$$\n\n\nMore challenging for humans is [counting backwards](http://www.psychpage.com/learning/library/assess/mse.htm) by 7:\n\n\n\n$$\n100, 93, 86, 79, \\dots\n$$\n\n\nThese are examples of [arithmetic sequences](http://en.wikipedia.org/wiki/Arithmetic_progression). The form of the first $n+1$ terms in such a sequence is:\n\n\n\n$$\na_0, a_0 + h, a_0 + 2h, a_0 + 3h, \\dots, a_0 + nh\n$$\n\n\nThe formula for the $a_n$th term can be written in terms of $a_0$, or any other $0 \\leq m \\leq n$ with $a_n = a_m + (n-m)\\cdot h$.\n\n\nA typical question might be: The first term of an arithmetic sequence is equal to $200$ and the common difference is equal to $-10$. Find the value of $a_{20}$. We could find this using $a_n = a_0 + n\\cdot h$:\n\n::: {.cell hold='true' execution_count=3}\n``` {.julia .cell-code}\na0, h, n = 200, -10, 20\na0 + n * h\n```\n\n::: {.cell-output .cell-output-display execution_count=172}\n```\n0\n```\n:::\n:::\n\n\nMore complicated questions involve an unknown first value, as with: an arithmetic sequence has a common difference equal to $10$ and its $6$th term is equal to $52$. Find its $15$th term, $a_{15}$. Here we have to answer: $a_0 + 15 \\cdot 10$. Either we could find $a_0$ (using $52 = a_0 + 6\\cdot(10)$) or use the above formula\n\n::: {.cell hold='true' execution_count=4}\n``` {.julia .cell-code}\na6, h, m, n = 52, 10, 6, 15\na15 = a6 + (n-m)*h\n```\n\n::: {.cell-output .cell-output-display execution_count=173}\n```\n142\n```\n:::\n:::\n\n\n### The colon operator\n\n\nRather than express sequences by the $a_0$, $h$, and $n$, `Julia` uses the starting point (`a`), the difference (`h`) and a *suggested* stopping value (`b`). That is, we need three values to specify these ranges of numbers: a `start`, a `step`, and an `endof`. `Julia` gives a convenient syntax for this: `a:h:b`. When the difference is just $1$, all numbers between the start and end are specified by `a:b`, as in\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\n1:10\n```\n\n::: {.cell-output .cell-output-display execution_count=174}\n```\n1:10\n```\n:::\n:::\n\n\nBut wait, nothing different printed? This is because `1:10` is efficiently stored. Basically, a recipe to generate the next number from the previous number is created and `1:10` just stores the start and end point and that recipe is used to generate the set of all values. To expand the values, you have to ask for them to be `collect`ed (though this typically isn't needed in practice):\n\n::: {.cell execution_count=6}\n``` {.julia .cell-code}\ncollect(1:10)\n```\n\n::: {.cell-output .cell-output-display execution_count=175}\n```\n10-element Vector{Int64}:\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10\n```\n:::\n:::\n\n\nWhen a non-default step size is needed, it goes in the middle, as in `a:h:b`. For example, counting by sevens from $1$ to $50$ is achieved by:\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\ncollect(1:7:50)\n```\n\n::: {.cell-output .cell-output-display execution_count=176}\n```\n8-element Vector{Int64}:\n 1\n 8\n 15\n 22\n 29\n 36\n 43\n 50\n```\n:::\n:::\n\n\nOr counting down from 100:\n\n::: {.cell execution_count=8}\n``` {.julia .cell-code}\ncollect(100:-7:1)\n```\n\n::: {.cell-output .cell-output-display execution_count=177}\n```\n15-element Vector{Int64}:\n 100\n 93\n 86\n 79\n 72\n 65\n 58\n 51\n 44\n 37\n 30\n 23\n 16\n 9\n 2\n```\n:::\n:::\n\n\nIn this last example, we said end with $1$, but it ended with $2$. The ending value in the range is a suggestion to go up to, but not exceed. Negative values for `h` are used to make decreasing sequences.\n\n\n### The range function\n\n\nFor generating points to make graphs, a natural set of points to specify is $n$ evenly spaced points between $a$ and $b$. We can mimic creating this set with the range operation by solving for the correct step size. We have $a_0=a$ and $a_0 + (n-1) \\cdot h = b$. (Why $n-1$ and not $n$?) Solving yields $h = (b-a)/(n-1)$. To be concrete we might ask for $9$ points between $-1$ and $1$:\n\n::: {.cell hold='true' execution_count=9}\n``` {.julia .cell-code}\na, b, n = -1, 1, 9\nh = (b-a)/(n-1)\ncollect(a:h:b)\n```\n\n::: {.cell-output .cell-output-display execution_count=178}\n```\n9-element Vector{Float64}:\n -1.0\n -0.75\n -0.5\n -0.25\n 0.0\n 0.25\n 0.5\n 0.75\n 1.0\n```\n:::\n:::\n\n\nPretty neat. If we were doing this many times - such as once per plot - we'd want to encapsulate this into a function, for exampleLine truncated
|
||||
"supporting": [
|
||||
"ranges_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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user