Skip to content

Commit 95a8c8d

Browse files
committed
Changed julia to 1.6. Small changes in admonitions.
1 parent b1d77b8 commit 95a8c8d

File tree

18 files changed

+1890
-1493
lines changed

18 files changed

+1890
-1493
lines changed

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ ProgressMeter = "1.4.1"
4545
Query = "1.0.0"
4646
RDatasets = "0.7.4"
4747
StatsPlots = "0.14.18"
48-
julia = "1.5"
48+
julia = "1.6"

docs/src/installation/git.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There is no need to change the default settings. However, we recommend changing
1616

1717
After setting the editor used by Git, finish the installation with default settings.
1818

19-
!!! info "GitHub Account"
19+
!!! info "GitHub Account:"
2020
Create a GitHub account on the official [GitHub page](https://github.com/). Do not forget to verify your email address.
2121

2222
## User settings

docs/src/lecture_02/conditions.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,14 @@ julia> compare(2.3, 2.3)
3535
x is equal to y
3636
```
3737

38-
```@raw html
39-
<div class="admonition is-info">
40-
<header class="admonition-header">Function declaration:</header>
41-
<div class="admonition-body">
42-
```
38+
!!! info "Function declaration:"
39+
So far, we did not show how to define functions. However, the above example should show the basic syntax for defining functions. The `return` keyword specifies the function output. In this case, the function returns nothing since we only want to compare numbers. If we need to define a function that returns more than one variable, the following syntax is used.
4340

44-
So far, we did not show how to define functions. However, the above example should show the basic syntax for defining functions. The `return` keyword specifies the function output. In this case, the function returns nothing since we only want to compare numbers. If we need to define a function that returns more than one variable, the following syntax is used.
41+
```julia
42+
return x, y, z
43+
```
4544

46-
```julia
47-
return x, y, z
48-
```
49-
50-
Here `x`, `y`, and `z` are some variables. We will discuss the function declaration in more detail in the [next lesson](@ref Functions).
51-
52-
```@raw html
53-
</div></div>
54-
```
45+
Here `x`, `y`, and `z` are some variables. We will discuss the function declaration in more detail in the [next lesson](@ref Functions).
5546

5647
The `elseif` and `else` keywords are optional. Moreover, it is possible to use as many `elseif` blocks as needed.
5748

@@ -279,7 +270,7 @@ julia> f(1) || println(2) # both expressions are evaluated
279270

280271
```@raw html
281272
<div class="admonition is-info">
282-
<header class="admonition-header">Short-circuit evaluation vs. bitwise boolean operators</header>
273+
<header class="admonition-header">Short-circuit evaluation vs. bitwise boolean operators:</header>
283274
<div class="admonition-body">
284275
```
285276

docs/src/lecture_02/exercises.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
So far, we used only the standard library shipped with Julia. However, the standard library provides only basic functionality. If we want to get additional functions, we have to use extra packages. There is a [Plots](https://github.com/JuliaPlots/Plots.jl) package for creating plots. Packages can be installed via Pkg REPL. To enter the Pkg REPL from the Julia REPL, press `]` and install the package by
44

55
```julia
6-
(@v1.5) pkg> add Plots
6+
(@v1.6) pkg> add Plots
77
```
88

99
We need to use the `using` keyword to load the package. For example, we can use the Plots package to visualize the `sin` and `cos` functions.
@@ -225,13 +225,14 @@ Try different values of variable `c` to create different plots. For inspiration,
225225

226226
## Animation
227227

228-
!!! warning "Warning"
228+
!!! warning "Warning:"
229229
It takes a lot of time to create the animation below, especially when using the default [GR](https://github.com/jheinen/GR.jl) backend for the Plots package. The plotting time can be reduced by using a different backend such as the [PyPlot](https://github.com/JuliaPy/PyPlot.jl) backend.
230230

231231
```julia
232232
using Plots, PyPlot
233233
pyplot()
234234
```
235+
235236
The PyPlot package must be installed first. An alternative way is to use the [Makie](https://github.com/JuliaPlots/Makie.jl) package instead of the Plots package.
236237

237238
We will now create an animation of the Julia sets for `c` defined as follows

docs/src/lecture_02/loops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ i = 5
4848

4949
```@raw html
5050
<div class="admonition is-info">
51-
<header class="admonition-header">An alternative notation for <code>for</code> loops</header>
51+
<header class="admonition-header">An alternative notation for <code>for</code> loops:</header>
5252
<div class="admonition-body">
5353
```
5454

docs/src/lecture_03/exercises.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The following few exercises will implement the Game of Life. We will consider fi
1717
<header class="admonition-header">Exercise:</header>
1818
<div class="admonition-body">
1919
```
20+
2021
Write a function `neighbours` that return the number of live neighbours of a cell. The function should accept the `world` matrix of boolean values representing the state of all cells (`true` if the cell is alive and `false` otherwise) and index of the row and column of the cell.
2122

