249 lines
8.3 KiB
Plaintext
249 lines
8.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Aufgabe 1: Ein eigenes kleines C++-Programm (*vector of vectors*) (1 Punkt)"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Erstellen Sie in [`task1.main.cpp`](task1.main.cpp) ein lauffähiges Ein-Dateien-Programm das folgende Struktur aufweist:\n",
|
|
"\n",
|
|
"- Einbinden benötigter Header-Dateien aus der Standardbibliothek, z.B.:\n",
|
|
"\t```cpp\n",
|
|
"\t#include <iostream> // std::cout, std::endl\n",
|
|
"\t#include <...>\n",
|
|
"\t```\n",
|
|
"- Definition/Implementierung einer eigenen Funktion, z.B.:\n",
|
|
"\t```cpp\n",
|
|
"\tint sum(...){\n",
|
|
"\t ...\n",
|
|
"\t}\n",
|
|
"\t``` \n",
|
|
"- Definition/Implementierung einer `main`-Funktion (Einstiegspunkt für jedes lauffähige Programm), die Ihre selbest geschriebene Funktion verwendet und die berechneten Ergebnisse in der Konsole ausgibt, z.B.:\n",
|
|
"\t```cpp\n",
|
|
"\tint main(){\n",
|
|
"\t ...\n",
|
|
"\t auto res = sum(...)\t\n",
|
|
"\t std::cout << res << std::endl;\n",
|
|
"\t return 0;\n",
|
|
"\t}\n",
|
|
"\t``` \n"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"- Eine genaue Beschreibung und Anforderungen finden Sie in [`task1.main.cpp`](task1.main.cpp)\n",
|
|
"- Ihre Implementierung erfolgt ebenfalls in [`task1.main.cpp`](task1.main.cpp)"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Aufgabe 2: Mathematische Funktionen abtasten, numerische Integration und Differenzierung (1 Punkt)"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Sie implementieren Funktionen, die\n",
|
|
"\n",
|
|
"- ein Intervall $[a,b]$ mittels $N$ Stellen gleichabständig abstasten -> $\\mathbf{x} = \\left[ x_1, x_2, ... , x_N \\right]$,\n",
|
|
"- eine Funktion $f(x)$ für die diskreten Werte im Intervall evaluieren -> $\\mathbf{y} = \\left[ f(x_1), f(x_2), ... , f(x_N) \\right]$,\n",
|
|
"- anhand der diskreten Wertepaare ($\\mathbf{x}, \\mathbf{y}$) die Ableitung approximieren:\n",
|
|
"\t- Vorwärts-Differenz an der ersten Stelle: $f'(x_1) \\approx \\frac{y_2 - y_1}{x_2 - x_1}$,\n",
|
|
"\t- Rückwarts-Differenz an der letzten Stelle: $f'(x_N) \\approx \\frac{y_N - y_{N-1}}{x_N - x_{N-1}}$,\n",
|
|
"\t- Zentrale-Differenz für alle anderen Stellen $f'(x_i) \\approx \\frac{y_{i+1} - y_{i-1} }{x_{i+1} - x_{i-1}}$, und\n",
|
|
"- anhand der diskreten Wertepaare ($\\mathbf{x}, \\mathbf{y}$) die Stammfunktion approximieren:\n",
|
|
"\t- Integrationskonstante an der ersten Stelle: $F(x_1) = C$\n",
|
|
"\t- Trapezregel für alle anderen Stellen: $F(x_i) \\approx C + \\sum_{2}^{i} \\left[ 0.5 \\cdot \\left(y_{i}+y_{i-1}\\right) \\cdot \\left(x_i - x_{i-1}\\right) \\right]$."
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Implementieren Sie die folgenden vier Funktionen:\n",
|
|
"\n",
|
|
"```cpp\n",
|
|
"using Vector = std::vector<double>;\n",
|
|
"using Callable = std::function<double(double)>;\n",
|
|
"\n",
|
|
"Vector range(double start, double end, unsigned int N);\n",
|
|
"Vector sample(Vector values, Callable func);\n",
|
|
"Vector numdiff(Vector x, Vector y);\n",
|
|
"Vector numint(Vector x, Vector y, double C);\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"- Die vorgegebenen Deklarationen und eine genaue Beschreibung und Anforderungen finden Sie in [`task2.hpp`](task2.hpp)\n",
|
|
"- Ihre Implementierung erfolgt in [`task2.cpp`](task2.cpp)\n",
|
|
"- Die zugeordneten Tests finden Sie in [`task2.test.cpp`](task2.test.cpp)\n"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Aufgabe 3: Diskrete Funktionswerte abspeichern und plotten (1 Punkt)\n",
|
|
"\n",
|
|
"Sie implementieren eine Funktion in C++ die eine `.csv`-Datei mit diskreten Funktionswerten erzeugt:\n",
|
|
"- verwenden Sie Ihre in Aufgabe 2 entwickelten Funktionen zum Abtasten und numerisch Integrieren/Differenzieren\n",
|
|
"- verwenden Sie die bereitgestellte Funktion [`iue::io::savetxt`](https://sgit.iue.tuwien.ac.at/360050/modules/src/commit/7b31b845bf2d1297553a8565ba6ca2474305394a/iue-io/csv.hpp#L20) zum Schreiben der `.csv`-Datei\n",
|
|
"\n",
|
|
"Ebenso implementieren Sie eine Funktion in Python, um die Funktionswerten in der von Ihnen erzeugten `.csv`-Datei zu plotten:\n",
|
|
"- verwenden Sie [numpy.loadtxt](https://numpy.org/doc/stable/reference/generated/numpy.loadtxt.html) zum Lesen der `.csv`-Datei\n",
|
|
"- verwenden Sie [`Matplotlib`](https://matplotlib.org/stable/tutorials/pyplot.html) zum Plotten der eingelesenen Daten"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Implementieren Sie folgende Funktion (**C++**):\n",
|
|
"\n",
|
|
"```cpp\n",
|
|
"\n",
|
|
"using Filename = std::filesystem::path;\n",
|
|
"using Callable = std::function<double(double)>;\n",
|
|
"\n",
|
|
"void sample_to_csv(Filename filepath, \n",
|
|
" char del, \n",
|
|
" char comments, \n",
|
|
" Callable func, \n",
|
|
" double start, \n",
|
|
" double end, \n",
|
|
" unsigned int N);\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"- Die vorgegebenen Deklaration und eine genaue Beschreibung und Anforderungen finden Sie in [`task3.hpp`](task3.hpp)\n",
|
|
"- Ihre Implementierung erfolgt in [`task3.cpp`](task3.cpp)\n",
|
|
"- Die zugeordneten Tests finden Sie in [`task3.test.cpp`](task3.test.cpp)\n"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Implementieren Sie zudem folgende Funktion (**Python**):\n",
|
|
"\n",
|
|
"```py\n",
|
|
"def plot_discrete_function(csvfile, delimiter, comments, pngfile):\n",
|
|
"\tpass # todo: implement\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"- Ihre Implementierung erfolgt in [`task3.py`](task3.py)\n",
|
|
"- Die zugeordneten Tests finden Sie in [`task3.test.py`](task3.test.py)\n"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Die final erzeugten Plots könnten z.B. so aussehen:\n",
|
|
"\n",
|
|
" \n",
|
|
""
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Kompilieren/Testen\n",
|
|
"\n",
|
|
"So testen Sie Ihre Implementierung (direkter Aufruf von `g++` und `python`):\n",
|
|
"\n",
|
|
"```shell\n",
|
|
"# prepare\n",
|
|
"mkdir build\n",
|
|
"# compile\n",
|
|
"g++ -g -std=c++20 task1.main.cpp -o build/task1.exe\n",
|
|
"g++ -g -std=c++20 task2.cpp task2.test.cpp -o build/task2.exe\n",
|
|
"g++ -g -Imodules -std=c++20 task2.cpp task3.cpp task3.test.cpp -o build/task3.exe\n",
|
|
"\n",
|
|
"# run tests\n",
|
|
"./build/task1.exe\n",
|
|
"./build/task2.exe\n",
|
|
"./build/task3.exe\n",
|
|
"python task3.test.py\n",
|
|
"```\n",
|
|
"\n",
|
|
"Alternativ (mittels CMake-Configuration):s\n",
|
|
"\n",
|
|
"```shell\n",
|
|
"# prepare\n",
|
|
"cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug\n",
|
|
"# compile\n",
|
|
"cmake --build build --config Debug --target task1\n",
|
|
"cmake --build build --config Debug --target task2\n",
|
|
"cmake --build build --config Debug --target task3\n",
|
|
"cmake --build build --config Debug # all\n",
|
|
"# run tests\n",
|
|
"ctest --test-dir build -C Debug -R task1 \n",
|
|
"ctest --test-dir build -C Debug -R task2 \n",
|
|
"ctest --test-dir build -C Debug -R task3 \n",
|
|
"ctest --test-dir build -C Debug # all\n",
|
|
"``` \n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.6.15"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|