Make new dirs for online
This commit is contained in:
1 parent
f5915418a2
commit
3699c26d29
3 files changed
No files matched your search
@@ -0,0 +1,175 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Übung\n",
|
||||
"\n",
|
||||
"Gegeben ist das folgende Array:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n = np.array([\n",
|
||||
" [0. , 0. , 0.5, 1. , 1. , 0. , 1. , 0. , 1. ],\n",
|
||||
" [0. , 1. , 1.5, 1. , 0. , 1. , 1. , 0. , 0. ]\n",
|
||||
"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Die erste Zeile sind dabei x-Werte, die zweite Zeile y-Werte von Punkten. Plotten Sie die Punkte als Linienzug mit `plt.plot(...)`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Linienzug plotten\n",
|
||||
"# plt.plot(...)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Als nächstes sollen die Punkte rotiert werden. Eine Matrix, die eine Rotation um einen Winkel $\\theta$ durchführt, lautet wie folgt:\n",
|
||||
"\n",
|
||||
"\\begin{equation}\n",
|
||||
"m_1 =\n",
|
||||
"\\begin{bmatrix}\n",
|
||||
"\\cos \\theta & -\\sin \\theta \\\\ \n",
|
||||
"\\sin \\theta & \\cos \\theta \\\\\n",
|
||||
"\\end{bmatrix}\n",
|
||||
"\\end{equation}\n",
|
||||
"\n",
|
||||
"Implementieren Sie eine Funktion, die für einen gegeben Winkel diese Matrix als `ndarray` erzeugt:\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# angle soll in Grad angegeben werden\n",
|
||||
"def rotation_matrix(angle):\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"# mögliche Tests\n",
|
||||
"# assert(np.allclose(rotation_matrix(90).dot(np.array([1,0])), np.array([0,1])))\n",
|
||||
"# assert(np.allclose(rotation_matrix(-90).dot(np.array([1,0])), np.array([0,-1])))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Zum Rotieren aller Punkte muss jeder Punkt mit der Matrix `m` multipliziert werden. Rotieren Sie alle Punkte um 60 Grad und plotten Sie das Ergebnis erneut (Bonus: Versuchen Sie ohne `for`-Schleife auszukommen):"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# n_rot soll die rotierten Punkte enthalten, n_rot.shape == n.shape\n",
|
||||
"n_rot = ...\n",
|
||||
"\n",
|
||||
"# und erneut plotten..."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Als nächstes sollen die Punkte bezüglich des Ursprungs skaliert werden werden. Eine Matrix, die eine Skalierung in x-Richtung mit Faktor $s_x$ und in y-Richtung mit Faktor $s_y$ durchführt, lautet:\n",
|
||||
"\n",
|
||||
"\\begin{equation}\n",
|
||||
"m_2 =\n",
|
||||
"\\begin{bmatrix}\n",
|
||||
"s_x & 0 \\\\ \n",
|
||||
"0 & s_y \\\\\n",
|
||||
"\\end{bmatrix}\n",
|
||||
"\\end{equation}\n",
|
||||
"\n",
|
||||
"Implementieren Sie eine Funktion, die für einen gegeben Winkel diese Matrix als `ndarray` erzeugt:\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def scale_matrix(sx, sy):\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# todo test schreiben?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Skalieren Sie die gegebenen Punkte um beliebige Faktoren und plotten Sie die ursprünglichen und skalierten Punkte im selben Diagramm:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Punkte skalieren\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# und plotten\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.11.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "82037ebd",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4f0d058b",
|
||||
"metadata": {
|
||||
"vscode": {
|
||||
"languageId": "plaintext"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "00d20df1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b986454c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Übung: Roboterbewegung\n",
|
||||
"\n",
|
||||
"Ein Roboter steht in einem Raum, seine Position auf dem Boden wird in ein Koordinatensystem eingetragen - die y-Achse ist dabei die Himmelsrichtung _Nord_, die x-Achse die Himmelsrichtung _Ost_. Zu Beginn steht der Roboter auf der Position $x=3$ und $y=5$. Danach führt der Roboter folgende Bewegungen durch.\n",
|
||||
"\n",
|
||||
"- Fahrt 1 Meter Ost, 2 Meter Nord\n",
|
||||
"- Fahrt 2 Meter Ost, 1 Meter Nord\n",
|
||||
"- Fahrt 2 Meter Ost, 1 Meter Süd\n",
|
||||
"- Fahrt 1 Meter West, 3 Meter Süd\n",
|
||||
"\n",
|
||||
"a) Drücken Sie die 4 Bewegungen als Arrays aus und speichern Sie diese in Python-Variablen."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "bec0fab0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"start = np.array([3,5])\n",
|
||||
"fahrt1 = ...\n",
|
||||
"fahrt2 = ...\n",
|
||||
"fahrt3 = ...\n",
|
||||
"fahrt4 = ..."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "e55f20bc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ValueError",
|
||||
"evalue": "all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 2 and the array at index 1 has size 1",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
||||
"\u001b[31mValueError\u001b[39m Traceback (most recent call last)",
|
||||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 8\u001b[39m\n\u001b[32m 5\u001b[39m plt.xlim((\u001b[32m0\u001b[39m,\u001b[32m10\u001b[39m))\n\u001b[32m 6\u001b[39m plt.ylim((\u001b[32m0\u001b[39m,\u001b[32m10\u001b[39m))\n\u001b[32m----> \u001b[39m\u001b[32m8\u001b[39m \u001b[43mplot_path\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[43mfahrt1\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfahrt2\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfahrt3\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfahrt4\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
|
||||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 3\u001b[39m, in \u001b[36mplot_path\u001b[39m\u001b[34m(start, moves)\u001b[39m\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mplot_path\u001b[39m(start, moves):\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m path = \u001b[43mnp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mvstack\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43mstart\u001b[49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[43mmoves\u001b[49m\u001b[43m)\u001b[49m.cumsum(axis=\u001b[32m0\u001b[39m)\n\u001b[32m 4\u001b[39m plt.plot(path[:,\u001b[32m0\u001b[39m], path[:,\u001b[32m1\u001b[39m])\n\u001b[32m 5\u001b[39m plt.xlim((\u001b[32m0\u001b[39m,\u001b[32m10\u001b[39m))\n",
|
||||
"\u001b[36mFile \u001b[39m\u001b[32m~/Computational_and_Data_Science/FS25/CDS104-Databases-and-Data-Processing/code/.venv/lib/python3.13/site-packages/numpy/_core/shape_base.py:292\u001b[39m, in \u001b[36mvstack\u001b[39m\u001b[34m(tup, dtype, casting)\u001b[39m\n\u001b[32m 290\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(arrs, \u001b[38;5;28mtuple\u001b[39m):\n\u001b[32m 291\u001b[39m arrs = (arrs,)\n\u001b[32m--> \u001b[39m\u001b[32m292\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_nx\u001b[49m\u001b[43m.\u001b[49m\u001b[43mconcatenate\u001b[49m\u001b[43m(\u001b[49m\u001b[43marrs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[43m=\u001b[49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcasting\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcasting\u001b[49m\u001b[43m)\u001b[49m\n",
|
||||
"\u001b[31mValueError\u001b[39m: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 2 and the array at index 1 has size 1"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Mit dieser Zelle können Sie die Fahrt des Roboters plotten - einfach ausführen\n",
|
||||
"def plot_path(start, moves):\n",
|
||||
" path = np.vstack([start] + moves).cumsum(axis=0)\n",
|
||||
" plt.plot(path[:,0], path[:,1])\n",
|
||||
" plt.xlim((0,10))\n",
|
||||
" plt.ylim((0,10))\n",
|
||||
"\n",
|
||||
"plot_path(start, [fahrt1, fahrt2, fahrt3, fahrt4])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9f47078c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"b) Berechnen Sie den Zielpunkt des Roboters nach seiner Fahrt."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "90852486",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3c8684d8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"c) Welche Strecke hat der Roboter zurückgelegt (nicht der direkte Weg)?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "6ee1ca50",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3474df24",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"d) Wie weit wäre der Roboter gefahren, wenn er die direkte Strecke von Start zu Ziel gefahren wäre?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "04a2e60a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "code (3.13.2)",
|
||||
"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.13.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in new issue
Block a user