diff --git a/src/4_Arrays_Linear_Algebra.ipynb b/src/4_Arrays_Linear_Algebra.ipynb index b8f7db6981a294945950e681589c1cb7298395af..924b065667daf25ce0d275d42f579b09eef2d632 100644 --- a/src/4_Arrays_Linear_Algebra.ipynb +++ b/src/4_Arrays_Linear_Algebra.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "4f17d479-4a7d-430c-a1ee-92fcd5ec0c16", "metadata": {}, @@ -9,6 +10,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "c02d808e-3b3d-46c6-8199-320d6fa778aa", "metadata": {}, @@ -30,10 +32,11 @@ "source": [ "a1 = [10, 20, 30, 40]\n", "a2 = [\"hi\", \"this\", \"is\", \"an\", \"array\"]\n", - "@show a1 a2;" + "@show a1 a2;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "f9bbdffd-c37b-4317-b07d-d75003b2f568", "metadata": {}, @@ -48,10 +51,11 @@ "metadata": {}, "outputs": [], "source": [ - "a3 = [\"spam\", 2.0, 5, [10, 20]]" + "a3 = [\"spam\", 2.0, 5, [10, 20]]\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "a364229e-ed7a-4b7d-b87f-40d073f24682", "metadata": {}, @@ -70,10 +74,11 @@ "cheeses = [\"Cheddar\", \"Edam\", \"Gouda\"];\n", "numbers = [42, 123];\n", "empty = [];\n", - "print(cheeses, \" \", numbers, \" \", empty)" + "print(cheeses, \" \", numbers, \" \", empty)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "0275af11-5f69-49aa-8b8a-794c82f27590", "metadata": {}, @@ -90,10 +95,11 @@ "metadata": {}, "outputs": [], "source": [ - "cheeses[1]" + "cheeses[1]\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "7983a3ae-f9cc-410d-888b-f281812add8c", "metadata": {}, @@ -109,10 +115,11 @@ "outputs": [], "source": [ "cheeses[2] = \"Gorgonzola\"\n", - "print(cheeses)" + "print(cheeses)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "918c617e-ffb9-4b90-b9e5-fea8e960ad1e", "metadata": {}, @@ -133,10 +140,11 @@ "outputs": [], "source": [ "@show \"Gouda\" ∈ cheeses\n", - "@show \"Brie\" in cheeses;" + "@show \"Brie\" in cheeses;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "7cd2705c-2d8f-43b3-bb9b-204c1674da50", "metadata": {}, @@ -155,10 +163,11 @@ "source": [ "for cheese in cheeses\n", " println(cheese)\n", - "end" + "end\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "3c83a447-2c3b-4cb2-8192-6f0f4249ae2e", "metadata": {}, @@ -175,10 +184,11 @@ "source": [ "for i in eachindex(numbers)\n", " numbers[i] = numbers[i] * 2\n", - "end" + "end\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "c6f78ad1-4717-42e8-bb94-6fe33691f563", "metadata": {}, @@ -195,10 +205,11 @@ "source": [ "for x in []\n", " println(\"This can never happens.\")\n", - "end" + "end\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "adcdb6d4-35bc-4a1c-bbe0-f023a9ab2509", "metadata": {}, @@ -215,10 +226,11 @@ "outputs": [], "source": [ "array = [\"spam\", 1, [\"Brie\", \"Roquefort\", \"Camembert\"], [1, 2, 3]]\n", - "@show length(array);" + "@show length(array);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "e64ec6e6-dfb7-4e05-ba9e-96cec72955bb", "metadata": {}, @@ -236,10 +248,11 @@ "source": [ "t = ['a', 'b', 'c', 'd', 'e', 'f']\n", "print(t[1:3])\n", - "print(t[3:end])" + "print(t[3:end])\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "beee009a-f707-4436-8144-8c7932f122e2", "metadata": {}, @@ -259,10 +272,11 @@ "@show t1 === t\n", "\n", "t2 = t\n", - "@show t2 === t;" + "@show t2 === t;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "42e8a620-d702-4f92-8d20-58608294fb38", "metadata": {}, @@ -278,10 +292,11 @@ "outputs": [], "source": [ "t[2:3] = ['x', 'y']\n", - "print(t)" + "print(t)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "2ed7448b-9efc-42bf-a24e-22a6e060a1eb", "metadata": {}, @@ -300,10 +315,11 @@ "t = ['a', 'b', 'c']\n", "push!(t, 'd')\n", "pushfirst!(t, '0')\n", - "print(t)" + "print(t)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "1fb6e797-9d98-4264-a7ad-7fd0b6eb3b89", "metadata": {}, @@ -321,10 +337,11 @@ "t1 = ['a', 'b', 'c']\n", "t2 = ['d', 'e']\n", "append!(t1, t2)\n", - "print(t1)" + "print(t1)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "b7a64ccf-077b-4f80-81a5-6c3ba0ac9ce3", "metadata": {}, @@ -340,10 +357,11 @@ "outputs": [], "source": [ "t = ['a', 'b', 'c']\n", - "print(insert!(t, 2, 'x'))" + "print(insert!(t, 2, 'x'))\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "e5fd6caf-c66c-4c5a-8f95-f72a72caaf9d", "metadata": {}, @@ -366,10 +384,11 @@ "\n", "t3 = sort(t2)\n", "println(t3)\n", - "@show t3 === t2;" + "@show t3 === t2;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "130876d4-db72-44a9-beec-c39b5b307df9", "metadata": {}, @@ -387,10 +406,11 @@ "t = ['a', 'b', 'c']\n", "element = splice!(t, 2)\n", "println(t)\n", - "println(element)" + "println(element)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "30b6b7fd-d07a-4792-8250-dd611653bbb1", "metadata": {}, @@ -408,10 +428,11 @@ "t = ['a', 'b', 'c']\n", "element = pop!(t)\n", "println(t)\n", - "println(element)" + "println(element)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "65fc2a2a-8b06-4dca-910e-2a5d37974460", "metadata": {}, @@ -428,16 +449,17 @@ "outputs": [], "source": [ "x = [1, 2, 3, 4, 5, 6, 7, 8, 9];\n", - "# TODO implement your code here" + "# TODO implement your code here\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "393c8cf4-3c4d-400b-a1af-5af69f4dbf87", "metadata": {}, "source": [ "### Dot syntax\n", - "For every binary operator like `^`, here is a corresponding dot operator .^ that is automatically defined to perform ^ element-by-element on arrays. For example, `[1, 2, 3]^3` is not defined, but `[1, 2, 3].^3` is defined as computing the elementwise result `[1^3, 2^3, 3^3]`:" + "For every binary operator like `^`, there is a corresponding dot operator .^ that is automatically defined to perform ^ element-by-element on arrays. For example, `[1, 2, 3]^3` is not defined, but `[1, 2, 3].^3` is defined as computing the elementwise result `[1^3, 2^3, 3^3]`:" ] }, { @@ -447,10 +469,11 @@ "metadata": {}, "outputs": [], "source": [ - "print([1, 2, 3] .^ 3)" + "print([1, 2, 3] .^ 3)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "8e88b86e-0284-4679-83c3-9b90e47b4e33", "metadata": {}, @@ -466,10 +489,11 @@ "outputs": [], "source": [ "t = uppercase.([\"abc\", \"def\", \"ghi\"])\n", - "print(t)" + "print(t)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "93c1a351-0b39-4baf-86cc-66e1f9277db8", "metadata": {}, @@ -486,10 +510,11 @@ "metadata": {}, "outputs": [], "source": [ - "print(collect(\"spam\"))" + "print(collect(\"spam\"))\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "c54747e6-1ebc-4b82-af65-77b982bc3835", "metadata": {}, @@ -505,15 +530,14 @@ "outputs": [], "source": [ "@show split(\"building an array of strings\")\n", - "@show split(\"02.11.2023\", \".\");" + "@show split(\"02.11.2023\", \".\");\n" ] }, { - "cell_type": "code", - "execution_count": null, + "attachments": {}, + "cell_type": "markdown", "id": "9f9cf023-a1d5-43d5-8322-13e8319b6637", "metadata": {}, - "outputs": [], "source": [ "Finally, `join` is the inverse of split. It takes an array of strings and concatenates the elements:" ] @@ -528,10 +552,11 @@ "t = [\"building\", \"a\", \"string\"]\n", "@show join(t)\n", "@show join(t, \" \")\n", - "@show join(t, \"-\");" + "@show join(t, \"-\");\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "c85d6757-a7ac-442c-879c-418137a2ebd0", "metadata": {}, @@ -547,10 +572,11 @@ "metadata": {}, "outputs": [], "source": [ - "# TODO: implement your code here" + "# TODO: implement your code here\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "45a34bfb-67c1-4fbc-ae18-c60403dc3dda", "metadata": {}, @@ -565,15 +591,16 @@ "metadata": {}, "outputs": [], "source": [ - "# TODO: implement your code here" + "# TODO: implement your code here\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "b5fc2426-b30b-4295-bf8e-f0c9b152267c", "metadata": {}, "source": [ - " - Write a function `even_numbers(x)` which takes as input an array of ingegers and returns a new array containing only the elements which are even." + " - Write a function `even_numbers(x)` which takes as input an array of integers and returns a new array containing only the elements which are even." ] }, { @@ -583,10 +610,11 @@ "metadata": {}, "outputs": [], "source": [ - "# TODO: implement your code here" + "# TODO: implement your code here\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "756cd401-77f2-4b90-9a87-10b4fcc6c7a7", "metadata": {}, @@ -595,6 +623,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "1c5d8a88-f00e-41a9-ac62-245a25d8c803", "metadata": {}, @@ -610,10 +639,11 @@ "outputs": [], "source": [ "A = zeros(Int, 2, 3, 4)\n", - "@show typeof(A);" + "@show typeof(A);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "e2dafffd-9538-477b-9aec-7fb04d3f9d99", "metadata": {}, @@ -631,10 +661,11 @@ "v = [1, 2, 3, 4, 5]\n", "@show typeof(v)\n", "m = [1 2 3; 4 5 6; 7 8 9]\n", - "@show typeof(m);" + "@show typeof(m);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "b1fc0ccd-1b16-4fec-9825-561198fa3763", "metadata": {}, @@ -650,10 +681,11 @@ "outputs": [], "source": [ "m = [1 2 3]\n", - "@show typeof(m);" + "@show typeof(m);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "9b91edb6-def2-4fa1-8b7a-b3db96e850be", "metadata": {}, @@ -670,10 +702,11 @@ "source": [ "@show Vector{Any} === Array{Any, 1}\n", "@show Matrix{Any} === Array{Any, 2}\n", - "@show Matrix{Any} === Array{Any, 3};" + "@show Matrix{Any} === Array{Any, 3};\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "00c7fd47-c3aa-41f7-81a4-d08510126d85", "metadata": {}, @@ -689,10 +722,11 @@ "outputs": [], "source": [ "@show Vector{Float32} <: Vector{Real}\n", - "@show Vector{Real} <: Vector{Any};" + "@show Vector{Real} <: Vector{Any};\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "1205c3f4-2e97-4952-86f2-bc8e44d638f7", "metadata": {}, @@ -701,6 +735,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "a6a69a05-dfa3-42f9-a011-579478a8a9c1", "metadata": {}, @@ -718,10 +753,11 @@ "v1 = [1, 2, 3]\n", "v2 = Float32[1, 2, 3]\n", "@show typeof(v1)\n", - "@show typeof(v2);" + "@show typeof(v2);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "1a73ec49-da56-4724-af51-883dd3c92da9", "metadata": {}, @@ -739,10 +775,11 @@ "v1 = zeros(5)\n", "v2 = ones(5)\n", "v3 = rand(5)\n", - "@show v1 v2 v3;" + "@show v1 v2 v3;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "95b897c2-f58c-48fa-a845-e0a6a8934b9f", "metadata": {}, @@ -760,10 +797,11 @@ "v1 = zeros(Integer, 5)\n", "v2 = ones(Float32, 5)\n", "v3 = rand(Float32, 10)\n", - "@show v1 v2 v3;" + "@show v1 v2 v3;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "d6315e57-2614-4caf-a50c-0e192ac19672", "metadata": {}, @@ -782,10 +820,11 @@ "v2 = [1, 1, 1]\n", "\n", "@show v1 - v2\n", - "@show v1 + 2*v2;" + "@show v1 + 2*v2;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "09784b0e-9e8d-4271-a8d7-2c2ad409fad9", "metadata": {}, @@ -802,10 +841,11 @@ "source": [ "using LinearAlgebra\n", "v = [1, 2, 3]\n", - "@show dot(v, v);" + "@show dot(v, v);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "4605b075-3754-46cc-9fbc-2c1bb22e95da", "metadata": {}, @@ -821,10 +861,11 @@ "outputs": [], "source": [ "@show typeof(v) v\n", - "@show typeof(v') v';" + "@show typeof(v') v';\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "3aad0875-2339-47f6-ae1f-bd5ca455bec2", "metadata": {}, @@ -833,6 +874,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "243b7d80-11c6-4b2f-af93-0e4f5a56deee", "metadata": {}, @@ -851,10 +893,11 @@ "m2 = ones(Float32, 3, 3)\n", "m3 = rand(Float32, 3, 3)\n", "m4 = Float32[1 2 3; 4 5 6]\n", - "@show m1 m2 m3 m4;" + "@show m1 m2 m3 m4;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "19df2da4-a6fe-44d5-aacc-070e27086c37", "metadata": {}, @@ -869,10 +912,11 @@ "metadata": {}, "outputs": [], "source": [ - "@show diagm([1, 2, 3]);" + "@show diagm([1, 2, 3]);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "98f05747-23ba-46f1-afc1-31c5de94de8c", "metadata": {}, @@ -888,10 +932,11 @@ "outputs": [], "source": [ "m1 = [1 2 3; 3 4 5; 6 7 8]\n", - "@show I*m1;" + "@show I*m1;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "0f341138-d1e7-425a-a54b-d5278ae1a48b", "metadata": {}, @@ -908,10 +953,11 @@ "source": [ "m1 = [1 2 3; 3 4 5; 6 7 8]\n", "m2 = [1 0 0; 0 0 0; 0 0 0]\n", - "@show m1 * m2;" + "@show m1 * m2;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "06b6d25f-92a1-4768-bdd8-760fa9212879", "metadata": {}, @@ -928,10 +974,11 @@ "source": [ "m1 = [1 2; -1 2]\n", "@show I/m1;\n", - "@show inv(m1);" + "@show inv(m1);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "eab561b9-b034-49e6-a100-09b201ff4caa", "metadata": {}, @@ -948,10 +995,11 @@ "source": [ "m1 = [0 -1im ; 2im 0];\n", "@show m1\n", - "@show m1';" + "@show m1';\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "d827b0b8-ead4-48c7-83bd-399ef7927414", "metadata": {}, @@ -968,10 +1016,11 @@ "source": [ "m1 = [1 2 3; 3 4 5; 6 7 8]\n", "@show det(m1);\n", - "@show tr(m1);" + "@show tr(m1);\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "5c2d37bb-4417-4f9c-a894-352a2a5c741b", "metadata": {}, @@ -988,10 +1037,11 @@ "metadata": {}, "outputs": [], "source": [ - "m = [3 0.5 0.1; 0.1 5 0.2; 0.2 0.1 3]" + "m = [3 0.5 0.1; 0.1 5 0.2; 0.2 0.1 3]\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "ff83a09a-6ede-44df-8151-96e7ce961489", "metadata": {}, @@ -1007,10 +1057,11 @@ "outputs": [], "source": [ "λ, V = eigen(m)\n", - "m1 = V * diagm(λ) * inv(V)" + "m1 = V * diagm(λ) * inv(V)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "cba4ddfc-bcdf-4c3b-8fb4-1237ec15bf44", "metadata": {}, @@ -1026,10 +1077,11 @@ "outputs": [], "source": [ "U, λ, V = svd(m)\n", - "m1 = U * diagm(λ) * V'" + "m1 = U * diagm(λ) * V'\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "3ae3a97a-aa0d-41a4-b957-1346860ad638", "metadata": {}, @@ -1048,10 +1100,11 @@ "m1 = L * U\n", "@show L\n", "@show U\n", - "@show m1;" + "@show m1;\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "d9116b9e-7650-4421-8497-40a440a842b8", "metadata": {}, @@ -1067,10 +1120,11 @@ "outputs": [], "source": [ "h = m + m'\n", - "L = cholesky(h)" + "L = cholesky(h)\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "3f6ecf2e-0ca5-4fa4-ba39-541a7359564b", "metadata": {}, @@ -1080,6 +1134,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "dae5385d-add4-47c2-9f7b-d8787942c22c", "metadata": {}, @@ -1088,6 +1143,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "f5332b7c-c974-4949-a395-7219fcfc049f", "metadata": {}, @@ -1102,10 +1158,11 @@ "metadata": {}, "outputs": [], "source": [ - "# TODO: implement your code here" + "# TODO: implement your code here\n" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "62c05d6b-6772-407b-a3cd-581ef829af4d", "metadata": {}, @@ -1120,7 +1177,7 @@ "metadata": {}, "outputs": [], "source": [ - "# TODO: implement your code here" + "# TODO: implement your code here\n" ] } ],