"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."
The first example is an array of four integers. The second is an array of five strings. The elements of an array don’t have to be the same type. The following array contains a string, a float, an integer, and another array:
The kind of the array is specified between curly braces and is composed of a type and a number. The number indicates the dimensions. The array empty contains values of type `Any`., i.e. it can hold values of all types.
The syntax for accessing the elements of an array is the bracket operator. The expression inside the brackets specifies the index. Remember that the indices start at 1:
Unlike tuples, arrays are **mutable**. When the bracket operator appears on the left side of an assignment, it identifies the element of the array that will be assigned:
This works well if you only need to read the elements of the array, as you will get only copies of the elements and changing the copies does not change the array. But if you want to write or update the elements, you need the indices. A common way to do that is to use the built-in function `eachindex`:
Julia provides functions that operate on arrays. For example, `push!` adds a new element to the end of an array (note the exclamation mark, as it is impure). `pushfirst!` adds a new element at the beginning of the array.
There are several ways to delete elements from an array. If you know the index of the element you want to delete, you can use `splice!`. `splice!` modifies the array and returns the element that was removed. `deleteat!` does the same without returning the element.
- The core functionality provides several other functions which act on an array. Given an array `x` try the following functions and try to guess what they do: `ndims(x)`, `eltype(x)`, `length(x)`, `size(x)`, `size(x, 1)`, `reshape(x, 3, 3)`.
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]`:
Any Julia function `f` can be applied elementwise to any array with the dot syntax. For example to capitalize an array of strings, we don’t need an explicit loop:
A string is a sequence of characters and an array is a sequence of values, but an array of characters is not the same as a string. To convert from a string to an array of characters, you can use the function `collect`:
If you want to break a string into words, you can use the `split` function. The default delimiter is the space, but you can pass a custom delimiter as a second argument.
**Note:**`Array` and `Vector` are always concrete types, independently from the type of the elements. So the usual type relations don't give the expected results:
The identity matrix is represented as a `I`. **Note**: this is not really a matrix, but rather a `UniformScaling` which brings the effect of the identity operation without needing allocated space. The uniform scalings automatically adapt to the size of the matrices they act on.
- Implement a solver for linear systems that uses the [Jacobi method](https://en.wikipedia.org/wiki/Jacobi_method). Then compare the result with the standard solution using matrix inversion.