2223
**Hint:** use the following properties of the `mod1` function to implement periodic boundaries.
@@ -28,11 +29,13 @@ mod1(5, 4)
2829
```
2930

3031
**Bonus:** implement a more general function which computes the number of alive cells in a neighbourhood of given size.
32+
3133
```@raw html
3234
</div></div>
3335
<details class = "solution-body">
3436
<summary class = "solution-header">Solution:</summary><p>
3537
```
38+
3639
One way to define the `neighbours` function is to check all neighbours manually.
3740

3841
```julia
@@ -78,7 +81,9 @@ end
7881
<header class="admonition-header">Exercise:</header>
7982
<div class="admonition-body">
8083
```
84+
8185
Add a new method to the `neighbours` function that for the `world` matrix returns a matrix containing numbers of living neighbours.
86+
8287
```@raw html
8388
</div></div>
8489
<details class = "solution-body">
@@ -105,7 +110,9 @@ This is an example of multiple dispatch. The function `neighbours` can have both
105110
<header class="admonition-header">Exercise:</header>
106111
<div class="admonition-body">
107112
```
113+
108114
Write a function `willsurvive` that returns `true` if the cell will survive based on the conditions described at the beginning of the section and `false` otherwise. This function should accept two arguments: state of the cell (`true`/`false`) and the number of living neighbours.
115+
109116
```@raw html
110117
</div></div>
111118
<details class = "solution-body">
@@ -142,7 +149,9 @@ willsurvive(cell, k) = k == 3 || k == 2 && cell
142149
<header class="admonition-header">Exercise:</header>
143150
<div class="admonition-body">
144151
```
152+
145153
Combine these functions to write a function `evolve!` that evolves the given `world` matrix into a new generation.
154+
146155
```@raw html
147156
</div></div>
148157
<details class = "solution-body">

