1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/julia_course.git synced 2024-11-16 13:28:10 +00:00

Day 1 done

This commit is contained in:
Mo8it 2022-03-27 18:47:09 +02:00
parent bb116d68ef
commit 1e3d07fbb0

View file

@ -4,6 +4,20 @@
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ 56ca47c1-6e4d-48a2-9f55-ca89362c7d3f
# Import packages and export their (public) functions
using Measurements, Unitful
# ╔═╡ 1f347724-1db2-48f0-87df-4e63ad6e8820
# Importing a builtin library that provides more functions for linear algebra.
# The keyword `using` imports the package and exports (public) functions automatically.
@ -45,17 +59,15 @@ md"""
md"""
## Pluto notebooks
- ⌨️ Press **`F1`** to see the full list of **shortcuts**.
- ▶️ Most important shortcut: `Shift` + `Enter` to run a cell.
- 📚️ Take a look at the **live docs** to the right.
"""
# ╔═╡ b559ef1a-76cf-4464-b5ec-f7d6bfa892e6
md"""
# Basics
"""
# ╔═╡ 938adcfe-8d1b-4c77-8d82-c48415f5673e
md"""
## Calculation
You can use Julia as a calculator 🧮
"""
# ╔═╡ 73190799-fd03-4cc4-9b4e-c523bc310468
@ -85,6 +97,19 @@ md"""
# Quotient of division
5 ÷ 2
# ╔═╡ 0dc9bbb4-fdde-4006-b04d-4509f7d041a7
3^2 * 2 - 8
# ╔═╡ 9c837673-79dd-4a6f-a11d-6f0f2c001587
3^2 * (2 - 8)
# ╔═╡ 0b6c6d50-e24c-43c7-8f04-4a53a3309bbf
md"""
Compare the results of the last two cells.
The followed operation priority is the same as in math (multiplication before addition/subtraction and so on). Use brackets to make sure that you get the result you want!
"""
# ╔═╡ d1bf37f9-5135-48b8-8f9b-84ddd4a86157
md"""
## Variables
@ -107,23 +132,68 @@ a * b
# You can also store the result of a computation
c = a + b
# ╔═╡ 4936c9fc-43da-4b8b-84ce-11e739802e07
# You can also use variables with long names, but make sure to connect the words with an underscore (_)
variable_with_a_long_name = 42
# ╔═╡ 5e7f8a5e-9354-442b-aa13-7b9b3de536b1
md"""
There is a useful syntax to update the value of a variable using an operator acting on the variable itself.
"""
# ╔═╡ cf08cc65-7a9e-490d-b7e6-eecf6a1d9977
md"""
From now on, blocks will be used sometimes when manipulating a varialbe to prevent dependency on execution order in the notebooks.
A block starts with `begin` and ends with `end`. Code in the block should be indented.
The output of a cell with a block is the output of the last line of this block.
"""
# ╔═╡ 4774fa16-a6f6-48ae-b9b6-8a279118c99a
begin
incr_var = 1
incr_var += 1
# Equivalent to the following:
# incr_var = incr_var + 1
incr_var
end
# ╔═╡ 30000e9f-ec3d-416a-b402-010da80cd9ea
md"""
This syntax can also be used for all other operators (`*`, `/`, `^`, etc.)
"""
# ╔═╡ 72daf832-dba6-49ad-8d5a-f2c3aecdb630
# Example with one more operator
begin
doppel_var = 5
doppel_var *= 2
doppel_var
end
# ╔═╡ 2121b949-06e7-4079-a25a-d0518ee2ba50
md"""
## Primitive types
- **`Bool`**
- **`Char`**
- `Float16`, `Float32`, **`Float64`**
- `Int8`, `Int16`, `Int32`, **`Int64`**, `Int128`
- `UInt8`, `UInt16`, `UInt32`, `UInt64`, `UInt128`
## Types
All other types (like strings) are composed.
These are the most important primitive types:
- `Bool`
- `Char`
- `Float64`
- `Int64`
Spoiler: You can compose your own types! More about this later 😉
Most other types (like `String`) are composed.
*Spoiler: You can compose your own types! More about this later* 😉
"""
# ╔═╡ 534f3b32-1fc9-4eed-887a-2cac66c2bdb4
# Bool
bo = true
# Bool has only two possible values: `true` or `false`.
bo1 = true
# ╔═╡ 3894b6b5-1952-409a-9966-502c277e26c3
bo2 = false
# ╔═╡ f20de3db-f270-4c43-aab7-692c313b5fa9
# Char
@ -148,9 +218,9 @@ hello = "Hello world!"
# ╔═╡ 196682db-f5e1-4c07-9d35-644da3eecdd6
md"""
Pluto notebooks automatically print the output of the cell.
Pluto notebooks automatically print the output of a cell.
When using scripts instead of notebooks, `println` is needed.
When using scripts instead of notebooks, `println` is needed to print to the console / terminal.
"""
# ╔═╡ 10fdb32f-b66f-4c4e-abd9-e856549941b8
@ -174,122 +244,6 @@ meaning_of_life = 42
# Int64 is the default
typeof(meaning_of_life)
# ╔═╡ 944e2d37-8280-47b8-b874-97221955d048
md"""
## Type hierarchy
Julia does have abstract types which are helpful for multiple dispatch.
More about multiple dispatch later 😉
"""
# ╔═╡ 23d4ac67-05ec-4b3d-8368-86256076be62
# The type hierarchy of Int64
supertypes(Int64)
# ╔═╡ e8d7de2f-7c7e-47cb-9364-27d583652167
md"""
All types showed in the output of the above cell except `Int64` are abstract.
This means that you can not have a variable with an abstract type.
You can only derive from an abstract type, but more about this when discussing structs and mutliple dispatch 😉
`Any` is the abstract type of everything.
"""
# ╔═╡ 866edf5e-a76c-448d-98e8-925eaed5eba5
# A number can either be real or complex
subtypes(Number)
# ╔═╡ a8ea4ac1-7f62-4485-a8c5-8ccf00c45720
# There are some types of real numbers.
subtypes(Real)
# ╔═╡ 786a96be-16cd-4f1b-9b5f-138e232d3183
# Integers can have a sign or no sign (only positive).
# A Bool is also treated as an integer with the value 0 or 1.
subtypes(Integer)
# ╔═╡ dd8dad86-6bc2-4489-8469-7eac80fc41bb
# Integers can have different number of bits.
subtypes(Signed)
# ╔═╡ fac04aa7-28e9-4f93-9312-a8f8f93c0877
# Minimum and maximum value of a type
typemin(Int8), typemax(Int8)
# ╔═╡ 86bc0ff0-b6bf-4700-a741-36323be58391
typemin(Int128), typemax(Int128)
# ╔═╡ ef35a3a7-c1df-4952-aa41-1ed22d7f3981
# BigInt does not have a minimum or maximum!
BigInt(10)^1000 + 1
# ╔═╡ c336d5f6-80ee-4994-a55f-2d6b3aa3d559
# Hierarchy of Float64
supertypes(Float64)
# ╔═╡ 608d4433-6e68-4f95-8581-437234b58e87
md"""
## Convertion
"""
# ╔═╡ beadbfd3-0015-449a-b6e7-b5182b396c1d
# Converting a float to an integer
convert(Int64, 3.0)
# ╔═╡ 552fafa4-fad5-4efe-895f-255b3ec5c858
# Complex is a composed type for complex numbers
convert(Complex, 3.0)
# ╔═╡ d11fde7f-3238-4013-bd2d-546aab0d9f9c
# This does not work! See rounding below.
# convert(Int64, 3.2)
# ╔═╡ 036a2c43-dbc9-487c-96aa-94324eeb4a52
md"""
## Rounding
"""
# ╔═╡ 1e954726-254e-41bb-a62f-17bdc9884bee
# We have to tell Julia explicitely what to do when converting a float with non zero digits after the decimal point.
round(Int64, 3.2)
# ╔═╡ d74f6c46-f5a8-4720-bcaf-936f1508efda
# The default is rounding to 0 digits after the decimal points, but keeping the float type.
round(π)
# ╔═╡ 3e5daca6-5aa8-42bf-988b-c09fb17388df
# ; marks the start of keyword arguments. More about it later!
round(π; digits=2)
# ╔═╡ 7ff20c67-58d5-4095-bb8e-7ab7522791c7
# You can provide a rounding mode, see the docs!
round(π, RoundUp)
# ╔═╡ 4a00035f-a1d1-409f-b73b-07f9073dc9d5
md"""
## Boolean operators
"""
# ╔═╡ d4ebb324-fa31-4058-9da1-35e07a971106
# Boolean AND
true && false
# ╔═╡ f8259580-5a29-4a13-811f-c91d6811a291
# Boolean OR
true || false
# ╔═╡ f813afd8-2e1b-43f7-beeb-ac9bd15fbeb6
# Boolean NOT
!false
# ╔═╡ 7ab3a69d-ac31-49cf-8d34-3a427b02ed06
md"""
⚠️ Don't try to use `and`, `or` or `not` if you are coming from Python!
"""
# ╔═╡ 5e45b854-c173-452b-b62b-54037a3780fd
md"""
## String operatorions
@ -354,19 +308,335 @@ a_mult_b = a * b
# Using the macro @show, helpful for usage in scripts
@show a * b
# ╔═╡ 1e7b103c-6cc9-4586-820b-9ec836b997da
md"""
### Why even string formatting?
The following is an example of a possible calculation in a physical context.
"""
# ╔═╡ 7ade3f89-4838-4a8b-815c-4e2d6ccd7fea
# Voltage
U1 = 12.0 # V
# ╔═╡ 35675b9b-a28a-427f-9da4-e6c756d2276a
# Voltage uncertainty
dU1 = 0.1 # V
# ╔═╡ 66d39465-8244-483f-9a82-8d17b95cf41d
# Current
I1 = 0.30 # mA
# ╔═╡ 879c5330-781f-44c2-b072-1ee0f9bd971d
# Current uncertainty
dI1 = 0.01 # mA
# ╔═╡ df5914e3-b250-4824-80a5-cac5d0bed084
# Resistance
R1 = U1 / I1 # kΩ
# ╔═╡ 099ac8f8-8c5c-410b-a11f-c98bc68230b2
# Resistance uncertainty calculated with the Gaussian propagation of uncertainty.
dR1 = R1 * ((dU1 / U1)^2 + (dI1 / I1)^2)^0.5 # kΩ
# ╔═╡ cd46845b-4980-465c-a64f-3a8bcb66f53e
# You can get the ± symbol by typing \pm and then pressing tab.
println("""U: $U1 ± $dU1 V
I: $I1 ± $dI1 mA
R: $R1 ± $(round(dR1; digits=2)) """) # We will get to rounding later
# ╔═╡ a0bd2da0-344d-470c-918e-e8760fc77355
md"""
Nice, we were able to generate a nice output 🤩
But wait, Julia can automatically handle physical units and propagation of uncertainty for us! 🙀
"""
# ╔═╡ a2c4c4d9-4f06-41d4-baeb-b5f9f3b5b7c3
md"""
## Measurements and units
"""
# ╔═╡ f4122e58-a30c-45a4-8ede-492ddb8deba4
U2 = (12.0 ± 0.1)u"V"
# ╔═╡ 949e7fb8-8eff-49ea-8e76-0306857b05b9
I2 = (0.30 ± 0.01)u"mA"
# ╔═╡ 26869678-32f0-46e8-8cb2-d45b84441f03
R2 = U2 / I2
# ╔═╡ 0121add2-b42b-4dcd-8912-f8420a8b4c72
R2_converted = uconvert(u"", R2)
# ╔═╡ 9df364d6-0f43-4fe3-8a10-4bf0dc79e04d
md"""
Magic 🪄
"""
# ╔═╡ b8d7bd0b-a0ea-499f-9e61-3875535887e9
md"""
## Functions
In the last example, we did calculate the resistance. The resistance is a function of two variables: `I` and `U`.
In physics or mathematics, you would write this function this way:
$R(U, I) = U / I$
Guess what: In Julia, you can just write the same thing and you get a function!
"""
# ╔═╡ 13dd1d3c-dec8-4871-8ffa-b3db1bdd2847
# Function definition
R(U, I) = U / I
# ╔═╡ 0078ea9a-9c94-4703-a878-3cdd2e11d625
md"""
Now, you can call the function with some arguments.
"""
# ╔═╡ 38d3105f-427b-427b-bf7b-8aa76dfb3bef
R(12.0, 0.30)
# ╔═╡ 41b17c21-5b57-4912-88ee-e33215c1e0c8
# You can also pass units and uncertainties, Julia will just handle them.
# You can store the result in a new variable.
R3 = R((12.0 ± 0.1)u"V", (0.30 ± 0.01)u"mA")
# ╔═╡ b6dcaf22-c075-442e-b0d0-e48eae2350ac
# Now convert the result
uconvert(u"", R3)
# ╔═╡ 7f01c4a5-0e56-43aa-8d14-5fecfa04b370
md"""
OK, I guess you are asking what the benefit is. Why functions? You can just write `U / I`, right? 🤔
It was just a demonstration! Functions are more useful when you have a long calculation.
Lets write a function that does more than one thing. We want to calculate and show the results in a nice way.
Function with more than one line start with the keyword `function` and end with `end`. After `function` the name of the function and the arguments follow.
Everything inbetween should be indented (with tab). The result has to be returned with `return`.
"""
# ╔═╡ 105362be-572c-4a4d-9163-15ed8b4f1fbf
function calc_and_print_R(U, I)
@show U
@show I
R = U / I
R = uconvert(u"", R)
@show R
return R
end
# ╔═╡ 18c2ffb9-a895-491b-96ee-a0b5c68da180
# Test the function
calc_and_print_R(U2, I2)
# ╔═╡ 62cdf927-4e2b-40bb-be2d-eb32e0789548
md"""
Now, everytime you want to calculate a resistance, you just use this function and it calculates and outputs for you 😃
"""
# ╔═╡ 9847a224-701a-489a-b125-95158aa805d4
# Take a look at this function doing some random calculation
function complex_function(a, b, c, d)
result = a + b
result = result * c
result = result / d
return result
end
# ╔═╡ 21163504-972d-4362-8c57-dbd708b2fa04
complex_function(1, 2, 3, 4)
# ╔═╡ 9ef91243-04fc-44f2-ae69-76f372364f21
# Try to access the variable `result`
# result
# ╔═╡ 3df766f0-38cb-4cdf-a68f-a4771c78fe31
md"""
Why can't we access the variable that we did define and use in the function? 😢
It is because of the concept of *scopes*. The variable result is only defined inside the function and it is only accecable inside of this function (in the scope of the function), not outside it!
`result` is called an *internal* variable. When you define a variable outside a function, it is called a *global* variable and is accecable everywhere.
"""
# ╔═╡ a6d882a0-c80e-4acf-b05b-c0ae120d698d
md"""
We will get back to data analysis. But first, we have to dive a bit deeper into the language 🤿
"""
# ╔═╡ 944e2d37-8280-47b8-b874-97221955d048
md"""
## Type hierarchy
Julia does have abstract types which are helpful for multiple dispatch.
More about multiple dispatch later 😉
"""
# ╔═╡ 23d4ac67-05ec-4b3d-8368-86256076be62
# The type hierarchy of Int64
supertypes(Int64)
# ╔═╡ e8d7de2f-7c7e-47cb-9364-27d583652167
md"""
All types showed in the output of the above cell except `Int64` are abstract.
This means that you can not have a variable with an abstract type.
You can only derive from an abstract type, but more about this when discussing structs and mutliple dispatch 😉
`Any` is the abstract type of everything.
"""
# ╔═╡ 866edf5e-a76c-448d-98e8-925eaed5eba5
# A number can either be real or complex
subtypes(Number)
# ╔═╡ a8ea4ac1-7f62-4485-a8c5-8ccf00c45720
# There are some types of real numbers.
subtypes(Real)
# ╔═╡ 786a96be-16cd-4f1b-9b5f-138e232d3183
# Integers can have a sign or no sign (only positive).
# A Bool is also treated as an integer with the value 0 or 1.
subtypes(Integer)
# ╔═╡ dd8dad86-6bc2-4489-8469-7eac80fc41bb
# Integers can have different number of bits.
subtypes(Signed)
# ╔═╡ fac04aa7-28e9-4f93-9312-a8f8f93c0877
# Minimum and maximum value of a type
typemin(Int8), typemax(Int8)
# ╔═╡ 86bc0ff0-b6bf-4700-a741-36323be58391
typemin(Int128), typemax(Int128)
# ╔═╡ ef35a3a7-c1df-4952-aa41-1ed22d7f3981
# BigInt does not have a minimum or maximum!
BigInt(10)^1000 + 1
# ╔═╡ c336d5f6-80ee-4994-a55f-2d6b3aa3d559
# Hierarchy of Float64
supertypes(Float64)
# ╔═╡ 608d4433-6e68-4f95-8581-437234b58e87
md"""
## Convertion
You can convert some types to others if it is possible.
"""
# ╔═╡ beadbfd3-0015-449a-b6e7-b5182b396c1d
# Converting a float to an integer
convert(Int64, 3.0)
# ╔═╡ 552fafa4-fad5-4efe-895f-255b3ec5c858
# Complex is a composed type for complex numbers
convert(Complex, 3.0)
# ╔═╡ d11fde7f-3238-4013-bd2d-546aab0d9f9c
# This does not work! See rounding below.
# convert(Int64, 3.2)
# ╔═╡ 036a2c43-dbc9-487c-96aa-94324eeb4a52
md"""
## Rounding
"""
# ╔═╡ 1e954726-254e-41bb-a62f-17bdc9884bee
# We have to tell Julia explicitely what to do when converting a float with non zero digits after the decimal point.
round(Int64, 3.2)
# ╔═╡ d74f6c46-f5a8-4720-bcaf-936f1508efda
# The default is rounding to 0 digits after the decimal points, but keeping the float type.
round(π)
# ╔═╡ 3e5daca6-5aa8-42bf-988b-c09fb17388df
# ; marks the start of keyword arguments. More about it later!
round(π; digits=2)
# ╔═╡ 7ff20c67-58d5-4095-bb8e-7ab7522791c7
# You can provide a rounding mode, see the docs!
round(π, RoundUp)
# ╔═╡ 3102810f-3467-4ed8-86c0-16e9177fa69d
md"""
## For loop
## `for` loop
You might be asking your self, why even bother learning a programming language when you can just use a calculator 🤨
One very improtant aspect of computers is their ability to do a computation for many times, without getting tired or missing a step 😴
To use this ability, programming languages provide `for` and `while` loops.
In a `for` loop, Julia iterates over every element of a given collection and does a specific computation with this element.
Lets see some examples!
"""
# ╔═╡ c1c705d2-7e46-4811-9fb1-6b88b5a4140e
for i in 1:3
# This for loop iterates over the numbers 1, 2, 3 and 4 and prints them.
for i in 1:4
println(i)
end
# ╔═╡ ddd3c019-6e70-4714-88fe-07d7a006ebc6
# This loop iterates over some strings and prints a welcoming message.
for name in ["Alice", "Bob", "everyone"]
println("Hello $name, welcome to this Julia course!")
end
# ╔═╡ 05db4e85-857d-4056-a576-5de992eabf29
md"""
Now, let's make our function for calculating and printing resistance more useful!
We want to iterate over some measured values of voltage and current.
To do so, we pair each element of one vector (list of measurements) with the corresponding element of the second vector.
*Vectors will be explained later. Until then, it is enough to understand a vector as an ordered list of elements.*
Lets take a look!
"""
# ╔═╡ 85c3c314-0f66-41be-8398-a5f9149ddfbd
# Vector of measured voltage values to different resistances
# The point is important, it will be explained later!
measured_U = [12.0, 15.0, 16.0, 12.5, 23.2, 22.6] .* u"V" 0.1u"V"
# ╔═╡ 566553a0-0202-4b59-b3ef-6954bf946b79
# Vector of measured current values to the different resistances
measured_I = [0.30, 0.25, 0.13, 0.22, 0.15, 0.75] .* u"mA" 0.05u"mA"
# ╔═╡ b70a48ca-362c-40d6-b703-2553a0b01275
for (u, i) in zip(measured_U, measured_I)
calc_and_print_R(u, i)
println("---") # Seperate output
end
# ╔═╡ c0b32101-5863-4c22-8ee5-8e29abe0da39
md"""
Now imagine that you have not only 6 measurements, but 1000 or more. How much time would you need with the calculator? ⏳️
Later, we will learn how to plot and further analyze calculated values!
"""
# ╔═╡ 00456b15-5d1c-4c74-a875-31ff9c8e1789
md"""
## While loop
## `while` loop
A `while` loop is similar to a `for` loop. The loop does the same computation with different values over and over. Instead of going through elements of a vector, a `while` loop checks a condition and runs the computation until the condition is `false`.
Lets see the following example!
"""
# ╔═╡ 91c4c623-5680-4b35-a694-2bd2612def94
@ -378,19 +648,56 @@ begin
end
end
# ╔═╡ 4a00035f-a1d1-409f-b73b-07f9073dc9d5
md"""
## Boolean operators
Boolean operators are especially needed to check conditions, for `while`, `if` or `elseif`.
"""
# ╔═╡ d4ebb324-fa31-4058-9da1-35e07a971106
# Boolean AND
true && false
# ╔═╡ f8259580-5a29-4a13-811f-c91d6811a291
# Boolean OR
true || false
# ╔═╡ f813afd8-2e1b-43f7-beeb-ac9bd15fbeb6
# Boolean NOT
!false
# ╔═╡ 7ab3a69d-ac31-49cf-8d34-3a427b02ed06
md"""
⚠️ Don't try to use `and`, `or` or `not` if you are coming from Python!
"""
# ╔═╡ 2a85d95b-51d2-4ea0-a2a2-43307a725f2a
md"""
## If, else, elseif
## `if`, `elseif`, `else`
"""
# ╔═╡ eef07cd2-0a83-491f-a3ff-c51400aadebb
md"""
`if` checks for a condition and runs the code indented under it if the condition is `true`.
"""
# ╔═╡ 9a78bf14-7fb4-448a-a8dd-69e244a0a297
test_value = 1
@bind test_value Slider(1:4)
# ╔═╡ a5a71d00-bf30-4c07-bcd8-2bf99698522e
test_value
# ╔═╡ 5281ef32-5de6-4488-8430-e5652cbf8299
if test_value == 1
println("The value is 1")
end
# ╔═╡ 9107a95e-6ef5-465f-bd28-9a774f99f4ab
md"""
`else` runs a piece of code indented under it if the condition of `if` is `false`.
"""
# ╔═╡ eec41279-e038-4415-81b3-ad5d4c396011
# change the value of the variable `test_value` and see how the input changes
if test_value == 1
@ -399,6 +706,13 @@ else
println("The value is not 1")
end
# ╔═╡ 544368b2-3e39-41e7-97ea-e2bbf44a7749
md"""
`elseif` checks for further conditions if the conditions before it were `false`. If the condition is `true`, then the code indentet under it is executed and `else` is ignored. Otherwise, the next `elseif` is checked or `else` is executed if no `elseif` is left.
Sounds complicated. It is best explained with an example.
"""
# ╔═╡ d2333817-e941-429b-b8e3-2ff07669096b
# change the value of the variable `test_value` and see how the input changes
if test_value == 1
@ -417,8 +731,11 @@ if (test_value == 1) || (test_value == 2)
println("Value is 1 or 2")
end
# ╔═╡ 54d654cd-110f-4b1f-9578-109a80db4574
@bind second_test_value Slider(1:2)
# ╔═╡ 96803a1e-0779-4eab-b120-b5569a44ac7b
second_test_value = 2
second_test_value
# ╔═╡ 5ab233d2-f360-4362-b1f8-3f3ae2a4fee1
# change the value of the variable `second_test_value` and see how the input changes
@ -506,13 +823,6 @@ md"""
## Mutation
"""
# ╔═╡ 6fdc6add-a478-4707-876b-cf6d660870ba
md"""
From now on, blocks will be used sometimes when manipulating an array to prevent dependency on execution order.
A block starts with `begin` and ends with `end`. Code in the block should be indented.
"""
# ╔═╡ e9e117af-1194-4d64-94a8-3e9fd51498aa
# Setting the first element to 3
begin
@ -701,6 +1011,10 @@ vecs[:, 1]
# Second eigenvector
vecs[:, 2]
# ╔═╡ 873be989-d587-4d9f-ad5d-5632ae24b0bf
# Transpose a matrix
first_matrix'
# ╔═╡ a9f39e34-4c2c-48f2-9353-babe1bc3cd05
md"""
## More dimensions
@ -726,14 +1040,54 @@ ones(3, 2)
# Fill with a value other than 0 or 1
fill(42, (2, 2, 3))
# ╔═╡ 91cc92b5-0be7-4ddf-91d1-bf56506e899c
md"""
## Range
While using `for` loops, we used a synatax like the following:
for i in 1:4
The `1:4` is a range. You can think of it as a vector that does not store all values in memory, but only the start, end and step values.
To see what a range contains, you can convert it to a vector by *collecting* its elements using `collect`.
"""
# ╔═╡ c24f0bf2-0054-49f2-bffc-8b3e3ff6409b
# Does not show the elements explicitely
1:4
# ╔═╡ 800d4999-d7d7-4818-95e7-d93027f23c53
collect(1:4)
# ╔═╡ a790ba58-c369-49eb-8f00-fdb73bcaab6c
# Using a step different from 1
collect(1:2:10)
# ╔═╡ 28c9ef22-25b9-4640-bdd1-1b8dc7b33090
# Ranges of floats are also possible
collect(0.0:0.4:2.0)
# ╔═╡ 1c4c05d7-455f-4a47-88aa-cf84a323a663
# You can generate a range by providing the number of elements you want between start and end. The step is then calculated automatically.
# This will be helpful for plotting later
r = range(0.0, 2.0; length=5)
# ╔═╡ e8c26d42-f841-4966-8d9e-3f11e9334551
collect(r)
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[compat]
Measurements = "~2.7.1"
PlutoUI = "~0.7.37"
Unitful = "~1.11.0"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
@ -758,6 +1112,12 @@ uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.Calculus]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f641eb0a4f00c343bbc32346e1217b86f3ce9dad"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.1"
[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597"
@ -768,6 +1128,12 @@ version = "0.11.0"
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f74e9d5388b8620b4cee35d4c5a618dd4dc547f4"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.3.0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@ -843,6 +1209,12 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
[[deps.Measurements]]
deps = ["Calculus", "LinearAlgebra", "Printf", "RecipesBase", "Requires"]
git-tree-sha1 = "88cd033eb781c698e75ae0b680e5cef1553f0856"
uuid = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
version = "2.7.1"
[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
@ -884,11 +1256,22 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[[deps.RecipesBase]]
git-tree-sha1 = "6bf3f380ff52ce0832ddd3a2a7b9538ed1bcca7d"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.2.1"
[[deps.Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"
[[deps.Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.3.0"
[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
@ -925,6 +1308,12 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[deps.Unitful]]
deps = ["ConstructionBase", "Dates", "LinearAlgebra", "Random"]
git-tree-sha1 = "b649200e887a487468b71821e2644382699f1b0f"
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
version = "1.11.0"
[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
@ -946,7 +1335,6 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╟─2c5e32f4-1d7d-4494-b025-a90d17919756
# ╟─21590bf1-1e1c-46b4-a2b6-7eb915e121ab
# ╟─d04af0fd-5ced-4f4f-b157-dd170e2ef8c8
# ╟─b559ef1a-76cf-4464-b5ec-f7d6bfa892e6
# ╟─938adcfe-8d1b-4c77-8d82-c48415f5673e
# ╠═73190799-fd03-4cc4-9b4e-c523bc310468
# ╠═4c242a67-6445-48e7-a6c3-418a489b89ba
@ -956,13 +1344,23 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═3f2c4ab8-4ba4-44d5-99d4-9d941e4df99e
# ╠═02282f61-e1ca-483d-b6de-feeccedd7bc0
# ╠═e4237ccd-b042-408b-8177-4c0d31a28caa
# ╠═0dc9bbb4-fdde-4006-b04d-4509f7d041a7
# ╠═9c837673-79dd-4a6f-a11d-6f0f2c001587
# ╟─0b6c6d50-e24c-43c7-8f04-4a53a3309bbf
# ╟─d1bf37f9-5135-48b8-8f9b-84ddd4a86157
# ╠═8d005ddd-0308-4a06-8bae-251387facf6f
# ╠═b7d27cd4-a655-492e-b2b3-cdc745b2c2da
# ╠═141950e5-e9f8-414b-b08d-86777428cbec
# ╠═2e7f29ce-3afa-4c12-838d-8051c0567e20
# ╠═4936c9fc-43da-4b8b-84ce-11e739802e07
# ╟─5e7f8a5e-9354-442b-aa13-7b9b3de536b1
# ╟─cf08cc65-7a9e-490d-b7e6-eecf6a1d9977
# ╠═4774fa16-a6f6-48ae-b9b6-8a279118c99a
# ╟─30000e9f-ec3d-416a-b402-010da80cd9ea
# ╠═72daf832-dba6-49ad-8d5a-f2c3aecdb630
# ╟─2121b949-06e7-4079-a25a-d0518ee2ba50
# ╠═534f3b32-1fc9-4eed-887a-2cac66c2bdb4
# ╠═3894b6b5-1952-409a-9966-502c277e26c3
# ╠═f20de3db-f270-4c43-aab7-692c313b5fa9
# ╠═c72f187f-9626-45d9-870a-267c8530202c
# ╠═e4295349-fc5c-48cb-975e-803e44d1a06e
@ -974,6 +1372,52 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═204cf77f-bf37-4110-9c9f-1f9236301ba9
# ╠═750bba32-e695-48f1-af70-70c94d13366b
# ╠═0b663bcb-4ff4-4597-b28b-b58c9cbfa181
# ╟─5e45b854-c173-452b-b62b-54037a3780fd
# ╠═0596fe87-4201-476e-8e11-618c621c5474
# ╠═28063282-5c60-4ffb-a715-9b1e88498df9
# ╠═da5fb1f9-2a2d-4148-8ba5-8c4a529829e9
# ╠═943da836-384d-4774-aaf4-54c27feb53d8
# ╠═a96f3ae9-12df-4df8-85da-09b9b1e47de1
# ╠═8d106ad2-5f92-4138-bfff-56ee21e098fa
# ╠═f8bc4051-93c6-4376-abaa-7b4cb4b8f607
# ╟─b25dc5f2-e186-4da1-b045-47b22c93799b
# ╠═e0d7fbc8-39fc-4b70-9b92-0c19fffb0c05
# ╠═398648e8-358e-4289-ae95-957e77d0c46f
# ╠═28fa32e7-4e50-4890-a765-5cfb1d3f791b
# ╠═d2607457-1794-4a0f-af41-cb80aadb598f
# ╠═23dbbe13-d997-4f9f-a300-7cb78c4fb8ee
# ╠═e767971a-7e1d-4a78-88d7-03e4ae4d51db
# ╟─1e7b103c-6cc9-4586-820b-9ec836b997da
# ╠═7ade3f89-4838-4a8b-815c-4e2d6ccd7fea
# ╠═35675b9b-a28a-427f-9da4-e6c756d2276a
# ╠═66d39465-8244-483f-9a82-8d17b95cf41d
# ╠═879c5330-781f-44c2-b072-1ee0f9bd971d
# ╠═df5914e3-b250-4824-80a5-cac5d0bed084
# ╠═099ac8f8-8c5c-410b-a11f-c98bc68230b2
# ╠═cd46845b-4980-465c-a64f-3a8bcb66f53e
# ╟─a0bd2da0-344d-470c-918e-e8760fc77355
# ╟─a2c4c4d9-4f06-41d4-baeb-b5f9f3b5b7c3
# ╠═56ca47c1-6e4d-48a2-9f55-ca89362c7d3f
# ╠═f4122e58-a30c-45a4-8ede-492ddb8deba4
# ╠═949e7fb8-8eff-49ea-8e76-0306857b05b9
# ╠═26869678-32f0-46e8-8cb2-d45b84441f03
# ╠═0121add2-b42b-4dcd-8912-f8420a8b4c72
# ╟─9df364d6-0f43-4fe3-8a10-4bf0dc79e04d
# ╟─b8d7bd0b-a0ea-499f-9e61-3875535887e9
# ╠═13dd1d3c-dec8-4871-8ffa-b3db1bdd2847
# ╟─0078ea9a-9c94-4703-a878-3cdd2e11d625
# ╠═38d3105f-427b-427b-bf7b-8aa76dfb3bef
# ╠═41b17c21-5b57-4912-88ee-e33215c1e0c8
# ╠═b6dcaf22-c075-442e-b0d0-e48eae2350ac
# ╟─7f01c4a5-0e56-43aa-8d14-5fecfa04b370
# ╠═105362be-572c-4a4d-9163-15ed8b4f1fbf
# ╠═18c2ffb9-a895-491b-96ee-a0b5c68da180
# ╟─62cdf927-4e2b-40bb-be2d-eb32e0789548
# ╠═9847a224-701a-489a-b125-95158aa805d4
# ╠═21163504-972d-4362-8c57-dbd708b2fa04
# ╠═9ef91243-04fc-44f2-ae69-76f372364f21
# ╟─3df766f0-38cb-4cdf-a68f-a4771c78fe31
# ╟─a6d882a0-c80e-4acf-b05b-c0ae120d698d
# ╟─944e2d37-8280-47b8-b874-97221955d048
# ╠═23d4ac67-05ec-4b3d-8368-86256076be62
# ╟─e8d7de2f-7c7e-47cb-9364-27d583652167
@ -994,37 +1438,33 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═d74f6c46-f5a8-4720-bcaf-936f1508efda
# ╠═3e5daca6-5aa8-42bf-988b-c09fb17388df
# ╠═7ff20c67-58d5-4095-bb8e-7ab7522791c7
# ╟─3102810f-3467-4ed8-86c0-16e9177fa69d
# ╠═c1c705d2-7e46-4811-9fb1-6b88b5a4140e
# ╠═ddd3c019-6e70-4714-88fe-07d7a006ebc6
# ╟─05db4e85-857d-4056-a576-5de992eabf29
# ╠═85c3c314-0f66-41be-8398-a5f9149ddfbd
# ╠═566553a0-0202-4b59-b3ef-6954bf946b79
# ╠═b70a48ca-362c-40d6-b703-2553a0b01275
# ╟─c0b32101-5863-4c22-8ee5-8e29abe0da39
# ╟─00456b15-5d1c-4c74-a875-31ff9c8e1789
# ╠═91c4c623-5680-4b35-a694-2bd2612def94
# ╟─4a00035f-a1d1-409f-b73b-07f9073dc9d5
# ╠═d4ebb324-fa31-4058-9da1-35e07a971106
# ╠═f8259580-5a29-4a13-811f-c91d6811a291
# ╠═f813afd8-2e1b-43f7-beeb-ac9bd15fbeb6
# ╟─7ab3a69d-ac31-49cf-8d34-3a427b02ed06
# ╟─5e45b854-c173-452b-b62b-54037a3780fd
# ╠═0596fe87-4201-476e-8e11-618c621c5474
# ╠═28063282-5c60-4ffb-a715-9b1e88498df9
# ╠═da5fb1f9-2a2d-4148-8ba5-8c4a529829e9
# ╠═943da836-384d-4774-aaf4-54c27feb53d8
# ╠═a96f3ae9-12df-4df8-85da-09b9b1e47de1
# ╠═8d106ad2-5f92-4138-bfff-56ee21e098fa
# ╠═f8bc4051-93c6-4376-abaa-7b4cb4b8f607
# ╟─b25dc5f2-e186-4da1-b045-47b22c93799b
# ╠═e0d7fbc8-39fc-4b70-9b92-0c19fffb0c05
# ╠═398648e8-358e-4289-ae95-957e77d0c46f
# ╠═28fa32e7-4e50-4890-a765-5cfb1d3f791b
# ╠═d2607457-1794-4a0f-af41-cb80aadb598f
# ╠═23dbbe13-d997-4f9f-a300-7cb78c4fb8ee
# ╠═e767971a-7e1d-4a78-88d7-03e4ae4d51db
# ╟─3102810f-3467-4ed8-86c0-16e9177fa69d
# ╠═c1c705d2-7e46-4811-9fb1-6b88b5a4140e
# ╟─00456b15-5d1c-4c74-a875-31ff9c8e1789
# ╠═91c4c623-5680-4b35-a694-2bd2612def94
# ╠═2a85d95b-51d2-4ea0-a2a2-43307a725f2a
# ╠═9a78bf14-7fb4-448a-a8dd-69e244a0a297
# ╟─2a85d95b-51d2-4ea0-a2a2-43307a725f2a
# ╟─eef07cd2-0a83-491f-a3ff-c51400aadebb
# ╠═a5a71d00-bf30-4c07-bcd8-2bf99698522e
# ╟─9a78bf14-7fb4-448a-a8dd-69e244a0a297
# ╠═5281ef32-5de6-4488-8430-e5652cbf8299
# ╟─9107a95e-6ef5-465f-bd28-9a774f99f4ab
# ╠═eec41279-e038-4415-81b3-ad5d4c396011
# ╟─544368b2-3e39-41e7-97ea-e2bbf44a7749
# ╠═d2333817-e941-429b-b8e3-2ff07669096b
# ╠═be0ff87b-229a-433e-a49e-2f1ced5bb9aa
# ╠═96803a1e-0779-4eab-b120-b5569a44ac7b
# ╟─54d654cd-110f-4b1f-9578-109a80db4574
# ╠═5ab233d2-f360-4362-b1f8-3f3ae2a4fee1
# ╠═0d100501-de84-4a5c-beb7-8ff9e83c473d
# ╟─9e3f698d-e57b-46c2-98e0-157fa7b06ae6
@ -1042,7 +1482,6 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═5b16ca43-1f56-4934-a420-5ffa5ed437ec
# ╠═628852dc-16e5-4a03-93a9-be209b1e8fb4
# ╟─3ea54f0d-2aa5-47a3-bbc3-92023a56b834
# ╟─6fdc6add-a478-4707-876b-cf6d660870ba
# ╠═e9e117af-1194-4d64-94a8-3e9fd51498aa
# ╠═027313d6-c247-43e9-872b-c3f0fe71b733
# ╠═e77e7ceb-31e3-4231-9923-f62b1382a2d1
@ -1075,10 +1514,18 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═cd5abd71-1bf8-484f-a46a-99cc8b994b91
# ╠═7cef46dc-803a-4a7a-9663-148b6de4a267
# ╠═70710989-9139-4970-a7b0-5702571e59a4
# ╠═873be989-d587-4d9f-ad5d-5632ae24b0bf
# ╟─a9f39e34-4c2c-48f2-9353-babe1bc3cd05
# ╠═83eca43d-2280-40f1-bf2a-016a843362a3
# ╠═f4c48701-d90e-48d6-bf9d-539c7fb7c7a5
# ╠═875cb2c2-e78d-41e3-808b-c6948f215b76
# ╟─91cc92b5-0be7-4ddf-91d1-bf56506e899c
# ╠═c24f0bf2-0054-49f2-bffc-8b3e3ff6409b
# ╠═800d4999-d7d7-4818-95e7-d93027f23c53
# ╠═a790ba58-c369-49eb-8f00-fdb73bcaab6c
# ╠═28c9ef22-25b9-4640-bdd1-1b8dc7b33090
# ╠═1c4c05d7-455f-4a47-88aa-cf84a323a663
# ╠═e8c26d42-f841-4966-8d9e-3f11e9334551
# ╟─d1a4ef8b-8e7d-4d34-80d8-cee195e237ae
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002