From 2756dcf672d642013dad9187af7513de5a6c5a21 Mon Sep 17 00:00:00 2001 From: Adam Friedrich Schrey <adam.schrey@gmx.de> Date: Sun, 29 Aug 2021 22:42:52 +0200 Subject: [PATCH] Add a sandbox notebook --- notebooks/Sandkasten.ipynb | 191 +++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 notebooks/Sandkasten.ipynb diff --git a/notebooks/Sandkasten.ipynb b/notebooks/Sandkasten.ipynb new file mode 100644 index 0000000..e859747 --- /dev/null +++ b/notebooks/Sandkasten.ipynb @@ -0,0 +1,191 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "sacred-child", + "metadata": {}, + "source": [ + "# <span style='color:OrangeRed'>Sandkasten</span>" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "adaptive-optimum", + "metadata": {}, + "outputs": [], + "source": [ + "from systheo2functions import *\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "outdoor-confidence", + "metadata": {}, + "outputs": [], + "source": [ + "# Untersuche Eigenschaften einer beliebigen Regelstrecke:\n", + "\n", + "Gs = 80/((1+2*s)**7) #Gebe hier eine beliebige Funktion ein; s**N steht für s^N \n", + "\n", + "print(\"Gs:\"+str(Gs))\n", + "\n", + "plt_bode(Gs)\n", + "\n", + "margin(Gs)\n", + "\n", + "#plt_nyquist(G,x-Skalierung,y-Skalierung,x-Anfang,x-Ende):\n", + "plt_nyquist(Gs,0.5,0.4,-20,0) #Benutze plt_nyquist(Gs,1,1,0,0) um das ganze Diagramm zu sehen\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fresh-reviewer", + "metadata": {}, + "outputs": [], + "source": [ + "# Erstellen einer einfachen Simulation mit einem Eingangs- und einem Ausgangs-Signal:\n", + "\n", + "tini = 0 # Start time\n", + "tfinal = 1.5 # End time\n", + "dt = 0.001 # Time Step\n", + "nflows = 3 # Number of data flows in the schematic\n", + "Ts = 0.1 # Sampling time for discrete time\n", + "\n", + "sc = Schema(tini,tfinal,dt,nflows) # Instance of the simulation schematic\n", + "\n", + "c1 = SinusoidalSignalSource(1,0,1,2*pi,0)#SinusoidalSignalSource(out,startv,Am,om,phi)\n", + "c2 = TransferFunction(1,2,[1],[1,1]);#TransferFunction(inp,out,num,den)\n", + "\n", + "sc.AddListComponents(np.array([c1,c2]));\n", + "\n", + "#Run the schematic and plot:\n", + "out = sc.Run(np.array([1, 2]))\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(1, 1, 1)\n", + "fig.set_dpi(120)\n", + "ax.plot(out[0,:],out[1,:],out[0,:],out[2,:])\n", + "ax.grid()\n", + "ax.legend(['Eingangssignal (SinusoidalSignalSource)','Ausgangssignal durch TransferFunction'])\n", + "plt.show()\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "hungry-newton", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "elementary-lambda", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "moving-knock", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "sapphire-member", + "metadata": {}, + "source": [ + "# Liste nützlicher Funktionen für Matrizen und Regelstrecken:\n", + "print_det(M)\n", + "\n", + "print_rank(M)\n", + "\n", + "print_eig(M)\n", + "\n", + "matmul_loop(mats)\n", + "\n", + "plt_bode(G)\n", + "\n", + "plt_nyquist(G,scale_x,scale_y,x0,x1)\n", + "\n", + "margin(G)\n", + "\n", + "# Liste nützlicher Klassen für Simulationen:\n", + "StepSource(self,out,startv,endv,ts)\n", + "\n", + "SinusoidalSignalSource(self,out,startv,Am,om,phi)\n", + "\n", + "SquareSignal(self,out,hi,lo,f,duty)\n", + "\n", + "Constant(out,value)\n", + "\n", + "Division(in1,in2,out)\n", + "\n", + "Product(in1,in2,out)\n", + "\n", + "Sum(in1,in2,out,sign1,sign2)\n", + "\n", + "Saturation(inp,out,minout,maxout)\n", + "\n", + "Gain(inp,out,k)\n", + "\n", + "PI(inp,out,Kp,Ki,ini)\n", + "\n", + "PID(inp,out,Kp,Ki,Kd,ini)\n", + "\n", + "Integrator(inp,out,ini)\n", + "\n", + "Not(inp,out)\n", + "\n", + "StateSpace(inp,out,A,B,C,D,xo)\n", + "\n", + "TransferFunction(inp,out,num,den)\n", + "### -------\n", + "FIR(inp,out,a,ts)\n", + "\n", + "DTIntegral(inp,out,ts,xo)\n", + "\n", + "ZOH(inp,out,ts)\n", + "\n", + "DTDelay(inp,out,init,ts)\n", + "\n", + "IIR(inp,out,a,b,ts)\n", + "\n", + "DTTransferFunction(inp,out,num,den,Ts)\n", + "\n", + "DTStateSpace(inp,out,A,B,C,D,xo,Ts)" + ] + } + ], + "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", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- GitLab