lots of cleanup
This commit is contained in:
@@ -14,22 +14,18 @@ using CalculusWithJulia
|
||||
nothing
|
||||
```
|
||||
|
||||
```{julia}
|
||||
#| echo: false
|
||||
imgfile = "figures/calculator.png"
|
||||
caption = "Screenshot of a calculator provided by the Google search engine."
|
||||
# ImageFile(:precalc, imgfile, caption)
|
||||
nothing
|
||||
```
|
||||
|
||||

|
||||
::: {#fig-google-calculator-screenshot}
|
||||

|
||||
|
||||
Screenshot of a calculator provided by the Google search engine
|
||||
:::
|
||||
|
||||
The 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.
|
||||
|
||||
|
||||
With `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 (sometimes thought of as symbol or label). 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.
|
||||
`Julia`, as with other programming languages, makes it is very easy to refer to many past evaluations.
|
||||
|
||||
This is done by *assignment* whereby the storage of a value in memory is associated with a name. This pairing results in a *variable* and the value can be referenced through the variable name. The variable name may be called an identifier and internally kept as a symbol. Julia is a dynamic language which means the pairing can be updated and the referenced values may have different storage types. An example of a built-in variable is the special variable `ans` which refers to the last computed value in an interactive session.
|
||||
|
||||
Assignment 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`
|
||||
|
||||
@@ -49,7 +45,7 @@ x
|
||||
Just typing a variable name (without a trailing semicolon) causes the assigned value to be displayed.
|
||||
|
||||
|
||||
Variable names can be reused (or reassigned), as here, where we redefine `x`:
|
||||
Variable names can be reused (or reassigned)^[The `Pluto` interface for `Julia` is idiosyncratic, as variables are *reactive*. This interface allows changes to a variable `x` to propagate 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.], as here, where we redefine `x`:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -57,13 +53,8 @@ Variable names can be reused (or reassigned), as here, where we redefine `x`:
|
||||
x = 2
|
||||
```
|
||||
|
||||
:::{.callout-note}
|
||||
## Note
|
||||
The `Pluto` interface for `Julia` is idiosyncratic, as variables are *reactive*. This interface allows changes to a variable `x` to propagate 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.
|
||||
|
||||
:::
|
||||
|
||||
`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 is different.)
|
||||
`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 is different.)
|
||||
|
||||
|
||||
More importantly than displaying a value, is the use of variables to build up more complicated expressions. For example, to compute
|
||||
@@ -181,12 +172,18 @@ Q = R^(2/3) * S^(1/2) / n * A
|
||||
## Where math and computer notations diverge
|
||||
|
||||
|
||||
It is important to recognize that `=` to `Julia` is not in analogy to how $=$ is used in mathematical notation. The following `Julia` code is not an equation:
|
||||
It is important to recognize that `=` to `Julia` is not in analogy to how $=$ is used in mathematical notation.
|
||||
|
||||
First, set `x` to be $3$:
|
||||
|
||||
```{julia}
|
||||
x = 3
|
||||
```
|
||||
|
||||
The following `Julia` code is not an equation:
|
||||
|
||||
|
||||
```{julia}
|
||||
#| hold: true
|
||||
x = 3
|
||||
x = x^2
|
||||
```
|
||||
|
||||
@@ -219,12 +216,12 @@ x = x - (x^2 - 2) / (2x)
|
||||
x = x - (x^2 - 2) / (2x)
|
||||
```
|
||||
|
||||
Repeating this last line will generate new values of `x` based on the previous one - no need for subscripts. This is exactly what the mathematical notation indicates is to be done.
|
||||
Repeating this last line will generate new values of `x` based on the previous one---no need for subscripts. This is exactly what the mathematical notation indicates is to be done.
|
||||
|
||||
::: {.callout-note}
|
||||
## Use of =
|
||||
|
||||
The distinction between ``=`` versus `=` is important and one area where common math notation and common computer notation diverge. The mathematical ``=`` indicates *equality*, and is often used with equations and also for assignment. Later, when symbolic math is introduced, the `~` symbol will be used to indicate an equation, though this is by convention and not part of base `Julia`. The computer syntax use of `=` is for *assignment* and *re-assignment*. Equality is tested with `==` and `===`.
|
||||
The distinction between ``=`` versus `=` is important and one area where common math notation and common computer notation diverge. The mathematical ``=`` indicates *equality*, and is often used with equations and also for assignment. Later, when symbolic math is introduced, the `~` symbol will be used to indicate an equation, though this is by convention and not part of base `Julia`. The computer syntax use of `=` is for *assignment* and *re-assignment*. Equality is tested with `==` and identicalness (or egal) with `===`.
|
||||
|
||||
:::
|
||||
|
||||
@@ -283,20 +280,14 @@ For example, we could have defined `theta` (`\theta[tab]`) and `v0` (`v\_0[tab]`
|
||||
θ = 45; v₀ = 200
|
||||
```
|
||||
|
||||
These notes often use Unicode alternatives for some variable.
|
||||
|
||||
:::{.callout-note}
|
||||
## Emojis
|
||||
There is even support for tab-completion of [emojis](https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/src/emoji_symbols.jl) such as `\:snowman:[tab]` or `\:koala:[tab]`
|
||||
|
||||
:::
|
||||
|
||||
|
||||
:::{.callout-note}
|
||||
## Unicode
|
||||
These notes often use Unicode alternatives for some variable. Originally this was to avoid a requirement of `Pluto` of a single use of assigning to a variable name in a notebook without placing the assignment in a `let` block or a function body. Now, they are just for clarity through distinction.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
##### Example
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user