diff --git a/1_Basics.ipynb b/1_Basics.ipynb index 22fc794797926bcd5bab59c03de4a5946df401f2..7f816cecfd0d785cda2d2f8c4fe5c084667c02a8 100644 --- a/1_Basics.ipynb +++ b/1_Basics.ipynb @@ -596,18 +596,112 @@ "Use this formula to compute an estimate of π. It should use a while loop ot compute terms of the summation untile the last term is smaller than 1e-15. Afterwards, you can check the result by comparing it to π (to get π in Julia, write \\pi and then press TAB)." ] }, + { + "cell_type": "markdown", + "id": "d4a870c3-7679-4775-94ce-4e7266a2bebe", + "metadata": {}, + "source": [ + "## Functions" + ] + }, + { + "cell_type": "markdown", + "id": "682a3feb-0b82-479d-9803-3011a1e6e521", + "metadata": {}, + "source": [ + "We have already seen one example of a function call:" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "cd1a716d-ddaf-4167-a83f-129dc3163ea1", + "id": "addaa346-7a88-4c18-9f1e-295665959a9d", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "println(\"Hello, World!\")" + ] + }, + { + "cell_type": "markdown", + "id": "3434842c-2af0-4f6a-a70b-a59fb8fcc4af", + "metadata": {}, + "source": [ + "The name of the function is println. The expression in parentheses is called the argument of the function.\n", + "It is common to say that a function “takes” an argument and “returns” a result. The result is also called the return value." + ] + }, + { + "cell_type": "markdown", + "id": "f63d270a-7149-4ffd-bc31-f746560a37ac", + "metadata": {}, + "source": [ + "Julia provides functions that convert values from one type to another. The parse function takes a string and converts it to any number type, if it can, or complains otherwise:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f05465a-4863-4205-9c73-26f0e93f049b", + "metadata": {}, + "outputs": [], + "source": [ + "parse(Int64, \"32\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e6ac9994-9cbb-4004-889d-a657b8396063", + "metadata": {}, + "outputs": [], + "source": [ + "parse(Int64, \"Hello\")" + ] + }, + { + "cell_type": "markdown", + "id": "793c9620-7b6e-443c-8765-8136fbfcb071", + "metadata": {}, + "source": [ + "Julia provides several mathematical functions.\n", + " - abs(x): Absolute value of x.\n", + " - sqrt(x): Square root of x.\n", + " - cbrt(x): Cube root of x.\n", + " - exp(x): Exponential function e^x.\n", + " - log(x): Natural logarithm of x.\n", + " - log10(x): Base 10 logarithm of x.\n", + " - log2(x): Base 2 logarithm of x.\n", + " - sin(x): Sine of x (in radians).\n", + " - cos(x): Cosine of x (in radians).\n", + " - tan(x): Tangent of x (in radians).\n", + " - asin(x): Arcsine of x (result in radians).\n", + " - acos(x): Arccosine of x (result in radians).\n", + " - atan(x): Arctangent of x (result in radians).\n", + " - sinh(x): Hyperbolic sine of x.\n", + " - cosh(x): Hyperbolic cosine of x.\n", + " - tanh(x): Hyperbolic tangent of x.\n", + " - asinh(x): Inverse hyperbolic sine of x.\n", + " - acosh(x): Inverse hyperbolic cosine of x.\n", + " - atanh(x): Inverse hyperbolic tangent of x.\n", + " - floor(x): Largest integer not greater than x.\n", + " - ceil(x): Smallest integer not less than x.\n", + " - round(x): Nearest integer to x.\n", + " - trunc(x): Integer part of x." + ] + }, + { + "cell_type": "markdown", + "id": "d048851b-8eac-4dc3-81b7-ea1d625a1db2", + "metadata": {}, + "source": [ + "So far, we have only been using the functions that come with Julia, but it is also possible to add new functions. A function definition specifies the name of a new function and the sequence of statements that run when the function is called. Here is an example:" + ] }, { "cell_type": "code", "execution_count": null, - "id": "4ff56e28-969e-4a2d-b33c-21b4a4ecc4de", + "id": "fd2f4828-47f5-4df4-b5bd-a42625487b5a", "metadata": {}, "outputs": [], "source": [] diff --git a/README.md b/README.md index 59ab6303bad1bbd0f95d1a130d60808434eff71d..4415f6880c5d1f7fecdfb5f0db17b8e6e34a2a0c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 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 Ben Lauwens ([Creative Commons Attribution-NonCommercial 3.0 Unported license](https://creativecommons.org/licenses/by-nc/3.0/deed.en)). + - 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):