Die Beispielprogramme des Kapitels 3 behandeln die Berechnung von dynamischen Systemen mit Python.
web301
Lösen einer DGL mit Python
Listing 3.1: Die Lösung einer linearen oder nicht linearen Differenzielgleichung ist mit dem SciPy-Paket möglich.
# -*- coding: utf-8 -*- """ Lösung einer linearen DGL Created on 6.9. 2018 @author: philippsen """ # P-T1 from scipy.integrate import odeint import numpy as np import matplotlib.pyplot as plt def deriv(xa, t, xe): a0 = 0.7 b0 = 0.2 xapunkt = -a0*xa + b0*xe return xapunkt time = np.arange(0.0, 10.0, 0.01) xaAnfang = 0 u = 1.0 xa = odeint(deriv, xaAnfang, time, args=(u,)) plt.figure() plt.plot(time,xa[:,0] ) # plt.title('Lösung DGL mit Python P-T1') plt.grid()
web302
Beispiel 3.4
Listing 3.2: Im Beispiel 3.4 wird die Berechnung des Bode-Diagramms, der Orstkurve und der Sprungantwort eines Regelkreises behandelt. Aus der Control Toolbox wird das Matlab-Kompatibilitätsmodul verwendet.
# -*- coding: utf-8 -*- """ Standardregelstrecke mit PI-Regler Beispiel 3.4 Created on 21.3. 2019 @author: philippsen """ import numpy as np import control from control.matlab import * # Funktionen sind ohne Präfix nutzbar import matplotlib.pyplot as plt a0 = 1.; a1 = 10. ; a2 = 31. ; a3 = 30. b0 = 1. num = np.array([b0]) den = np.array([a3, a2, a1, a0]) strecke = tf(num,den) regler = tf([5, 1],[5, 0]) G0 = regler*strecke # Reihenschaltung R(s) und G(s) bode(G0) Gw = feedback(G0, 1) bode(Gw) gm, pm, wg, wp = control.matlab.margin(G0) gmdb = 20*np.log10(gm); wphz = wp/(2*np.pi) print('Amplitudenreserve = ',gm,' in dB = ',gmdb) print('Phasenreserve = ',pm) print('Durchtrittsfrequenz = ',wp,' in Hertz = ',wphz) plt.figure() y, t = control.matlab.step(Gw) plt.plot(t,y) plt.title('Regelkreis') plt.xlabel('t [s]'); plt.ylabel('h(t)') plt.grid() plt.show() plt.figure() real, imag, ww = control.matlab.nyquist(G0) plt.plot(real,imag) plt.title('Ortskurve') plt.xlabel('Real'); plt.ylabel('Imag') plt.grid(True)