diff --git a/Day_5/Day_5.jl b/Day_5/Day_5.jl new file mode 100644 index 0000000..a60bf2a --- /dev/null +++ b/Day_5/Day_5.jl @@ -0,0 +1,469 @@ +### A Pluto.jl notebook ### +# v0.18.4 + +using Markdown +using InteractiveUtils + +# ╔═║ c7e76680-571e-427d-a564-8819df8b3750 +# Oh, no, you found my secret! 😱 +# Don't change this hidden cell! +begin + using PlutoUI + + TableOfContents() +end + +# ╔═║ c7256818-f2ab-4f8a-be6f-1d2c97dca981 +md""" +# Structs +Julia as a functional language does not have classes like in object oriented languages. Instead, Julia has structs. + +Using structs, you can define your own types. Structs use type composition. This means that you combine types into a new one. + +In Julia, type annotations DO NOT lead to any performance boosts. Structs build an exception! If you are writing a struct, you have to use type annotations with concrete types (not abstract)! +""" + +# ╔═║ 3e3e324d-5650-4f81-87cf-fb0f6f55d9d1 +struct Vec2d + x::Float64 + y::Float64 +end + +# ╔═║ 2ab6f97f-8eed-4b86-9eb6-1de88e6c846d +vec_2d = Vec2d(1.0, 1.0) + +# ╔═║ 377a9100-efd8-479c-b9f6-68584c886800 +typeof(vec_2d) + +# ╔═║ 0e62a7b2-0636-4018-b005-0ae674fec45e +# Wow, we did reach infinity ♾️ +Vec2d(factorial(big(1000)), 2.0) + +# ╔═║ 6046417c-460b-4b0c-8423-4d6c4c18731f +struct BadVec2d + x::Real + y::Real +end + +# ╔═║ 3e21d34f-3758-427f-85c0-7c457f3f0904 +bad_vec2d = BadVec2d(factorial(big(1000)), 2.0) + +# ╔═║ 4a07f5e3-2413-49c4-824c-b9c844695052 +typeof(bad_vec2d) + +# ╔═║ 9008b1c4-ad76-4d4f-b6c5-001a77543b97 +struct BetterVec2d{T<:Real} + x::T + y::T +end + +# ╔═║ 830dd737-4fdc-42c7-b105-d0622b055db1 +big_vec2d = BetterVec2d(factorial(big(1000)), big(1)) + +# ╔═║ f91b0c58-bc44-414a-b357-145d8c4339d2 +typeof(big_vec2d) + +# ╔═║ 3f1b8df9-104b-42c3-97ee-11782f9f744f +# BetterVec2d(1.0, 1) + +# ╔═║ 10c380fd-80e6-4cb7-b50e-1a7998ec00c5 +abstract type Student end + +# ╔═║ 58de483d-c2b5-4252-b6da-64bd8bfac1ac +struct MathStudent<:Student + name::String + hobby::String +end + +# ╔═║ 4024358d-f673-45f1-a12a-00a5554622e3 +struct PhysicsStudent<:Student + name::String + hobby::String + favorite_particle::String +end + +# ╔═║ b535fd1d-695d-49fb-8a6a-2f2f0053a6f6 +function print_name(student::Student) + println(student.name) + + return +end + +# ╔═║ 63f32169-b98c-4212-bbd9-4c601266f209 +function print_information(math_student::MathStudent) + println("Math student: $(math_student.name)") + println("hobby: $(math_student.hobby)") + + return +end + +# ╔═║ cb49717b-0584-430e-a30c-c4d02cf55eb2 +function print_information(physics_student::PhysicsStudent) + println("Physics student: $(physics_student.name)") + println("hobby: $(physics_student.hobby)") + println("Favorite particle: $(physics_student.favorite_particle)") + + return +end + +# ╔═║ be428fea-fd34-4a08-94d2-c23ba0ecc586 +math_student = MathStudent("Felix", "Proofing stuff") + +# ╔═║ da805692-8bf4-4eb5-a4ef-5a068c8a503b +physics_student = PhysicsStudent("Robert", "Using harmonic oscillators", "Photon") + +# ╔═║ 268904d5-6252-4ff7-9d8b-315b73736cac +print_name(math_student) + +# ╔═║ bc43e76c-3a9b-4f3f-9f88-28f2f7f868d1 +print_name(physics_student) + +# ╔═║ 0a2619e4-9eed-4eb3-a411-c616ee840062 +print_information(math_student) + +# ╔═║ bc8ef92b-1c68-4c9d-948a-6196dcd2b378 +print_information(physics_student) + +# ╔═║ d8a2ae5c-b42a-4673-9a95-24cfc69ea3e7 +md""" +# Writing documentation + +""" + +# ╔═║ c24c04e4-b131-11ec-2c1b-7de12fe0c324 +md""" +# Ecosystem +In this section, some interessting Julia packages will be presented briefly. If you want to learn more about them, check out their documentation! +""" + +# ╔═║ 279d81e7-77d5-4855-bf45-a1a613265f65 +md""" +## `PhysicalConstants.jl` +""" + +# ╔═║ 62e2481a-3fa1-4f2f-a7b6-7879c675701d +md""" +## `PeriodicTable.jl` +""" + +# ╔═║ aa40dc25-6355-45be-b577-c5a8a28f1a8a +md""" +## `PrettyTables.jl` +""" + +# ╔═║ 1ef034c9-da8d-4b35-8a98-532793b03718 +md""" +## `GuadGK.jl` +""" + +# ╔═║ e80c4d19-d746-4ab8-88e0-2389a722edb6 +md""" +## Makie +""" + +# ╔═║ 724f3fb4-1e49-4d58-a490-39d1110ba18c +md""" +### `CairoMakie.jl` +`LaTeXStrings.jl` +""" + +# ╔═║ 431ffe1d-9e90-4344-ba35-0a5375954c0a +md""" +### `GLMakie.jl` +""" + +# ╔═║ eb836cdc-de12-430c-a6f3-1524ebd28865 +md""" +## `JLD2.jl` +""" + +# ╔═║ 7e75da58-f110-41cb-ab19-79376370965f +md""" +## `Luxor.jl` +""" + +# ╔═║ 6b417e5d-01c2-4b06-9708-62c422a6b64b +md""" +## `DifferentialEquations.jl` +""" + +# ╔═║ b621819d-6ce3-41e1-9e61-3ad0a2c9b016 +md""" +## `Intervals.jl` +""" + +# ╔═║ 0174178f-3ed9-4890-8482-714cb51a635d +md""" +## `ProgressMeter.jl` +""" + +# ╔═║ d29338b3-3c25-4ae4-90d0-1176538c635e +md""" +## `NaturallyUnitful.jl` +""" + +# ╔═║ 2430f309-be28-4bc2-9692-92489c31f7b2 +md""" +# Resources + +""" + +# ╔═║ 00000000-0000-0000-0000-000000000001 +PLUTO_PROJECT_TOML_CONTENTS = """ +[deps] +PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8" + +[compat] +PlutoUI = "~0.7.38" +""" + +# ╔═║ 00000000-0000-0000-0000-000000000002 +PLUTO_MANIFEST_TOML_CONTENTS = """ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.7.2" +manifest_format = "2.0" + +[[deps.AbstractPlutoDingetjes]] +deps = ["Pkg"] +git-tree-sha1 = "8eaf9f1b4921132a4cff3f36a1d9ba923b14a481" +uuid = "6e696c72-6542-2067-7265-42206c756150" +version = "1.1.4" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.ColorTypes]] +deps = ["FixedPointNumbers", "Random"] +git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.11.0" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.Downloads]] +deps = ["ArgTools", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" + +[[deps.FixedPointNumbers]] +deps = ["Statistics"] +git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.8.4" + +[[deps.Hyperscript]] +deps = ["Test"] +git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9" +uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91" +version = "0.0.4" + +[[deps.HypertextLiteral]] +git-tree-sha1 = "2b078b5a615c6c0396c77810d92ee8c6f470d238" +uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2" +version = "0.9.3" + +[[deps.IOCapture]] +deps = ["Logging", "Random"] +git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a" +uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +version = "0.2.2" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.3" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" + +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" + +[[deps.Parsers]] +deps = ["Dates"] +git-tree-sha1 = "621f4f3b4977325b9128d5fae7a8b4829a0c2222" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.2.4" + +[[deps.Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[deps.PlutoUI]] +deps = ["AbstractPlutoDingetjes", "Base64", "ColorTypes", "Dates", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "UUIDs"] +git-tree-sha1 = "670e559e5c8e191ded66fa9ea89c97f10376bb4c" +uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8" +version = "0.7.38" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.Reexport]] +git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "1.2.2" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[deps.Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" + +[[deps.p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" +""" + +# ╔═║ Cell order: +# ╠═c7256818-f2ab-4f8a-be6f-1d2c97dca981 +# ╠═3e3e324d-5650-4f81-87cf-fb0f6f55d9d1 +# ╠═2ab6f97f-8eed-4b86-9eb6-1de88e6c846d +# ╠═377a9100-efd8-479c-b9f6-68584c886800 +# ╠═0e62a7b2-0636-4018-b005-0ae674fec45e +# ╠═6046417c-460b-4b0c-8423-4d6c4c18731f +# ╠═3e21d34f-3758-427f-85c0-7c457f3f0904 +# ╠═4a07f5e3-2413-49c4-824c-b9c844695052 +# ╠═9008b1c4-ad76-4d4f-b6c5-001a77543b97 +# ╠═830dd737-4fdc-42c7-b105-d0622b055db1 +# ╠═f91b0c58-bc44-414a-b357-145d8c4339d2 +# ╠═3f1b8df9-104b-42c3-97ee-11782f9f744f +# ╠═10c380fd-80e6-4cb7-b50e-1a7998ec00c5 +# ╠═58de483d-c2b5-4252-b6da-64bd8bfac1ac +# ╠═4024358d-f673-45f1-a12a-00a5554622e3 +# ╠═b535fd1d-695d-49fb-8a6a-2f2f0053a6f6 +# ╠═63f32169-b98c-4212-bbd9-4c601266f209 +# ╠═cb49717b-0584-430e-a30c-c4d02cf55eb2 +# ╠═be428fea-fd34-4a08-94d2-c23ba0ecc586 +# ╠═da805692-8bf4-4eb5-a4ef-5a068c8a503b +# ╠═268904d5-6252-4ff7-9d8b-315b73736cac +# ╠═bc43e76c-3a9b-4f3f-9f88-28f2f7f868d1 +# ╠═0a2619e4-9eed-4eb3-a411-c616ee840062 +# ╠═bc8ef92b-1c68-4c9d-948a-6196dcd2b378 +# ╠═d8a2ae5c-b42a-4673-9a95-24cfc69ea3e7 +# β•Ÿβ”€c24c04e4-b131-11ec-2c1b-7de12fe0c324 +# ╠═279d81e7-77d5-4855-bf45-a1a613265f65 +# ╠═62e2481a-3fa1-4f2f-a7b6-7879c675701d +# ╠═aa40dc25-6355-45be-b577-c5a8a28f1a8a +# ╠═1ef034c9-da8d-4b35-8a98-532793b03718 +# ╠═e80c4d19-d746-4ab8-88e0-2389a722edb6 +# ╠═724f3fb4-1e49-4d58-a490-39d1110ba18c +# ╠═431ffe1d-9e90-4344-ba35-0a5375954c0a +# ╠═eb836cdc-de12-430c-a6f3-1524ebd28865 +# ╠═7e75da58-f110-41cb-ab19-79376370965f +# ╠═6b417e5d-01c2-4b06-9708-62c422a6b64b +# ╠═b621819d-6ce3-41e1-9e61-3ad0a2c9b016 +# ╠═0174178f-3ed9-4890-8482-714cb51a635d +# ╠═d29338b3-3c25-4ae4-90d0-1176538c635e +# ╠═2430f309-be28-4bc2-9692-92489c31f7b2 +# β•Ÿβ”€c7e76680-571e-427d-a564-8819df8b3750 +# β•Ÿβ”€00000000-0000-0000-0000-000000000001 +# β•Ÿβ”€00000000-0000-0000-0000-000000000002