GDET3 Primer Komplexe Zahlen.ipynb 9.79 KB
 Christian Rohlfing committed Aug 28, 2019 1 2 3 4 5 { "cells": [ { "cell_type": "code", "execution_count": null,  Christian Rohlfing committed Sep 03, 2019 6 7 8 9 10  "metadata": { "jupyter": { "source_hidden": true } },  Christian Rohlfing committed Aug 28, 2019 11 12  "outputs": [], "source": [  Hafiz Emin Kosar committed Mar 19, 2020 13  "# Copyright 2020 Institut für Nachrichtentechnik, RWTH Aachen University\n",  Christian Rohlfing committed Sep 03, 2019 14  "%matplotlib widget\n",  Christian Rohlfing committed Aug 28, 2019 15 16 17 18 19 20  "\n", "from ipywidgets import interact, interactive, fixed, interact_manual\n", "import ipywidgets as widgets\n", "\n", "from ient_nb.ient_plots import *\n", "import matplotlib\n",  Christian Rohlfing committed Oct 21, 2019 21 22 23 24  "from matplotlib.patches import ConnectionPatch\n", "\n", "highlight_args = {'color':'rot', 'marker':'o'}; arrow_args = {'width':1,'headlength':10,'headwidth':10,'fc':'rot'}\n", "anno_args = {'color':'rot-50', 'linestyle':'--', 'arrowstyle':\"-\", 'coordsA':'data', 'coordsB':'data'}"  Christian Rohlfing committed Aug 28, 2019 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "# Primer Komplexe Zahlen" ] }, { "cell_type": "markdown", "metadata": {}, "source": [  Iris Heisterklaus committed Nov 04, 2019 42  "Eine komplexe Zahl kann auch als Zeiger interpretiert werden, der sich in einer komplexen Ebene um den Koordinatenursprung dreht. Dies soll hier kurz veranschaulicht werden.\n",  Christian Rohlfing committed Oct 21, 2019 43  "Als Beispiel wird eine reellwertige Wechselspannung\n",  Christian Rohlfing committed Aug 28, 2019 44  "$$\n",  Christian Rohlfing committed Oct 21, 2019 45  "u(t)\n",  Christian Rohlfing committed Aug 28, 2019 46  "=\n",  Christian Rohlfing committed Oct 21, 2019 47 48  "B \\cos(2\\pi F t + \\phi)\n", "$$\n",  Iris Heisterklaus committed Nov 04, 2019 49  "mit Frequenz $F$ und Scheitelwert $B$ betrachtet. Mit dem Spannungszeiger\n",  Christian Rohlfing committed Oct 21, 2019 50 51  "$$\n", "\\mathbf{u} \n",  Christian Rohlfing committed Aug 28, 2019 52  "=\n",  Christian Rohlfing committed Oct 21, 2019 53 54  "B \\mathrm{e}^{\\mathrm{j} \\phi}\n", "$$\n",  Iris Heisterklaus committed Nov 04, 2019 55  "\n",  Christian Rohlfing committed Oct 21, 2019 56  "kann $u(t)$ wie folgt beschrieben werden:\n",  Iris Heisterklaus committed Nov 04, 2019 57  "\n",  Christian Rohlfing committed Oct 21, 2019 58 59 60 61 62 63 64 65 66 67 68 69 70  "$$\n", "u(t)\n", "=\n", "\\mathrm{Re}\\left\\{\n", "\\mathbf{u} \\cdot \\mathrm{e}^{\\mathrm{j}2\\pi F t}\n", "\\right\\}\n", "=\n", "\\mathrm{Re}\\left\\{\n", "B \\mathrm{e}^{\\mathrm{j} \\phi} \\cdot \\mathrm{e}^{\\mathrm{j}2\\pi F t}\n", "\\right\\}\n", "=\n", "B \\cos(2\\pi F t + \\phi)\n", "\\text{.}$$\n",  Christian Rohlfing committed Aug 28, 2019 71  "\n",  Christian Rohlfing committed Oct 21, 2019 72  "Im Folgenden wird $B=F=1$ betrachtet."  Christian Rohlfing committed Aug 28, 2019 73 74 75 76 77 78  ] }, { "cell_type": "markdown", "metadata": {}, "source": [  Christian Rohlfing committed Oct 21, 2019 79  "## Demo Zeigerdiagramm\n",  Iris Heisterklaus committed Nov 04, 2019 80  "In dieser Demo wird die Interpretation einer komplexen Zahl als Zeiger deutlich gemacht. Die Länge des Zeigers ist konstant. Durch Verschieben des Schiebereglers kann die Phase $\\phi$ von\n",  Christian Rohlfing committed Oct 21, 2019 81 82 83 84 85 86 87 88 89 90 91 92 93 94  "$$\n", "u(t)\n", "=\n", "\\mathrm{Re}\\left\\{\n", "B \\mathrm{e}^{\\mathrm{j} \\phi} \\cdot \\mathrm{e}^{\\mathrm{j}2\\pi F t}\n", "\\right\\}\n", "=\n", "B \\cos(2\\pi F t + \\phi)\n", "\\qquad\n", "\\text{mit }\n", "\\mathbf{u} \n", "=\n", "B \\mathrm{e}^{\\mathrm{j} \\phi}\n", "$$\n",  Iris Heisterklaus committed Nov 04, 2019 95 96 97 98 99 100 101 102 103 104 105 106 107  "variiert werden, dies bewirkt eine Drehung des Drehzeigers.\n", "\n", "\n", "\n", "Links oben ist der komplexe Drehzeiger dargestellt, rechts davon die Abbildung des aktuellen Zeigers auf die imaginäre Achse, unten die auf die reelle Achse. \n", "Des Weiteren interessant ist das Verhalten der Phase, welches in der vierten Abbildung dargestellt wird. Die Phase ist definiert als\n", "$$\n", "\\varphi(t)=\\mathrm{arctan}\\frac{\\mathrm{Im}\\{\\mathbf{u}\\}}{\\mathrm{Re}\\{\\mathbf{u}\\}}\\pm k\\cdot \\pi \\quad \\text{mit}\\quad k=\\left\\{\n", "\\begin{array}{l l}\n", "0, \\quad \\text{für } \\mathrm{Re}\\{\\mathbf{u}\\}\\geq 0 \\\\ \n", "1, \\quad \\text{für } \\mathrm{Re}\\{\\mathbf{u}\\}< 0\n", "\\end{array}\n", "\\right\\}\\text{.}\n",  Christian Rohlfing committed Oct 31, 2019 108  "$$\n",  Iris Heisterklaus committed Nov 04, 2019 109 110  "Hierbei muss beachtet werden, in welchem Quadrant sich der Zeiger aktuell befindet, je nachdem muss das Plus oder das Minus in der Gleichung berücksichtigt werden. Ist der Realteil positiv, befindet sich der Zeiger im ersten oder vierten Quadranten und die Phase läuft entlang der mittleren Linie im Plot. Ist der Realteil negativ, also wenn der Zeiger im zweiten oder dritten Quadranten ist, befindet man sich auf einer der beiden anderen Kurven. Dies ist abhängig vom Imaginärteil. Befindet sich der Zeiger im zweiten Quadranten, ist der Imaginärteil positiv und in der Formel muss $+\\pi$ gerechnet werden. Befindet sich der Zeiger im dritten Quadranten, ist der Imaginärteil negativ und in der Formel muss $-\\pi$ gerechnet werden.\n", "Dieses Springen kann sehr schön in der Abbildung verfolgt werden. "  Christian Rohlfing committed Aug 28, 2019 111 112 113 114 115 116 117  ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true,  Christian Rohlfing committed Sep 03, 2019 118 119 120  "jupyter": { "source_hidden": true }  Christian Rohlfing committed Aug 28, 2019 121 122 123  }, "outputs": [], "source": [  Christian Rohlfing committed Oct 21, 2019 124  "t = np.linspace(-2,2,5001);\n",  Christian Rohlfing committed Oct 31, 2019 125  "x = np.linspace(-10,10,5001);\n",  Christian Rohlfing committed Oct 21, 2019 126 127  "F = 1; B = 1;\n", "\n",  Christian Rohlfing committed Aug 28, 2019 128  "fig,axs=plt.subplots(2,2,figsize=(6, 6)); fig.tight_layout();\n",  Christian Rohlfing committed Oct 21, 2019 129 130  "@widgets.interact(phiPi = widgets.FloatSlider(min=-5, max=5, step=0.05, value=0, \n", " description='$\\phi/\\pi$:', continuous_update=True),\n",  Christian Rohlfing committed Aug 28, 2019 131  " show_lines = widgets.Checkbox(value=True, description='Zeige Hilfslinien', style=ient_wdgtl_style))\n",  Christian Rohlfing committed Oct 21, 2019 132  "def update_plot(phiPi, show_lines):\n",  Christian Rohlfing committed Oct 31, 2019 133  " global u_versor\n",  Christian Rohlfing committed Oct 21, 2019 134 135 136  " phi = phiPi*np.pi\n", " u_versor = B*np.exp(1J*phi)\n", " u_compl = u_versor * np.exp(2J*F*np.pi*t)\n",  Christian Rohlfing committed Oct 31, 2019 137 138 139  " ur = np.real(u_versor); ui = np.imag(u_versor)\n", " ku = (ur<0)*(-1)**(ui<0) \n", " xyP = (ur, ui); xyR = (ur, 0); xyI = (0, ui);\n",  Christian Rohlfing committed Oct 21, 2019 140  "\n",  Christian Rohlfing committed Aug 28, 2019 141 142  " if not axs[0,0].lines: # create plots\n", " # Complex number at time t0\n",  Christian Rohlfing committed Oct 21, 2019 143  " ax = axs[0,0]; ient_axis(ax); ax.axis('equal'); ax00 = ax;\n",  Christian Rohlfing committed Aug 28, 2019 144  " an = np.linspace(0, 2 * np.pi, 100); ax.plot(np.cos(an), np.sin(an), 'black-50')\n",  Christian Rohlfing committed Oct 21, 2019 145 146  " ax.annotate(\"\", xy=(np.real(u_versor),np.imag(u_versor)), xytext=(0, 0), arrowprops=arrow_args)\n", " ax.set_xlabel(r'$\\rightarrow \\mathrm{Re}\\{\\mathbf{u} \\}$'); ax.set_ylabel(r'$\\uparrow \\mathrm{Im}\\{\\mathbf{u}\\}$')\n",  Christian Rohlfing committed Aug 28, 2019 147 148  " \n", " # Imaginary part\n",  Christian Rohlfing committed Oct 21, 2019 149 150  " ax = axs[0,1]; ax.plot(t, np.imag(u_compl), 'black-50'); ax.plot(0, np.imag(u_versor), **highlight_args); ient_axis(ax); \n", " ax.set_xlabel(r'$\\rightarrow t$'); ax.set_ylabel(r'$\\uparrow \\mathrm{Im}\\left\\{\\mathbf{u} \\cdot \\mathrm{e}^{\\mathrm{j}2\\pi F t}\\right\\}$'); ax.set_zorder(-1)\n",  Christian Rohlfing committed Aug 28, 2019 151 152  "\n", " # Real part\n",  Christian Rohlfing committed Oct 21, 2019 153 154  " ax = axs[1,0]; ax.plot(np.real(u_compl),t, 'black-50'); ax.plot(np.real(u_versor), 0, **highlight_args); ient_axis(ax);\n", " ax.set_ylabel(r'$\\downarrow t$'); ax.set_xlabel(r'$\\rightarrow u(t) = \\mathrm{Re}\\left\\{\\mathbf{u} \\cdot \\mathrm{e}^{\\mathrm{j}2\\pi F t}\\right\\}$', bbox=ient_wbbox); \n",  Christian Rohlfing committed Aug 28, 2019 155  " ax.invert_yaxis(); ax.set_zorder(-1)\n",  Christian Rohlfing committed Sep 20, 2019 156 157  " \n", " # Angle\n",  Christian Rohlfing committed Oct 31, 2019 158 159 160 161 162 163 164 165  " ax = axs[1,1]; ient_axis(ax);\n", " ax.plot(x, np.arctan(x), 'rwth'); \n", " x_ind = np.where(x>0); x_ind = x_ind[0][0]; tmp = np.arctan(x)+np.pi; tmp[x_ind:] = np.nan; ax.plot(x, tmp, 'rwth')\n", " x_ind = np.where(x<0); x_ind = x_ind[0][-1]; tmp = np.arctan(x)-np.pi; tmp[:x_ind] = np.nan; ax.plot(x, tmp, 'rwth')\n", " ax.plot(np.imag(u_versor)/np.real(u_versor), phi, **highlight_args); \n", " ax.set_xlim([-7.5,7.5])\n", " ax.set_xlabel(r'$\\rightarrow \\mathrm{Im} / \\mathrm{Re}$'); ax.set_ylabel(r'$\\uparrow \\angle\\{\\mathbf{u}\\}$');\n", " ax.set_yticks([-np.pi, -np.pi/2, np.pi/2, np.pi]); ax.yaxis.set_ticklabels([r'$-\\pi$',r'$-\\pi/2$',r'$\\pi/2$', r'$\\pi$'])\n",  Christian Rohlfing committed Oct 21, 2019 166  " #fig.tight_layout(); # hide last axis and tighten layout\n",  Christian Rohlfing committed Aug 28, 2019 167 168 169  " else: # update plots\n", " annotations = [child for child in axs[0,0].get_children() if isinstance(child, matplotlib.text.Annotation)]\n", " annotations[0].remove()\n",  Christian Rohlfing committed Oct 21, 2019 170 171 172  " axs[0,0].annotate(\"\", xy=(np.real(u_versor),np.imag(u_versor)), xytext=(0, 0), arrowprops=arrow_args)\n", " axs[0,1].lines[0].set_ydata(np.imag(u_compl)); axs[0,1].lines[1].set_ydata(np.imag(u_versor))\n", " axs[1,0].lines[0].set_xdata(np.real(u_compl)); axs[1,0].lines[1].set_xdata(np.real(u_versor))\n",  Christian Rohlfing committed Oct 31, 2019 173 174  " \n", " axs[1,1].lines[3].set_ydata(np.arctan(ui/ur)+ku*np.pi); axs[1,1].lines[3].set_xdata(ui / ur)\n",  Christian Rohlfing committed Aug 28, 2019 175 176 177 178  " annotations = [child for child in axs[0,0].get_children() if isinstance(child, matplotlib.patches.ConnectionPatch)]\n", " if len(annotations): annotations[0].remove(); annotations[1].remove();\n", " if show_lines:\n", " con = ConnectionPatch(xyA=xyP, xyB=xyI, axesA=axs[0,0], axesB=axs[0,1],**anno_args); axs[0,0].add_artist(con)\n",  Christian Rohlfing committed Sep 03, 2019 179 180  " con = ConnectionPatch(xyA=xyP, xyB=xyR, axesA=axs[0,0], axesB=axs[1,0],**anno_args); axs[0,0].add_artist(con)\n", " axs[1,0].set_xlim(axs[0,0].get_xlim()); axs[0,1].set_ylim(axs[0,0].get_ylim())"  Christian Rohlfing committed Aug 28, 2019 181 182 183 184 185 186  ] }, { "cell_type": "markdown", "metadata": {}, "source": [  Hafiz Emin Kosar committed Mar 19, 2020 187  "___\n",  Christian Rohlfing committed Aug 28, 2019 188 189 190  "This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources) (OER). Feel free to use the notebook for your own purposes. The code is licensed under the [MIT license](https://opensource.org/licenses/MIT). \n", "\n", "Please attribute the work as follows: \n",  Hafiz Emin Kosar committed Mar 19, 2020 191  "*Christian Rohlfing, Übungsbeispiele zur Vorlesung \"Grundgebiete der Elektrotechnik 3 - Signale und Systeme\"*, gehalten von Jens-Rainer Ohm, 2020, Institut für Nachrichtentechnik, RWTH Aachen University."  Christian Rohlfing committed Aug 28, 2019 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210  ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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",  Hafiz Emin Kosar committed Mar 19, 2020 211  "version": "3.8.1"  Christian Rohlfing committed Aug 28, 2019 212 213 214  } }, "nbformat": 4,  Christian Rohlfing committed Sep 03, 2019 215  "nbformat_minor": 4  Christian Rohlfing committed Aug 28, 2019 216 }