docs/src/lecture_03/functions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ julia> x3
9090
<header class="admonition-header">Exercise:</header>
9191
<div class="admonition-body">
9292
```
93+
9394
Write function `power(x::Real, p::Integer)` that for a number ``x`` and a (possibly negative) integer ``p`` computes ``x^p`` without using the `^` operator. Use only basic arithmetic operators `+`, `-`, `*`, `/` and the `if` condition. The annotation `p::Integer` ensures that the input `p` is always an integer.
9495

9596
**Hint:** use recursion.
97+
9698
```@raw html
9799
</div></div>
98100
<details class = "solution-body">
@@ -210,9 +212,11 @@ However, for better code readability, the traditional multiline syntax is prefer
210212
<header class="admonition-header">Exercise:</header>
211213
<div class="admonition-body">
212214
```
215+
213216
Write a one-line function that returns `true` if the input argument is an even number and `false` otherwise.
214217

215218
**Hint:** use modulo function and [ternary operator](@ref Ternary-operator) `?`.
219+
216220
```@raw html
217221
</div></div>
218222
<details class = "solution-body">
@@ -318,6 +322,7 @@ ERROR: UndefVarError: y not defined
318322
<header class="admonition-header">Exercise:</header>
319323
<div class="admonition-body">
320324
```
325+
321326
Write a function which computes the value of the following quadratic form
322327

323328
```math
@@ -331,6 +336,7 @@ a = 1, \quad b = 2a, \quad c = 3(a + b).
331336
```
332337

333338
What is the function value at point ``(4, 2)`` for default parameters? What is the function value at the same point if we use ``c = 3``?
339+
334340
```@raw html
335341
</div></div>
336342
<details class = "solution-body">
@@ -426,6 +432,7 @@ julia> linear(2; a, b)
426432
<header class="admonition-header">Exercise:</header>
427433
<div class="admonition-body">
428434
```
435+
429436
Write a probability density function for the [Gaussian distribution](https://en.wikipedia.org/wiki/Normal_distribution)
430437

431438
```math
@@ -435,6 +442,7 @@ f_{\mu, \sigma}(x) = \frac{1}{\sigma \sqrt{ 2\pi }} \exp\left\{ -\frac{1}{2} \le
435442
where ``\mu \in \mathbb{R}`` and ``\sigma^2 > 0``. Use keyword arguments to obtain the standardized normal distribution (``\mu = 0`` and ``\sigma = 1``). Check that the inputs are correct.
436443

437444
**Bonus:** verify that this function is a probability density function, i.e., its integral equals 1.
445+
438446
```@raw html
439447
</div></div>
440448
<details class = "solution-body">
@@ -598,11 +606,13 @@ This construction is beneficial whenever there are multiple chained functions, a
598606
<header class="admonition-header">Exercise:</header>
599607
<div class="admonition-body">
600608
```
609+
601610
Write a function `wrapper`, that accepts a number and applies one of `round`, `ceil` or `floor` functions based on the keyword argument `type`. Use the function to solve the following tasks:
602611
- Round `1252.1518` to the nearest larger integer and convert the resulting value to `Int64`.
603612
- Round `1252.1518` to the nearest smaller integer and convert the resulting value to `Int16`.
604613
- Round `1252.1518` to `2` digits after the decimal point.
605614
- Round `1252.1518` to `3` significant digits.
615+
606616
```@raw html
607617
</div></div>
608618
<details class = "solution-body">

docs/src/lecture_03/methods.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The problem with the `supertype` function is that it does not return the whole s
9292
<header class="admonition-header">Exercise:</header>
9393
<div class="admonition-body">
9494
```
95+
9596
Create a function `supertypes_tree` which prints the whole tree of all supertypes. If the input type `T` satisfies the following condition `T === Any`, then the function should do nothing. Use the following function declaration:
9697

9798
```julia
@@ -105,6 +106,7 @@ The optional argument `level` sets the printing indentation level.
105106
**Hints:**
106107
- Use the `supertype` function in combination with recursion.
107108
- Use the `repeat` function and string with white space `" "` to create a proper indentation.
109+
108110
```@raw html
109111
</div></div>
110112
<details class = "solution-body">
@@ -166,6 +168,7 @@ This function suffers from a similar disadvantage as the `supertype` function: I
166168
<header class="admonition-header">Exercise:</header>
167169
<div class="admonition-body">
168170
```
171+
169172
Create a function `subtypes_tree` which prints the whole tree of all subtypes for the given type. Use the following function declaration:
170173

171174
```@meta
@@ -185,11 +188,13 @@ The optional argument `level` sets the printing indentation level.
185188
**Hints:**
186189
- Use the `subtypes` function in combination with recursion.
187190
- Use the `repeat` function and string with white space `" "` to create a proper indentation.
191+
188192
```@raw html
189193
</div></div>
190194
<details class = "solution-body">
191195
<summary class = "solution-header">Solution:</summary><p>
192196
```
197+
193198
The `subtypes_tree` function is similar to `supertypes_tree`. The only differences are that we do not need to check for the top level of `Any`, and that we need to call the vectorized version `subtypes_tree.` because `subtypes(T)` returns an array.
194199

195200
```jldoctest methods; output = false
@@ -320,9 +325,10 @@ Closest candidates are:
320325

321326
```@raw html
322327
<div class="admonition is-info">
323-
<header class="admonition-header">Do not overuse type annotation!!!</header>
328+
<header class="admonition-header">Do not overuse type annotation:</header>
324329
<div class="admonition-body">
325330
```
331+
326332
The `product` function should be defined without the type annotation. It is a good practice not to restrict input argument types unless necessary. The reason is that, in this case, there is no benefit of using the type annotation. It is better to define the function `product_new` by:
327333

328334
```jldoctest methods; output = false
@@ -360,19 +366,21 @@ ERROR: MethodError: no method matching *(::String, ::Symbol)
360366
```
361367

362368
Here we get a different error. However, the error returned by the `product_new` function is more useful because it tells us what the real problem is. We can see that it is impossible to use the `*` operator to multiply a `String` and a `Symbol`. We can decide if this is the desired behaviour, and if not, we can define a method for the `*` operator that will fix it.
369+
363370
```@raw html
364371
</div></div>
365372
```
366373

367-
368374
We show a simple example when the multiple dispatch is useful.
369375

370376
```@raw html
371377
<div class="admonition is-category-exercise">
372378
<header class="admonition-header">Exercise:</header>
373379
<div class="admonition-body">
374380
```
381+
375382
We define the abstract type `Student` and specific types `Master` and `Doctoral`. The latter two are defined as structures containing one and three fields, respectively.
383+
376384
```@example methods
377385
abstract type Student end
378386
@@ -388,13 +396,16 @@ end
388396
389397
nothing # hide
390398
```
399+
391400
We can check that the `subtypes_tree` works correctly on any type, including the type `Student` which we defined.
401+
392402
```julia
393403
julia> subtypes_tree(Student)
394404
Student
395405
Doctoral
396406
Master
397407
```
408+
398409
We create instances of two students by providing values for the struct fields.
399410

400411
```@example methods
@@ -403,20 +414,25 @@ s2 = Doctoral(30000, 1, 0)
403414
404415
nothing # hide
405416
```
417+
406418
Write the `salary_yearly` function which computes the yearly salary for both student types. The monthly salary is computed from the base salary (which can be accessed via `s1.salary`). Monthly bonus for doctoral students is 2000 for the mid exam and 1000 for the English exam.
419+
407420
```@raw html
408421
</div></div>
409422
<details class = "solution-body">
410423
<summary class = "solution-header">Solution:</summary><p>
411424
```
425+
412426
Julia prefers to write many simple functions. We write `salary_yearly` based on the not-yet-defined `salary_monthly` function.
427+
413428
```@example methods
414429
salary_yearly(s::Student) = 12*salary_monthly(s)
415430
416431
nothing # hide
417432
```
418433

419434
We specified that the input to `salary_yearly` is any `Student`. Since `Student` is an abstract type, we can call `salary_yearly` with both `Master` and `Doctoral` student. Now we need to define the `salary_monthly` function. Since the salary is computed in different ways for both students, we write two methods.
435+
420436
```@example methods
421437
salary_monthly(s::Master) = s.salary
422438
salary_monthly(s::Doctoral) = s.salary + s.exam_mid*2000 + s.exam_english*1000
@@ -450,6 +466,7 @@ f (generic function with 2 methods)
450466
```
451467

452468
Here, `f` has two methods. The first method applies if the first argument is of type `Float64`, and the second method applies if the second argument is of type `Float64`.
469+
453470
```jldoctest methods_amb
454471
julia> f(2.0, 3)
455472
6.0

docs/src/lecture_04/DataFrames.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,8 @@ col[1] = 4
4141
df
4242
```
4343

44-
```@raw html
45-
<div class="admonition is-info">
46-
<header class="admonition-header">Column names</header>
47-
<div class="admonition-body">
48-
```
49-
DataFrames allow using symbols (like `:A`) and strings (like `"A"`) for all column indexing operations. Using symbols is slightly faster and should be preferred. One exception is when the column names are generated using string manipulation.
50-
```@raw html
51-
</div></div>
52-
```
44+
!!! info "Column names:"
45+
DataFrames allow using symbols (like `:A`) and strings (like `"A"`) for all column indexing operations. Using symbols is slightly faster and should be preferred. One exception is when the column names are generated using string manipulation.
5346

5447
The standard format for storing table data is the `csv` file format. The [CSV](https://github.com/JuliaData/CSV.jl) package provides an interface for saving and loading `csv` files.
5548

0 commit comments

Comments
 (0)