diff --git a/0_Installation.ipynb b/0_Installation.ipynb index 30c9e83c93dcb74b356641ac4a72a8ea8a7919e0..15edf52b4e1428867ec036369da81edd7527b8b4 100644 --- a/0_Installation.ipynb +++ b/0_Installation.ipynb @@ -8,49 +8,241 @@ "# Installation and Setup" ] }, + { + "cell_type": "markdown", + "id": "31ac33c0-18a9-4cfa-8e04-3ee1a0c909eb", + "metadata": {}, + "source": [ + "# Installation und Einrichtung" + ] + }, { "cell_type": "markdown", "id": "8829affd", "metadata": {}, "source": [ "## Software and material\n", - "What you need for the workshop (quick overview):\n", + "The course requires various things: a working installation of [Julia 1.9](https://julialang.org/downloads/), [Jupyter](https://jupyter.org/), [IJulia.jl](https://github.com/JuliaLang/IJulia.jl), the course material and various dependencies. To get everything follow these steps:\n", "\n", - "- [Julia](https://julialang.org/downloads/)\n", - "- [Jupyter](https://jupyter.org/) and [IJulia.jl](https://github.com/JuliaLang/IJulia.jl)\n", - "- This repository of workshop materials\n", - "- All required dependencies (Julia packages) for the workshop\n", - "\n", - "### Getting Julia\n", - "For following the course you will need at least Julia 1.6, but for full compatibility **Julia 1.8** is recommended.\n", + "### 1) Getting Julia\n", + "For following the course you will need **Julia 1.9**.\n", "Julia can be easily obtained in binary form from [Julia downloads](https://julialang.org/downloads/).\n", "\n", - "### Getting all the rest\n", - "The easiest way to get the remaining files and dependencies\n", - "is to [download the install.jl script](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/blob/main/install.jl?ref_type=heads) and run it from julia. See the instructions [on the github repository](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/).\n", + "### 2) Getting all the rest\n", + "\n", + "To get the remaining files and dependencies start up `julia` and in the resulting REPL shell, copy and paste the following:\n", + "```julia\n", + "import Downloads\n", + "script = Downloads.download(\"https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads\")\n", + "include(script)\n", + "```\n", + "This [downloads the install.jl script](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads) and runs it from julia.\n", + "\n", + "### 2) Getting all the rest (expert version)\n", "\n", - "As an alternative you can also also run the following commands manually\n", - "(this requires to have `git` and `julia` available from the commandline):\n", + "As an alternative you can also also run the following commands manually (this requires to have `git` and `julia` available from the commandline): \n", "```\n", "git clone https://gitlab.mathematik.uni-stuttgart.de/stammbn/Julia-seminar/\n", "cd Julia-seminar\n", "julia install-manual.jl\n", "```\n", "\n", + "### 3) Starting the notebook\n", + "To start the notebook make sure to be in the folder `Julia-seminar` and then run `julia`: an interactive Julia command line will open. In there run this command\n", + "\n", + "```\n", + "using IJulia; notebook(dir=pwd())\n", + "```\n", + "and the notebook will automatically open in a browser.\n", + "\n", "### Troubleshooting\n", "If you are facing issues, check out\n", "the [great troubleshooting section](https://carstenbauer.github.io/WorkshopWizard.jl/dev/troubleshooting/)\n", "from the WorkshopWizard package by Carsten Bauer (which is being used by `install.jl`)." ] }, + { + "cell_type": "markdown", + "id": "b495d658-ab7a-41fb-819e-0fef02c10772", + "metadata": {}, + "source": [ + "## Software und Material\n", + "Der Kurs erfordert verschiedene Dinge: eine funktionierende Installation von [Julia 1.9](https://julialang.org/downloads/), [Jupyter](https://jupyter.org/), [IJulia.jl](https://github.com/JuliaLang/IJulia.jl), das Kursmaterial und verschiedene Abhängigkeiten. Um alles zu herunterzuladen und zu installieren, befolgst Du diese Schritte:\n", + "\n", + "### 1) Julia herunterladen\n", + "Um dem Kurs zu folgen, benötigst du **Julia 1.9**.\n", + "Julia kann leicht in binärer Form von den [Julia-Downloads](https://julialang.org/downloads/) bezogen werden.\n", + "\n", + "### 2) Alles andere\n", + "\n", + "Um die verbleibenden Dateien und Abhängigkeiten zu erhalten, starte `julia` und kopiere im resultierenden REPL-Shell folgenden Code:\n", + "```julia\n", + "import Downloads\n", + "script = Downloads.download(\"https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads\")\n", + "include(script)\n", + "```\n", + "Das [lädt das install.jl-Skript herunter](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads) und führt es in Julia aus.\n", + "\n", + "### 2) Alles andere (Experten-Version)\n", + "\n", + "Als Alternative kannst Du auch die folgenden Befehle manuell ausführen (dies setzt voraus, dass `git` und `julia` von der Kommandozeile aus verfügbar sind):\n", + "```\n", + "git clone https://gitlab.mathematik.uni-stuttgart.de/stammbn/Julia-seminar/\n", + "cd Julia-seminar\n", + "julia install-manual.jl\n", + "```\n", + "\n", + "### 3) Starten des Notebooks\n", + "Um das Notebook zu starten, stelle sicher, dass Du Dich im Ordner `Julia-seminar` befindest, und führe dann `julia` aus: Eine interaktive Julia-Befehlszeile wird geöffnet. Führe darin folgenden Befehl aus:\n", + "\n", + "```\n", + "using IJulia; notebook(dir=pwd())\n", + "```\n", + "und das Notebook wird automatisch im Browser geöffnet.\n", + "\n", + "### Fehlerbehebung\n", + "Wenn Du auf Probleme stößt, werfe einen Blick auf den [ausgezeichneten Problembehandlungsabschnitt](https://carstenbauer.github.io/WorkshopWizard.jl/dev/troubleshooting/) aus dem WorkshopWizard-Paket von Carsten Bauer (das von `install.jl` verwendet wird)." + ] + }, + { + "cell_type": "markdown", + "id": "9161160b-87ff-4b12-bd5a-bca54228672d", + "metadata": {}, + "source": [ + "## Information about notebooks\n", + "\n", + "Notebooks are tools to interactively run code and display output. They are quite convenient for experimenting with code.\n", + "\n", + "The julia commands are run in a backend julia instance, the browser let's you interact with the notebooks (create new ones, run them, modify them). If the backend program is closed, the browser editor will stop working.\n", + "\n", + "However, if the browser is closed, the backend will keep running. You can get back to it by opening the address:\n", + "[http://localhost:8888](http://localhost:8888)" + ] + }, + { + "cell_type": "markdown", + "id": "ff3c6951-2bc8-42b9-b2f4-acbb473300c6", + "metadata": {}, + "source": [ + "## Informationen zu Notebooks\n", + "\n", + "Notebooks sind Werkzeuge, um interaktiven Code auszuführen und die Ausgabe anzuzeigen. Sie sind sehr praktisch, um mit Code zu experimentieren und eine Programmiersprache neu zu lernen.\n", + "\n", + "Die Julia-Befehle werden in einer separaten Julia-Instanz im Hintergrund ausgeführt, der Browser ermöglicht die Interaktion mit den Notebooks (das Erstellen neuer Notebooks, das Ausführen und Modifizieren von ihnen). Beachte dass der Browser-Editor nicht mehr funktioniert wenn das Backend-Programm geschlossen wird.\n", + "\n", + "Wenn jedoch der Browser geschlossen wird, läuft das Backend weiter. Du kannst darauf zugreifen, indem Du die Adresse öffnest:\n", + "[http://localhost:8888](http://localhost:8888)" + ] + }, + { + "cell_type": "markdown", + "id": "a915cd2f-dc38-4679-8d79-c2204e2073cf", + "metadata": {}, + "source": [ + "### Notebooks\n", + "\n", + "Notebooks are files characterized by the extension `.ipynb`. Using the interactive file explorer you can open them.\n", + "\n", + "The notebooks contain code, the output of the code, and can contain additional comments (like these ones). All the material of the course does not contain yet the output of the code, you will get it by running the code first.\n", + "\n", + "The notebooks are automatically saved every now and then, however to make sure they are saved, you can press \"Ctrl + S\"." + ] + }, + { + "cell_type": "markdown", + "id": "c974b7c0-119c-4223-ad80-dce5a3ceead3", + "metadata": {}, + "source": [ + "### Notebooks\n", + "\n", + "Notebooks sind Dateien, die durch die Erweiterung `.ipynb` gekennzeichnet sind. Mit dem interaktiven Datei-Explorer kannst Du sie öffnen.\n", + "\n", + "Die Notebooks enthalten Code, die Ausgabe des Codes und können zusätzliche Kommentare enthalten (wie diese hier). Das gesamte Material des Kurses enthält noch nicht die Ausgabe des Codes, Du erhälst sie, indem Du den Code zuerst ausführst.\n", + "\n", + "Die Notebooks werden automatisch alle paar Minuten gespeichert, um jedoch sicherzustellen, dass sie gespeichert sind, kannst Du \"Strg + S\" drücken.\n" + ] + }, + { + "cell_type": "markdown", + "id": "93606623-16a4-4263-9906-a79dd3fae22f", + "metadata": {}, + "source": [ + "### Cells\n", + "\n", + "Notebooks are made up of **cells**. There are two main types: **code** and **markdown**. This is a markdown cell, it is used to display text in a formatted way.\n", + "\n", + "The next is a code cell, it is used to run code and display its output. To run it, click on it and press \"Shift + Enter\"." + ] + }, + { + "cell_type": "markdown", + "id": "8c98e5f5-5a92-415a-b9ec-865972d45b6f", + "metadata": {}, + "source": [ + "### Zellen\n", + "\n", + "Notebooks bestehen aus **Zellen**. Es gibt zwei Hauptarten: **Code** und **Markdown**. Dies ist eine Markdown-Zelle und wird verwendet, um Text auf eine formatierte Weise anzuzeigen.\n", + "\n", + "Die nächste ist eine Code-Zelle und wird verwendet, um Code auszuführen und dessen Ausgabe anzuzeigen. Um sie auszuführen, klicken Sie darauf und drücken Sie Shift + Enter." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8074a659-e100-49db-b83c-f0738b25cf28", + "metadata": {}, + "outputs": [], + "source": [ + "println(\"Hello World!\")" + ] + }, + { + "cell_type": "markdown", + "id": "5fc38ba1-65d0-490f-8c06-4136a7ff1372", + "metadata": {}, + "source": [ + "When you click on a code cell, you can also modify its content.\n", + "To modify a markdown cell, you need to double click on it (however this is not required by this course).\n", + "\n", + "It is also possible to transform a code cell in a markdown cell, or the other way around. To do so, go in the top menu, Run, Cell Type.\n", + "\n", + "Finally, new cells can be added by using the `+` symbol in the top menu.\n", + "\n", + "Every time there is an exercise left to the reader, we added an empty code cell." + ] + }, + { + "cell_type": "markdown", + "id": "192dac00-072c-4699-bd06-9af6ae4e3055", + "metadata": {}, + "source": [ + "Wenn Du auf eine Code-Zelle klickst, kannst Du auch deren Inhalt ändern. Um eine Markdown-Zelle zu ändern, musst Du darauf doppelklicken (dies ist jedoch für diesen Kurs nicht erforderlich).\n", + "\n", + "Es ist auch möglich, eine Code-Zelle in eine Markdown-Zelle oder umgekehrt zu ändern. Gehe dazu im oberen Menü auf Ausführen, Zellentyp.\n", + "\n", + "Schließlich können neue Zellen hinzugefügt werden, indem Du das `+`-Symbol im oberen Menü verwendest.\n", + "\n", + "Jedes Mal, wenn eine Übung für den Leser übrig bleibt, haben wir eine leere Code-Zelle hinzugefügt." + ] + }, { "cell_type": "markdown", "id": "d3d75953", "metadata": {}, "source": [ - "## Verifying everything works\n", + "## Verifying that everything works\n", + "\n", + "To check if the installation was successfull, run the following cell." + ] + }, + { + "cell_type": "markdown", + "id": "e7730114-5064-46d1-b724-e92277ff2f90", + "metadata": {}, + "source": [ + "## Überprüfen, ob alles funktioniert\n", "\n", - "A few quick commands to run:" + "Um zu überprüfen, ob die Installation erfolgreich war, führe die folgende Zelle aus." ] }, { @@ -73,7 +265,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1f9376ca-21b5-429f-99f3-5612979662bb", + "id": "c7d2870e", "metadata": {}, "outputs": [], "source": [] diff --git a/1_Basics.ipynb b/1_Basics.ipynb index 587665c32312422df323f0869380d863d573fd73..30e68c2b6eb35b8a30eae2a84b0664a1f7e52283 100644 --- a/1_Basics.ipynb +++ b/1_Basics.ipynb @@ -203,7 +203,10 @@ "id": "cc36688b-c983-43f8-8bdf-9b82aae59909", "metadata": {}, "source": [ - "It turns out that `struct` is one of Julia’s keywords, and they cannot be used as variable names." + "It turns out that `struct` is one of Julia’s keywords, and they cannot be used as variable names. \n", + "\n", + "- For more Julia's keywords, see [https://docs.julialang.org/en/v1/base/base/#Keywords](https://docs.julialang.org/en/v1/base/base/#Keywords). \n", + "- For more details on `Variable`, see [https://docs.julialang.org/en/v1/manual/variables/](https://docs.julialang.org/en/v1/manual/variables/)." ] }, { @@ -211,7 +214,10 @@ "id": "2e5659b9-9e66-448a-a768-23d7085d7dac", "metadata": {}, "source": [ - "Es stellt sich heraus, dass `struct` eines der Schlüsselwörter von Julia ist und nicht als Variablennamen verwendet werden kann." + "Es stellt sich heraus, dass `struct` eines der Schlüsselwörter von Julia ist und nicht als Variablennamen verwendet werden kann.\n", + "\n", + "- Für weitere Schlüsselwörter von Julia, siehe [https://docs.julialang.org/en/v1/base/base/#Keywords](https://docs.julialang.org/en/v1/base/base/#Keywords).\n", + "- Für weitere Details über `Variable`, siehe [https://docs.julialang.org/en/v1/manual/variables/](https://docs.julialang.org/en/v1/manual/variables/)." ] }, { @@ -294,6 +300,22 @@ "\"hello! \"^5" ] }, + { + "cell_type": "markdown", + "id": "362f9d04-eff9-4594-aa22-a9c8d601fb1e", + "metadata": {}, + "source": [ + "For more details: [https://docs.julialang.org/en/v1/manual/strings/](https://docs.julialang.org/en/v1/manual/strings/)." + ] + }, + { + "cell_type": "markdown", + "id": "7b7ff4e3", + "metadata": {}, + "source": [ + "Für weitere Details: [https://docs.julialang.org/en/v1/manual/strings/](https://docs.julialang.org/en/v1/manual/strings/)." + ] + }, { "cell_type": "markdown", "id": "61ff8194-669c-4ece-ba31-44e88ed808ac", @@ -593,7 +615,7 @@ "id": "b597c363-8066-470e-b1c8-edd00b114317", "metadata": {}, "source": [ - "For more details: [https://docs.julialang.org/en/v1/manual/control-flow/](https://docs.julialang.org/en/v1/manual/control-flow/)" + "For more details: [https://docs.julialang.org/en/v1/manual/control-flow/](https://docs.julialang.org/en/v1/manual/control-flow/)." ] }, { @@ -762,6 +784,22 @@ "end" ] }, + { + "cell_type": "markdown", + "id": "b8eac9e9-dff9-4b86-88a7-e14f27b7f677", + "metadata": {}, + "source": [ + "For more detials: [https://docs.julialang.org/en/v1/base/collections/#lib-collections-iteration](https://docs.julialang.org/en/v1/base/collections/#lib-collections-iteration)." + ] + }, + { + "cell_type": "markdown", + "id": "d2e93721", + "metadata": {}, + "source": [ + "Für weitere Details: [https://docs.julialang.org/en/v1/base/collections/#lib-collections-iteration](https://docs.julialang.org/en/v1/base/collections/#lib-collections-iteration)." + ] + }, { "cell_type": "markdown", "id": "990cefae-abfe-4649-8d68-3fac1b1e268b", @@ -918,7 +956,9 @@ " - floor: Largest integer not greater than x.\n", " - ceil: Smallest integer not less than x.\n", " - round: Nearest integer to x.\n", - " - trunc: Integer part of x." + " - trunc: Integer part of x.\n", + "\n", + "For more details: [https://docs.julialang.org/en/v1/base/math/#Mathematical-Functions](https://docs.julialang.org/en/v1/base/math/#Mathematical-Functions)." ] }, { @@ -933,7 +973,9 @@ " - floor: Größte ganze Zahl, die nicht größer als x ist.\n", " - ceil: Kleinste ganze Zahl, die nicht kleiner als x ist.\n", " - round: Nächstgelegene ganze Zahl zu x.\n", - " - trunc: Ganzzahliger Teil von x." + " - trunc: Ganzzahliger Teil von x.\n", + "\n", + "Für weitere Details: [https://docs.julialang.org/en/v1/base/math/#Mathematical-Functions](https://docs.julialang.org/en/v1/base/math/#Mathematical-Functions)." ] }, { @@ -1738,19 +1780,11 @@ "source": [ "- Schreiben Sie eine Funktion, die einen Satz analysiert. Die Funktion sollte dann die Anzahl der Vokale (sowohl in Groß- als auch in Kleinbuchstaben) im Satz zählen und anzeigen." ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8de11d46-125a-4648-88ec-23707c2c4b1b", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Julia 1.9.3", + "display_name": "Julia 1.9.2", "language": "julia", "name": "julia-1.9" }, diff --git a/3_Advanced_Data_Types.ipynb b/3_Advanced_Data_Types.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..bb61f351c2d59a9bcc28a3dfd14bedccae1efebd --- /dev/null +++ b/3_Advanced_Data_Types.ipynb @@ -0,0 +1,983 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4fe99eff-729a-4d93-ab82-487e5143bae5", + "metadata": {}, + "source": [ + "# Advanced Data Types" + ] + }, + { + "cell_type": "markdown", + "id": "7969b8f9-335a-4bd2-82f7-1d9795234ed5", + "metadata": {}, + "source": [ + "## Dictionaries" + ] + }, + { + "cell_type": "markdown", + "id": "ea8518c1-8e1d-4532-8055-e04c3aa3e7c4", + "metadata": {}, + "source": [ + "A dictionary contains a collection of indices, which are called keys, and a collection of values. Each key is associated with a single value. The association of a key and a value is called a key-value pair or sometimes an item.\n", + "\n", + "The function `Dict` creates a new dictionary with no items. Because Dict is the name of a built-in function, you should avoid using it as a variable name. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "59ae8d17-a6f6-4210-95bc-0e7492bc8a7a", + "metadata": {}, + "outputs": [], + "source": [ + "eng2de = Dict()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28490ea3-c4d3-4e4d-915f-612ad36c9472", + "metadata": {}, + "outputs": [], + "source": [ + "eng2de[\"one\"] = \"ein\";" + ] + }, + { + "cell_type": "markdown", + "id": "f2aff40c-6dcb-421a-b67f-1662c5bf4702", + "metadata": {}, + "source": [ + "You can also initialize a dictionary with items as:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "92fc203b-4ba8-432a-a541-c4ccf3292195", + "metadata": {}, + "outputs": [], + "source": [ + "eng2de = Dict(\"one\" => \"ein\", \"two\" => \"zwei\", \"three\" => \"drei\")" + ] + }, + { + "cell_type": "markdown", + "id": "c52d24af-ec90-4b8c-bdd9-988129a7fa81", + "metadata": {}, + "source": [ + "Dictionaries are mutable, meaning that it is always possible to modify their elements, add new key-value pairs or removing existing ones." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "22b295dc-994e-4bbc-ac8d-da5ab9e73493", + "metadata": {}, + "outputs": [], + "source": [ + "eng2de[\"four\"] = \"VIER\"\n", + "@show eng2de\n", + "eng2de[\"four\"] = \"vier\"\n", + "@show eng2de\n", + "delete!(eng2de, \"four\")\n", + "@show eng2de;" + ] + }, + { + "cell_type": "markdown", + "id": "01513ad2-3083-4c89-adca-ccc8a88d93d4", + "metadata": {}, + "source": [ + "In general, the order of the key-value pairs is unpredictable. However this is not important, as the values are always accessed using the keys." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e9e4c5b9-9539-4294-a6ec-0a29fb76bf7b", + "metadata": {}, + "outputs": [], + "source": [ + "eng2de[\"two\"]" + ] + }, + { + "cell_type": "markdown", + "id": "9944dbbd-478b-4ae1-ac89-e16be08a0868", + "metadata": {}, + "source": [ + "If the key isn’t in the dictionary, you get an exception:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8221269b-7a8f-4cfd-ab8e-0aa4fd6c962d", + "metadata": {}, + "outputs": [], + "source": [ + "eng2de[\"four\"]" + ] + }, + { + "cell_type": "markdown", + "id": "a545abaa-78dc-4625-84e9-03b1c8beaaf8", + "metadata": {}, + "source": [ + "The `length` function works on dictionaries; it returns the number of key-value pairs:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e242667-b921-4242-bdcc-cbcac14909b2", + "metadata": {}, + "outputs": [], + "source": [ + "length(eng2de)" + ] + }, + { + "cell_type": "markdown", + "id": "8e42655b-f2a0-41f0-be90-015ebfeafdb9", + "metadata": {}, + "source": [ + "The function `keys` returns a collection with the keys of the dictionary:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3236f973-d3fa-42ba-a1c0-41e0002446cb", + "metadata": {}, + "outputs": [], + "source": [ + "keys(eng2de)" + ] + }, + { + "cell_type": "markdown", + "id": "acfa7044-5695-4af8-b4bc-320c8a48a220", + "metadata": {}, + "source": [ + "Now you can use the `∈` operator to see whether something appears as a key in the dictionary:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1fdeb10c-0d84-4c22-b734-d68e2eafe375", + "metadata": {}, + "outputs": [], + "source": [ + "@show \"one\" ∈ keys(eng2de)\n", + "@show \"four\" ∈ keys(eng2de);" + ] + }, + { + "cell_type": "markdown", + "id": "986919d6-4f27-4fad-b222-20697bf6af40", + "metadata": {}, + "source": [ + "To see whether something appears as a value in a dictionary, you can use the function `values`, which returns a collection of values, and then use the `∈` operator:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab90dad1-61d0-4dbd-b829-a354c13fcb71", + "metadata": {}, + "outputs": [], + "source": [ + "@show \"ein\" ∈ values(eng2de)\n", + "@show \"vier\" ∈ values(eng2de);" + ] + }, + { + "cell_type": "markdown", + "id": "049c9dfd-1e51-4898-98e5-a4b812d0bba2", + "metadata": {}, + "source": [ + "### Loops over dictionaries\n", + "\n", + "You can traverse the keys of the dictionary in a `for` statement." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7062d3f-2125-4ecd-ab13-d04944a71fe1", + "metadata": {}, + "outputs": [], + "source": [ + "function print_dictionary(dic)\n", + " for key in keys(dic)\n", + " println(key, \" \", dic[key])\n", + " end\n", + "end\n", + "\n", + "print_dictionary(eng2de)" + ] + }, + { + "cell_type": "markdown", + "id": "cf27195c-e601-49ca-b03d-63162bf59bce", + "metadata": {}, + "source": [ + "Again, the keys are in no particular order. To traverse the keys in alphabetically sorted order, you can combine `sort` and `collect`:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d52aeba-3c7e-405c-bcfe-d76e37e94f51", + "metadata": {}, + "outputs": [], + "source": [ + "function print_dictionary_sorted(dic)\n", + " for key in sort(collect(keys(dic)))\n", + " println(key, \" \", dic[key])\n", + " end\n", + "end\n", + "\n", + "print_dictionary_sorted(eng2de)" + ] + }, + { + "cell_type": "markdown", + "id": "8daa9d3e-19de-4415-ba6c-6aeb174b38fa", + "metadata": {}, + "source": [ + "### Exercises\n", + " - Write a function that given a string as input counts how many times each letter appears. Use a dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aba1978b-e675-48a7-89aa-75553db70537", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "3a9b281f-6cc0-4d39-b9e2-d816823f9873", + "metadata": {}, + "source": [ + "## Tuples and named tuples" + ] + }, + { + "cell_type": "markdown", + "id": "a722109e-86cc-44e3-9256-a3e93a1668f5", + "metadata": {}, + "source": [ + "A tuple is a sequence of values. The values can be of any type, and they are indexed by integers. The tuples are immutable and each element can have its own type." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8502cf2e-8bea-4707-811c-f4e6e1de3c8f", + "metadata": {}, + "outputs": [], + "source": [ + "t = 'a', 'b', 'c', 'd', 'e'" + ] + }, + { + "cell_type": "markdown", + "id": "d01f5647-a240-4620-9a3a-782835aca39c", + "metadata": {}, + "source": [ + "Although it is not necessary, it is common to enclose tuples in parentheses:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bfa31b99-bf9d-49bb-babc-fe8a65248429", + "metadata": {}, + "outputs": [], + "source": [ + "t = ('a', 'b', 'c', 'd', 'e')" + ] + }, + { + "cell_type": "markdown", + "id": "3fa935e0-0611-4b8a-982c-329c33a74f99", + "metadata": {}, + "source": [ + "To create a tuple with a single element, you have to include a final comma:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb1bea15-2b80-43b2-be8e-27507d550fca", + "metadata": {}, + "outputs": [], + "source": [ + "t1 = ('a',)\n", + "@show typeof(t1)\n", + "\n", + "t2 = ('a')\n", + "@show typeof(t2);" + ] + }, + { + "cell_type": "markdown", + "id": "193457ac-4e4b-4e58-8c28-6d8b4331d532", + "metadata": {}, + "source": [ + "Another way to create a tuple is the built-in function tuple. With no argument, it creates an empty tuple:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "952acafe-ca5d-4b58-8969-224b0fe3a28f", + "metadata": {}, + "outputs": [], + "source": [ + "t3 = tuple()\n", + "@show typeof(t3)\n", + "\n", + "t4 = tuple(1, 'a', π, 12.0)\n", + "@show typeof(t4);" + ] + }, + { + "cell_type": "markdown", + "id": "729c3597-1a35-4a26-ae7a-6dadee31daeb", + "metadata": {}, + "source": [ + "Using the bracket operator it is possible to access an element. Note, differently from other programming languages (for example C, C++, Python) in Julia the first element is 1." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9817c28f-428d-4d5b-8384-608f9b4d763d", + "metadata": {}, + "outputs": [], + "source": [ + "t4[2]" + ] + }, + { + "cell_type": "markdown", + "id": "2519be57-8c10-4878-a772-017b099f6a4c", + "metadata": {}, + "source": [ + "It is also possible to get multiple elements by using slices." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c48ac07f-3a4e-4bb8-9551-2973ea8d2f9c", + "metadata": {}, + "outputs": [], + "source": [ + "@show t4[1:3];" + ] + }, + { + "cell_type": "markdown", + "id": "aeda8602-f9da-4173-a692-54e2e9a0e178", + "metadata": {}, + "source": [ + "But if you try to modify one of the elements of the tuple, you get an error:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cfc94cc9-832c-45d2-85b8-aaf789f33f6a", + "metadata": {}, + "outputs": [], + "source": [ + "t4[2] = 'b'" + ] + }, + { + "cell_type": "markdown", + "id": "b9f13b5c-9e61-46b9-a47d-f90199bd7bd2", + "metadata": {}, + "source": [ + "Because tuples are immutable, you can’t modify the elements." + ] + }, + { + "cell_type": "markdown", + "id": "a10cb9a7-8f44-44f8-831f-178b780e4ac9", + "metadata": {}, + "source": [ + "Strictly speaking, a function can only return one value, but if the value is a tuple, the effect is the same as returning multiple values. For example, if you want to divide two integers and compute the quotient and remainder, it is inefficient to compute x ÷ y and then x % y. It is better to compute them both at the same time.\n", + "\n", + "The built-in function `divrem` takes two arguments and returns a tuple of two values, the quotient and remainder. You can store the result as a tuple: " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1dde137-036f-4b93-8010-13b3e835ebd8", + "metadata": {}, + "outputs": [], + "source": [ + "t = divrem(7, 3)" + ] + }, + { + "cell_type": "markdown", + "id": "ea615dbd-effb-4442-b160-20e7c9b6c22e", + "metadata": {}, + "source": [ + "Alternatively, we can use tuple assignment to store the elements separately:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4969556-7945-43c9-8b96-1ea1032cbb3c", + "metadata": {}, + "outputs": [], + "source": [ + "q, r = divrem(7, 3)\n", + "\n", + "@show q r;" + ] + }, + { + "cell_type": "markdown", + "id": "4574e191-aaa8-4834-8837-54947d6ddf30", + "metadata": {}, + "source": [ + "### Gather and scatter\n", + "\n", + "Functions can take a variable number of arguments. A parameter name that ends with `...` gathers arguments into a tuple. For example, `printall` takes any number of arguments and prints them one by line:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43f8c7ad-5ac2-425e-a50f-c45624bb3d8a", + "metadata": {}, + "outputs": [], + "source": [ + "function printall(args...)\n", + " for arg in args\n", + " println(arg)\n", + " end\n", + "end\n", + "\n", + "printall(1)\n", + "printall(1, 2.0, '3')" + ] + }, + { + "cell_type": "markdown", + "id": "eb662374-fe83-49d7-a5be-d9582d037ad1", + "metadata": {}, + "source": [ + "The complement of gather is scatter. If you have a sequence of values and you want to pass it to a function as multiple arguments, you can use the `...` operator. For example, `divrem` takes exactly two arguments; it doesn’t work with a tuple:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf55fc10-8432-41e3-bd6c-2244c8c96513", + "metadata": {}, + "outputs": [], + "source": [ + "t = (7, 3)\n", + "divrem(t)" + ] + }, + { + "cell_type": "markdown", + "id": "d05def39-3244-4acd-a082-a7ee532f8f1d", + "metadata": {}, + "source": [ + "But if you scatter the tuple, it works:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7df53bc-6b2d-4501-9ca8-61e3cb79eb1a", + "metadata": {}, + "outputs": [], + "source": [ + "t = (7, 3)\n", + "divrem(t...)" + ] + }, + { + "cell_type": "markdown", + "id": "2cf01c32-9d1b-4e83-9375-f737e51c58ed", + "metadata": {}, + "source": [ + "### Dictionaries and Tuples" + ] + }, + { + "cell_type": "markdown", + "id": "00e97ccc-8e64-4eef-84be-85a266eb3490", + "metadata": {}, + "source": [ + "Dictionaries can be used as iterators that iterate the key-value pairs. You can use it in a `for` loop like this:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed483334-36d0-4700-b178-cd9dc5f12189", + "metadata": {}, + "outputs": [], + "source": [ + "d = Dict('a'=>1, 'b'=>2, 'c'=>3);\n", + "for (key, value) in d\n", + " println(key, \" \", value)\n", + "end" + ] + }, + { + "cell_type": "markdown", + "id": "dcb05236-810a-410b-aaa0-0cb431e3e64f", + "metadata": {}, + "source": [ + "It is common to use tuples as keys in dictionaries. For example, a telephone directory might map from last-name, first-name pairs to telephone numbers. Assuming that we have defined last, first and number, we could write:" + ] + }, + { + "cell_type": "markdown", + "id": "e5462d35-fa68-42d8-ba00-c5dd1747c557", + "metadata": {}, + "source": [ + "`directory[last, first] = number`" + ] + }, + { + "cell_type": "markdown", + "id": "9980d710-392b-4716-b44d-98e6c5c8b838", + "metadata": {}, + "source": [ + "### Named tuples" + ] + }, + { + "cell_type": "markdown", + "id": "e514c4bd-c17c-44f4-a89f-88154cc1bf6c", + "metadata": {}, + "source": [ + "Named tuples are a special type of tuple in Julia where each element has a specific name associated with it. This allows you to access elements by their names, making the code more readable and self-explanatory." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78fb5959-407a-4128-9287-bb9d455f22dc", + "metadata": {}, + "outputs": [], + "source": [ + "person = (name = \"Michele\", age = 28, city = \"Stuttgart\")" + ] + }, + { + "cell_type": "markdown", + "id": "63075b2d-ef86-48e4-8f84-981f81fdece0", + "metadata": {}, + "source": [ + "Named tuples are immutable, however it is possible to update the content, or to add new elements, by creating a new version. For example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ecd22e07-5ba3-4f11-bc77-d967a6fc3fe8", + "metadata": {}, + "outputs": [], + "source": [ + "updated_person = (person..., age = 29)\n", + "updated_person = (person..., number = \"0711 ...\")" + ] + }, + { + "cell_type": "markdown", + "id": "347fe4ea-5b63-4fb8-91bc-2b7b8a0c6a30", + "metadata": {}, + "source": [ + "### Exercises\n", + " - Write a function `swap_first_last` that takes a tuple and returns a new tuple with the first and last elements swapped. Tip: use a combination of the `...` operator and of this slice `[2:end-1]`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3721b654-b182-426d-b799-a69e0b53a550", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "647530cd-480a-414f-a8ec-1375e05a9e1b", + "metadata": {}, + "source": [ + "## Structs" + ] + }, + { + "cell_type": "markdown", + "id": "00b9bdb1-86ad-47f6-b8c3-88e85878eaff", + "metadata": {}, + "source": [ + "At this point you know how to use functions to organize code and built-in types to organize data. The next step is to learn how to build your own types to organize both code and data.\n", + "\n", + "We have used many of Julia’s built-in types; now we are going to define a new type. As an example, we will create a type called Point that represents a point in two-dimensional space.\n", + " \n", + "There are several ways we might represent points in Julia:\n", + " - We could store the coordinates separately in two variables, x and y.\n", + " - We could store the coordinates as elements in an tuple.\n", + " - We could create a new type to represent points as objects.\n", + "\n", + "Here we will investigate the third option." + ] + }, + { + "cell_type": "markdown", + "id": "9aa53d46-033b-4559-a5d8-e95357a257a5", + "metadata": {}, + "source": [ + "A programmer-defined composite type is also called a struct. The struct definition for a point looks like this:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c2e3f646-2d82-46a4-a265-01b919412c6d", + "metadata": {}, + "outputs": [], + "source": [ + "struct Point\n", + " x::Real\n", + " y::Real\n", + "end" + ] + }, + { + "cell_type": "markdown", + "id": "fb9be134-9730-4dbd-9e05-51dd94e9d8e0", + "metadata": {}, + "source": [ + "The header indicates that the new struct is called Point. The body defines the attributes or fields of the struct. The Point struct has two fields: x and y.\n", + "\n", + "A struct is like a factory for creating objects. To create a point, you call Point as if it were a function having as arguments the values of the fields. When Point is used as a function, it is called a constructor. The constructor returns an instance of the object." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "197339a2-0d8b-4882-bab2-80ba56410f21", + "metadata": {}, + "outputs": [], + "source": [ + "p = Point(3.0, 4.0)\n", + "@show p;" + ] + }, + { + "cell_type": "markdown", + "id": "b0134aa7-f356-4d71-9d46-959bd3cfe89a", + "metadata": {}, + "source": [ + "The type speficication (`::Real`) is optional, but can be helpful to enforce correct usage of the struct." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "849f1460-d228-4b22-a797-1077d75d1a2d", + "metadata": {}, + "outputs": [], + "source": [ + "p = Point(\"a\", 4.0)" + ] + }, + { + "cell_type": "markdown", + "id": "e3011b23-816d-4aa2-be61-7eb8f4aee9d1", + "metadata": {}, + "source": [ + "The values of the fields can be accessed using the `.` operator." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00d090e4-d74d-4fad-ae8b-369c1046e48b", + "metadata": {}, + "outputs": [], + "source": [ + "@show p.x p.y;\n", + "@show distance = sqrt(p.x^2 + p.y^2);" + ] + }, + { + "cell_type": "markdown", + "id": "08748a8c-f76c-4f14-b3d2-9db99fb28e87", + "metadata": {}, + "source": [ + "Structs are however by default immutable, after construction the fields can not change value:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91bd6248-a358-43e3-90cc-6b8398445aaf", + "metadata": {}, + "outputs": [], + "source": [ + "p.x = 2" + ] + }, + { + "cell_type": "markdown", + "id": "629c1004-5d0f-4093-b546-473c94c91b44", + "metadata": {}, + "source": [ + "Where required, mutable composite types can be declared with the keyword mutable struct. Here is the definition of a mutable point:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "804c2c32-7a84-4261-88d8-1bad6ba5e18c", + "metadata": {}, + "outputs": [], + "source": [ + "mutable struct MPoint\n", + " x::Real\n", + " y::Real\n", + "end\n", + "p = MPoint(3.0, 4.0)\n", + "p.x = 2.0\n", + "@show p;" + ] + }, + { + "cell_type": "markdown", + "id": "1bd558dd-e6c3-4dc0-9476-768c59178708", + "metadata": {}, + "source": [ + "A third option is to let some fields of an unmutable struct to be mutable. For example a dictionary inside an unmutable struct can be modified." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62cab9ae-5e58-401c-bc93-17720914e530", + "metadata": {}, + "outputs": [], + "source": [ + "struct Book\n", + " title::String\n", + " author::String\n", + " properties::Dict{String, Any}\n", + "end\n", + "\n", + "book = Book(\"Der Hobbit\", \"J.R.R. Tolkien\", Dict(\"available\" => false))\n", + "@show book\n", + "book.properties[\"available\"] = true\n", + "@show book;" + ] + }, + { + "cell_type": "markdown", + "id": "31e2098b-5079-4cb5-bf64-a7a78754af32", + "metadata": {}, + "source": [ + "You can pass an instance as an argument in the usual way. For example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e6113221-0c03-484a-99e0-f7d4fab70f03", + "metadata": {}, + "outputs": [], + "source": [ + "function printpoint(p)\n", + " println(\"($(p.x), $(p.y))\")\n", + "end\n", + "printpoint(p)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5c6fa9e-c31d-4aff-a3fd-db3449904519", + "metadata": {}, + "outputs": [], + "source": [ + "function printbook(book)\n", + " println(\"Title: $(book.title)\")\n", + " println(\"Author: $(book.author)\")\n", + " available = book.properties[\"available\"]\n", + " println(\"Available: $(available)\")\n", + "end\n", + "printbook(book)" + ] + }, + { + "cell_type": "markdown", + "id": "3b12a004-81d9-4bbc-9e2e-d2c281dcbe18", + "metadata": {}, + "source": [ + "Functions can return instances as return values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c57c9f7-c4fd-4263-a55f-62f123aaaa8a", + "metadata": {}, + "outputs": [], + "source": [ + "function find_center(point1, point2)\n", + " x = (point1.x + point2.x)/2.0\n", + " y = (point1.y + point2.y)/2.0\n", + " return Point(x, y)\n", + "end\n", + "\n", + "point1 = Point(0.0, 0.0)\n", + "point2 = Point(10.0, 10.0)\n", + "\n", + "@show find_center(point1, point2);" + ] + }, + { + "cell_type": "markdown", + "id": "078b31ab-11e1-4596-8271-f0d33418eab8", + "metadata": {}, + "source": [ + "### Exercise\n", + "\n", + " - Write a function called `point_distance` which takes two points as arguments and returns the Euclidean distance between them." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5957a05-e396-41c3-9b8f-f14f089115ab", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "0fb1f6bc-e6e5-4897-bbb6-880e40e3bf20", + "metadata": {}, + "source": [ + "### References and values\n", + "\n", + "Each object (instance of a struct) is stored at some memory address. The operator `===` checks if two variables point to the same memory address of the object. For example\n", + "\n", + "book_copy = book\n", + "@show book_copy === book;" + ] + }, + { + "cell_type": "markdown", + "id": "636b6713-f4ed-4220-a159-2918bd44f78e", + "metadata": {}, + "source": [ + "This means that any change made to `book_copy` will also modify `book`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a9c46bac-d234-4616-a604-63bdf03b1393", + "metadata": {}, + "outputs": [], + "source": [ + "book.properties[\"available\"] = true\n", + "book_copy.properties[\"available\"] = false\n", + "\n", + "@show book;" + ] + }, + { + "cell_type": "markdown", + "id": "6bcbf983-40fa-4fc8-8eca-7cd7c45778dc", + "metadata": {}, + "source": [ + "If a new, distinct, object is needed (in other words, a copy by value), we can use the function `deepcopy`. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c36d23c8-2292-4568-aef4-7416c6f3e538", + "metadata": {}, + "outputs": [], + "source": [ + "book_copy = deepcopy(book)\n", + "@show book_copy === book;" + ] + }, + { + "cell_type": "markdown", + "id": "02cc3ec7-e712-4c4b-abf5-9bfc98e68a91", + "metadata": {}, + "source": [ + "Finally, the `==` operator between structs defaults to the `===` operator as Julia has no way of knowing how to compare custom structs. However, it is always possible to reimplement the `==` operator for our custom types." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3372eb89-cde6-4040-aa51-b4e76af97851", + "metadata": {}, + "outputs": [], + "source": [ + "import Core\n", + "\n", + "function ==(book1::Book, book2::Book)\n", + " return book1.title == book2.title && book1.author == book2.author\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03594f56-48ee-4152-a42f-8e3588c3ab2e", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.9.3", + "language": "julia", + "name": "julia-1.9" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/README.md b/README.md index 4415f6880c5d1f7fecdfb5f0db17b8e6e34a2a0c..553e529fcc5acee42e9f4279384d416946cd638b 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,98 @@ # Julia-seminar +Material für den Julia-Seminar-Kurs. +Das Kursmaterial wurde aus zwei Quellen angepasst: + - der [Kurs](https://github.com/mfherbst/2022-rwth-julia-workshop.git) von Michael Herbst ([MIT Lizenz](https://opensource.org/licenses/mit/)). + - das Buch [ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html) von Allen Downey und Ben Lauwens ([Creative Commons Namensnennung-Nicht-kommerziell 3.0 Unported Lizenz](https://creativecommons.org/licenses/by-nc/3.0/deed.de)). + +## Software und Material +Der Kurs erfordert verschiedene Dinge: eine funktionierende Installation von [Julia 1.9](https://julialang.org/downloads/), [Jupyter](https://jupyter.org/), [IJulia.jl](https://github.com/JuliaLang/IJulia.jl), das Kursmaterial und verschiedene Abhängigkeiten. Um alles zu bekommen, befolgen Sie diese Schritte: + +### 1) Julia herunterladen +Um dem Kurs zu folgen, benötigst du **Julia 1.9**. +Julia kann leicht in binärer Form von den [Julia-Downloads](https://julialang.org/downloads/) bezogen werden. + +### 2) Alles andere herunterladen + +Um die verbleibenden Dateien und Abhängigkeiten zu erhalten, starte `julia` und kopiere im resultierenden REPL-Shell folgenden Code: +```julia +import Downloads +script = Downloads.download("https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads") +include(script) +``` +Das [lädt das install.jl-Skript herunter](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads) und führt es in Julia aus. + +### 2) Den Rest bekommen (Experten-Version) + +Als Alternative können Sie auch die folgenden Befehle manuell ausführen (dies setzt voraus, dass `git` und `julia` von der Kommandozeile aus verfügbar sind): +``` +git clone https://gitlab.mathematik.uni-stuttgart.de/stammbn/Julia-seminar/ +cd Julia-seminar +julia install-manual.jl +``` + +### 3) Starten des Notebooks +Um das Notebook zu starten, stellen Sie sicher, dass Sie sich im Ordner `Julia-seminar` befinden, und führen Sie dann `julia` aus: Eine interaktive Julia-Befehlszeile wird geöffnet. Führen Sie darin folgenden Befehl aus: + +``` +using IJulia; notebook(dir=pwd()) +``` +und das Notebook wird automatisch im Browser geöffnet. + +Navigiere zu den Dateien und öffne das Notebook Nummer 0. + +### Fehlerbehebung +Wenn Sie auf Probleme stoßen, werfen Sie einen Blick auf den [ausgezeichneten Problembehandlungsabschnitt](https://carstenbauer.github.io/WorkshopWizard.jl/dev/troubleshooting/) aus dem WorkshopWizard-Paket von Carsten Bauer (das von `install.jl` verwendet wird). + +# Julia-seminar + Material for the Julia seminar course. The course material is adapted from two sources: - the [course](https://github.com/mfherbst/2022-rwth-julia-workshop.git) from Michael Herbst ([MIT license](https://opensource.org/license/mit/)). - the book [ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html) from Allen Downey and Ben Lauwens ([Creative Commons Attribution-NonCommercial 3.0 Unported license](https://creativecommons.org/licenses/by-nc/3.0/deed.en)). ## Software and material -What you need for the workshop (quick overview): +The course requires various things: a working installation of [Julia 1.9](https://julialang.org/downloads/), [Jupyter](https://jupyter.org/), [IJulia.jl](https://github.com/JuliaLang/IJulia.jl), the course material and various dependencies. To get everything follow these steps: -- [Julia 1.8](https://julialang.org/downloads/) -- [Jupyter](https://jupyter.org/) and [IJulia.jl](https://github.com/JuliaLang/IJulia.jl) -- This repository of workshop materials -- All required dependencies (Julia packages) for the workshop - -### Getting Julia -For following the course you will need at least **Julia 1.8**. +### 1) Getting Julia +For following the course you will need **Julia 1.9**. Julia can be easily obtained in binary form from [Julia downloads](https://julialang.org/downloads/). -### Getting all the rest -To get the remaining files and dependencies -start up `julia` and in the resulting REPL shell, -copy and paste the following: +### 2) Getting all the rest +To get the remaining files and dependencies start up `julia` and in the resulting REPL shell, copy and paste the following: ```julia import Downloads script = Downloads.download("https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads") include(script) ``` -This [downloads the install.jl script](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads) -and runs it from julia. -Follow the instructions on the screen and start the Jupyter notebook server -with the command that will be printed. +This [downloads the install.jl script](https://gitlab.mathematik.uni-stuttgart.de/stammbn/julia-seminar/-/raw/main/install.jl?ref_type=heads) and runs it from julia. + +### 2) Getting all the rest (expert version) -As an alternative you can also also run the following commands manually -(this requires to have `git` and `julia` available from the commandline): +As an alternative you can also also run the following commands manually (this requires to have `git` and `julia` available from the commandline): ``` git clone https://gitlab.mathematik.uni-stuttgart.de/stammbn/Julia-seminar/ cd Julia-seminar julia install-manual.jl ``` +### 3) Starting the notebook +To start the notebook make sure to be in the folder `Julia-seminar` and then run `julia`: an interactive Julia command line will open. In there run this command + +``` +using IJulia; notebook(dir=pwd()) +``` +and the notebook will automatically open in a browser. + +Navigate the files and open notebook number 0. + ### Troubleshooting If you are facing issues, check out the [great troubleshooting section](https://carstenbauer.github.io/WorkshopWizard.jl/dev/troubleshooting/) -from the WorkshopWizard package by Carsten Bauer (which `install.jl` is using). - -### Check everything works -There is a section in the [00_Installation](00_Installation.ipynb) notebook -with a few quick commands to check everything works as expected. -Please run these **before the course**. +from the WorkshopWizard package by Carsten Bauer (which is being used by `install.jl`). -### For Developers: Setting Up `pre-commit` +## For Developers: Setting Up `pre-commit` [`pre-commit`](https://pre-commit.com/) is a framework that helps to manage and maintain pre-commit hooks to ensure that your code adheres to a consistent style, prevents errors, and adheres to other quality assurance checks.