|
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | 7 | "# Functions\n", |
8 | | - "So far in this course we've explored equations that perform algebraic operations to produce one or more results. A *function* is a way of encapsulating an operation that takes an input and produces exactly one ouput.\n", |
| 8 | + "So far in this course we've explored equations that perform algebraic operations to produce one or more results. A *function* is a way of encapsulating an operation that takes an input and produces exactly one output.\n", |
9 | 9 | "\n", |
10 | 10 | "For example, consider the following function definition:\n", |
11 | 11 | "\n", |
|
17 | 17 | "\n", |
18 | 18 | "\\begin{equation}f(3) = 11\\end{equation}\n", |
19 | 19 | "\n", |
20 | | - "You've already seen a few examples of Python functions, which are defined using the **def** keyword. However, the strict definition of an algebraic function is that it must return a single value. Here's an example of defining and using a Python function that meets this criteria:" |
| 20 | + "You've already seen a few examples of R functions, which are defined using the **def** keyword. However, the strict definition of an algebraic function is that it must return a single value. Here's an example of defining and using a R function that meets this criteria:" |
21 | 21 | ] |
22 | 22 | }, |
23 | 23 | { |
|
60 | 60 | "\n", |
61 | 61 | "\\begin{equation}y = f(x) - 1\\end{equation}\n", |
62 | 62 | "\n", |
63 | | - "To calculate a value for ***y***, we take the ***f*** of ***x*** and subtract 1. So assuming that ***f*** is defined as previously, given an ***x*** value of 4, this equation returns a ***y*** value of **17** (*f*(4) returns 4<sup>2</sup> + 2, so 16 + 2 = 18; and then the equation subtracts 1 to give us 17). Here it is in Python:" |
| 63 | + "To calculate a value for ***y***, we take the ***f*** of ***x*** and subtract 1. So assuming that ***f*** is defined as previously, given an ***x*** value of 4, this equation returns a ***y*** value of **17** (*f*(4) returns 4<sup>2</sup> + 2, so 16 + 2 = 18; and then the equation subtracts 1 to give us 17). Here it is in R:" |
64 | 64 | ] |
65 | 65 | }, |
66 | 66 | { |
|
232 | 232 | "\n", |
233 | 233 | "When plotting a function line that marks the end of a continuous range, the end of the line is shown as a circle, which is filled if the function includes the value at that point, and unfilled if it does not.\n", |
234 | 234 | "\n", |
235 | | - "Here's the Python to plot function ***h***:" |
| 235 | + "Here's the R to plot function ***h***:" |
236 | 236 | ] |
237 | 237 | }, |
238 | 238 | { |
|
298 | 298 | "\\begin{equation}\\{x \\in \\rm I\\!R\\;\\;|\\;\\; 0 \\lt x \\lt 5 \\}\\end{equation}\n", |
299 | 299 | "\\begin{equation}\\{x \\in \\rm I\\!R\\;\\;|\\;\\; (0,5) \\}\\end{equation}\n", |
300 | 300 | "\n", |
301 | | - "Here's function ***j*** in Python:" |
| 301 | + "Here's function ***j*** in R:" |
302 | 302 | ] |
303 | 303 | }, |
304 | 304 | { |
|
363 | 363 | "\n", |
364 | 364 | "Note that this does not include all real numbers, it only includes 0 and 100.\n", |
365 | 365 | "\n", |
366 | | - "When we use Python to plot this function, note that it only makes sense to plot a scatter plot showing the individual values returned, there is no line in between because the function is not continuous between the values within the domain. " |
| 366 | + "When we use R to plot this function, note that it only makes sense to plot a scatter plot showing the individual values returned, there is no line in between because the function is not continuous between the values within the domain. " |
367 | 367 | ] |
368 | 368 | }, |
369 | 369 | { |
|
422 | 422 | "\n", |
423 | 423 | "\\begin{equation}\\{p(x) \\in \\rm I\\!R\\;\\;|\\;\\; p(x) \\ge 1 \\}\\end{equation}\n", |
424 | 424 | "\n", |
425 | | - "Let's create and plot the function for a range of ***x*** values in Python:" |
| 425 | + "Let's create and plot the function for a range of ***x*** values in R:" |
426 | 426 | ] |
427 | 427 | }, |
428 | 428 | { |
|
478 | 478 | "mimetype": "text/x-r-source", |
479 | 479 | "name": "R", |
480 | 480 | "pygments_lexer": "r", |
481 | | - "version": "3.4.1" |
| 481 | + "version": "3.5.0" |
482 | 482 | } |
483 | 483 | }, |
484 | 484 | "nbformat": 4, |
|
0 commit comments